LSSTApplications  16.0-10-g0ee56ad+5,16.0-11-ga33d1f2+5,16.0-12-g3ef5c14+3,16.0-12-g71e5ef5+18,16.0-12-gbdf3636+3,16.0-13-g118c103+3,16.0-13-g8f68b0a+3,16.0-15-gbf5c1cb+4,16.0-16-gfd17674+3,16.0-17-g7c01f5c+3,16.0-18-g0a50484+1,16.0-20-ga20f992+8,16.0-21-g0e05fd4+6,16.0-21-g15e2d33+4,16.0-22-g62d8060+4,16.0-22-g847a80f+4,16.0-25-gf00d9b8+1,16.0-28-g3990c221+4,16.0-3-gf928089+3,16.0-32-g88a4f23+5,16.0-34-gd7987ad+3,16.0-37-gc7333cb+2,16.0-4-g10fc685+2,16.0-4-g18f3627+26,16.0-4-g5f3a788+26,16.0-5-gaf5c3d7+4,16.0-5-gcc1f4bb+1,16.0-6-g3b92700+4,16.0-6-g4412fcd+3,16.0-6-g7235603+4,16.0-69-g2562ce1b+2,16.0-8-g14ebd58+4,16.0-8-g2df868b+1,16.0-8-g4cec79c+6,16.0-8-gadf6c7a+1,16.0-8-gfc7ad86,16.0-82-g59ec2a54a+1,16.0-9-g5400cdc+2,16.0-9-ge6233d7+5,master-g2880f2d8cf+3,v17.0.rc1
LSSTDataManagementBasePackage
Functions
lsst.jointcal.testUtils Namespace Reference

Functions

def createTwoFakeCcdImages (num1=4, num2=4, seed=100, fakeCcdId=12, photoCalibMean1=1e-2, photoCalibMean2=1.2e-2)
 
def createFakeCcdImage (butler, visit, num, fluxFieldName, photoCalibMean=1e-2, photoCalibErr=1.0, fakeCcdId=12)
 
def createFakeCatalog (num, bbox, fluxFieldName, skyWcs=None, refCat=False)
 
def fillCatalog (schema, num, bbox, centroidKey, xErrKey, yErrKey, shapeKey, fluxFieldName, skyWcs=None, fluxErrFraction=0.05, refCat=False)
 
def getMeasuredStarsFromCatalog (catalog, pixToFocal)
 

Function Documentation

◆ createFakeCatalog()

def lsst.jointcal.testUtils.createFakeCatalog (   num,
  bbox,
  fluxFieldName,
  skyWcs = None,
  refCat = False 
)
Return a fake minimally-useful catalog for jointcal.

Parameters
----------
num : `int`
    Number of sources to put in the catalogs. Should be
    a square, to have sqrt(num) centroids on a grid.
bbox : `lsst.afw.geom.Box2I`
    Bounding Box of the detector to populate.
fluxFieldName : `str`
    Name of the flux field to populate in the catalog, without `_instFlux`
    (e.g. "slot_CalibFlux").
skyWcs : `lsst.afw.geom.SkyWcs` or None, optional
    If supplied, use this to fill in coordinates from centroids.
refCat : `bool`, optional
    Return a ``SimpleCatalog`` so that it behaves like a reference catalog?

Returns
-------
catalog : `lsst.afw.table.SourceCatalog`
    A populated source catalog.

Definition at line 154 of file testUtils.py.

