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

Set dtype for get_lonlats() in NIR reflectance calculation #2642

Merged
merged 29 commits into from
Nov 23, 2023

Conversation

pnuu
Copy link
Member

@pnuu pnuu commented Nov 21, 2023

This simple addition finalizes pytroll/pyspectral#206 so that NIRReflectance modifier doesn't up-cast the input data to float64.

Includes also some refactoring between NIRReflectance and NIREmissivePartFromReflectance.

  • Closes #xxxx
  • Tests added
  • Fully documented
  • Add your name to AUTHORS.md if not there already

@pnuu pnuu added the enhancement code enhancements, features, improvements label Nov 21, 2023
@pnuu pnuu self-assigned this Nov 21, 2023
Copy link

codecov bot commented Nov 21, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (5ecf1ab) 95.21% compared to head (d250a9d) 95.21%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2642      +/-   ##
==========================================
- Coverage   95.21%   95.21%   -0.01%     
==========================================
  Files         356      356              
  Lines       51591    51588       -3     
==========================================
- Hits        49120    49117       -3     
  Misses       2471     2471              
Flag Coverage Δ
behaviourtests 4.22% <18.18%> (+<0.01%) ⬆️
unittests 95.83% <100.00%> (-0.01%) ⬇️

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.

@pnuu pnuu marked this pull request as ready for review November 21, 2023 08:50
@pnuu
Copy link
Member Author

pnuu commented Nov 21, 2023

Hmm, maybe checking NIR dtype is passed to .get_lonlats() is enogh? The modifier tests don't call Pyspectral at all, so pytroll/pyspectral#206 isn't required for this PR.

@coveralls
Copy link

coveralls commented Nov 21, 2023

Pull Request Test Coverage Report for Build 6966833397

  • 22 of 22 (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.783%

Totals Coverage Status
Change from base Build 6938939151: 0.0%
Covered Lines: 49243
Relevant Lines: 51411

💛 - Coveralls

@@ -107,7 +107,7 @@ def _get_sun_zenith_from_provided_data(projectables, optional_datasets):
if sun_zenith_angle is None:
raise ImportError("Module pyorbital.astronomy needed to compute sun zenith angles.")
_nir = projectables[0]
lons, lats = _nir.attrs["area"].get_lonlats(chunks=_nir.data.chunks)
lons, lats = _nir.attrs["area"].get_lonlats(chunks=_nir.data.chunks, dtype=_nir.dtype)
Copy link
Member

Choose a reason for hiding this comment

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

I don't understand what the dtype of nir has to do with the type of longitudes and latitudes, och sun angles? I don't think it's the role of this function to decide on the type of the sun zenith...

Copy link
Member Author

Choose a reason for hiding this comment

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

The dtype of sun angles is determined by the lon and lat dtypes. If the dtype of sun angles is float64 it forces the 3.9 um reflectance to be float64 no matter what the dtype of the input data is. NIR is the input data, so using its dtype is plain logical, and to save everything in between to be up- and then later downcast the best way to is to get the lonlats with the same dtype. Lons, lats and SZA are just intermediate data in the NIR reflectance determination, so it this saves a lot to use the intended type from the beginning without side-effects.

Copy link
Member

Choose a reason for hiding this comment

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

Ok, I understand now that we need the sunz to be the same type as nir for later computations. But still, it's really hard to understand without context why the dtype is set to nir's, and could be confusing in the future.
Looking up a bit, it looks like this function is called from _get_reflectance_as_dataarray right? That function is at a higher abstraction level, and I think there it would make sense to decide the type of the sunz. So can we just pass down the dtype from there to _get_sun_zenith_from_provided_data?

Copy link
Member

Choose a reason for hiding this comment

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

also, if we're modifying this function, it seems we are passing projectables here, while we just use the first element of the list, can we change that to just pass nir to the method?

Copy link
Member Author

@pnuu pnuu Nov 21, 2023

Choose a reason for hiding this comment

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

Ok, those make sense. Updated in 4c7b330

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, just one little comment inline.

@@ -95,7 +95,7 @@ def _get_tb13_4_from_optionals(optional_datasets):
return tb13_4

@staticmethod
def _get_sun_zenith_from_provided_data(projectables, optional_datasets):
def _get_sun_zenith_from_provided_data(_nir, optional_datasets, dtype):
Copy link
Member

Choose a reason for hiding this comment

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

just nitpicking here, but I would rename _nirto nir here.

Copy link
Member Author

Choose a reason for hiding this comment

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

Renamed in b992edb

@mraspaud
Copy link
Member

I'm merging this now, thanks for the hard work!

@mraspaud mraspaud merged commit f2f1b33 into pytroll:main Nov 23, 2023
17 of 19 checks passed
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