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 GONG H-Alpha map source #7451

Merged
merged 5 commits into from
Mar 21, 2024
Merged

Add GONG H-Alpha map source #7451

merged 5 commits into from
Mar 21, 2024

Conversation

samaloney
Copy link
Contributor

@samaloney samaloney commented Feb 16, 2024

PR Description

Closes #6656 by adding a GONG H-alpha map source.

TODO:

  • Add changelog
  • Update docs and add links to source material
  • Add tests
  • Use Earth lat, lon header to set observatory location
  • Better default plot settings

Image from GONG site

From sunpy with this PR

gong_sunpy

@nabobalis nabobalis added the map Affects the map submodule label Feb 16, 2024
@samaloney samaloney marked this pull request as ready for review February 16, 2024 17:14
@samaloney samaloney requested a review from a team as a code owner February 16, 2024 17:14
@samaloney
Copy link
Contributor Author

Because of the asdf issue with the .fz extension you have to open these maps with the well hidden filetype keyword Map('/path/to/file/20240216000002Bh.fits.fz', filetype='fits')

@nabobalis
Copy link
Contributor

We need to fix that bug, and milestone it for 6.0


@property
def observer_coordinate(self):
return SkyCoord(self.earth_location.itrs).heliographic_stonyhurst
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we have a test for this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No but I can add one but there is a test for self.earth_location and if this were to break it would be in SkyCoord or EarthLocation

sunpy/map/sources/gong.py Show resolved Hide resolved
sunpy/map/sources/gong.py Outdated Show resolved Hide resolved
sunpy/map/sources/gong.py Outdated Show resolved Hide resolved
sunpy/map/sources/gong.py Outdated Show resolved Hide resolved
sunpy/map/sources/gong.py Outdated Show resolved Hide resolved
@samaloney
Copy link
Contributor Author

I think the test fail is related to this issue astropy/astropy/issues/16128

@samaloney
Copy link
Contributor Author

Yea so if I extract the test command and run in a terminal it works I guess it could be something to do with remote_data but I tried adding that marker and it didn't work either?

import astropy.units as u
from numpy.testing import assert_equal
from sunpy.data.test import get_dummy_map_from_header, get_test_filepath

gm = get_dummy_map_from_header(get_test_filepath('gong_halpha.header'))
assert_equal(gm.observer_coordinate.data.xyz, 
             [146712246479.363, -5563586.169750214, -17605285536.73928] * u.m)

@wtbarnes
Copy link
Member

wtbarnes commented Mar 7, 2024

Yea so if I extract the test command and run in a terminal it works I guess it could be something to do with remote_data but I tried adding that marker and it didn't work either?

import astropy.units as u
from numpy.testing import assert_equal
from sunpy.data.test import get_dummy_map_from_header, get_test_filepath

gm = get_dummy_map_from_header(get_test_filepath('gong_halpha.header'))
assert_equal(gm.observer_coordinate.data.xyz, 
             [146712246479.363, -5563586.169750214, -17605285536.73928] * u.m)

I'm able to reproduce this test fail locally. The reason is because the last date in the IERS table that astropy is grabbing is 1/12/2024 and the date of this observation is 2/16/2024. Thus, its throwing a warning that you're beyond the last date in the IERS table and your accuracy may be degraded.

@samaloney
Copy link
Contributor Author

Yea but is that specific to test runs e.g. strict remote data runner as if I run it from local shell it works?

    ~/Projects/sunpy-dev    feat-gong-halpha *3 ?1                                                                                                                                                                                                                                                                                                 ✔  sunpy-dev 
    ~/Projects/sunpy-dev    feat-gong-halpha *3 ?1  ipython                                                                                                                                                                                                                                                                                        ✔  sunpy-dev 
Python 3.11.7 (main, Dec  4 2023, 18:10:11) [Clang 15.0.0 (clang-1500.1.0.2.5)]
Type 'copyright', 'credits' or 'license' for more information
IPython 8.21.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: import astropy.units as u
   ...: from numpy.testing import assert_equal
   ...: from sunpy.data.test import get_dummy_map_from_header, get_test_filepath
   ...:
   ...: gm = get_dummy_map_from_header(get_test_filepath('gong_halpha.header'))
   ...: assert_equal(gm.observer_coordinate.data.xyz,
   ...:              [146712246479.363, -5563586.169750214, -17605285536.73928] * u.m)

In [2]:

@wtbarnes
Copy link
Member

wtbarnes commented Mar 7, 2024

Ok I think that should fix the test. Let me know what you think about that. I changed the assert_equal to an isclose with a tolerance of 1e-9. If we really need the assert_equal then we can interrogate what the actual differences are between the two.

@wtbarnes
Copy link
Member

wtbarnes commented Mar 7, 2024

Yea but is that specific to test runs e.g. strict remote data runner as if I run it from local shell it works?

    ~/Projects/sunpy-dev    feat-gong-halpha *3 ?1                                                                                                                                                                                                                                                                                                 ✔  sunpy-dev 
    ~/Projects/sunpy-dev    feat-gong-halpha *3 ?1  ipython                                                                                                                                                                                                                                                                                        ✔  sunpy-dev 
