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

Sso initial #86

Merged
merged 32 commits into from
Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes from 30 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
8163bd6
add optional exposure argument in lots of places
JoanneBogart Jan 22, 2024
befcc3e
Create a single "main" skyCatalogs file for sso
JoanneBogart Jan 24, 2024
3a87b5e
add sso object type to standard output config
JoanneBogart Jan 24, 2024
7c91076
some progress on API, flux file creation. Also cosmetic changes for f…
JoanneBogart Jan 25, 2024
7d32822
exposure parameter is only needed for get_gsobject_components
JoanneBogart Jan 25, 2024
6b051e7
erfa.pmsafe did not like mixture of dataframe columns and np arrays
JoanneBogart Jan 26, 2024
f099e62
implement creation of sso flux files (so far largely untested)
JoanneBogart Jan 29, 2024
d095b89
various bug fixes for sso support, mostly trivial
JoanneBogart Jan 30, 2024
b55fe63
Can create flux file; contents need to be validated
JoanneBogart Jan 30, 2024
7a0cfab
save sso file data correctly
JoanneBogart Jan 30, 2024
605f0d4
partition by hp, not time
JoanneBogart Feb 7, 2024
33f017b
able to make flux files partitioned by hp
JoanneBogart Feb 8, 2024
52e1c65
partition by hp; eliminate unneeded sso-specific code
JoanneBogart Feb 8, 2024
53dd077
Bug fix for sso in get_object_type_by_hp
JoanneBogart Feb 9, 2024
f886e94
extra check for empty ObjectCollection
JoanneBogart Feb 9, 2024
e3b5aaa
option to simulate sso streaks
JoanneBogart Feb 14, 2024
878d214
better way to find arc length of chord
JoanneBogart Feb 14, 2024
b84068e
use latest Sorcha output for default sso trruth
JoanneBogart Feb 15, 2024
d282137
Allow creation of SSO catalogs for specified healpixels as well as fo…
JoanneBogart Feb 18, 2024
37c4b71
adjustment for changed field name in Sorcha output
JoanneBogart Feb 18, 2024
500e1a2
assume ra rate of change from Sorcha catalog has incorporate cos(dec)
JoanneBogart Feb 18, 2024
59bf447
parallelize flux computation
JoanneBogart Feb 21, 2024
b316e21
make latest Sorcha output our default input
JoanneBogart Feb 21, 2024
31af3da
handle very small input SSO files
JoanneBogart Feb 21, 2024
bad041f
window for SSO mjd match now is exposure interval
JoanneBogart Mar 1, 2024
d5f761b
address reviewer comments
JoanneBogart Mar 3, 2024
5376376
continue addressing reviewer comments
JoanneBogart Mar 3, 2024
e74473f
make docstring consistent with call interface
JoanneBogart Mar 3, 2024
192d626
avoid conflict with main branch
JoanneBogart Mar 3, 2024
11793bd
Merge branch 'main' into sso_initial
JoanneBogart Mar 3, 2024
d02844d
Let galsim simplify SED-with-magnitude calculation
JoanneBogart Mar 4, 2024
34dee33
reinstate inadvertantly deleted line
JoanneBogart Mar 4, 2024
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
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
Loading