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
Fix projections in cf writer #307
Conversation
…o feature-xarray Conflicts: satpy/writers/cf_writer.py
One test for header attributes and one for encoding as a kwarg.
[WIP] Improve compatibility of cf_writer with CF-conventions
satpy/tests/writer_tests/test_cf.py
Outdated
@@ -40,7 +40,65 @@ | |||
class TestCFWriter(unittest.TestCase): | |||
def test_init(self): | |||
from satpy.writers.cf_writer import CFWriter | |||
w = CFWriter() | |||
import satpy.config | |||
w = CFWriter(config_files=[os.path.join(satpy.config.CONFIG_PATH, |
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.
F841 local variable 'w' is assigned to but never used
W291 trailing whitespace
satpy/tests/writer_tests/test_cf.py
Outdated
import satpy.config | ||
w = CFWriter(config_files=[os.path.join(satpy.config.CONFIG_PATH, | ||
'writers', 'cf.yaml')]) | ||
|
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.
W293 blank line contains whitespace
satpy/tests/writer_tests/test_cf.py
Outdated
'writers', 'cf.yaml')]) | ||
|
||
|
||
def test_save_array(self): |
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.
E303 too many blank lines (2)
satpy/tests/writer_tests/test_cf.py
Outdated
import xarray as xr | ||
import tempfile | ||
scn = Scene() | ||
scn['test-array'] = xr.DataArray([1,2,3]) |
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.
E231 missing whitespace after ','
satpy/tests/writer_tests/test_cf.py
Outdated
scn.save_datasets(filename=filename, writer='cf') | ||
import h5netcdf as nc4 | ||
f = nc4.File(filename) | ||
self.assertTrue(all(f['test-array'][:] == [1,2,3])) |
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.
E231 missing whitespace after ','
satpy/writers/cf_writer.py
Outdated
dtnp64 = dataarray['time'].data[0] | ||
time_bnds = [(np.datetime64(start_time) - dtnp64), | ||
(np.datetime64(end_time) - dtnp64)] | ||
return xr.DataArray(np.array(time_bnds) / np.timedelta64(1, 's'), |
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.
E271 multiple spaces after keyword
W291 trailing whitespace
satpy/writers/cf_writer.py
Outdated
(np.datetime64(end_time) - dtnp64)] | ||
return xr.DataArray(np.array(time_bnds) / np.timedelta64(1, 's'), | ||
dims=['time_bnds'], coords={'time_bnds': [0, 1]}) | ||
|
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.
W293 blank line contains whitespace
satpy/writers/cf_writer.py
Outdated
datas[new_ds.attrs['name']] = self.da2cf(new_ds, | ||
kwargs.get('epoch', | ||
EPOCH)) | ||
|
||
dataset = xr.Dataset(datas) | ||
|
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.
W293 blank line contains whitespace
satpy/writers/cf_writer.py
Outdated
|
||
dataset = xr.Dataset(datas) | ||
|
||
dataset = xr.Dataset(datas) |
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.
W291 trailing whitespace
satpy/writers/cf_writer.py
Outdated
dataset = xr.Dataset(datas) | ||
|
||
dataset = xr.Dataset(datas) | ||
dataset['time_bnds'] = make_time_bounds(dataset, |
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.
W291 trailing whitespace
Codecov Report
@@ Coverage Diff @@
## master #307 +/- ##
==========================================
+ Coverage 65.98% 67.33% +1.34%
==========================================
Files 119 120 +1
Lines 14493 15471 +978
==========================================
+ Hits 9563 10417 +854
- Misses 4930 5054 +124
Continue to review full report at Codecov.
|
end_times) | ||
dataset['time'].attrs['bounds'] = "time_bnds" | ||
except KeyError: | ||
logger.warning('No time dimension in datasets, skipping time bounds creation.') |
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.
Should this be no time coordinate / no time variable? It doesn't seem to be specifically looking for a dimension (and still isn't with the refactoring to how this code is today). I think that having a time dimension is pretty rare in Satpy. The only way I can think of is either from a reader (maybe the GRIB reader?) or from a MultiScene
with (mscn.blend(blend_function=timeseries)
).
This PR fixes the cf writer with better support for some projection parameters
git diff origin/master **/*py | flake8 --diff