Skip to content

Commit

Permalink
Merge pull request #86 from LSSTDESC/sso_initial
Browse files Browse the repository at this point in the history
Sso initial
  • Loading branch information
JoanneBogart authored Mar 4, 2024
2 parents 5bf6d8c + 34dee33 commit 4be8699
Show file tree
Hide file tree
Showing 11 changed files with 819 additions and 179 deletions.
203 changes: 105 additions & 98 deletions cfg/object_types.yaml
Original file line number Diff line number Diff line change
@@ -1,102 +1,109 @@
# Yaml fragment to be incorporated into configs
object_types :
galaxy :
file_template : 'galaxy_(?P<healpix>\d+).parquet'
flux_file_template : 'galaxy_flux_(?P<healpix>\d+).parquet'
data_file_type : parquet
area_partition :
{ type: healpix, ordering : ring, nside : 32}
composite :
bulge : required
disk : required
knots : optional
attribute_aliases :
size_knots_true : size_disk_true
size_minor_knots_true : size_minor_disk_true
bulge_basic :
subtype : bulge
parent : galaxy
sed_model : tophat
internal_extinction : CCM
MW_extinction : F19
spatial_model : sersic2D
disk_basic :
subtype : disk
parent : galaxy
sed_model : tophat
internal_extinction : CCM
MW_extinction : F19
spatial_model : sersic2D
knots_basic :
subtype : knots
parent : galaxy
sed_model : tophat
internal_extinction : CCM
MW_extinction : F19
spatial_model : knots
diffsky_galaxy :
file_template : 'galaxy_(?P<healpix>\d+).parquet'
flux_file_template : 'galaxy_flux_(?P<healpix>\d+).parquet'
sed_file_template : 'galaxy_sed_(?P<healpix>\d+).hdf5'
data_file_type : parquet
area_partition :
{ type: healpix, ordering : ring, nside : 32}
composite :
bulge : required
disk : required
knots : optional
diffsky_bulge :
subtype : bulge
parent : diffsky_galaxy
sed_model : TBD
internal_extinction : CCM
MW_extinction : F19
spatial_model : sersic2D
diffsky_disk :
subtype : disk
parent : diffsky_galaxy
sed_model : TBD
internal_extinction : CCM
MW_extinction : F19
spatial_model : sersic2D
diffsky_knots :
subtype : knots
parent : diffsky_galaxy
sed_model : TBD
internal_extinction : CCM
MW_extinction : F19
spatial_model : knots
galaxy:
file_template: 'galaxy_(?P<healpix>\d+).parquet'
flux_file_template: 'galaxy_flux_(?P<healpix>\d+).parquet'
data_file_type: parquet
area_partition:
{ type: healpix, ordering: ring, nside: 32}
composite:
bulge: required
disk: required
knots: optional
attribute_aliases:
size_knots_true: size_disk_true
size_minor_knots_true: size_minor_disk_true
bulge_basic:
subtype: bulge
parent: galaxy
sed_model: tophat
internal_extinction: CCM
MW_extinction: F19
spatial_model: sersic2D
disk_basic:
subtype: disk
parent: galaxy
sed_model: tophat
internal_extinction: CCM
MW_extinction: F19
spatial_model: sersic2D
knots_basic:
subtype: knots
parent: galaxy
sed_model: tophat
internal_extinction: CCM
MW_extinction: F19
spatial_model: knots
diffsky_galaxy:
file_template: 'galaxy_(?P<healpix>\d+).parquet'
flux_file_template: 'galaxy_flux_(?P<healpix>\d+).parquet'
sed_file_template: 'galaxy_sed_(?P<healpix>\d+).hdf5'
data_file_type: parquet
area_partition:
{ type: healpix, ordering: ring, nside: 32}
composite:
bulge: required
disk : required
knots: optional
diffsky_bulge:
subtype: bulge
parent: diffsky_galaxy
sed_model: TBD
internal_extinction: CCM
MW_extinction: F19
spatial_model: sersic2D
diffsky_disk:
subtype: disk
parent: diffsky_galaxy
sed_model: TBD
internal_extinction: CCM
MW_extinction: F19
spatial_model: sersic2D
diffsky_knots:
subtype: knots
parent: diffsky_galaxy
sed_model: TBD
internal_extinction: CCM
MW_extinction: F19
spatial_model: knots

