do not expand_dims if dim is already present#324
do not expand_dims if dim is already present#324cosunae wants to merge 3 commits intoecmwf:masterfrom
Conversation
|
cosunae seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account. You have signed the CLA already but the status is still pending? Let us recheck it. |
|
Hello @cosunae, many thanks for your contribution! Could you just give a little more concrete detail about when this problem manifests? And would you also be able to add a small test to the test suite to confirm that the fix works please? |
Codecov ReportPatch coverage:
Additional details and impacted files@@ Coverage Diff @@
## master #324 +/- ##
==========================================
+ Coverage 95.65% 95.67% +0.01%
==========================================
Files 26 26
Lines 2073 2082 +9
Branches 238 238
==========================================
+ Hits 1983 1992 +9
Misses 59 59
Partials 31 31
☔ View full report in Codecov by Sentry. |
|
Hi @iainrussell , thanks for looking into it and apologies for the delay and the original lack of details. |
|
btw, I did sign the cla, not sure why it does not recognize it. |
Description
while loading a dataset from a grib file that contains both grib2 and grib1 messages, most of the variables look like this:
There are two dimension coordinates (latitude, longitude) and few other non-dimension coordinates.
However some data arrays additionally made
stepa dimension coordinate :I did not investigate further why this difference in behaviour, since anyhow I thought the dataset is in a valid state and both representations are fine.
However when trying to write back to grib, using canonical_dataarray_to_grib, cfgrib will raise an exception.
Here
cfgrib/cfgrib/xarray_to_grib.py
Line 221 in b2fc0ed
the function tries to add make all coordinates a dimension coordinate, i.e. adding a dimension with the same name and size 1.
However, that method fails (raises) to add dimension "step" in the data array above since it already exists.
Below a stack trace (based on cfgrib==0.9.10.3)