diff --git a/docs/reference/index.rst b/docs/reference/index.rst index f12351f..7f9d40f 100644 --- a/docs/reference/index.rst +++ b/docs/reference/index.rst @@ -7,14 +7,14 @@ Reference .. toctree:: :maxdepth: 2 + calibration coordinates data - calibration - timeseries - science map product science + science + timeseries timeseries visualisation diff --git a/examples/imaging_demo.py b/examples/imaging_demo.py index 35f37d4..2459784 100644 --- a/examples/imaging_demo.py +++ b/examples/imaging_demo.py @@ -30,7 +30,6 @@ from stixpy.imaging.em import em from stixpy.product import Product - logger = logging.getLogger(__name__) logger.setLevel("DEBUG") diff --git a/stixpy/coordinates/frames.py b/stixpy/coordinates/frames.py index 33218e5..26bdd27 100644 --- a/stixpy/coordinates/frames.py +++ b/stixpy/coordinates/frames.py @@ -97,9 +97,9 @@ def stix_wcs_to_frame(wcs): hgs_latitude = wcs.wcs.aux.hglt_obs hgs_distance = wcs.wcs.aux.dsun_obs - observer = HeliographicStonyhurst(hgs_latitude * u.deg, - hgs_longitude * u.deg, - hgs_distance * u.m, + observer = HeliographicStonyhurst(lat=hgs_latitude * u.deg, + lon=hgs_longitude * u.deg, + radius=hgs_distance * u.m, obstime=dateobs, rsun=rsun) @@ -113,7 +113,7 @@ def stix_wcs_to_frame(wcs): def stix_frame_to_wcs(frame, projection='TAN'): r""" For a given frame, this function returns the corresponding WCS object. - + It registers the WCS coordinates types from their associated frame in the `astropy.wcs.utils.celestial_frame_to_wcs` registry. diff --git a/stixpy/coordinates/tests/test_frames.py b/stixpy/coordinates/tests/test_frames.py index 1402bdb..ff0ec48 100644 --- a/stixpy/coordinates/tests/test_frames.py +++ b/stixpy/coordinates/tests/test_frames.py @@ -3,8 +3,10 @@ import pytest from astropy.coordinates import SkyCoord from astropy.wcs import WCS +from sunpy.coordinates import get_horizons_coord from sunpy.coordinates.frames import HeliographicStonyhurst, Helioprojective from sunpy.map import Map, make_fitswcs_header +from sunpy.map.mapbase import SpatialPair from stixpy.coordinates.frames import STIXImaging, stix_frame_to_wcs, stix_wcs_to_frame from stixpy.map.stix import STIXMap @@ -42,10 +44,19 @@ def stix_frame(): frame = STIXImaging(**frame_args) return frame + def test_stix_wcs_to_frame(stix_wcs): frame = stix_wcs_to_frame(stix_wcs) assert isinstance(frame, STIXImaging) + assert frame.obstime.isot == '2024-01-01T00:00:00.000' + assert frame.rsun == 695700 * u.km + assert frame.observer == HeliographicStonyhurst(10 * u.deg, + 20 * u.deg, + 1.5e11 * u.m, + obstime='2024-01-01T00:00:00.000') + + def test_stix_wcs_to_frame_none(): w = WCS(naxis=2) @@ -73,10 +84,18 @@ def test_stix_frame_to_wcs_none(): wcs = stix_frame_to_wcs(Helioprojective()) assert wcs is None +@pytest.mark.remote_data def test_stix_frame_map(): - data = np.random.rand(10, 10) - coord = SkyCoord(0 * u.arcsec, 0 * u.arcsec, obstime='now', observer='earth', frame=STIXImaging) - header = make_fitswcs_header(data, coord, scale=[2, 2]*u.arcsec/u.pix, telescope='STIX', + data = np.random.rand(512, 512) + obstime = '2023-01-01 12:00:00' + solo = get_horizons_coord('solo', time=obstime) + coord = SkyCoord(0 * u.arcsec, 0 * u.arcsec, obstime=obstime, observer=solo, frame=STIXImaging) + header = make_fitswcs_header(data, coord, scale=[8, 8] * u.arcsec / u.pix, telescope='STIX', instrument='STIX', observatory='Solar Orbiter') smap = Map((data, header)) assert isinstance(smap, STIXMap) + assert smap.coordinate_system == SpatialPair(axis1='SXLN-TAN', axis2='SXLT-TAN') + assert isinstance(smap.coordinate_frame, STIXImaging) + smap.plot() + smap.draw_limb() + smap.draw_grid() diff --git a/stixpy/coordinates/tests/test_transforms.py b/stixpy/coordinates/tests/test_transforms.py index fd168c3..d46fb8e 100644 --- a/stixpy/coordinates/tests/test_transforms.py +++ b/stixpy/coordinates/tests/test_transforms.py @@ -3,16 +3,13 @@ import astropy.units as u import numpy as np import pytest +from astropy.tests.helper import assert_quantity_allclose from astropy.time import Time from sunpy.coordinates import HeliographicStonyhurst, Helioprojective from stixpy.coordinates.frames import STIXImaging -def assert_quantity_allclose(x, param): - pass - - @pytest.mark.skip(reason="Test data maybe incorrect") @pytest.mark.remote_data def test_transforms_with_know_values(): diff --git a/stixpy/map/stix.py b/stixpy/map/stix.py index 8d73fff..0b84107 100644 --- a/stixpy/map/stix.py +++ b/stixpy/map/stix.py @@ -25,42 +25,3 @@ def plot(self, **kwargs): res.axes.coords[1].set_format_unit(u.arcsec) return res - - # @property - # def wcs(self): - # if not self.coordinate_system.axis1 == 'SXLN-TAN' and self.coordinate_system.axis2 == 'SXLT-TAN': - # return super().wcs - # - # w2 = astropy.wcs.WCS(naxis=2) - # - # # Add one to go from zero-based to one-based indexing - # w2.wcs.crpix = u.Quantity(self.reference_pixel) + 1 * u.pix - # # Make these a quantity array to prevent the numpy setting element of - # # array with sequence error. - # # Explicitly call ``.to()`` to check that scale is in the correct units - # w2.wcs.cdelt = u.Quantity([self.scale[0].to(self.spatial_units[0] / u.pix), - # self.scale[1].to(self.spatial_units[1] / u.pix)]) - # w2.wcs.crval = u.Quantity([self._reference_longitude, self._reference_latitude]) - # w2.wcs.ctype = self.coordinate_system - # w2.wcs.pc = self.rotation_matrix - # w2.wcs.set_pv(self._pv_values) - # # FITS standard doesn't allow both PC_ij *and* CROTA keywords - # w2.wcs.crota = (0, 0) - # w2.wcs.cunit = self.spatial_units - # w2.wcs.dateobs = self.date.isot - # w2.wcs.aux.rsun_ref = self.rsun_meters.to_value(u.m) - # - # obs_frame = self.observer_coordinate - # if hasattr(obs_frame, 'frame'): - # obs_frame = obs_frame.frame - # - # w2.wcs.aux.hgln_obs = obs_frame.lon.to_value(u.deg) - # w2.wcs.aux.hglt_obs = obs_frame.lat.to_value(u.deg) - # w2.wcs.aux.dsun_obs = obs_frame.radius.to_value(u.m) - # - # w2.wcs.dateobs = self.date.utc.iso - # - # # Set the shape of the data array - # w2.array_shape = self.data.shape - # - # return w2