Skip to content

Commit 2406a09

Browse files
Merge pull request #9 from LSSTDESC/u/arunkannawadi/roman_pointsources
Allow for Roman fluxes (optionally) for point sources
2 parents ba341fc + 281a895 commit 2406a09

3 files changed

Lines changed: 52 additions & 25 deletions

File tree

‎.github/workflows/ci.yml‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,8 @@ jobs:
166166
python ${SCRIPTS}/create_main.py trilegal --skycatalog-root \
167167
${CI_DATA} --pixels $TRILEGAL_PIXEL
168168
python ${SCRIPTS}/create_flux.py --object-type trilegal \
169-
--skycatalog-root ${CI_DATA} --flux-parallel 24 --pixels $TRILEGAL_PIXEL
169+
--skycatalog-root ${CI_DATA} --flux-parallel 24 --pixels $TRILEGAL_PIXEL \
170+
--include-roman-flux
170171
pytest tests
171172
172173
# Clean up after running compare tests

‎skycatalogs_creator/flux_catalog_creator.py‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ def __init__(self, object_type, parts,
157157
self._include_roman_flux = include_roman_flux
158158
self._obs_sed_factory = None
159159
self._sso_creator = SsoFluxCatalogCreator(self)
160-
self._trilegal_creator = TrilegalFluxCatalogCreator(self)
160+
self._trilegal_creator = TrilegalFluxCatalogCreator(self, include_roman_flux=self._include_roman_flux)
161161
self._run_options = run_options
162162
self._tophat_sed_bins = None
163163
self._sed_gen = None
@@ -392,8 +392,10 @@ def create_pointsource_flux_catalog(self, config_file=None):
392392
throughputs_versions=thru_v)
393393

394394
self._ps_flux_schema = make_star_flux_schema(self._logname,
395+
include_roman_flux=self._include_roman_flux,
395396
metadata_input=file_metadata)
396397

398+
self._ps_flux_needed = [field.name for field in self._ps_flux_schema]
397399
self._flux_template = self._cat.raw_config['object_types']['star']['flux_file_template']
398400

399401
self._logger.info('Creating pointsource flux files')
@@ -433,7 +435,12 @@ def _create_pointsource_flux_pixel(self, pixel):
433435

434436
object_list = self._cat.get_object_type_by_hp(pixel, 'star')
435437
writer = None
436-
instrument_needed = ['lsst'] # for now
438+
instrument_needed = []
439+
for field in self._ps_flux_needed:
440+
if 'lsst' in field and 'lsst' not in instrument_needed:
441+
instrument_needed.append('lsst')
442+
if 'roman' in field and 'roman' not in instrument_needed:
443+
instrument_needed.append('roman')
437444
rg_written = 0
438445
fields_needed = self._ps_flux_schema.names
439446

‎skycatalogs_creator/trilegal_catalog_creator.py‎

Lines changed: 41 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@
1212
import json
1313
import galsim
1414
from skycatalogs.objects.base_object import LSST_BANDS, load_lsst_bandpasses
15+
from skycatalogs.objects.base_object import load_roman_bandpasses
1516
from skycatalogs.objects.trilegal_object import TrilegalConfigFragment
1617
from .utils.config_creator_utils import assemble_provenance
1718
from .utils.config_creator_utils import assemble_file_metadata
19+
from .utils.parquet_schema_utils import make_star_flux_schema
1820
from skycatalogs.utils.trilegal_utils import get_trilegal_hp_nrows
1921
from skycatalogs.utils.trilegal_utils import find_trilegal_subpixels
2022