154 def createFakeCatalog(num, bbox, fluxFieldName, skyWcs=None, refCat=False):
155  """Return a fake minimally-useful catalog for jointcal.
156 
157  Parameters
158  ----------
159  num : `int`
160  Number of sources to put in the catalogs. Should be
161  a square, to have sqrt(num) centroids on a grid.
162  bbox : `lsst.afw.geom.Box2I`
163  Bounding Box of the detector to populate.
164  fluxFieldName : `str`
165  Name of the flux field to populate in the catalog, without `_instFlux`
166  (e.g. "slot_CalibFlux").
167  skyWcs : `lsst.afw.geom.SkyWcs` or None, optional
168  If supplied, use this to fill in coordinates from centroids.
169  refCat : `bool`, optional
170  Return a ``SimpleCatalog`` so that it behaves like a reference catalog?
171 
172  Returns
173  -------
174  catalog : `lsst.afw.table.SourceCatalog`
175  A populated source catalog.
176  """
178  # centroid
179  centroidKey = lsst.afw.table.Point2DKey.addFields(schema, "centroid", "centroid", "pixels")
180  xErrKey = schema.addField("centroid_xErr", type="F")
181  yErrKey = schema.addField("centroid_yErr", type="F")
182  # shape
183  shapeKey = lsst.afw.table.QuadrupoleKey.addFields(schema, "shape", "",
184  lsst.afw.table.CoordinateType.PIXEL)
185  # Put the fake sources in the minimal catalog.
186  schema.addField(fluxFieldName+"_instFlux", type="D", doc="post-ISR instFlux")
187  schema.addField(fluxFieldName+"_instFluxErr", type="D", doc="post-ISR instFlux stddev")
188  schema.addField(fluxFieldName+"_flux", type="D", doc="source flux (nJy)")
189  schema.addField(fluxFieldName+"_fluxErr", type="D", doc="flux stddev (nJy)")
190  schema.addField(fluxFieldName+"_mag", type="D", doc="magnitude")
191  schema.addField(fluxFieldName+"_magErr", type="D", doc="magnitude stddev")
192  return fillCatalog(schema, num, bbox,
193  centroidKey, xErrKey, yErrKey, shapeKey, fluxFieldName,
194  skyWcs=skyWcs, refCat=refCat)
195 
196 
def createFakeCatalog(num, bbox, fluxFieldName, skyWcs=None, refCat=False)
Definition: testUtils.py:154
def fillCatalog(schema, num, bbox, centroidKey, xErrKey, yErrKey, shapeKey, fluxFieldName, skyWcs=None, fluxErrFraction=0.05, refCat=False)
Definition: testUtils.py:199
static QuadrupoleKey addFields(Schema &schema, std::string const &name, std::string const &doc, CoordinateType coordType=CoordinateType::PIXEL)
Add a set of quadrupole subfields to a schema and return a QuadrupoleKey that points to them...
Definition: aggregates.cc:100
static Schema makeMinimalSchema()
Return a minimal schema for Source tables and records.
Definition: Source.h:250

◆ createFakeCcdImage()

def lsst.jointcal.testUtils.createFakeCcdImage (   butler,
  visit,
  num,
  fluxFieldName,
  photoCalibMean = 1e-2,
  photoCalibErr = 1.0,
  fakeCcdId = 12 
)
Create a fake CcdImage by making a fake catalog.

Parameters
----------
butler : `lsst.daf.persistence.Butler`
    Butler to load metadata from.
visit : `int`
    Visit identifier to build a butler dataId.
num : `int`
    Number of sources to put in the catalogs. Should be
    a square, to have sqrt(num) centroids on a grid.
fluxFieldName : `str`
    Name of the flux field to populate in the catalog, without `_instFlux`
    (e.g. "slot_CalibFlux").
photoCalibMean : `float`, optional
    Value to set for calibrationMean in the created PhotoCalib.
    Note: this value is 1/instFluxMag0, so it should be less than 1.
photoCalibErr : `float`, optional
    Value to set for calibrationErr in the created PhotoCalib.
fakeCcdId : `int`, optional
    Use this as the ccdId in the returned CcdImage.

Returns
-------
struct : `lsst.pipe.base.Struct`
   Result struct with components:

   - `catalog` : Catalogs containing fake sources
       (`lsst.afw.table.SourceCatalog`).
   - `ccdImage` : CcdImage containing the metadata and fake sources
       (`lsst.jointcal.CcdImage`).
   - `bbox` : Bounding Box of the image (`lsst.afw.geom.Box2I`).

