Skip to content

Commit

Permalink
Merge pull request USNavalResearchLaboratory#98 from wtbarnes/fix-map…
Browse files Browse the repository at this point in the history
…-coord-ref-date

Prioritize `date_start` when defining WCS and coordinate frame
  • Loading branch information
MJWeberg authored Sep 3, 2024
2 parents 58782ad + 359f721 commit 3ac2abb
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 32 deletions.
21 changes: 14 additions & 7 deletions eispac/core/eismap.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,20 @@ def date_average(self):
return self._get_date('date_avg') or super().date_average

@property
def date(self):
# NOTE: we override this property to prioritize date_average
# over DATE-OBS (or DATE_OBS). In GenericMap, this is reversed.
# We do this because we want to make sure we are constructing our
# coordinate frames from DATE_AVG (the midpoint of the raster) and
# not DATE-OBS which is the beginning of the raster.
return self.date_average or super().date
def reference_date(self):
"""
The reference date for the coordinate system
According to Section 2.4 of
`EIS Software Note 9 <https://solarb.mssl.ucl.ac.uk/SolarB/eis_docs/eis_notes/09_POINTING/eis_swnote_09.pdf>`_,
the pointing keywords are defined at the start of the raster. As such, this property returns the
time at the beginning of the raster.
.. note:: This property is overridden because `sunpy.map.GenericMap` sets
this to be the ``.date_average`` which in this case is the midpoint
of the raster.
"""
return self.date_start

@classmethod
def is_datasource_for(cls, data, header, **kwargs):
Expand Down
38 changes: 13 additions & 25 deletions eispac/tests/test_eismap.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""
Tests for `eispac.EISMap`
"""
import copy
from textwrap import dedent

import numpy as np
Expand Down Expand Up @@ -104,30 +103,19 @@ def test_date_props(test_eis_map, attr, key):
assert getattr(test_eis_map, attr).isot == test_eis_map.meta[key]


def test_date(test_eis_map, test_header):
# Case 1: date-average exists
assert test_eis_map.date.isot == test_eis_map.meta['date_avg']
# Case 2: date-average is None so default to date_obs
header = copy.deepcopy(test_header)
del header['date_beg']
del header['date_end']
del header['date_avg']
new_map = sunpy.map.Map(test_eis_map.data, header)
assert new_map.date.isot == new_map.meta['date_obs']
# Case 3: date_avg is None so default to date_start
header = copy.deepcopy(test_header)
del header['date_avg']
del header['date_end']
del header['date_obs']
new_map = sunpy.map.Map(test_eis_map.data, header)
assert new_map.date.isot == new_map.meta['date_beg']
# Case 4: date_end and date_avg do not exist
header = copy.deepcopy(test_header)
del header['date_avg']
del header['date_beg']
del header['date_obs']
new_map = sunpy.map.Map(test_eis_map.data, header)
assert new_map.date.isot == new_map.meta['date_end']
def test_date_is_dateobs(test_eis_map):
"Test that .date returns DATE_OBS"
assert test_eis_map.date.isot == test_eis_map.meta['date_obs']


def test_date_is_date_start(test_eis_map):
"Test that .date returns the same date as .date_start"
assert test_eis_map.date == test_eis_map.date_start


def test_reference_date_is_date_start(test_eis_map):
"Test that the reference date is the time at the beginning of the raster"
assert test_eis_map.reference_date == test_eis_map.date_start


def test_plot_settings(test_eis_map):
Expand Down

0 comments on commit 3ac2abb

Please sign in to comment.