Skip to content

Commit

Permalink
Merge pull request #20 from lsst-dm/transform_update
Browse files Browse the repository at this point in the history
update to include gaiaXp_u
  • Loading branch information
psferguson authored Jul 15, 2024
2 parents ae8b307 + 2302f72 commit 3b4c0e0
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 31 deletions.
27 changes: 14 additions & 13 deletions python/lsst/the/monster/isolate_and_transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from lsst.pipe.tasks.isolatedStarAssociation import IsolatedStarAssociationTask
from .splinecolorterms import ColortermSpline
from .refcats import GaiaXPInfo, GaiaDR3Info, SkyMapperInfo, PS1Info, VSTInfo, DESInfo
from .refcats import GaiaXPInfo, GaiaDR3Info, SkyMapperInfo, PS1Info, VSTInfo, DESInfo, GaiaXPuInfo
from .utils import read_stars, makeRefSchema, makeRefCat

__all__ = ["MatchAndTransform"]
Expand Down Expand Up @@ -42,7 +42,8 @@ class MatchAndTransform:
def __init__(self,
gaia_reference_class=GaiaDR3Info,
catalog_info_class_list=[GaiaXPInfo, SkyMapperInfo,
PS1Info, VSTInfo, DESInfo],
PS1Info, VSTInfo, DESInfo,
GaiaXPuInfo],
transformed_path_inp=None,
testing_mode=False,
):
Expand Down Expand Up @@ -81,10 +82,10 @@ def run(self,
# cat_info = self.CatInfoClass() e.g. gaia cat

# output columns are target catalog id, gaia id, coordinates,
# and the des fluxes
# and the des (or sdss for u-band) fluxes
outcols = ["id", self.gaia_reference_info.name + "_id", "coord_ra", "coord_dec"]
outcols += [f"decam_{band}_from_{cat_info.name}_flux" for band in cat_info.bands]
outcols += [f"decam_{band}_from_{cat_info.name}_fluxErr" for band in cat_info.bands]
outcols += [cat_info.get_transformed_flux_field(band) for band in cat_info.bands]
outcols += [cat_info.get_transformed_flux_field(band) + "Err" for band in cat_info.bands]

# read in star cat (if it exists)
if os.path.isfile(cat_info.path+'/'+str(htmid)+'.fits'):
Expand All @@ -111,7 +112,7 @@ def run(self,
# apply colorterms to transform to des mag
band_1, band_2 = cat_info.get_color_bands(band)
orig_flux = cat_stars[cat_info.get_flux_field(band)]
orig_flux_err = cat_stars[cat_info.get_flux_field(band)+'Err']
orig_flux_err = cat_stars[cat_info.get_flux_field(band) + 'Err']
model_flux = colorterm_spline.apply(
cat_stars[cat_info.get_flux_field(band_1)],
cat_stars[cat_info.get_flux_field(band_2)],
Expand All @@ -123,21 +124,21 @@ def run(self,

# Append the modeled flux columns to cat_stars
cat_stars.add_column(model_flux,
name=f"decam_{band}_from_{cat_info.name}_flux")
name=cat_info.get_transformed_flux_field(band))
cat_stars.add_column(model_flux_err,
name=f"decam_{band}_from_{cat_info.name}_fluxErr")
name=cat_info.get_transformed_flux_field(band) + 'Err')

# Apply selection to ensure that only useful stars have
# transformations.
selected = cat_info.select_stars(cat_stars, band)
cat_stars[f"decam_{band}_from_{cat_info.name}_flux"][~selected] = np.nan
cat_stars[f"decam_{band}_from_{cat_info.name}_fluxErr"][~selected] = np.nan
cat_stars[cat_info.get_transformed_flux_field(band)][~selected] = np.nan
cat_stars[cat_info.get_transformed_flux_field(band) + 'Err'][~selected] = np.nan

# If any stars are nans in all transformed filters, they should
# be removed.
n_measurements = np.zeros(len(cat_stars))
for band in cat_info.bands:
n_measurements[np.isfinite(cat_stars[f"decam_{band}_from_{cat_info.name}_flux"])] += 1
n_measurements[np.isfinite(cat_stars[cat_info.get_transformed_flux_field(band)])] += 1
cat_stars = cat_stars[n_measurements > 0]

if self.transformed_path_inp is None:
Expand All @@ -150,10 +151,10 @@ def run(self,
output_file = os.path.join(transformed_path, f"{htmid}.fits")

# Convert the refcat to a SimpleCatalog
refSchema = makeRefSchema(cat_info.name, cat_info.bands,
refSchema = makeRefSchema(cat_info,
self.gaia_reference_info.name)
refCat = makeRefCat(refSchema, cat_stars[outcols],
cat_info.name, cat_info.bands,
cat_info,
self.gaia_reference_info.name)

# Save the shard to FITS.
Expand Down
10 changes: 10 additions & 0 deletions python/lsst/the/monster/refcats.py
Original file line number Diff line number Diff line change
Expand Up @@ -628,6 +628,8 @@ def get_imz_color_range(self):
class GaiaXPuInfo(GaiaXPInfo):
FLAG = 64
NAME = "GaiaXPu"
bands = ["u"]
TRANSFORMED_PATH = "/sdf/data/rubin/shared/the_monster/sharded_refcats/gaia_xp_u_20240116_transformed"

def get_flux_field(self, band):
return f"Sdss_flux_{band}_flux"
Expand All @@ -647,6 +649,14 @@ def colorterm_file(self, band):

return filename

def get_transformed_flux_field(self, band):
"""for u band internal bandpass is sdss
"""
if band != "u":
raise NotImplementedError(f"{self.NAME} should only be used with u-band, not band={band}")

return f"sdss_{band}_from_{self.NAME}_flux"


class SDSSInfo(RefcatInfo):
PATH = "/sdf/data/rubin/shared/the_monster/sharded_refcats/sdss_16_standards_20221205"
Expand Down
45 changes: 27 additions & 18 deletions python/lsst/the/monster/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,15 @@ def read_stars(path, indices, allow_missing=False):
return stars


def makeRefSchema(survey, bands, reference_name):
def makeRefSchema(cat_info, reference_name):
"""
Make the refcat schema
Parameters
----------
survey : `str`
Name of the survey whose refcat we are writing
bands : `List` of `str`
Names of the bands in the refcat
cat_info : `RefcatInfo`
Reference catalog information for the
refcat we are writing
reference_name : `str`
Name of the overall reference catalog
Expand All @@ -80,20 +79,31 @@ def makeRefSchema(survey, bands, reference_name):
refSchema = afwTable.SimpleTable.makeMinimalSchema()
refSchema.addField(reference_name+'_id', type='L', doc='Gaia DR3 ID')

for band in bands:
colname = 'decam_'+band+'_from_'+survey+'_flux'
colname_err = colname+'Err'
for band in cat_info.bands:
# use cat info class to get transformed flux field name
colname = cat_info.get_transformed_flux_field(band)
colname_err = colname + 'Err'

# check which internal bandpass is used
# this should be decam for everything except for u band
if 'decam_' in colname:
target_system = 'DECam'
elif 'sdss_' in colname:
target_system = 'SDSS'
else:
raise ValueError(f"Unknown target system for band {band}")

refSchema.addField(colname, type='D',
doc='flux transformed to DECam system',
doc=f'flux transformed to {target_system} system',
units='nJy')
refSchema.addField(colname_err, type='D',
doc='error on flux transformed to DECam system',
doc=f'error on flux transformed to {target_system} system',
units='nJy')

return refSchema


def makeRefCat(refSchema, refTable, survey, bands, reference_name):
def makeRefCat(refSchema, refTable, cat_info, reference_name):
"""
Make the standard star catalog for persistence
Expand All @@ -103,10 +113,9 @@ def makeRefCat(refSchema, refTable, survey, bands, reference_name):
Standard star catalog schema
refTable: `Astropy Table`
Reference catalog to convert
survey : `str`
Name of the survey whose refcat we are writing
bands : `List` of `str`
Names of the bands in the refcat
cat_info : `RefcatInfo`
Reference catalog information for the
refcat we are writing
reference_name : `str`
Name of the overall reference catalog
Expand All @@ -124,9 +133,9 @@ def makeRefCat(refSchema, refTable, survey, bands, reference_name):
refCat['coord_ra'][:] = np.deg2rad(refTable['coord_ra'])
refCat['coord_dec'][:] = np.deg2rad(refTable['coord_dec'])

for band in bands:
colname = 'decam_'+band+'_from_'+survey+'_flux'
colname_err = colname+'Err'
for band in cat_info.bands:
colname = cat_info.get_transformed_flux_field(band)
colname_err = colname + 'Err'
refCat[colname][:] = refTable[colname]
refCat[colname_err][:] = refTable[colname_err]

Expand Down

0 comments on commit 3b4c0e0

Please sign in to comment.