Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add mjd/fraction_of_year/fraction_of_day maps. #17

Merged
merged 1 commit into from
Dec 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading