Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions lib/iris/fileformats/_pp_lbproc_pairs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# (C) British Crown Copyright 2017, Met Office
#
# This file is part of Iris.
#
# Iris is free software: you can redistribute it and/or modify it under
# the terms of the GNU Lesser General Public License as published by the
# Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Iris is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with Iris. If not, see <http://www.gnu.org/licenses/>.

from __future__ import (absolute_import, division, print_function)
from six.moves import (filter, input, map, range, zip) # noqa
import six

import itertools


# LBPROC codes and their English equivalents
LBPROC_PAIRS = ((1, "Difference from another experiment"),
(2, "Difference from zonal (or other spatial) mean"),
(4, "Difference from time mean"),
(8, "X-derivative (d/dx)"),
(16, "Y-derivative (d/dy)"),
(32, "Time derivative (d/dt)"),
(64, "Zonal mean field"),
(128, "Time mean field"),
(256, "Product of two fields"),
(512, "Square root of a field"),
(1024, "Difference between fields at levels BLEV and BRLEV"),
(2048, "Mean over layer between levels BLEV and BRLEV"),
(4096, "Minimum value of field during time period"),
(8192, "Maximum value of field during time period"),
(16384, "Magnitude of a vector, not specifically wind speed"),
(32768, "Log10 of a field"),
(65536, "Variance of a field"),
(131072, "Mean over an ensemble of parallel runs"))

# lbproc_map is dict mapping lbproc->English and English->lbproc
# essentially a one to one mapping
LBPROC_MAP = {x: y for x, y in
itertools.chain(LBPROC_PAIRS, ((y, x) for x, y in LBPROC_PAIRS))}
31 changes: 5 additions & 26 deletions lib/iris/fileformats/pp.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import abc
import collections
from copy import deepcopy
import itertools
import operator
import os
import re
Expand All @@ -43,6 +42,11 @@
import iris.config
import iris.fileformats.pp_rules
from iris.fileformats.pp_save_rules import verify

# NOTE: this is for backwards-compatitibility *ONLY*
# We could simply remove it for v2.0 ?
from iris.fileformats._pp_lbproc_pairs import (LBPROC_PAIRS,
LBPROC_MAP as lbproc_map)
import iris.fileformats.rules
import iris.coord_systems

Expand Down Expand Up @@ -222,31 +226,6 @@
'default': np.dtype('>f4'),
}

# LBPROC codes and their English equivalents
LBPROC_PAIRS = ((1, "Difference from another experiment"),
(2, "Difference from zonal (or other spatial) mean"),
(4, "Difference from time mean"),
(8, "X-derivative (d/dx)"),
(16, "Y-derivative (d/dy)"),
(32, "Time derivative (d/dt)"),
(64, "Zonal mean field"),
(128, "Time mean field"),
(256, "Product of two fields"),
(512, "Square root of a field"),
(1024, "Difference between fields at levels BLEV and BRLEV"),
(2048, "Mean over layer between levels BLEV and BRLEV"),
(4096, "Minimum value of field during time period"),
(8192, "Maximum value of field during time period"),
(16384, "Magnitude of a vector, not specifically wind speed"),
(32768, "Log10 of a field"),
(65536, "Variance of a field"),
(131072, "Mean over an ensemble of parallel runs"))

# lbproc_map is dict mapping lbproc->English and English->lbproc
# essentially a one to one mapping
lbproc_map = {x: y for x, y in
itertools.chain(LBPROC_PAIRS, ((y, x) for x, y in LBPROC_PAIRS))}


class STASH(collections.namedtuple('STASH', 'model section item')):
"""
Expand Down
5 changes: 3 additions & 2 deletions lib/iris/fileformats/pp_rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@
from iris.coords import AuxCoord, CellMethod, DimCoord
from iris.fileformats.rules import (ConversionMetadata, Factory, Reference,
ReferenceTarget)
import iris.fileformats.pp
from iris.fileformats._pp_lbproc_pairs import LBPROC_MAP
from iris.fileformats.um_cf_map import (LBFC_TO_CF, STASH_TO_CF,
STASHCODE_IMPLIED_HEIGHTS)
import iris.fileformats.pp


###############################################################################
Expand Down Expand Up @@ -1027,7 +1028,7 @@ def _all_other_rules(f):
if unhandled_lbproc:
attributes["ukmo__process_flags"] = tuple(sorted(
[name
for value, name in six.iteritems(iris.fileformats.pp.lbproc_map)
for value, name in six.iteritems(LBPROC_MAP)
if isinstance(value, int) and f.lbproc & value]))

if (f.lbsrce % 10000) == 1111:
Expand Down
4 changes: 2 additions & 2 deletions lib/iris/fileformats/pp_save_rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
import iris
from iris.fileformats._ff_cross_references import STASH_TRANS
from iris.aux_factory import HybridHeightFactory, HybridPressureFactory
from iris.fileformats.pp import lbproc_map
from iris.fileformats.um_cf_map import CF_TO_LBFC
from iris.fileformats._pp_lbproc_pairs import LBPROC_MAP
from iris.fileformats.rules import (aux_factory,
has_aux_factory,
scalar_cell_method,
Expand Down Expand Up @@ -568,7 +568,7 @@ def _lbproc_rules(cube, pp):
pp.lbproc = 0

if cube.attributes.get("ukmo__process_flags", None):
pp.lbproc += sum([lbproc_map[name]
pp.lbproc += sum([LBPROC_MAP[name]
for name in cube.attributes["ukmo__process_flags"]])

# Zonal-mean: look for a CellMethod which is a "mean" over "longitude" or
Expand Down
1 change: 0 additions & 1 deletion lib/iris/fileformats/rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -911,4 +911,3 @@ def loadcubes_user_callback_wrapper(cube, field, filename):
converter=loader.converter,
user_callback_wrapper=loadcubes_user_callback_wrapper):
yield cube