Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removal of TEST_COMPAT and OLD_XML code #31

Merged
merged 1 commit into from
Aug 14, 2012
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
76 changes: 38 additions & 38 deletions etc/iris_tests_results/file_load/theta_levels.cml

Large diffs are not rendered by default.

76 changes: 38 additions & 38 deletions etc/iris_tests_results/file_load/u_wind_levels.cml

Large diffs are not rendered by default.

76 changes: 38 additions & 38 deletions etc/iris_tests_results/file_load/v_wind_levels.cml

Large diffs are not rendered by default.

152 changes: 76 additions & 76 deletions etc/iris_tests_results/file_load/wind_levels.cml

Large diffs are not rendered by default.

98 changes: 0 additions & 98 deletions lib/iris/coords.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,6 @@ def name(self, default='unknown'):
return self.standard_name or self.long_name or default


USE_OLD_XML = False

# Coordinate cell styles. Used in plot and cartography.
POINT_MODE = 0
BOUND_MODE = 1
Expand Down Expand Up @@ -893,102 +891,6 @@ def _value_type_name(self):
value_type_name = 'unicode'
return value_type_name

if USE_OLD_XML:
def xml_element(self, doc):
"""Return a DOM element describing this Coord."""
# Create the xml element
element = doc.createElement(self._xml_element_name())
self._xml_element_basic_attributes(element)

if getattr(self, '_TEST_COMPAT_hybrid', False):
hybrid = doc.createElement('hybridHeightCS')
hybrid.setAttribute('orography', self._TEST_COMPAT_hybrid)
element.appendChild(hybrid)
else:
# Add a user-attributes sub-element?
if len(self.attributes) > 0:
attributes_element = doc.createElement("attributes")
for k, v in self.attributes.items():
attributes_element.setAttribute(k, str(v))
element.appendChild(attributes_element)

# Add a coord system sub-element?
if self.coord_system:
element.appendChild(self.coord_system.xml_element(doc))

return element

def _xml_element_name(self):
"""Get xml CS name from class name."""
name = "explicitCoord"
from iris.fileformats.rules import is_regular
if is_regular(self) and not (getattr(self, '_TEST_COMPAT_force_explicit', False)):
name = "regularCoord"
if self.shape == (1,) and getattr(self, '_TEST_COMPAT_force_regular_scalar', False):
name = "regularCoord"
return name

def _xml_element_basic_attributes(self, element):
"""Add atomic, non-structural attributes to the xml element."""
# Common
element.setAttribute('name', self.name())
element.setAttribute('unit', repr(self.units))
if hasattr(self, '_TEST_COMPAT_override_axis'):
axis = self._TEST_COMPAT_override_axis
elif self.name() == 'forecast_reference_time':
axis = 'rt'
elif self.name() in ('level_height', 'sigma', 'model_level_number'):
axis = 'z'
else:
axis = str(iris.util.guess_coord_axis(self) or self.name())
element.setAttribute('axis', axis.lower())
# approximation to definitive
definitive = False
if hasattr(self, '_TEST_COMPAT_definitive'):
definitive = self._TEST_COMPAT_definitive
elif self._xml_element_name() != 'regularCoord':
definitive = (numpy.unique(self.points).size == self.points.size and
self.name() != 'history' and self.name() != 'source')
if definitive:
element.setAttribute('definitive', 'true')
value_type = getattr(self, '_TEST_COMPAT_value_type', self._value_type_name())
element.setAttribute('value_type', str(value_type))
if getattr(self, "circular", False):
element.setAttribute('circular', str(self.circular))

# Regular
from iris.fileformats.rules import is_regular, regular_step
if is_regular(self) and not (getattr(self, '_TEST_COMPAT_force_explicit', False)):
element.setAttribute('start', str(self.points[0]))
element.setAttribute('step', str(regular_step(self)))
element.setAttribute('count', str(len(self.points)))
if self.bounds is not None:
if regular_step(self) == 0:
bp = 0.5 # undefined so set to default value
else:
bp = (self.points[0] - self.bounds[0][0]) / (self.bounds[0][1] - self.bounds[0][0])
element.setAttribute('bound_position', str(bp))
# Scalar
elif self.shape == (1,) and getattr(self, '_TEST_COMPAT_force_regular_scalar', False):
element.setAttribute('start', str(self.points[0]))
element.setAttribute('step', str(0.0))
element.setAttribute('count', str(len(self.points)))
if self.bounds is not None:
bp = (self.points[0] - self.bounds[0][0]) / (self.bounds[0][1] - self.bounds[0][0])
element.setAttribute('bound_position', str(bp))
# Explicit
else:
if getattr(self, '_TEST_COMPAT_points', True) and self.standard_name != 'surface_altitude':
if hasattr(self._points, 'to_xml_attr'):
element.setAttribute('points', self._points.to_xml_attr())
else:
element.setAttribute('points', self._array_for_xml(self.points))
if self._bounds is not None:
if hasattr(self._bounds, 'to_xml_attr'):
element.setAttribute('bounds', self._bounds.to_xml_attr())
else:
element.setAttribute('bounds', self._array_for_xml(self.bounds))