Definition at line 103 of file testUtils.py.

103  photoCalibMean=1e-2, photoCalibErr=1.0, fakeCcdId=12):
104  """Create a fake CcdImage by making a fake catalog.
105 
106  Parameters
107  ----------
108  butler : `lsst.daf.persistence.Butler`
109  Butler to load metadata from.
110  visit : `int`
111  Visit identifier to build a butler dataId.
112  num : `int`
113  Number of sources to put in the catalogs. Should be
114  a square, to have sqrt(num) centroids on a grid.
115  fluxFieldName : `str`
116  Name of the flux field to populate in the catalog, without `_instFlux`
117  (e.g. "slot_CalibFlux").
118  photoCalibMean : `float`, optional
119  Value to set for calibrationMean in the created PhotoCalib.
120  Note: this value is 1/instFluxMag0, so it should be less than 1.
121  photoCalibErr : `float`, optional
122  Value to set for calibrationErr in the created PhotoCalib.
123  fakeCcdId : `int`, optional
124  Use this as the ccdId in the returned CcdImage.
125 
126  Returns
127  -------
128  struct : `lsst.pipe.base.Struct`
129  Result struct with components:
130 
131  - `catalog` : Catalogs containing fake sources
132  (`lsst.afw.table.SourceCatalog`).
133  - `ccdImage` : CcdImage containing the metadata and fake sources
134  (`lsst.jointcal.CcdImage`).
135  - `bbox` : Bounding Box of the image (`lsst.afw.geom.Box2I`).
136  """
137  ccdId = 12 # we only have data for ccd=12
138 
139  dataId = dict(visit=visit, ccd=ccdId)
140  skyWcs = butler.get('calexp_wcs', dataId=dataId)
141  visitInfo = butler.get('calexp_visitInfo', dataId=dataId)
142  bbox = butler.get('calexp_bbox', dataId=dataId)
143  detector = butler.get('calexp_detector', dataId=dataId)
144  filt = butler.get("calexp_filter", dataId=dataId).getName()
145  photoCalib = lsst.afw.image.PhotoCalib(photoCalibMean, photoCalibErr)
146 
147  catalog = createFakeCatalog(num, bbox, fluxFieldName, skyWcs=skyWcs)
148  ccdImage = lsst.jointcal.ccdImage.CcdImage(catalog, skyWcs, visitInfo, bbox, filt, photoCalib,
149  detector, visit, fakeCcdId, fluxFieldName)
150 
151  return lsst.pipe.base.Struct(catalog=catalog, ccdImage=ccdImage, bbox=bbox)
152 
153 
The photometric calibration of an exposure.
Definition: PhotoCalib.h:111
def createFakeCatalog(num, bbox, fluxFieldName, skyWcs=None, refCat=False)
Definition: testUtils.py:154

◆ createTwoFakeCcdImages()

def lsst.jointcal.testUtils.createTwoFakeCcdImages (   num1 = 4,
  num2 = 4,
  seed = 100,
  fakeCcdId = 12,
  photoCalibMean1 = 1e-2,
  photoCalibMean2 = 1.2e-2 
)
Return two fake ccdImages built on CFHT Megacam metadata.

If ``num1 == num2``, the catalogs will align on-sky so each source will
have a match in the other catalog.

This uses the butler dataset stored in `tests/data/cfht_minimal` to
bootstrap the metadata.

Parameters
----------
num1, num2 : `int`, optional
    Number of sources to put in the first and second catalogs. Should be
    a square, to have sqrt(num) centroids on a grid.
seed : `int`, optional
    Seed value for np.random.
fakeCcdId : `int`, optional
    Sensor identifier to use for both CcdImages. The wcs, bbox, calib, etc.
    will still be drawn from the CFHT ccd=12 files, as that is the only
    testdata that is included in this simple test dataset.
