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