@@ -254,14 +256,16 @@ def _do_trilegal_flux_chunk(send_conn, collection, instrument_needed,
254256
id = collection.get_native_attribute('id')
255257
imag = collection.get_native_attribute('imag')
256258
out_dict['id'] = id[l_bnd: u_bnd]
259+
260+
# Compute LSST fluxes
257261
fluxes = []
258262
sed_ix = 0
259263
for ix in range(l_bnd, u_bnd):
260264
obj_fluxes = []
261265
sed = seds[sed_ix]
262266

263267
if sed is None:
264-
obj_fluxes = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
268+
obj_fluxes = [0.0]*len(LSST_BANDS)
265269
else:
266270
# Apply extinction; calculate fluxes
267271
sed = extinguisher.extinguish(sed, av[ix])
@@ -277,6 +281,32 @@ def _do_trilegal_flux_chunk(send_conn, collection, instrument_needed,
277281
out_dict.update(flux_dict)
278282
del fluxes_transpose
279283

284+
# Compute Roman fluxes if requested
285+
if 'roman' in instrument_needed:
286+
roman_bandpasses = load_roman_bandpasses(include_all_bands=True)
287+
roman_fluxes = []
288+
sed_ix = 0
289+
for ix in range(l_bnd, u_bnd):
290+
obj_fluxes = []
291+
sed = seds[sed_ix]
292+
293+
if sed is None:
294+
obj_fluxes = [0.0] * len(roman_bandpasses)
295+
else:
296+
# Apply extinction; calculate Roman fluxes
297+
sed = extinguisher.extinguish(sed, av[ix])
298+
for band in roman_bandpasses:
299+
obj_fluxes.append(collection[ix].get_roman_flux(
300+
band, sed=sed, cache=False))
301+
roman_fluxes.append(obj_fluxes)
302+
sed_ix += 1
303+
304+
colnames = [f'roman_flux_{band}' for band in roman_bandpasses]
305+
roman_fluxes_transpose = zip(*roman_fluxes)
306+
roman_flux_dict = dict(zip(colnames, roman_fluxes_transpose))
307+
out_dict.update(roman_flux_dict)
308+
del roman_fluxes_transpose
309+
280310
if debug:
281311
now = datetime.now().isoformat()[:19]
282312
print(f'{now} Leaving _do_trilegal_flux_chunk, l_bnd={l_bnd}, row_group={row_group}', flush=True)
@@ -288,7 +318,7 @@ def _do_trilegal_flux_chunk(send_conn, collection, instrument_needed,
288318

289319

290320
class TrilegalFluxCatalogCreator:
291-
def __init__(self, catalog_creator):
321+
def __init__(self, catalog_creator, include_roman_flux=False):
292322
'''
293323
Parameters
294324
----------
@@ -297,28 +327,10 @@ def __init__(self, catalog_creator):
297327
self._catalog_creator = catalog_creator
298328
self._output_dir = catalog_creator._output_dir
299329
self._logger = catalog_creator._logger
330+
self._include_roman_flux = include_roman_flux
300331
global tri_lsst_bandpasses
301332
tri_lsst_bandpasses = load_lsst_bandpasses()
302333

303-
def _create_flux_schema(self, metadata_input=None,
304-
metadata_key='provenance'):
305-
# id and 6 flux fields (for now. Maybe later also Roman)
306-
fields = [
307-
pa.field('id', pa.string()),
308-
pa.field('lsst_flux_u', pa.float32(), True),
309-
pa.field('lsst_flux_g', pa.float32(), True),
310-
pa.field('lsst_flux_r', pa.float32(), True),
311-
pa.field('lsst_flux_i', pa.float32(), True),
312-
pa.field('lsst_flux_z', pa.float32(), True),
313-
pa.field('lsst_flux_y', pa.float32(), True)]
314-
if metadata_input:
315-
metadata_bytes = json.dumps(metadata_input).encode('utf8')
316-
final_metadata = {metadata_key: metadata_bytes}
317-
else:
318-
final_metadata = None
319-
320-
return pa.schema(fields, metadata=final_metadata)
321-
322334
def _create_trilegal_flux_pixel(self, pixel, arrow_schema):
323335
output_filename = f'trilegal_flux_{pixel}.parquet'
324336
output_path = os.path.join(self._catalog_creator._output_dir,
@@ -340,6 +352,9 @@ def _create_trilegal_flux_pixel(self, pixel, arrow_schema):
340352
writer = pq.ParquetWriter(output_path, arrow_schema)
341353

342354
instrument_needed = ['lsst']
355+
if self._include_roman_flux:
356+
instrument_needed.append('roman')
357+
343358
rg_written = 0
344359
writer = None
345360
fields_needed = arrow_schema.names
@@ -436,13 +451,17 @@ def create_trilegal_flux_catalog(self):
436451
self._main_template = trilegal_config['file_template']
437452

438453
thru_v = {'lsst_throughputs_version': self._cat._lsst_thru_v}
454+
if self._include_roman_flux:
455+
thru_v['roman_throughputs_version'] = self._cat._roman_thru_v
439456
file_metadata = assemble_file_metadata(
440457
self._catalog_creator._pkg_root,
441458
run_options=self._catalog_creator._run_options,
442459
flux_file=True,
443460
throughputs_versions=thru_v)
444461

445-
arrow_schema = self._create_flux_schema(metadata_input=file_metadata)
462+
arrow_schema = make_star_flux_schema(self._logger.name,
463+
include_roman_flux=self._include_roman_flux,
464+
metadata_input=file_metadata)
446465

447466
self._logger.info('Creating trilegal flux files')
448467

0 commit comments

Comments
 (0)