photoCalibMean1, photoCalibMean2: `float`, optional
    The mean photometric calibration to pass to each ccdImage construction.
    Note: this value is 1/instFluxMag0, so it should be less than 1.

Returns
-------
struct : `lsst.pipe.base.Struct`
   Result struct with components:

   - `camera` : Camera representing these catalogs
       (`lsst.afw.cameraGeom.Camera`).
   - `catalogs` : Catalogs containing fake sources
       (`list` of `lsst.afw.table.SourceCatalog`).
   - `ccdImageList` : CcdImages containing the metadata and fake sources
       (`list` of `lsst.jointcal.CcdImage`).
   - `bbox` : Bounding Box of the image (`lsst.afw.geom.Box2I`).
   - 'fluxFieldName' : name of the instFlux field in the catalogs ('str').

Definition at line 38 of file testUtils.py.

38  photoCalibMean1=1e-2, photoCalibMean2=1.2e-2):
39  """Return two fake ccdImages built on CFHT Megacam metadata.
40 
41  If ``num1 == num2``, the catalogs will align on-sky so each source will
42  have a match in the other catalog.
43 
44  This uses the butler dataset stored in `tests/data/cfht_minimal` to
45  bootstrap the metadata.
46 
47  Parameters
48  ----------
49  num1, num2 : `int`, optional
50  Number of sources to put in the first and second catalogs. Should be
51  a square, to have sqrt(num) centroids on a grid.
52  seed : `int`, optional
53  Seed value for np.random.
54  fakeCcdId : `int`, optional
55  Sensor identifier to use for both CcdImages. The wcs, bbox, calib, etc.
56  will still be drawn from the CFHT ccd=12 files, as that is the only
57  testdata that is included in this simple test dataset.
58  photoCalibMean1, photoCalibMean2: `float`, optional
59  The mean photometric calibration to pass to each ccdImage construction.
60  Note: this value is 1/instFluxMag0, so it should be less than 1.
61 
62  Returns
63  -------
64  struct : `lsst.pipe.base.Struct`
65  Result struct with components:
66 
67  - `camera` : Camera representing these catalogs
68  (`lsst.afw.cameraGeom.Camera`).
69  - `catalogs` : Catalogs containing fake sources
70  (`list` of `lsst.afw.table.SourceCatalog`).
71  - `ccdImageList` : CcdImages containing the metadata and fake sources
72  (`list` of `lsst.jointcal.CcdImage`).
73  - `bbox` : Bounding Box of the image (`lsst.afw.geom.Box2I`).
74  - 'fluxFieldName' : name of the instFlux field in the catalogs ('str').
75  """
76  np.random.seed(seed)
77 
78  visit1 = 849375
79  visit2 = 850587
80  fluxFieldName = "SomeFlux"
81 
82  # Load or fake the necessary metadata for each CcdImage
83  dataDir = lsst.utils.getPackageDir('jointcal')
84  inputDir = os.path.join(dataDir, 'tests/data/cfht_minimal')
85  butler = lsst.daf.persistence.Butler(inputDir)
86 
87  # so we can access parts of the camera later (e.g. focal plane)
88  camera = butler.get('camera', visit=visit1)
89 
90  struct1 = createFakeCcdImage(butler, visit1, num1, fluxFieldName,
91  photoCalibMean=photoCalibMean1, photoCalibErr=1.0, fakeCcdId=fakeCcdId)
92  struct2 = createFakeCcdImage(butler, visit2, num2, fluxFieldName,
93  photoCalibMean=photoCalibMean2, photoCalibErr=5.0, fakeCcdId=fakeCcdId)
94 
95  return lsst.pipe.base.Struct(camera=camera,
96  catalogs=[struct1.catalog, struct2.catalog],
97  ccdImageList=[struct1.ccdImage, struct2.ccdImage],
98  bbox=struct1.bbox,
99  fluxFieldName=fluxFieldName)
100 
101 
def createFakeCcdImage(butler, visit, num, fluxFieldName, photoCalibMean=1e-2, photoCalibErr=1.0, fakeCcdId=12)
Definition: testUtils.py:103
std::string getPackageDir(std::string const &packageName)
return the root directory of a setup package
Definition: packaging.cc:33

