Esempio n. 1
0
 def test_update_iers(self):
     """Test updating the IERS table.  Requires a network connection."""
     save_name = os.path.join(self.tmpdir, 'iers.ecsv')
     utils.update_iers(save_name)
     # Second write should overwrite original file.
     utils.update_iers(save_name)
     utils.freeze_iers(save_name)
Esempio n. 2
0
def dateobs2night(dateobs):
    '''
    Convert UTC dateobs to KPNO YEARMMDD night string

    Args:
        dateobs:
            float -> interpret as MJD
            str -> interpret as ISO 8601 YEAR-MM-DDThh:mm:ss.s string
            astropy.time.Time -> UTC
            python datetime.datetime -> UTC

    TODO: consider adding format option to pass to astropy.time.Time without
        otherwise questioning the dateobs format
    '''
    # See pixsim.py
    from desisurvey.utils import freeze_iers
    freeze_iers()
    import astropy.time
    import datetime
    if isinstance(dateobs, float):
        dateobs = astropy.time.Time(dateobs, format='mjd')
    elif isinstance(dateobs, datetime.datetime):
        dateobs = astropy.time.Time(dateobs, format='datetime')
    elif isinstance(dateobs, str):
        dateobs = astropy.time.Time(dateobs, format='isot')
    elif not isinstance(dateobs, astropy.time.Time):
        raise ValueError(
            'dateobs must be float, str, datetime, or astropy time object')

    import astropy.units as u
    kpno_time = dateobs - 7 * u.hour

    #- "night" rolls over at local noon, not midnight, so subtract another 12 hours
    yearmmdd = (kpno_time - 12 * u.hour).isot[0:10].replace('-', '')
    assert len(yearmmdd) == 8

    return yearmmdd
Esempio n. 3
0
import desimodel.io
import desispec.io
from desispec.image import Image
import desispec.cosmics

from . import obs, io
from desiutil.log import get_logger
log = get_logger()

# Inhibit download of IERS-A catalog, even from a good server.
# Note that this is triggered by a call to astropy.time.Time(),
# which is subsequently used to compute sidereal_time().
# It's the initialization of astropy.time.Time() itself that makes the call.
from desisurvey.utils import freeze_iers
freeze_iers()
from astropy.time import Time

def simulate_exposure(simspecfile, rawfile, cameras=None,
        ccdshape=None, simpixfile=None, addcosmics=None, comm=None,
        **kwargs):
    """
    Simulate frames from an exposure, including I/O

    Args:
        simspecfile: input simspec format file with spectra
        rawfile: output raw data file to write

    Options:
        cameras: str or list of str, e.g. b0, r1, .. z9
        ccdshape: (npix_y, npix_x) primarily used to limit memory while testing
Esempio n. 4
0
 def test_freeze_iers_bad_format(self):
     """Test freezing from valid file with wrong format"""
     with self.assertRaises(ValueError):
         utils.freeze_iers('config.yaml')
Esempio n. 5
0
 def test_freeze_iers_bad_name(self):
     """Test freezing from package data/"""
     with self.assertRaises(ValueError):
         utils.freeze_iers('_non_existent_.ecsv')
Esempio n. 6
0
 def test_freeze_iers(self):
     """Test freezing from package data/"""
     utils.freeze_iers()
     future = astropy.time.Time('2024-01-01', location=utils.get_location())
     lst = future.sidereal_time('apparent')