Skip to content

Commit

Permalink
Add mjd/fraction_of_year/fraction_of_day maps.
Browse files Browse the repository at this point in the history
  • Loading branch information
erykoff committed Apr 28, 2023
1 parent 60539f1 commit 49fe8d9
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
39 changes: 39 additions & 0 deletions decasu/region_mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import esutil
import time
from functools import lru_cache
from astropy.time import Time

import coord

Expand Down Expand Up @@ -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]

Expand Down Expand Up @@ -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):
Expand Down
3 changes: 3 additions & 0 deletions tests/configs/config_tilename.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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']
6 changes: 6 additions & 0 deletions tests/test_tilename.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit 49fe8d9

Please sign in to comment.