◆ fillCatalog()

def lsst.jointcal.testUtils.fillCatalog (   schema,
  num,
  bbox,
  centroidKey,
  xErrKey,
  yErrKey,
  shapeKey,
  fluxFieldName,
  skyWcs = None,
  fluxErrFraction = 0.05,
  refCat = False 
)
Return a catalog populated with fake, but reasonable, sources.

Centroids are placed on a uniform grid, errors are normally distributed.

Parameters
----------
schema : `lsst.afw.table.Schema`
    Pre-built schema to make the catalog from.
num : `int`
    Number of sources to put in the catalog.
bbox : `lsst.afw.geom.Box2I`
    Bounding box of the ccd to put sources in.
centroidKey : `lsst.afw.table.Key`
    Key for the centroid field to populate.
xErrKey : `lsst.afw.table.Key`
    Key for the xErr field to populate.
yErrKey : `lsst.afw.table.Key`
    Key for the yErr field to populate.
shapeKey : `lsst.afw.table.Key`
    Key for the shape field to populate.
fluxFieldName : `str`
    Name of the flux field to populate in the catalog, without `_instFlux`
    (e.g. "slot_CalibFlux").
skyWcs : `lsst.afw.geom.SkyWcs` or None, optional
    If supplied, use this to fill in coordinates from centroids.
fluxErrFraction : `float`, optional
    Fraction of instFlux to use for the instFluxErr.
refCat : `bool`, optional
    Return a ``SimpleCatalog`` so that it behaves like a reference catalog?

Returns
-------
catalog : `lsst.afw.table.SourceCatalog`
    The filled catalog.

Definition at line 199 of file testUtils.py.

199  skyWcs=None, fluxErrFraction=0.05, refCat=False):
200  """Return a catalog populated with fake, but reasonable, sources.
201 
202  Centroids are placed on a uniform grid, errors are normally distributed.
203 
204  Parameters
205  ----------
206  schema : `lsst.afw.table.Schema`
207  Pre-built schema to make the catalog from.
208  num : `int`
209  Number of sources to put in the catalog.
210  bbox : `lsst.afw.geom.Box2I`
211  Bounding box of the ccd to put sources in.
212  centroidKey : `lsst.afw.table.Key`
213  Key for the centroid field to populate.
214  xErrKey : `lsst.afw.table.Key`
215  Key for the xErr field to populate.
216  yErrKey : `lsst.afw.table.Key`
217  Key for the yErr field to populate.
218  shapeKey : `lsst.afw.table.Key`
219  Key for the shape field to populate.
220  fluxFieldName : `str`
221  Name of the flux field to populate in the catalog, without `_instFlux`
222  (e.g. "slot_CalibFlux").
223  skyWcs : `lsst.afw.geom.SkyWcs` or None, optional
224  If supplied, use this to fill in coordinates from centroids.
225  fluxErrFraction : `float`, optional
226  Fraction of instFlux to use for the instFluxErr.
227  refCat : `bool`, optional
228  Return a ``SimpleCatalog`` so that it behaves like a reference catalog?
229 
230  Returns
231  -------
232  catalog : `lsst.afw.table.SourceCatalog`
233  The filled catalog.
234  """
235  table = lsst.afw.table.SourceTable.make(schema)
236  table.defineCentroid('centroid')
237  table.defineShape('shape')
238  table.defineCalibFlux(fluxFieldName)
239  if refCat:
240  catalog = lsst.afw.table.SimpleCatalog(table)
241  else:
242  catalog = lsst.afw.table.SourceCatalog(table)
243 
244  instFlux = np.random.random(num)*10000
245  instFluxErr = np.abs(instFlux * np.random.normal(fluxErrFraction, scale=0.1, size=num))
246  xx = np.linspace(bbox.getMinX(), bbox.getMaxX(), int(np.sqrt(num)))
247  yy = np.linspace(bbox.getMinY(), bbox.getMaxY(), int(np.sqrt(num)))
248  xv, yv = np.meshgrid(xx, yy)
249  vx = np.random.normal(scale=0.1, size=num)
250  vy = np.random.normal(scale=0.1, size=num)
251 
252  # make all the sources perfectly spherical, for simplicity.
253  mxx = 1
254  myy = 1
255  mxy = 0
256 
257  for i, (x, y) in enumerate(zip(xv.ravel(), yv.ravel())):
258  record = catalog.addNew()
259  record.set('id', i)
260  record.set(centroidKey, lsst.afw.geom.Point2D(x, y))
261  record.set(shapeKey, lsst.afw.geom.ellipses.Quadrupole(mxx, myy, mxy))
262 
263  if skyWcs is not None:
264  lsst.afw.table.updateSourceCoords(skyWcs, catalog)
265 
266  catalog[xErrKey] = vx
267  catalog[yErrKey] = vy
268  catalog[fluxFieldName + '_instFlux'] = instFlux
269  catalog[fluxFieldName + '_instFluxErr'] = instFluxErr
270 
271  return catalog
272 
273 
An ellipse core with quadrupole moments as parameters.
Definition: Quadrupole.h:47
void updateSourceCoords(geom::SkyWcs const &wcs, SourceCollection &sourceList)
Update sky coordinates in a collection of source objects.
Definition: wcsUtils.cc:96
Custom catalog class for record/table subclasses that are guaranteed to have an ID, and should generally be sorted by that ID.
Definition: fwd.h:63
static std::shared_ptr< SourceTable > make(Schema const &schema, std::shared_ptr< IdFactory > const &idFactory)
Construct a new table.
Definition: Source.cc:384