class DimCoord(Coord):
"""
Expand Down
67 changes: 0 additions & 67 deletions lib/iris/cube.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,6 @@
from iris._cube_coord_common import CFVariableMixin, LimitedAttributeDict


USE_OLD_XML = False


__all__ = ['Cube', 'CubeList', 'CubeMetadata']


Expand Down Expand Up @@ -1510,70 +1507,6 @@ def _xml_element(self, doc, checksum=False):

return cube_xml_element

if USE_OLD_XML:
def _xml_element(self, doc, checksum=False):
cube_xml_element = doc.createElement("cube")

cube_xml_element.setAttribute('standard_name', self.name(''))
cube_xml_element.setAttribute('unit', str(self.units))

if self.attributes:
attributes_element = doc.createElement('attributes')
for name in sorted(self.attributes.iterkeys()):
attribute_element = doc.createElement('attribute')
attribute_element.setAttribute('name', name)
if name == 'history':
value = re.sub("[\d\/]{8} [\d\:]{8} Iris\: ", '', str(self.attributes[name]))
else:
value = str(self.attributes[name])
attribute_element.setAttribute('value', value)
attributes_element.appendChild(attribute_element)
cube_xml_element.appendChild(attributes_element)

coords_xml_element = doc.createElement("coords")
coords = self.dim_coords + self.aux_coords
for coord in sorted(coords, key=lambda coord: coord.name()):
coord_xml_element_wrapper = doc.createElement("coord")
if self.coord_dims(coord):
coord_xml_element_wrapper.setAttribute('datadims', str(self.coord_dims(coord)))
coord_xml_element = coord.xml_element(doc)
coord_xml_element_wrapper.appendChild(coord_xml_element)
coords_xml_element.appendChild(coord_xml_element_wrapper)

cube_xml_element.appendChild(coords_xml_element)

# cell methods (no sorting!)
cell_methods_xml_element = doc.createElement("cellMethods")
for cm in self.cell_methods:
cell_method_xml_element = cm.xml_element(doc)
cell_methods_xml_element.appendChild(cell_method_xml_element)
cube_xml_element.appendChild(cell_methods_xml_element)

if self._data is not None:
data_xml_element = doc.createElement("data")

data_xml_element.setAttribute("shape", str(self.shape))

# Add the datatype
if self._data_manager is not None:
data_xml_element.setAttribute("dtype", self._data_manager.data_type.name)
else:
data_xml_element.setAttribute("dtype", self._data.dtype.name)

# getting a checksum triggers any deferred loading
if checksum:
data_xml_element.setAttribute("checksum", hex(zlib.crc32(self.data)))
if isinstance(self.data, numpy.ma.core.MaskedArray):
data_xml_element.setAttribute("mask_checksum", hex(zlib.crc32(self.data.mask)))
elif self._data_manager is not None:
data_xml_element.setAttribute("state", "deferred")
else:
data_xml_element.setAttribute("state", "loaded")

cube_xml_element.appendChild(data_xml_element)

return cube_xml_element

def copy(self, data=None):
"""
Returns a deep copy of this cube.
Expand Down
32 changes: 0 additions & 32 deletions lib/iris_tests/stock.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,8 @@ def callback_global_pp(cube, field, filename):
return cube

def simple_pp():

filename = tests.get_data_path(['PP', 'simple_pp', 'global.pp']) # Differs from global_pp()
cube = iris.load_strict(filename)

cube.coord("forecast_period")._TEST_COMPAT_override_axis = "forecast_period"
cube.coord("source")._TEST_COMPAT_override_axis = "source"
cube.coord("source")._TEST_COMPAT_definitive = False

return cube


Expand Down Expand Up @@ -121,14 +115,6 @@ def simple_2d(with_bounds=True):
x_bounds = numpy.array([[-15, 0], [0, 15], [15, 30], [30, 45]], dtype=numpy.int32)
x_coord = iris.coords.DimCoord(x_points, long_name='foo', units='1', bounds=x_bounds if with_bounds else None)

# TEMPORARY compat fixes
y_coord._TEST_COMPAT_force_explicit = True
y_coord._TEST_COMPAT_definitive = False
y_coord._TEST_COMPAT_override_axis = 'y'
x_coord._TEST_COMPAT_force_explicit = True
x_coord._TEST_COMPAT_definitive = False
x_coord._TEST_COMPAT_override_axis = 'x'