star :
file_template : 'pointsource_(?P<healpix>\d+).parquet'
flux_file_template : 'pointsource_flux_(?P<healpix>\d+).parquet'
data_file_type : parquet
area_partition :
{ type: healpix, ordering : ring, nside : 32}
sed_model : file_nm
sed_file_root_env_var : SIMS_SED_LIBRARY_DIR
MW_extinction : F19
internal_extinction : None
sncosmo :
file_template : 'pointsource_(?P<healpix>\d+).parquet'
data_file_type : parquet
area_partition :
{ type: healpix, ordering : ring, nside : 32}
star:
file_template: 'pointsource_(?P<healpix>\d+).parquet'
flux_file_template: 'pointsource_flux_(?P<healpix>\d+).parquet'
data_file_type: parquet
area_partition:
{ type: healpix, ordering: ring, nside: 32}
sed_model: file_nm
sed_file_root_env_var: SIMS_SED_LIBRARY_DIR
MW_extinction: F19
internal_extinction: None
sncosmo:
file_template: 'pointsource_(?P<healpix>\d+).parquet'
data_file_type: parquet
area_partition:
{ type: healpix, ordering: ring, nside: 32}

sed_model : sncosmo
MW_extinction : F19
internal_extinction : None
gaia_star :
data_file_type : butler_refcat
butler_parameters :
collections : HSC/defaults
dstype : gaia_dr2_20200414
area_partition : None
sed_method : use_lut
snana :
file_template : 'snana_(?P<healpix>\d+).parquet'
data_file_type : parquet
area_partition :
{ type: healpix, ordering : ring, nside : 32}
sed_model : snana
internal_extinction : None
sed_model: sncosmo
MW_extinction: F19
internal_extinction: None
gaia_star:
data_file_type: butler_refcat
butler_parameters:
collections: HSC/defaults
dstype: gaia_dr2_20200414
area_partition: None
sed_method: use_lut
snana:
file_template: 'snana_(?P<healpix>\d+).parquet'
data_file_type: parquet
area_partition:
{ type: healpix, ordering: ring, nside: 32}
sed_model: snana
internal_extinction: None
sso:
file_template: 'sso_(?P<healpix>\d+).parquet'
flux_file_template: 'sso_flux_(?P<healpix>\d+).parquet'
data_file_type: parquet
area_partition:
{ type: healpix, ordering: ring, nside: 32}
sed_model: dbfile_angstrom_flambda
26 changes: 23 additions & 3 deletions skycatalogs/catalog_creator.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from .utils.creator_utils import make_MW_extinction_av, make_MW_extinction_rv
from .objects.base_object import LSST_BANDS
from .objects.base_object import ROMAN_BANDS
from .sso_catalog_creator import SsoCatalogCreator

