Skip to content

Commit

Permalink
Automatically download IERS A table if needed
Browse files Browse the repository at this point in the history
Closes #197
  • Loading branch information
mwcraig committed May 22, 2015
1 parent 3863ef2 commit 2b11f9d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
21 changes: 19 additions & 2 deletions msumastro/header_processing/patchers.py
Expand Up @@ -54,6 +54,22 @@ def IRAF_image_type(image_type):
return image_type.split()[0].upper()


def _lst_from_obstime(obstime):
try:
LST = obstime.sidereal_time('apparent',
longitude=feder.site.longitude)
except IndexError:
# We are outside the range of the IERS table installed with astropy,
# so get a newer one.
from astropy.utils import iers
from astropy.utils.data import download_file
iers.IERS.iers_table = iers.IERS_A.open(download_file(iers.IERS_A_URL,
cache=True))
LST = obstime.sidereal_time('apparent',
longitude=feder.site.longitude)
return LST


def add_time_info(header, history=False):
"""
Add JD, MJD, LST to FITS header
Expand All @@ -69,7 +85,8 @@ def add_time_info(header, history=False):
feder.JD_OBS.value = dateobs.jd
feder.MJD_OBS.value = dateobs.mjd

LST_tmp = dateobs.sidereal_time('apparent', longitude=feder.site.longitude)
LST_tmp = _lst_from_obstime(dateobs)

feder.LST.value = LST_tmp.to_string(unit=u.hour, sep=':', precision=4,
pad=True)

Expand Down Expand Up @@ -122,7 +139,7 @@ def add_object_pos_airmass(header, history=False):
feder.AIRMASS.value = round(1 / np.cos(np.pi / 2 - alt_az.alt.radian), 3)

# TODO: replace the LST calculation
LST = obstime.sidereal_time('apparent', longitude=feder.site.longitude)
LST = _lst_from_obstime(obstime)
HA = LST.hour - obj_coord2.ra.hour
HA = Angle(HA, unit=u.hour)

Expand Down
8 changes: 8 additions & 0 deletions msumastro/header_processing/tests/test_patchers.py
Expand Up @@ -17,6 +17,7 @@
from astropy import units as u
from astropy.table import Table
from astropy.extern import six
from astropy.time import Time

from .. import patchers as ph
from ..feder import Feder, ApogeeAltaU9, FederSite
Expand Down Expand Up @@ -627,6 +628,13 @@ def test_unit_is_added():
assert h['BUNIT'] == str(instrument.image_unit)


def test_lst_in_future():
header = fits.Header()
future = Time.now() + 1 * u.year
header['date-obs'] = future.isot
ph.add_time_info(header)


@pytest.fixture(params=['object', 'OBJECT', 'Object'])
def object_file_ra_change_col_case(request):
object_file_with_ra_dec(_test_dir, object_col_name=request.param)
Expand Down

0 comments on commit 2b11f9d

Please sign in to comment.