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

Updated tests for cf_units 2 #3023

Merged
merged 2 commits into from
May 23, 2018
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
2 changes: 1 addition & 1 deletion INSTALL
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ netcdf4-python (http://netcdf4-python.googlecode.com/)
thread-safe build of HDF5 to avoid segmentation faults when using
lazy evaluation.)

cf_units v1.0 or later (https://github.com/SciTools/cf_units)
cf_units v2.0 or later (https://github.com/SciTools/cf_units)
CF data units handling, using udunits.

setuptools v36.0 or later (http://pypi.python.org/pypi/setuptools/)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Iris updated its cf_units dependency to cf_units v2. cf_units 2 is almost entirely backwards compatible,
although the ability to preserve some alias calendars has been removed. For this reason, it is possible
that NetCDF load of a variable with a "standard" calendar will result in a saved NetCDF of a "gregorian"
calendar.
4 changes: 2 additions & 2 deletions lib/iris/fileformats/nimrod_load_rules.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# (C) British Crown Copyright 2010 - 2016, Met Office
# (C) British Crown Copyright 2010 - 2018, Met Office
#
# This file is part of Iris.
#
Expand Down Expand Up @@ -40,7 +40,7 @@
NIMROD_DEFAULT = -32767.0

TIME_UNIT = cf_units.Unit('hours since 1970-01-01 00:00:00',
calendar=cf_units.CALENDAR_STANDARD)
calendar=cf_units.CALENDAR_GREGORIAN)


FIELD_CODES = {73: "orography"}
Expand Down
2 changes: 1 addition & 1 deletion lib/iris/tests/results/netcdf/netcdf_lcc.cml
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
[273.0, 303.0],
[304.0, 333.0],
[334.0, 364.0]]" id="1c4a69ce" long_name="time" points="[15.0, 44.5, 74.0, 104.5, 135.0, 165.5, 196.0,
227.0, 257.5, 288.0, 318.5, 349.0]" shape="(12,)" standard_name="time" units="Unit('days since 2010-01-01 12:00:00', calendar='standard')" value_type="float64" var_name="time"/>
227.0, 257.5, 288.0, 318.5, 349.0]" shape="(12,)" standard_name="time" units="Unit('days since 2010-01-01 12:00:00', calendar='gregorian')" value_type="float64" var_name="time"/>
</coord>
</coords>
<cellMethods>
Expand Down
4 changes: 2 additions & 2 deletions lib/iris/tests/results/nimrod/load_2flds.cml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</attributes>
<coords>
<coord>
<dimCoord id="9c8bdf81" points="[355014.0]" shape="(1,)" standard_name="forecast_reference_time" units="Unit('hours since 1970-01-01 00:00:00', calendar='standard')" value_type="float64"/>
<dimCoord id="9c8bdf81" points="[355014.0]" shape="(1,)" standard_name="forecast_reference_time" units="Unit('hours since 1970-01-01 00:00:00', calendar='gregorian')" value_type="float64"/>
</coord>
<coord>
<dimCoord id="a2cbc1ea" points="[9999.0]" shape="(1,)" standard_name="height" units="Unit('m')" value_type="float32">
Expand All @@ -32,7 +32,7 @@
</dimCoord>
</coord>
<coord datadims="[0]">
<dimCoord id="cb784457" points="[355017.0, 363777.0]" shape="(2,)" standard_name="time" units="Unit('hours since 1970-01-01 00:00:00', calendar='standard')" value_type="float64"/>
<dimCoord id="cb784457" points="[355017.0, 363777.0]" shape="(2,)" standard_name="time" units="Unit('hours since 1970-01-01 00:00:00', calendar='gregorian')" value_type="float64"/>
</coord>
</coords>
<cellMethods/>
Expand Down
2 changes: 1 addition & 1 deletion lib/iris/tests/results/nimrod/period_of_interest.cml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<cube dtype="int64" units="unknown">
<coords>
<coord>
<dimCoord bounds="[[379973.0, 379974.0]]" id="cb784457" points="[379974.0]" shape="(1,)" standard_name="time" units="Unit('hours since 1970-01-01 00:00:00', calendar='standard')" value_type="float64"/>
<dimCoord bounds="[[379973.0, 379974.0]]" id="cb784457" points="[379974.0]" shape="(1,)" standard_name="time" units="Unit('hours since 1970-01-01 00:00:00', calendar='gregorian')" value_type="float64"/>
</coord>
</coords>
<cellMethods/>
Expand Down
3 changes: 1 addition & 2 deletions lib/iris/tests/test_coding_standards.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# (C) British Crown Copyright 2013 - 2017, Met Office
# (C) British Crown Copyright 2013 - 2018, Met Office
#
# This file is part of Iris.
#
Expand Down Expand Up @@ -123,7 +123,6 @@ class StandardReportWithExclusions(pep8.StandardReport):
'*/iris/tests/test_pp_to_cube.py',
'*/iris/tests/test_quickplot.py',
'*/iris/tests/test_std_names.py',
'*/iris/tests/test_unit.py',
'*/iris/tests/test_uri_callback.py',
'*/iris/tests/test_util.py']

