-
Notifications
You must be signed in to change notification settings - Fork 5
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 function to add calibration exposures #55
Merged
Merged
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
1b724fe
add function to add calibration exposures
weaverba137 7db9010
make conversion function less sensitive to column order
weaverba137 559b8ef
check exposures.colnames
8eeffb8
don't modify input table
weaverba137 2c1e5ef
add monotonic tests
weaverba137 dc37bae
guarantee that the input is sorted by MJD
weaverba137 File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import unittest | ||
import numpy as np | ||
from astropy.table import Table, Column | ||
from ..util import add_calibration_exposures | ||
|
||
class TestUtil(unittest.TestCase): | ||
|
||
@classmethod | ||
def setUpClass(cls): | ||
pass | ||
|
||
@classmethod | ||
def tearDownClass(cls): | ||
pass | ||
|
||
def setUp(self): | ||
pass | ||
|
||
def tearDown(self): | ||
pass | ||
|
||
def test_add_calibration_exposures(self): | ||
exposures = Table() | ||
exposures['TILEID'] = Column(np.array([0, 1], dtype=np.int32)) | ||
exposures['PASS'] = Column(np.array([0, 0], dtype=np.int16)) | ||
exposures['RA'] = Column(np.array([0.0, 1.0], dtype=np.float64)) | ||
exposures['DEC'] = Column(np.array([0.0, 1.0], dtype=np.float64)) | ||
exposures['EBMV'] = Column(np.array([0.0, 1.0], dtype=np.float64)) | ||
exposures['NIGHT'] = Column(np.array(['20200101', '20200102'], dtype=(str, 8))) | ||
exposures['MJD'] = Column(np.array([0.0, 1.0], dtype=np.float64)) | ||
exposures['EXPTIME'] = Column(np.array([0.0, 1.0], dtype=np.float64), unit='s') | ||
exposures['SEEING'] = Column(np.array([0.0, 1.0], dtype=np.float64), unit='arcsec') | ||
exposures['TRANSPARENCY'] = Column(np.array([0.0, 1.0], dtype=np.float64)) | ||
exposures['AIRMASS'] = Column(np.array([0.0, 1.0], dtype=np.float64)) | ||
exposures['MOONFRAC'] = Column(np.array([0.0, 1.0], dtype=np.float64)) | ||
exposures['MOONALT'] = Column(np.array([0.0, 1.0], dtype=np.float64), unit='deg') | ||
exposures['MOONSEP'] = Column(np.array([0.0, 1.0], dtype=np.float64), unit='deg') | ||
exposures['PROGRAM'] = Column(np.array(['DARK', 'DARK'], dtype=(str, 6))) | ||
exposures['FLAVOR'] = Column(np.array(['science', 'science'], dtype=(str, 7))) | ||
output = add_calibration_exposures(exposures) | ||
self.assertEqual(len(output), 14) | ||
self.assertEqual('EXPID', output.colnames[0]) | ||
self.assertTrue(np.all(output['EXPID'] == np.arange(14, dtype=np.int32))) | ||
self.assertEqual(output['RA'].unit, 'deg') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
"""Simulation utilities that may be used by other packages. | ||
""" | ||
from __future__ import print_function, division, absolute_import | ||
import numpy as np | ||
from astropy.table import Column | ||
|
||
|
||
def add_calibration_exposures(exposures, arcs_per_night=3, flats_per_night=3): | ||
"""Adds calibration exposures to a set of science exposures and | ||
assigns exposure IDs. | ||
|
||
Parameters | ||
---------- | ||
exposures : :class:`astropy.table.Table` | ||
A table of science exposures, produced by *e.g.* | ||
``desisurvey.progress.Progress.get_exposures()``. | ||
arcs_per_night : :class:`int`, optional | ||
Add this many arc exposures per night (default 3). | ||
flats_per_night : :class:`int`, optional | ||
Add this many arc exposures per night (default 3). | ||
|
||
Returns | ||
------- | ||
:class:`astropy.table.Table` | ||
A table augmented with calibration exposures. | ||
""" | ||
if 'EXPID' not in exposures: | ||
expidc = Column(np.arange(len(exposures), dtype=np.int32), | ||
name='EXPID', description='Exposure ID') | ||
exposures.add_column(expidc, index=0) | ||
for c in ('RA', 'DEC'): | ||
if exposures[c].unit is None: | ||
exposures[c].unit = 'deg' | ||
output = exposures[:0].copy() | ||
current_night = '19730703' | ||
expid = 0 | ||
for i, night in enumerate(exposures['NIGHT']): | ||
if night != current_night: | ||
current_night = night | ||
for j in range(flats_per_night): | ||
output.add_row([expid, -1, -1, 0.0, 0.0, 0.0, night, | ||
0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, | ||
'NONE', 'flat']) | ||
expid += 1 | ||
for j in range(arcs_per_night): | ||
output.add_row([expid, -1, -1, 0.0, 0.0, 0.0, night, | ||
0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, | ||
'NONE', 'arc']) | ||
expid += 1 | ||
output.add_row(exposures[i]) | ||
output['EXPID'][expid] = expid | ||
expid += 1 | ||
return output |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This
add_row
logic makes me nervous because it is fragilely dependent upon exactly which columns exist and in what order they appear in the input exposures table, thus creating a tight coupling withdesisurvey.progress.Progress.get_exposures()
and making it harder to use outside of that context. How about callingadd_row
with a dict, where you have filled in the keys of the dict only for columns that actually exist in the inputexposures
table? If that suggestion doesn't make sense, ping me and I'll put together a code example that might be clearer.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm pretty sure I understand what you mean here, & that's reasonable.