◆ getMeasuredStarsFromCatalog()

def lsst.jointcal.testUtils.getMeasuredStarsFromCatalog (   catalog,
  pixToFocal 
)
Return a list of measuredStars built from a catalog.

Parameters
----------
catalog : `lsst.afw.table.SourceCatalog`
    The table to get sources from.
pixToFocal : `lsst.afw.geom.TransformPoint2ToPoint2`
    Transform that goes from pixel to focal plane coordinates, to set the
    MeasuredStar x/y focal points.

Returns
-------
stars : `list` of `lsst.jointcal.MeasuredStar`
    MeasuredStars built from the catalog sources.

Definition at line 274 of file testUtils.py.

274 def getMeasuredStarsFromCatalog(catalog, pixToFocal):
275  """Return a list of measuredStars built from a catalog.
276 
277  Parameters
278  ----------
279  catalog : `lsst.afw.table.SourceCatalog`
280  The table to get sources from.
281  pixToFocal : `lsst.afw.geom.TransformPoint2ToPoint2`
282  Transform that goes from pixel to focal plane coordinates, to set the
283  MeasuredStar x/y focal points.
284 
285  Returns
286  -------
287  stars : `list` of `lsst.jointcal.MeasuredStar`
288  MeasuredStars built from the catalog sources.
289  """
290  stars = []
291  for record in catalog:
292  star = lsst.jointcal.star.MeasuredStar()
293  star.x = record.getX()
294  star.y = record.getY()
295  star.setInstFluxAndErr(record.getCalibInstFlux(), record.getCalibInstFluxErr())
296  # TODO: cleanup after DM-4044
297  point = lsst.afw.geom.Point2D(star.x, star.y)
298  pointFocal = pixToFocal.applyForward(point)
299  star.setXFocal(pointFocal.getX())
300  star.setYFocal(pointFocal.getY())
301  stars.append(star)
302 
303  return stars
304 
def getMeasuredStarsFromCatalog(catalog, pixToFocal)
Definition: testUtils.py:274