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

Preserve chunks in CF Writer #1254

Merged
merged 8 commits into from Sep 18, 2020
Merged

Conversation

sfinkens
Copy link
Member

@sfinkens sfinkens commented Jul 9, 2020

This PR updates the encoding applied by the CF writer so that generated netCDF files are chunked like the original dask arrays. Chunks specified by the user via encoding={'foo': {'chunksizes': (1024, 1024)}} take precedence.

I tested this with a LEO scene (avhrr_gaclac_l1b), a single geostationary scene (ahi_hsd) and a timeseries of ahi_hsd scenes (via Multiscene). The latter has some problems with time bounds (see #1242), but the chunking works fine.

I also tested both the netCDF4 and the h5netcdf backend.

Edit: I also removed the new _satpy* attributes before writing datasets to netcdf`.

  • Tests added
  • Tests passed
  • Passes flake8 satpy

@sfinkens sfinkens self-assigned this Jul 9, 2020
@sfinkens sfinkens added component:writers enhancement code enhancements, features, improvements labels Jul 9, 2020
@coveralls
Copy link

coveralls commented Jul 9, 2020

Coverage Status

Coverage increased (+0.006%) to 90.523% when pulling 9525cc9 on sfinkens:cf-writer-chunks into aa65035 on pytroll:master.

@codecov
Copy link

codecov bot commented Jul 9, 2020

Codecov Report

Merging #1254 into master will increase coverage by 0.00%.
The diff coverage is 93.93%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #1254   +/-   ##
=======================================
  Coverage   90.51%   90.52%           
=======================================
  Files         228      228           
  Lines       33334    33377   +43     
=======================================
+ Hits        30173    30214   +41     
- Misses       3161     3163    +2     
Impacted Files Coverage Δ
satpy/writers/cf_writer.py 93.84% <90.69%> (-0.26%) ⬇️
satpy/tests/writer_tests/test_cf.py 99.65% <100.00%> (+0.01%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update aa65035...9525cc9. Read the comment docs.

@sfinkens
Copy link
Member Author

sfinkens commented Jul 9, 2020

I just noticed that also coordinate variables like latitude or longitude can be chunked.

Copy link
Member

@mraspaud mraspaud left a comment

Choose a reason for hiding this comment

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

The logic is sound, so I'm good with this. I have two comments about cleanliness though.

satpy/tests/writer_tests/test_cf.py Outdated Show resolved Hide resolved
satpy/writers/cf_writer.py Outdated Show resolved Hide resolved
@@ -616,6 +632,7 @@ def save_datasets(self, datasets, filename=None, groups=None, header_attrs=None,
root.attrs['Conventions'] = CF_VERSION

# Remove satpy-specific kwargs
to_netcdf_kwargs = copy.deepcopy(to_netcdf_kwargs) # may contain dictionaries (encoding)
satpy_kwargs = ['overlay', 'decorate', 'config_files']
Copy link
Member

Choose a reason for hiding this comment

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

I know you didn't do this, but it is too bad we have to do this. I'm sure it will come to bite us in the future.

@mraspaud mraspaud added this to the v0.23.0 milestone Sep 9, 2020
@mraspaud
Copy link
Member

@sfinkens what is the status on this? Do you think you can have it ready by friday?

@sfinkens
Copy link
Member Author

@mraspaud Yes, I think that's possible!

@sfinkens
Copy link
Member Author

@mraspaud Done!

Copy link
Member

@mraspaud mraspaud left a comment

Choose a reason for hiding this comment

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

LGTM, two small style comments inline.

satpy/writers/cf_writer.py Outdated Show resolved Hide resolved
satpy/writers/cf_writer.py Outdated Show resolved Hide resolved
@mraspaud mraspaud merged commit 5063081 into pytroll:master Sep 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component:writers enhancement code enhancements, features, improvements
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants