-
Notifications
You must be signed in to change notification settings - Fork 45
Preserve metadata during anomalies computation when using iris cubes difference #652
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
Changes from all commits
062ffdd
b2047ee
de9b03e
2285fd7
9c46e6c
3510565
80a371f
15ff704
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,25 +1,26 @@ | ||
| """Unit tests for the :func:`esmvalcore.preprocessor._time` module.""" | ||
|
|
||
| import copy | ||
| import unittest | ||
| import pytest | ||
| import tests | ||
|
|
||
| import numpy as np | ||
| from numpy.testing import assert_array_equal, assert_array_almost_equal | ||
|
|
||
| from cf_units import Unit | ||
| import iris | ||
| import iris.coord_categorisation | ||
| import iris.coords | ||
| import numpy as np | ||
| import pytest | ||
| from cf_units import Unit | ||
| from iris.cube import Cube | ||
| from numpy.testing import assert_array_almost_equal, assert_array_equal | ||
|
|
||
| from esmvalcore.preprocessor._time import ( | ||
| extract_month, extract_season, extract_time, | ||
| regrid_time, | ||
| decadal_statistics, annual_statistics, seasonal_statistics, | ||
| monthly_statistics, daily_statistics, timeseries_filter, | ||
| climate_statistics, anomalies | ||
| ) | ||
| import tests | ||
| from esmvalcore.preprocessor._time import (annual_statistics, anomalies, | ||
| climate_statistics, | ||
| daily_statistics, | ||
| decadal_statistics, extract_month, | ||
| extract_season, extract_time, | ||
| monthly_statistics, regrid_time, | ||
| seasonal_statistics, | ||
| timeseries_filter) | ||
|
|
||
|
|
||
| def _create_sample_cube(): | ||
|
|
@@ -1022,6 +1023,20 @@ def test_standardized_anomalies(period, standardize=True): | |
| ) | ||
|
|
||
|
|
||
| @pytest.mark.parametrize('period, reference', PARAMETERS) | ||
| def test_anomalies_preserve_metadata(period, reference, standardize=False): | ||
| cube = make_map_data(number_years=2) | ||
| cube.var_name = "si" | ||
| cube.units = "m" | ||
| metadata = copy.deepcopy(cube.metadata) | ||
| result = anomalies(cube, period, reference, standardize=standardize) | ||
| assert result.metadata == metadata | ||
| for coord_cube, coord_res in zip(cube.coords(), result.coords()): | ||
| if coord_cube.has_bounds() and coord_res.has_bounds(): | ||
| assert_array_equal(coord_cube.bounds, coord_res.bounds) | ||
| assert coord_cube == coord_res | ||
|
Comment on lines
+1034
to
+1037
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure if this is needed, because you're testing that the metadata was preserved, right?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the metadata object does not contain information on the coords, I was quite surprised by that too |
||
|
|
||
|
|
||
| @pytest.mark.parametrize('period, reference', PARAMETERS) | ||
| def test_anomalies(period, reference, standardize=False): | ||
| cube = make_map_data(number_years=2) | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that if one array is longer than the other, zip will only iterate over the number of elements in the shortest iterable, so this does not test that the cubes have the same coordinates
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good point actually! but the cubes should have the same number of coords otherwise the iris cube difference would fail beforehand