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

Make CF encoding of dataset attributes public #2675

Merged
merged 4 commits into from
Feb 20, 2024

Conversation

sfinkens
Copy link
Member

@sfinkens sfinkens commented Dec 11, 2023

In some of my projects I have been using satpy.writer.encode_attrs_nc, which has been made private in Satpy 0.45. This is an attempt to get it back 🙂

Also, xarray still doesn't support the compression kwarg, so I bumped the anticipated version number by two months. Solved by Panu

  • Tests added
  • Fully documented

Copy link

codecov bot commented Dec 11, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (d90acf5) 95.30% compared to head (bd50436) 95.30%.
Report is 2 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2675   +/-   ##
=======================================
  Coverage   95.30%   95.30%           
=======================================
  Files         371      371           
  Lines       52435    52435           
=======================================
  Hits        49971    49971           
  Misses       2464     2464           
Flag Coverage Δ
behaviourtests 4.16% <0.00%> (ø)
unittests 95.91% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@coveralls
Copy link

Pull Request Test Coverage Report for Build 7168333052

  • 5 of 5 (100.0%) changed or added relevant lines in 2 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 95.886%

Totals Coverage Status
Change from base Build 7168284023: 0.0%
Covered Lines: 50108
Relevant Lines: 52258

💛 - Coveralls

@djhoese djhoese added the enhancement code enhancements, features, improvements label Dec 11, 2023
Copy link
Member

@djhoese djhoese left a comment

Choose a reason for hiding this comment

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

I'm fine merging this, but just so we're sure we're not missing some feature or other use case here, @sfinkens could you provide more information about your use case? Are you using xarray? What makes you need this lower-level function versus the higher-level ones that call it?

@sfinkens
Copy link
Member Author

sfinkens commented Dec 11, 2023

Sure! I have an algorithm that returns an xarray dataset, which I want to save to disk. The dataset's to_netcdf method is almost fine, I just need to make the attribute data types CF compatible.

ds = my_algo()
ds = encode_attrs_nc(ds)
ds.to_netcdf()

The higher-level method would be satpy.cf.attrs.preprocess_attrs, which does more than just encoding (adding long name for example).

@djhoese
Copy link
Member

djhoese commented Dec 11, 2023

Good point on the preprocess function. Makes sense.

@mraspaud mraspaud merged commit 80ab922 into pytroll:main Feb 20, 2024
18 of 19 checks passed
@sfinkens sfinkens deleted the encode-attrs-cf branch October 18, 2024 15:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement code enhancements, features, improvements
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants