-
Notifications
You must be signed in to change notification settings - Fork 78
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 get_observer_look for satellite exactly at nadir #77
Fix get_observer_look for satellite exactly at nadir #77
Conversation
When the satellite is exactly above the observer the satellite elevation angle is 90 degrees the azimuth angle is undefined. Set asimuth angle to 0 when satellite elevation is 90 degrees. Also handle the case when top_z / rg_ is larger than 1.0 due to rounding.
Codecov Report
@@ Coverage Diff @@
## main #77 +/- ##
==========================================
+ Coverage 85.31% 85.67% +0.35%
==========================================
Files 13 13
Lines 1893 1947 +54
==========================================
+ Hits 1615 1668 +53
- Misses 278 279 +1
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
👉 View analysis in DeepCode’s Dashboard | Configure the bot |
This happens when satellite is exactly at observer nadir. The problem depends on rounding and varies between array types: numpy, dask, and xarray. Removed the check for sat_at_nadir as is not needed any longer.
While slightly out-of-scope for this PR, do you know if this problem that you've fixed here would also affect solar angles? |
Good question! It should not happen for solar azimuth angles as pyorbital in astronomy get_alt_az uses np.artan2 that handles special values For the sun zenith angle the formulas are different so I don't think the arcsine for values larger than 1 could happen. |
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.
Thanks for unrooting this bug!
I think some parts can be simplified, see inline comments.
Good work!
pyorbital/orbital.py
Outdated
top_z_divided_by_rg_ = top_z / rg_ | ||
el_ = np.arcsin(top_z_divided_by_rg_) |
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.
Using clip
might help avoid the extra filtering later:
top_z_divided_by_rg_ = top_z / rg_ | |
el_ = np.arcsin(top_z_divided_by_rg_) | |
top_z_divided_by_rg_ = top_z / rg_ | |
top_z_divided_by_rg_ = top_z_divided_by_rg_.clip(max=1) | |
el_ = np.arcsin(top_z_divided_by_rg_) |
pyorbital/orbital.py
Outdated
# And azimuth undefined when elevation is 90 degrees | ||
if has_dask and isinstance(az_data, da.Array): | ||
el_data = da.where(top_z_divided_by_rg_ > 1.0, np.pi/2, el_data) | ||
az_data = da.where(el_data == np.pi / 2, 0, az_data) |
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.
Instead of this filtering and the undet_azi
higher up, would np.nan_to_num
be helpfull here? or do we still want some azimuths to be nans?
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.
LGTM!
When the satellite is exactly above the observer the satellite
elevation angle should be 90 degrees and the azimuth angle is undefined.
Set azimuth angle to 180 (initially 0) when satellite elevation is 90 degrees.
Also handle the case when top_z / rg_ is larger than 1.0 due to rounding.
Previously nans were often returned for satellite elevation 90 degrees.
The Orbital class also has a get_observer_look function which does not handle
dask and xarray. This function has not been updated.
flake8 pyorbital