Python 3.11.7 (main, Dec  4 2023, 18:10:11) [Clang 15.0.0 (clang-1500.1.0.2.5)]
Type 'copyright', 'credits' or 'license' for more information
IPython 8.21.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: import astropy.units as u
   ...: from numpy.testing import assert_equal
   ...: from sunpy.data.test import get_dummy_map_from_header, get_test_filepath
   ...:
   ...: gm = get_dummy_map_from_header(get_test_filepath('gong_halpha.header'))
   ...: assert_equal(gm.observer_coordinate.data.xyz,
   ...:              [146712246479.363, -5563586.169750214, -17605285536.73928] * u.m)

In [2]:

Either you're silencing the warning or using a different IERS table (that has a more recent date). Can you check which table you're using?

@samaloney
Copy link
Contributor Author

samaloney commented Mar 7, 2024

Hum I cleared the downloaded cache in the process of trying to reproduce the errors so maybe that's related.

from astropy.utils import iers

iers.IERS_A_FILE
'finals2000A.all'

iers.IERS_B_FILE
'/Users/sm/.virtualenvs/sunpy-dev/lib/python3.11/site-packages/astropy/utils/iers/data/eopc04_IAU2000.62-now'

I could use an older H-alpha file for the tests before 2024/02/12?

@wtbarnes
Copy link
Member

wtbarnes commented Mar 7, 2024

Maybe? Whatever I did also I did not fix the issue on the CI though did fix the fail for me locally. The most annoying combination.

Yeah, maybe just using an older file is the easiest solution. People will of course run into this if they use the newer files, but it's probably not a big deal in terms of accuracy or they'll have a more up-to-date IERS table.

def test_scale(gong_halpha):
"""Tests the scale property of the GONGHalphaMap map."""
assert_equal(gong_halpha.scale.axis1, 1.0794939681708389 * (u.arcsec / u.pix))
assert_equal(gong_halpha.scale.axis1, 1.0794939681708389 * (u.arcsec / u.pix))
Copy link
Member

@wtbarnes wtbarnes Mar 8, 2024

Choose a reason for hiding this comment

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

Should this be axis2?

@wtbarnes
Copy link
Member

wtbarnes commented Mar 9, 2024

Just to cross-reference, the actual underlying in astropy is now being discussed here: astropy/astropy#13227 (comment)

The tl;dr is that astropy will ignore a just-downloaded IERS table if you have iers.conf.auto_download = False even though that table exists on your machine already.

I would suggest that if we don't want this PR held up by this bugfix, then we just choose a GONG header at an earlier date.

@nabobalis nabobalis requested a review from wtbarnes March 21, 2024 00:42
@nabobalis nabobalis added the Needs Review Needs reviews before merge label Mar 21, 2024
Comment on lines 55 to 56
with pytest.warns(AstropyWarning, match='Tried to get polar motions for times after IERS data is valid.'):
with pytest.warns(AstropyWarning, match='times are outside of range covered by IERS table'):
Copy link
Contributor

Choose a reason for hiding this comment

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

Had to add an extra warning?

Copy link
Contributor

Choose a reason for hiding this comment

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

I broke oldest build do this.

>       with pytest.warns(AstropyWarning, match='Tried to get polar motions for times after IERS data is valid.'):
E       Failed: DID NOT WARN. No warnings of type (<class 'astropy.utils.exceptions.AstropyWarning'>,) were emitted. The list of emitted warnings is: [].

Copy link
Member

Choose a reason for hiding this comment

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

Again I think we should just choose an older test header to avoid having to deal with this IERS behavior since an upstream fix is needed.

Copy link
Member

Choose a reason for hiding this comment

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

Even though the upstream fix (astropy/astropy#16187) will likely be merged imminently, it probably won't be backported, so it will be a long while before it is in all versions of astropy we support. The alternative to picking an older test header is to simply filter away warnings within the unit test.

Copy link
Member

Choose a reason for hiding this comment

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

That is, the unit test don't actually care if there's a warning or not, so catching/matching with pytest.warns() is unnecessary.

Copy link
Member

@ayshih ayshih Mar 21, 2024

Choose a reason for hiding this comment

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

(And yes, there are two warnings, from two different parts of the astropy codebase.)

Copy link
Contributor

Choose a reason for hiding this comment

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

Done.

samaloney and others added 5 commits March 20, 2024 20:25
* Add tests and test data
* Add observer_coord and update docs.
Co-authored-by: Will Barnes <will.t.barnes@gmail.com>
@nabobalis nabobalis added the No Backport A PR that isn't to be backported to any release branch. (To be used as a flag to other maintainers) label Mar 21, 2024
@wtbarnes wtbarnes merged commit 4c17a50 into sunpy:main Mar 21, 2024
25 of 28 checks passed
@samaloney samaloney deleted the feat-gong-halpha branch March 21, 2024 14:03
@nabobalis nabobalis removed the Needs Review Needs reviews before merge label Mar 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
map Affects the map submodule No Backport A PR that isn't to be backported to any release branch. (To be used as a flag to other maintainers)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

No map source to handle GONG H-alpha data
5 participants