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

Add Sun-Earth distance corrector utility and apply in SEVIRI readers #1341

Merged
merged 13 commits into from
Sep 9, 2020
Merged

Add Sun-Earth distance corrector utility and apply in SEVIRI readers #1341

merged 13 commits into from
Sep 9, 2020

Conversation

simonrp84
Copy link
Member

@simonrp84 simonrp84 commented Sep 4, 2020

The distance between the sun and the Earth varies slightly during the year due to the Earth's orbital eccentricity. This means that the incoming solar irradiance, and hence outgoing radiance measured by a satellite sensor, also varies throughout the year as a function of day.

Many sensors do not account for this in their L1 data products, so a correction must be applied.
As an example, for SEVIRI:

Reflectance = (pi * se_dist^2 * radiance) / (solar_irradiance * cos(solar_zenith))

Where:
se_dist is the Sun-Earth distance on a given day.
radiance is the satellite-measured pixel radiance.
solar_irradiance is the average solar irradiance for the band.
solar_zenith is the solar zenith angle (with nadir = 0) for a given pixel.

Currently, the SEVIRI reader (and possibly others too) doesn't apply the se_dist factor, and therefore the reflectances given by satpy are slightly incorrect (by up to ~4%).

This PR creates a utility function apply_earthsun_distance_correction that applies the correction. It also adds this function to the SEVIRI calibration code and adds the various test functions to ensure everything works.
In addition, a remove_earthsun_distance_correction function is also supplied for the case that a user wishes to remove the correction.

@coveralls
Copy link

coveralls commented Sep 4, 2020

Coverage Status

Coverage increased (+0.1%) to 90.377% when pulling 098fb6b on simonrp84:reflectance_earthsun_distance into e77cd29 on pytroll:master.

@codecov
Copy link

codecov bot commented Sep 4, 2020

Codecov Report

Merging #1341 into master will increase coverage by 0.13%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1341      +/-   ##
==========================================
+ Coverage   90.24%   90.37%   +0.13%     
==========================================
  Files         222      228       +6     
  Lines       32719    33068     +349     
==========================================
+ Hits        29526    29886     +360     
+ Misses       3193     3182      -11     
Impacted Files Coverage Δ
satpy/readers/seviri_l1b_hrit.py 92.18% <ø> (ø)
satpy/readers/seviri_l1b_native.py 73.94% <ø> (ø)
satpy/readers/seviri_l1b_nc.py 43.10% <ø> (ø)
satpy/readers/seviri_base.py 92.07% <100.00%> (+1.17%) ⬆️
satpy/readers/utils.py 90.00% <100.00%> (+1.80%) ⬆️
satpy/tests/reader_tests/test_seviri_base.py 100.00% <100.00%> (ø)
.../tests/reader_tests/test_seviri_l1b_calibration.py 96.72% <100.00%> (+0.49%) ⬆️
satpy/tests/reader_tests/test_utils.py 100.00% <100.00%> (ø)
satpy/tests/reader_tests/test_netcdf_utils.py 94.79% <0.00%> (-0.82%) ⬇️
satpy/composites/__init__.py 82.76% <0.00%> (-0.17%) ⬇️
... and 24 more

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 e77cd29...098fb6b. Read the comment docs.

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.

Looks good so far, just a couple of programmatic corrections I'd like to see included here. Otherwise, I think you missed _vis_calibrate usages in reader_tests and in seviri_l1b_nc.

satpy/readers/seviri_base.py Outdated Show resolved Hide resolved
satpy/readers/utils.py Outdated Show resolved Hide resolved
…ime if included in the xarray data. Otherwise, fall back to value being passed or raise an error.
@mraspaud
Copy link
Member

mraspaud commented Sep 4, 2020

The preferred way to access dataarray attributes is array.attrs['something']

@simonrp84
Copy link
Member Author

Fixed :-)

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.

Now that the code works, let's refactor to make it right :)

satpy/readers/utils.py Outdated Show resolved Hide resolved
satpy/tests/reader_tests/test_utils.py Outdated Show resolved Hide resolved
Copy link
Member

@sfinkens sfinkens left a comment

Choose a reason for hiding this comment

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

Very nice feature, thanks! A couple of questions and comments.

satpy/readers/utils.py Outdated Show resolved Hide resolved
satpy/readers/utils.py Outdated Show resolved Hide resolved
satpy/readers/seviri_base.py Show resolved Hide resolved
satpy/readers/seviri_base.py Show resolved Hide resolved
satpy/readers/seviri_base.py Outdated Show resolved Hide resolved
@sfinkens
Copy link
Member

sfinkens commented Sep 8, 2020

Also pinging @ninahakansson here, as this might be relevant in level1c4pps

@ninahakansson
Copy link
Contributor

Thanks @sfinkens for notifying me. At the moment in level1c4pps assume that sun-earth distance correction is not applied for SEVIRI, so this need to be updated when this is merged to satpy.

@simonrp84
Copy link
Member Author

I just pushed some changes that are not yet complete, as my git skills are low and I want to transfer my code changes between home and office :-) Will complete the updates after review ASAP.

… function to retrieve UTC time. Also restructure appropriate tests into a class.
@simonrp84 simonrp84 added this to the v0.23.0 milestone Sep 9, 2020
… correction is applied and, if so, what the Sun-Earth distance is.
Copy link
Member

@sfinkens sfinkens left a comment

Choose a reason for hiding this comment

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

LGTM

utc_date = get_array_date(reflectance, utc_date)
sun_earth_dist = sun_earth_distance_correction(utc_date)

reflectance.attrs['sun_earth_distance_correction_applied'] = False
Copy link
Member

Choose a reason for hiding this comment

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

@ninahakansson You can use these attributes in level1c4pps

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

@mraspaud
Copy link
Member

mraspaud commented Sep 9, 2020

@simonrp84 one last thing: could you mention in the module docstrings of the seviri readers that earth-sun distance correction is now applied?

…stance correction is taken into account when computing reflectances.
@simonrp84
Copy link
Member Author

@mraspaud Ok, this is done now!

@mraspaud
Copy link
Member

mraspaud commented Sep 9, 2020

Perfect. Merging this when the tests pass.

@mraspaud mraspaud merged commit 0434faf into pytroll:master Sep 9, 2020
@simonrp84 simonrp84 deleted the reflectance_earthsun_distance branch October 15, 2020 08:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

SEVIRI reader doesn't include Earth-Sun distance in the rad->refl calibration
5 participants