Expand Down
32 changes: 20 additions & 12 deletions lib/iris/tests/test_pandas.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# (C) British Crown Copyright 2013 - 2017, Met Office
# (C) British Crown Copyright 2013 - 2018, Met Office
#
# This file is part of Iris.
#
Expand Down Expand Up @@ -101,18 +101,22 @@ def test_time_360(self):
time_coord = DimCoord([0, 100.1, 200.2, 300.3, 400.4],
long_name="time", units=time_unit)
cube.add_dim_coord(time_coord, 0)
if netCDF4.__version__ > '1.2.4':
# TODO Remove this if statement as we move to cftime
if cf_units.__version__ > '1':
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is really ugly, but will be removed with #3016.

import cftime
expected_index = [cftime.Datetime360Day(2000, 1, 1, 0, 0),
cftime.Datetime360Day(2000, 4, 11, 2, 24),
cftime.Datetime360Day(2000, 7, 21, 4, 48),
cftime.Datetime360Day(2000, 11, 1, 7, 12),
cftime.Datetime360Day(2001, 2, 11, 9, 36)]

else:
expected_index = [netcdftime.Datetime360Day(2000, 1, 1, 0, 0),
netcdftime.Datetime360Day(2000, 4, 11, 2, 24),
netcdftime.Datetime360Day(2000, 7, 21, 4, 48),
netcdftime.Datetime360Day(2000, 11, 1, 7, 12),
netcdftime.Datetime360Day(2001, 2, 11, 9, 36)]
else:
expected_index = [netcdftime.datetime(2000, 1, 1, 0, 0),
netcdftime.datetime(2000, 4, 11, 2, 24),
netcdftime.datetime(2000, 7, 21, 4, 48),
netcdftime.datetime(2000, 11, 1, 7, 12),
netcdftime.datetime(2001, 2, 11, 9, 36)]

series = iris.pandas.as_series(cube)
self.assertArrayEqual(series, cube.data)
self.assertArrayEqual(series.index, expected_index)
Expand Down Expand Up @@ -244,12 +248,16 @@ def test_time_360(self):
time_coord = DimCoord([100.1, 200.2], long_name="time",
units=time_unit)
cube.add_dim_coord(time_coord, 0)
if netCDF4.__version__ > '1.2.4':
# TODO: Remove this if statement once we move to exclusive cftime.
if cf_units.__version__ > '1':
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is really ugly, but will be removed with #3016.

# cf_units depends upon cftime, so we can safely assume we
# have it.
import cftime
expected_index = [cftime.Datetime360Day(2000, 4, 11, 2, 24),
cftime.Datetime360Day(2000, 7, 21, 4, 48)]
else:
expected_index = [netcdftime.Datetime360Day(2000, 4, 11, 2, 24),
netcdftime.Datetime360Day(2000, 7, 21, 4, 48)]
else:
expected_index = [netcdftime.datetime(2000, 4, 11, 2, 24),
netcdftime.datetime(2000, 7, 21, 4, 48)]
expected_columns = [0, 1, 2, 3, 4]
data_frame = iris.pandas.as_data_frame(cube)
self.assertArrayEqual(data_frame, cube.data)
Expand Down
Loading