Skip to content
Open
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
24 changes: 23 additions & 1 deletion lib/iris/fileformats/nimrod.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,8 +251,8 @@ def to_cube(self):
if self.tm_meridian_scaling != MISSING_INT:
raise TranslationError("tm_meridian_scaling not yet handled")

# "NG" (British National Grid).
if self.horizontal_grid_type == 0:
# "NG", means osgb grid.
osgb_cs = iris.coord_systems.OSGB()
cube.add_dim_coord(
DimCoord(numpy.arange(self.num_cols) * self.column_step + self.x_origin,
Expand All @@ -263,6 +263,21 @@ def to_cube(self):
long_name="y", units="m", coord_system=osgb_cs), 0)
else:
raise TranslationError("Corner {0} not yet implemented".format(self.origin_corner))

# Latlon
elif self.horizontal_grid_type == 1:
# latlon
from iris.analysis.cartography import DEFAULT_SPHERICAL_EARTH_RADIUS
ll_cs = iris.coord_systems.GeogCS(DEFAULT_SPHERICAL_EARTH_RADIUS)
cube.add_dim_coord(
DimCoord(numpy.arange(self.num_cols) * self.column_step + self.x_origin,
standard_name="longitude", units="degrees", coord_system=ll_cs), 1)
if self.origin_corner == 0: # top left
cube.add_dim_coord(
DimCoord(numpy.arange(self.num_rows)[::-1] * -self.row_step + self.y_origin,
standard_name="latitude", units="degrees", coord_system=ll_cs), 0)
else:
raise TranslationError("Corner {0} not yet implemented".format(self.origin_corner))
else:
raise TranslationError("Grid type %d not yet implemented" %
self.horizontal_grid_type)
Expand All @@ -276,6 +291,13 @@ def to_cube(self):
standard_name="height", units="m"))
else:
raise TranslationError("Bounded vertical not yet implemented")
elif self.vertical_coord_type == 1:
if (self.reference_vertical_coord_type == MISSING_INT or
self.reference_vertical_coord == MISSING_FLOAT):
cube.add_aux_coord(DimCoord(self.vertical_coord,
standard_name="altitude", units="m"))
else:
raise TranslationError("Bounded vertical not yet implemented")
else:
raise TranslationError("Vertical coord type %d currently unhanded" %
self.vertical_coord_type)
Expand Down
39 changes: 39 additions & 0 deletions lib/iris/tests/results/nimrod/korean.cml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?xml version="1.0" ?>
<cubes xmlns="urn:x-iris:cubeml-0.2">
<cube long_name="orography" units="m">
<attributes>
<attribute name="field_code" value="73"/>
<attribute name="nimrod_version" value="2"/>
<attribute name="num_model_levels" value="1"/>
<attribute name="source" value="umqg"/>
</attributes>
<coords>
<coord>
<DimCoord id="641851dc8003dd28" points="[9999.0]" shape="(1,)" standard_name="altitude" units="Unit('m')" value_type="float32"/>
</coord>
<coord>
<DimCoord id="5634c91ba5717382" long_name="experiment_number" points="[0]" shape="(1,)" units="Unit('1')" value_type="int16"/>
</coord>
<coord>
<DimCoord id="49db77bb88e9d046" points="[375288.0]" shape="(1,)" standard_name="forecast_reference_time" units="Unit('hours')" value_type="float64"/>
</coord>
<coord datadims="[0]">
<DimCoord id="31a3be9e9cebe09a" long_name="latitude" points="[32.0166660938, 32.0333327614, 32.0499994289,
..., 42.9666666649, 42.9833333325, 43.0]" shape="(660,)" units="Unit('degrees')" value_type="float64">
<geogCS earth_radius="6367470.0"/>
</DimCoord>
</coord>
<coord datadims="[1]">
<DimCoord id="31a3be9e9cebe09a" long_name="longitude" points="[124.0, 124.016666668, 124.033333335, ...,
131.950000415, 131.966667082, 131.98333375]" shape="(480,)" units="Unit('degrees')" value_type="float64">
<geogCS earth_radius="6367470.0"/>
</DimCoord>
</coord>
<coord>
<DimCoord id="7655d345fead4375" points="[375288.0]" shape="(1,)" standard_name="time" units="Unit('hours')" value_type="float64"/>
</coord>
</coords>
<cellMethods/>
<data checksum="0x4f48c140" dtype="int16" shape="(660, 480)"/>
</cube>
</cubes>
24 changes: 17 additions & 7 deletions lib/iris/tests/test_nimrod.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,32 @@

import matplotlib.pyplot as plt
import numpy as np
import cartopy.crs as ccrs

import iris
import iris.plot as iplt
import iris.quickplot as qplt


@iris.tests.skip_data
class TestGribLoad(tests.GraphicsTest):
class TestLoad(tests.GraphicsTest):

def test_load(self):
cube = iris.load(tests.get_data_path(('NIMROD', 'uk2km', 'WO0000000003452',
'201007020900_u1096_ng_ey00_visibility0180_screen_2km')))[0]
self.assertCML(cube, ("nimrod", "load.cml"))
# def test_load(self):
# cube = iris.load(tests.get_data_path(('NIMROD', 'uk2km', 'WO0000000003452',
# '201007020900_u1096_ng_ey00_visibility0180_screen_2km')))[0]
# self.assertCML(cube, ("nimrod", "load.cml"))
#
# c = plt.contourf(cube.data, levels=np.linspace(-25000, 6000, 10))
# self.check_graphic()

c = plt.contourf(cube.data, levels=np.linspace(-25000, 6000, 10))
self.check_graphic()
def test_korean(self):
# cubes = iris.load(tests.get_data_path(('NIMROD', 'Korea', '201210240000_k0880_ll_umqg_height0000_orography_2km')))
cube = iris.load_cube('/data/local/dataZoo/NIMROD/Korea/201210240000_k0880_ll_umqg_height0000_orography_2km')
self.assertCML(cube, ("nimrod", "korean.cml"))

qplt.contourf(cube)
plt.gcs().coastlines()
self.check_graphic()

if __name__ == "__main__":
tests.main()