diff --git a/decasu/region_mapper.py b/decasu/region_mapper.py index fbebd02..d11ee09 100644 --- a/decasu/region_mapper.py +++ b/decasu/region_mapper.py @@ -5,6 +5,7 @@ import esutil import time from functools import lru_cache +from astropy.time import Time import coord @@ -281,6 +282,12 @@ def __call__(self, hpix_or_tilename, indices, clobber=False): value = (np.tan(zenith)**2.)*np.sin(2*par_angle) elif map_type == 'parallactic': value = par_angle + elif map_type == 'mjd': + value = dg.table[self.config.mjd_field][ind] + elif map_type == 'fraction_of_year': + value = self._compute_fraction_of_year(dg.table[self.config.mjd_field][ind]) + elif map_type == 'fraction_of_day': + value = self._compute_fraction_of_day(dg.table[self.config.mjd_field][ind]) else: value = dg.table[map_type][ind] @@ -784,6 +791,38 @@ def _get_maskcircle_from_row(self, table_row): value=1) return maskcircle + def _compute_fraction_of_year(self, mjds): + """Compute day of year. + + Parameters + ---------- + mjd : `np.ndarray` + Array of MJD values. + + Returns + ------- + fraction_of_year : `np.ndarray` + Fraction of year for MJDs. + """ + t = Time(mjds, format='mjd') + decimal_year = t.to_value('decimalyear') + return decimal_year - np.floor(decimal_year) + + def _compute_fraction_of_day(self, mjds): + """Compute fraction of day. + + Parameters + ---------- + mjd : `np.ndarray` + Array of MJD values. + + Returns + ------- + fraction_of_day : `np.ndarray` + Fraction of day (UTC) for MJDs. + """ + return mjds - np.floor(mjds) + @lru_cache(maxsize=200) def _get_numpy_corners_from_detector(detector, amp_name): diff --git a/tests/configs/config_tilename.yaml b/tests/configs/config_tilename.yaml index 0990e1e..02e1c2e 100644 --- a/tests/configs/config_tilename.yaml +++ b/tests/configs/config_tilename.yaml @@ -16,3 +16,6 @@ map_types: skybrite: ['wmean', 'wmean-scaled', 'min-scaled', 'max-scaled', 'mean', 'mean-scaled'] skyvar: ['wmean', 'min'] fwhm: ['wmean'] + mjd: ['wmean'] + fraction_of_year: ['wmean'] + fraction_of_day: ['wmean'] diff --git a/tests/test_tilename.py b/tests/test_tilename.py index 6127c23..ff53678 100644 --- a/tests/test_tilename.py +++ b/tests/test_tilename.py @@ -67,6 +67,9 @@ def test_tilename(self): expected_dict['skysigma_wmean'] = [51.4, 77.2, 'float64'] expected_dict['skyvar_wmean'] = [2950.0, 5991.0, 'float64'] expected_dict['skyvar_min'] = [2705.0, 5991.0, 'float64'] + expected_dict['mjd_wmean'] = [56602.0, 57335.0, 'float64'] + expected_dict['fraction_of_year_wmean'] = [0.67, 0.94, 'float64'] + expected_dict['fraction_of_day_wmean'] = [0.03, 0.23, 'float64'] self.check_expected_maps_tile(expected_dict, 'DES0003-5457', band) @@ -97,6 +100,9 @@ def test_tilename(self): expected_dict['skysigma_wmean'] = [50.1, 78.7, 'float64'] expected_dict['skyvar_wmean'] = [2520.0, 6223.0, 'float64'] expected_dict['skyvar_min'] = [2503.0, 6223.0, 'float64'] + expected_dict['mjd_wmean'] = [56602.0, 57259.0, 'float64'] + expected_dict['fraction_of_year_wmean'] = [0.63, 0.94, 'float64'] + expected_dict['fraction_of_day_wmean'] = [0.05, 0.28, 'float64'] self.check_expected_maps_tile(expected_dict, 'DES2358-5457', band)