"""
Code to create a sky catalog for particular object types
Expand Down Expand Up @@ -197,7 +198,8 @@ def __init__(self, parts, area_partition=None, skycatalog_root=None,
no_flux=False, flux_parallel=16, galaxy_nside=32,
galaxy_stride=1000000, provenance=None,
dc2=False, sn_object_type='sncosmo', galaxy_type='cosmodc2',
include_roman_flux=False, star_input_fmt='sqlite'):
include_roman_flux=False, star_input_fmt='sqlite',
sso_truth=None, sso_sed=None, sso_partition='healpixel'):
"""
Store context for catalog creation
Expand Down Expand Up @@ -244,6 +246,9 @@ def __init__(self, parts, area_partition=None, skycatalog_root=None,
galaxy_type Currently allowed values are cosmodc2 and diffsky
include_roman_flux Calculate and write Roman flux values
star_input_fmt May be either 'sqlite' or 'parquet'
sso_truth Directory containing Sorcha output
sso_sed Path to sed file to be used for all SSOs
sso_partition Whether to partition by time or by healpixels
Might want to add a way to specify template for output file name
and template for input sedLookup file name.
Expand Down Expand Up @@ -291,6 +296,7 @@ def __init__(self, parts, area_partition=None, skycatalog_root=None,
self._star_truth = _star_db
elif self._star_input_fmt == 'parquet':
self._star_truth = _star_parquet

self._cat = None

self._parts = parts
Expand Down Expand Up @@ -326,6 +332,11 @@ def __init__(self, parts, area_partition=None, skycatalog_root=None,
self._dc2 = dc2
self._include_roman_flux = include_roman_flux
self._obs_sed_factory = None
self._sso_sed_factory = None # do we need this?
self._sso_creator = SsoCatalogCreator(self, sso_truth, sso_sed)
self._sso_truth = self._sso_creator.sso_truth
self._sso_sed = self._sso_creator.sso_sed
self._sso_partition = sso_partition

def _make_tophat_columns(self, dat, names, cmp):
'''
Expand Down Expand Up @@ -357,8 +368,8 @@ def create(self, catalog_type):
Parameters
----------
catalog_type string Currently 'galaxy' and 'pointsource' are
the only values allowed
catalog_type string Currently 'galaxy', 'pointsource'
and 'sso' are the only values allowed
Return
------
None
Expand All @@ -373,6 +384,12 @@ def create(self, catalog_type):
self.create_pointsource_catalog()
if not self._no_flux:
self.create_pointsource_flux_catalog()
elif catalog_type == ('sso'):
if not self._flux_only:
self._sso_creator.create_sso_catalog()
if not self._main_only:
self._sso_creator.create_sso_flux_catalog()

else:
raise NotImplementedError(f'CatalogCreator.create: unsupported catalog type {catalog_type}')

Expand Down Expand Up @@ -1081,6 +1098,9 @@ def write_config(self, overwrite=False, path_only=False):
inputs['sn_truth'] = self._sn_truth
if self._star_truth:
inputs['star_truth'] = self._star_truth
if self._sso_truth:
inputs['sso_truth'] = self._sso_truth
inputs['sso_sed'] = self._sso_sed
config.add_key('provenance', assemble_provenance(self._pkg_root,
inputs=inputs))

Expand Down
17 changes: 13 additions & 4 deletions skycatalogs/objects/base_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ def _get_sed_from_file(self, fpath, redshift=0):
sed = sed.atRedshift(redshift)
return sed

def get_gsobject_components(self, gsparams=None, rng=None):
def get_gsobject_components(self, gsparams=None, rng=None, exposure=None):
"""
Return a dictionary of the GSObject components for the
sky catalogs object, keyed by component name.
Expand Down Expand Up @@ -570,7 +570,10 @@ def __contains__(self, obj):
return id in self._id

def __len__(self):
return len(self._id)
if self._id is not None:
return len(self._id)
else:
return 0

# def __iter__(self): Standard impl based on __getitem__ should be ok
# def __reversed__(self): Default implementation ok
Expand Down Expand Up @@ -654,8 +657,14 @@ def __init__(self):

def append_collection(self, coll):
old = self._total_len
self._total_len += len(coll)
self._located.append(LocatedCollection(coll, old, self._total_len))
if isinstance(coll, ObjectCollection):
self._total_len += len(coll)
self._located.append(LocatedCollection(coll, old, self._total_len))
else: # list of collections
for c in coll:
self._total_len += len(c)
self._located.append(LocatedCollection(c, old, self._total_len))
old = self._total_len

def append_object_list(self, object_list):
for e in object_list._located:
Expand Down
8 changes: 5 additions & 3 deletions skycatalogs/objects/gaia_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,11 @@ def load_collection(region, skycatalog, mjd=None):
rv1 = np.zeros(len(df))
epNa = 2400000.5 # "part A" of starting and ending epochs for MJDs.
ep2b = mjd
pm_outputs = erfa.pmsafe(df['coord_ra'], df['coord_dec'],
df['pm_ra'], df['pm_dec'], df['parallax'],
rv1, epNa, df['epoch'], epNa, ep2b)
pm_outputs = erfa.pmsafe(np.array(df['coord_ra']),
np.array(df['coord_dec']),
np.array(df['pm_ra']), np.array(df['pm_dec']),
np.array(df['parallax']),
rv1, epNa, np.array(df['epoch']), epNa, ep2b)
# Update ra, dec values.
df['coord_ra'] = pm_outputs[0]
df['coord_dec'] = pm_outputs[1]
Expand Down
2 changes: 1 addition & 1 deletion skycatalogs/objects/snana_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def get_observer_sed_component(self, component, mjd=None):
if mjd is None:
mjd = self._belongs_to._mjd
if mjd is None:
txt = 'SnananObject._get_sed: no mjd specified for this call\n'
txt = 'SnananObject.get_observer_sed_component: no mjd specified for this call\n'
txt += 'nor when generating object list'
raise ValueError(txt)
sed, _ = self._get_sed(mjd=mjd)
Expand Down
Loading

0 comments on commit 4be8699

Please sign in to comment.