cube.add_dim_coord(y_coord, 0)
cube.add_dim_coord(x_coord, 1)
return cube
Expand Down Expand Up @@ -196,12 +182,7 @@ def simple_3d_w_multidim_coords(with_bounds=True):
[[-25, 0], [0, 8], [8, 45], [45, 50]],
[[-5, 10], [10, 18], [18, 55], [18, 70]]], dtype=numpy.int32)
x_coord = iris.coords.AuxCoord(points=x_points, long_name='foo', units='1', bounds=x_bounds if with_bounds else None)

wibble_coord = iris.coords.DimCoord(numpy.array([ 10., 30.], dtype=numpy.float32), long_name='wibble', units='1')
x_coord._TEST_COMPAT_override_axis = 'x'
x_coord._TEST_COMPAT_definitive = False
y_coord._TEST_COMPAT_override_axis = 'y'
wibble_coord._TEST_COMPAT_override_axis = 'w'

cube.add_dim_coord(wibble_coord, [0])
cube.add_aux_coord(y_coord, [1, 2])
Expand Down Expand Up @@ -254,19 +235,6 @@ def simple_2d_w_multidim_and_scalars():
my_multi_dim_coord = iris.coords.AuxCoord(numpy.arange(50, dtype=numpy.int32).reshape(5, 10),
long_name='my_multi_dim_coord', units='1',
bounds=numpy.arange(200, dtype=numpy.int32).reshape(5, 10, 4))


dim1._TEST_COMPAT_override_axis = 'y'
dim1._TEST_COMPAT_definitive = False
dim2._TEST_COMPAT_override_axis = 'x'
dim2._TEST_COMPAT_definitive = False
dim2._TEST_COMPAT_force_explicit = True
an_other._TEST_COMPAT_override_axis = 't'
an_other._TEST_COMPAT_definitive = False
an_other._TEST_COMPAT_force_explicit = True
my_multi_dim_coord._TEST_COMPAT_override_axis = 'foo'
my_multi_dim_coord._TEST_COMPAT_definitive = False
my_multi_dim_coord._TEST_COMPAT_force_explicit = True

cube.add_dim_coord(dim1, 0)
cube.add_dim_coord(dim2, 1)
Expand Down
44 changes: 0 additions & 44 deletions lib/iris_tests/test_aggregate_by.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,47 +99,6 @@ def setUp(self):
[[15., 30., 45.], [60., 75., 90.], [105., 120., 135.]],
[[16.5, 33., 49.5], [66., 82.5, 99.], [115.5, 132., 148.5]]], dtype=np.float64)

def assertCML(self, cube, path, *args, **kwargs):
try:
coord = cube.coord('height')
coord._TEST_COMPAT_force_explicit = True
coord._TEST_COMPAT_definitive = False
coord._TEST_COMPAT_override_axis = 'z'
except iris.exceptions.CoordinateNotFoundError:
pass
try:
coord = cube.coord('model_level')
coord._TEST_COMPAT_override_axis = 'z'
coord._TEST_COMPAT_definitive = False
coord._TEST_COMPAT_points = False
coord._TEST_COMPAT_value_type = 'int32'
except iris.exceptions.CoordinateNotFoundError:
pass
try:
coord = cube.coord('level')
coord._TEST_COMPAT_override_axis = 'z'
except iris.exceptions.CoordinateNotFoundError:
pass
try:
coord = cube.coord('gamma')
coord._TEST_COMPAT_force_explicit = True
coord._TEST_COMPAT_override_axis = 'z'
coord._TEST_COMPAT_definitive = False
coord._TEST_COMPAT_points = False
coord._TEST_COMPAT_value_type = 'int32'
except iris.exceptions.CoordinateNotFoundError:
pass
try:
coord = cube.coord('sigma')
coord._TEST_COMPAT_force_explicit = True
coord._TEST_COMPAT_override_axis = 'z'
coord._TEST_COMPAT_definitive = False
coord._TEST_COMPAT_points = False
coord._TEST_COMPAT_value_type = 'int32'
except iris.exceptions.CoordinateNotFoundError:
pass
super(TestAggregateBy, self).assertCML(cube, path, *args, **kwargs)

def test_single(self):
# group-by with single coordinate name.
aggregateby_cube = self.cube_single.aggregated_by('height', iris.analysis.MEAN)
Expand Down Expand Up @@ -230,9 +189,6 @@ def test_easy(self):
#
aggregateby_cube = cube.aggregated_by('longitude', iris.analysis.MEAN)
np.testing.assert_almost_equal(aggregateby_cube.data, np.array([[8., 15.], [10., 17.], [15., 8.]], dtype=np.float32))
coord = aggregateby_cube.coord('longitude')
coord._TEST_COMPAT_force_explicit = True
coord._TEST_COMPAT_definitive = False
self.assertCML(aggregateby_cube, ('analysis', 'aggregated_by', 'easy.cml'), checksum=False)

aggregateby_cube = cube.aggregated_by('latitude', iris.analysis.MEAN)
Expand Down
Loading