62def createFootprintsTable(catalog, xy0=None, insertColumn=4):
63 """make a VOTable of SourceData table and footprints
64
65 Parameters:
66 -----------
67 catalog : `lsst.afw.table.SourceCatalog`
68 Source catalog from which to display footprints.
69 xy0 : tuple or list or None
70 Pixel origin to subtract off from the footprint coordinates.
71 If None, the value used is (0,0)
72 insertColumn : `int`
73 Column at which to insert the "family_id" and "category" columns
74
75 Returns:
76 --------
77 `astropy.io.votable.voTableFile`
78 VOTable object to upload to Firefly
79 """
80 if xy0 is None:
82
84 _catalog.extend(catalog, deep=True)
85 sourceTable = _catalog.asAstropy()
86
87
88 for colName in sourceTable.colnames:
89 if sourceTable[colName].dtype.num == 9:
90 sourceTable[colName].dtype = np.dtype('long')
91
92 inputColumnNames = sourceTable.colnames
93
94 x0, y0 = xy0
95 spanList = []
96 peakList = []
97 familyList = []
98 categoryList = []
99 fpxll = []
100 fpyll = []
101 fpxur = []
102 fpyur = []
103 for record in catalog:
104 footprint = record.getFootprint()
105 recordId = record.getId()
106 spans = footprint.getSpans()
107 scoords = [(s.getY()-y0, s.getX0()-x0, s.getX1()-x0) for s in spans]
108 scoords = np.array(scoords).flatten()
109 scoords = np.ma.MaskedArray(scoords, mask=np.zeros(len(scoords),
110 dtype=np.bool))
111 fpbbox = footprint.getBBox()
112 corners = [(c.getX()-x0, c.getY()-y0) for c in fpbbox.getCorners()]
113 fpxll.append(corners[0][0])
114 fpyll.append(corners[0][1])
115 fpxur.append(corners[2][0])
116 fpyur.append(corners[2][1])
117 peaks = footprint.getPeaks()
118 pcoords = [(p.getFx()-x0, p.getFy()-y0) for p in peaks]
119 pcoords = np.array(pcoords).flatten()
120 pcoords = np.ma.MaskedArray(pcoords, mask=np.zeros(len(pcoords),
121 dtype=np.bool))
122 fpbbox = footprint.getBBox()
123 parentId = record.getParent()
124 nChild = record.get('deblend_nChild')
125 if parentId == 0:
126 familyList.append(recordId)
127 if nChild > 0:
128
129 categoryList.append('blended parent')
130 else:
131
132 categoryList.append('isolated')
133 else:
134
135 familyList.append(parentId)
136 categoryList.append('deblended child')
137 spanList.append(scoords)
138 peakList.append(pcoords)
139
140 sourceTable.add_column(Column(np.array(familyList)),
141 name='family_id',
142 index=insertColumn)
143 sourceTable.add_column(Column(np.array(categoryList)),
144 name='category',
145 index=insertColumn+1)
146 sourceTable.add_column(Column(np.array(spanList)), name='spans')
147 sourceTable.add_column(Column(np.array(peakList)), name='peaks')
148 sourceTable.add_column(Column(np.array(fpxll)), name='footprint_corner1_x')
149 sourceTable.add_column(Column(np.array(fpyll)), name='footprint_corner1_y')
150 sourceTable.add_column(Column(np.array(fpxur)), name='footprint_corner2_x')
151 sourceTable.add_column(Column(np.array(fpyur)), name='footprint_corner2_y')
152
153 outputVO = from_table(sourceTable)
154 outTable = outputVO.get_first_table()
155
156 outTable.infos.append(Info(name='contains_lsst_footprints', value='true'))
157 outTable.infos.append(Info(name='contains_lsst_measurements', value='true'))
158 outTable.infos.append(Info(name='FootPrintColumnNames',
159 value='id;footprint_corner1_x;footprint_corner1_y;' +
160 'footprint_corner2_x;footprint_corner2_y;spans;peaks'))
161 outTable.infos.append(Info(name='pixelsys', value='zero-based'))
162
163 if (('slot_Centroid_x' in inputColumnNames) and
164 ('slot_Centroid_y' in inputColumnNames) and
165 np.isfinite(outTable.array['slot_Centroid_x']).any() and
166 np.isfinite(outTable.array['slot_Centroid_y']).any()):
167 coord_column_string = 'slot_Centroid_x;slot_Centroid_y;ZERO_BASED'
168 elif (('coord_ra' in inputColumnNames) and
169 ('coord_dec' in inputColumnNames) and
170 np.isfinite(outTable.array['coord_ra']).any() and
171 np.isfinite(outTable.array['coord_dec']).any()):
172 coord_column_string = 'coord_ra;coord_dec;EQ_J2000'
173 elif (('base_SdssCentroid_x' in inputColumnNames) and
174 ('base_SdssCentroid_y' in inputColumnNames) and
175 np.isfinite(outTable.array['base_SdssCentroid_x']).any() and
176 np.isfinite(outTable.array['base_SdssCentroid_y']).any()):
177 coord_column_string = 'base_SdssCentroid_x;base_SdssCentroid_y;ZERO_BASED'
178 else:
179 raise RuntimeError('No valid coordinate columns in catalog')
180 outTable.infos.append(Info(name='CatalogCoordColumns',
181 value=coord_column_string))
182
183 for f in outTable.fields:
184 if f.datatype == 'bit':
185 f.datatype = 'boolean'
186
187 outTable._config['version_1_3_or_later'] = True
188 outputVO.set_all_tables_format('binary2')
189
190 return outputVO