-
Notifications
You must be signed in to change notification settings - Fork 19
/
dc2_source.py
125 lines (107 loc) · 4.52 KB
/
dc2_source.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
"""
DC2 Source Catalog Reader
"""
import os
import numpy as np
from .dc2_dm_catalog import DC2DMVisitCatalog, convert_flux_to_nanoJansky, create_basic_flag_mask
__all__ = ['DC2SourceCatalog']
class DC2SourceCatalog(DC2DMVisitCatalog):
r"""DC2 Source Catalog reader
Parameters
----------
base_dir (str): Directory of data files being served, required
filename_pattern (str): The optional regex pattern of served data files
use_cache (bool): Cache read data in memory
is_dpdd (bool): File are already in DPDD-format. No translation.
Attributes
----------
base_dir (str): The directory of data files being served
Notes
-----
"""
# pylint: disable=too-many-instance-attributes
FILE_DIR = os.path.dirname(os.path.abspath(__file__))
FILE_PATTERN = r'source_visit_\d+\.parquet$'
SCHEMA_FILENAME = 'schema.yaml'
META_PATH = os.path.join(FILE_DIR, 'catalog_configs/_dc2_source_meta.yaml')
@staticmethod
def _generate_modifiers(dm_schema_version=3, **kwargs):
"""Creates a dictionary relating native and homogenized column names
Args:
dm_schema_version (int): DM schema version (1, 2, or 3)
Returns:
A dictionary of the form {<homogenized name>: <native name>, ...}
"""
flux_name = 'flux' if dm_schema_version <= 2 else 'instFlux'
flux_err_name = 'Sigma' if dm_schema_version <= 1 else 'Err'
modifiers = {
'sourceId': 'id',
'visit': 'visit',
'detector': 'detector',
'filter': 'filter',
'objectId': 'objectId',
'parentObjectId': 'parent',
'ra': (np.rad2deg, 'coord_ra'),
'dec': (np.rad2deg, 'coord_dec'),
'x': 'slot_Centroid_x',
'y': 'slot_Centroid_y',
'xErr': 'slot_Centroid_x{}'.format(flux_err_name),
'yErr': 'slot_Centroid_y{}'.format(flux_err_name),
'xy_flag': 'slot_Centroid_flag',
'sky': (convert_flux_to_nanoJansky,
'base_LocalBackground_{}'.format(flux_name),
'fluxmag0'),
'skyErr': (convert_flux_to_nanoJansky,
'base_LocalBackground_{}{}'.format(flux_name, flux_err_name),
'fluxmag0'),
'sky_flag': 'base_LocalBackground_flag',
'I_flag': 'slot_Shape_flag',
'Ixx': 'slot_Shape_xx',
'IxxPSF': 'slot_PsfShape_xx',
'Iyy': 'slot_Shape_yy',
'IyyPSF': 'slot_PsfShape_yy',
'Ixy': 'slot_Shape_xy',
'IxyPSF': 'slot_PsfShape_xy',
'mag': 'mag',
'magerr': 'mag_err',
'fluxmag0': 'fluxmag0',
'apFlux': (convert_flux_to_nanoJansky,
'slot_ApFlux_{}'.format(flux_name),
'fluxmag0'),
'apFluxErr': (convert_flux_to_nanoJansky,
'slot_ApFlux_{}{}'.format(flux_name, flux_err_name),
'fluxmag0'),
'apFlux_flag': 'slot_ApFlux_flag',
'psFlux': (convert_flux_to_nanoJansky,
'slot_PsfFlux_{}'.format(flux_name),
'fluxmag0'),
'psFluxErr': (convert_flux_to_nanoJansky,
'slot_PsfFlux_{}{}'.format(flux_name, flux_err_name),
'fluxmag0'),
'psFlux_flag': 'slot_PsfFlux_flag',
'psNdata': 'slot_PsfFlux_area',
'psf_fwhm_pixels': (
lambda xx, yy, xy: 2.355 * (xx * yy - xy * xy) ** 0.25,
'slot_PsfShape_xx',
'slot_PsfShape_yy',
'slot_PsfShape_xy',
),
# There are no 'slot_*' values for the extendedness and blendedness
# in the Run 1.2i processing (as of 2019-03-05)
'extendedness': 'base_ClassificationExtendedness_value',
'blendedness': 'base_Blendedness_abs_{}'.format(flux_name),
}
not_good_flags = (
'base_PixelFlags_flag_edge',
'base_PixelFlags_flag_interpolatedCenter',
'base_PixelFlags_flag_saturatedCenter',
'base_PixelFlags_flag_crCenter',
'base_PixelFlags_flag_bad',
'base_PixelFlags_flag_suspectCenter',
)
modifiers['good'] = (create_basic_flag_mask,) + not_good_flags
modifiers['clean'] = (
create_basic_flag_mask,
'deblend_skipped',
) + not_good_flags
return modifiers