From 594c87d04b1304955fd8bb0910f4b33acdf4afd4 Mon Sep 17 00:00:00 2001 From: Stuart Mumford Date: Sun, 9 Jun 2024 09:28:31 +0100 Subject: [PATCH] Don't leave me adaptmap --- docs/changelog.rst | 12 ++++++++---- sunkit_magex/pfss/__init__.py | 2 ++ sunkit_magex/pfss/map.py | 24 ++++++++++++++++++++++++ sunkit_magex/pfss/tests/test_map.py | 12 ++++++++++++ 4 files changed, 46 insertions(+), 4 deletions(-) create mode 100644 sunkit_magex/pfss/map.py create mode 100644 sunkit_magex/pfss/tests/test_map.py diff --git a/docs/changelog.rst b/docs/changelog.rst index e1ea3bc..c42861c 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -7,8 +7,9 @@ Full Changelog 1.0.0 (2024-05-31) ================== -* First release that keeps API the same from `pfsspy` to `sunkit-magex`. - The main difference is that you will need to replace the import like so: +This is the first release and aims to keep the API the same from `pfsspy` to +`sunkit-magex`. The main difference is that you will need to replace the +import like so: .. code-block:: python @@ -20,5 +21,8 @@ Full Changelog from sunkit_magex import pfss as pfsspy from sunkit_magex.pfss import tracing -The main breaking changes is that the old sunpy Map classes were removed and added to sunpy. -You will need to make sure you have sunpy 6.0.0 installed. +The main changes from the previous release of `pfsspy` are as follows: + +* The ``GongSynopticMap`` class has moved into `sunpy`, note that the new + class in ``sunpy`` is slightly different in that it does not modify the + header. diff --git a/sunkit_magex/pfss/__init__.py b/sunkit_magex/pfss/__init__.py index 8ae25ab..56f5c3c 100644 --- a/sunkit_magex/pfss/__init__.py +++ b/sunkit_magex/pfss/__init__.py @@ -1,3 +1,5 @@ +# Import this to register map sources +import sunkit_magex.pfss.map as _ from sunkit_magex.pfss import coords, fieldline, sample_data, tracing, utils from sunkit_magex.pfss.input import Input from sunkit_magex.pfss.output import Output diff --git a/sunkit_magex/pfss/map.py b/sunkit_magex/pfss/map.py new file mode 100644 index 0000000..ce3ddeb --- /dev/null +++ b/sunkit_magex/pfss/map.py @@ -0,0 +1,24 @@ +""" +Custom `sunpy.map.GenericMap` sub-classes for different magnetogram sources. +""" +import sunpy.map + +__all__ = ['ADAPTMap'] + + +class ADAPTMap(sunpy.map.GenericMap): + def __init__(self, data, header, **kwargs): + if 'date-obs' not in header: + header['date-obs'] = header['maptime'] + # Fix CTYPE + if header['ctype1'] == 'Long': + header['ctype1'] = 'CRLN-CAR' + if header['ctype2'] == 'Lat': + header['ctype2'] = 'CRLT-CAR' + + super().__init__(data, header, **kwargs) + + @classmethod + def is_datasource_for(cls, data, header, **kwargs): + """Determines if header corresponds to an ADAPT map.""" + return header.get('model') == 'ADAPT' diff --git a/sunkit_magex/pfss/tests/test_map.py b/sunkit_magex/pfss/tests/test_map.py new file mode 100644 index 0000000..0b994d4 --- /dev/null +++ b/sunkit_magex/pfss/tests/test_map.py @@ -0,0 +1,12 @@ +import astropy.io + +import sunpy.map + +import sunkit_magex.pfss.map + + +def test_adapt_map(adapt_test_file): + with astropy.io.fits.open(adapt_test_file) as adapt_fits: + for map_slice in adapt_fits[0].data: + m = sunpy.map.Map((map_slice, adapt_fits[0].header)) + assert isinstance(m, sunkit_magex.pfss.map.ADAPTMap)