Skip to content

Reader for matched-table catalog and config files for composite add-o… #393

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

Merged
merged 14 commits into from
Nov 6, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
10 changes: 10 additions & 0 deletions GCRCatalogs/catalog_configs/dc2_object_run2.1.1i_matched.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
subclass_name: dc2_matched_table.DC2MatchedTable
filename: '/global/projecta/projectdirs/lsst/groups/SSim/DC2/matched_ids_run2.1.1i_dpdd.fits.gz'
version: '2.1.1i'
truth_version: 'cosmoDC2_v1.1.4'
object_id: 'objectId'
truth_id: 'truthId'
match_flag: 'is_matched'
is_star: 'is_star'
creator: 'Javier Sanchez'
description: 'This is the table of matches between the object catalog and the extragalactic catalog'
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
subclass_name: composite.CompositeReader
description: DC2 Run 2.1.1i Object Catalog Matched Table addon catalog
creators: ['Javi Sanchez', 'Eve Kovacs']
catalogs:
- catalog_name: dc2_object_run2.1i_dr1
matching_method: objectId
- catalog_name: dc2_object_run2.1.1i_matched
matching_method: objectId
70 changes: 70 additions & 0 deletions GCRCatalogs/dc2_matched_table.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
"""
DC2 matched table reader

This reader was written by Eve Kovacs
based on a matching table provided by Javier Sanchez .
"""

import numpy as np
import numpy.ma as ma
from astropy.io import fits
from GCRCatalogs import BaseGenericCatalog

__all__ = ['DC2MatchedTable']

class DC2MatchedTable(BaseGenericCatalog):

def _subclass_init(self, **kwargs):

"""
DC2MatchedTable reader, inherited from BaseGenericCatalog class
"""
self._filename = kwargs.get('filename', None)
if not self._filename:
print('Filename for matching table required')
return
object_id = kwargs.get('object_id', 'objectId')
truth_id = kwargs.get('truth_id', 'truthId')
match_flag = kwargs.get('match_flag', 'is_matched')
is_star = kwargs.get('is_star', 'is_star')
self._version = kwargs.get('version', '')
self._truth_version = kwargs.get('truth_version', '')

# check matched table quantities
with fits.open(self._filename) as hdul:
cols = hdul[1].columns.names
if not object_id in cols or not match_flag in cols or not is_star in cols or not truth_id in cols:
print('Matching table does not have minimal expected columns')
return

self._galaxy_match_mask = (~hdul[1].data[is_star]) & (hdul[1].data[match_flag])
self._matched_galaxy_count = np.count_nonzero(self._galaxy_match_mask)
self._star_match_mask = (hdul[1].data[is_star]) & (hdul[1].data[match_flag])
self._matched_star_count = np.count_nonzero(self._star_match_mask)

# modify native quantities
self._quantity_modifiers = {}
modified_quantity_list = [c for c in cols if not is_star in c and not match_flag in c]
for q in modified_quantity_list:
self._quantity_modifiers[q + '_galaxy'] = (lambda x: x[self._galaxy_match_mask], q)
self._quantity_modifiers[q + '_star'] = (lambda x: x[self._star_match_mask], q)


def _generate_native_quantity_list(self):
"""
Return an iterable of all native quantity names.
"""
with fits.open(self._filename) as hdul:
return hdul[1].columns.names


def _iter_native_dataset(self, native_filters=None):
"""
Must yield a callable, *native_quantity_getter*.
Must return a numpy 1d array.
"""
assert not native_filters, '*native_filters* is not supported'
with fits.open(self._filename) as hdul:
def native_quantity_getter(native_quantity):
return hdul[1].data[native_quantity]
yield native_quantity_getter