def trim_sensors(self, instcat): obs_md, _, _ \ = desc.imsim.parsePhoSimInstanceFile(instcat, (), numRows=50) camera = desc.imsim.get_obs_lsstSim_camera() sensors = [] for det in list(camera): if det.getType() != cameraGeom.SCIENCE: continue det_name = det.getName() corners = np.array(getCornerRaDec(det_name, camera, obs_md)) if (any([self.contains(*corner) for corner in corners]) or self.contains_region_corners(corners)): sensors.append(det_name) return sensors
def test_cornerRaDec(self): """ Verify that getCornerRaDec has not changed """ dtype = np.dtype([('name', str, 15), ('x0', float), ('y0', float), ('x1', float), ('y1', float), ('x2', float), ('y2', float), ('x3', float), ('y3', float)]) data = np.genfromtxt(os.path.join(self.data_dir, 'lsst_camera_corners.txt'), dtype=dtype, delimiter=';') detector_name_list = [dd.getName() for dd in self.camera] detector_name_list.sort() x0 = np.zeros(len(detector_name_list), dtype=float) x1 = np.zeros(len(detector_name_list), dtype=float) x2 = np.zeros(len(detector_name_list), dtype=float) x3 = np.zeros(len(detector_name_list), dtype=float) y0 = np.zeros(len(detector_name_list), dtype=float) y1 = np.zeros(len(detector_name_list), dtype=float) y2 = np.zeros(len(detector_name_list), dtype=float) y3 = np.zeros(len(detector_name_list), dtype=float) for i_chip in range(len(detector_name_list)): name = detector_name_list[i_chip] corners = getCornerRaDec(name, self.camera, self.obs) x0[i_chip] = corners[0][0] x1[i_chip] = corners[1][0] x2[i_chip] = corners[2][0] x3[i_chip] = corners[3][0] y0[i_chip] = corners[0][1] y1[i_chip] = corners[1][1] y2[i_chip] = corners[2][1] y3[i_chip] = corners[3][1] np.testing.assert_array_almost_equal(x0, data['x0'], decimal=4) np.testing.assert_array_almost_equal(x1, data['x1'], decimal=4) np.testing.assert_array_almost_equal(x2, data['x2'], decimal=4) np.testing.assert_array_almost_equal(x3, data['x3'], decimal=4) np.testing.assert_array_almost_equal(y0, data['y0'], decimal=4) np.testing.assert_array_almost_equal(y1, data['y1'], decimal=4) np.testing.assert_array_almost_equal(y2, data['y2'], decimal=4) np.testing.assert_array_almost_equal(y3, data['y3'], decimal=4)
def trim_sensors(self, instcat_or_obs_md): if isinstance(instcat_or_obs_md, ObservationMetaData): obs_md = instcat_or_obs_md else: obs_md = get_obs_md(instcat_or_obs_md) #camera = obs_lsst.LsstCamMapper().camera camera = lsst.sims.coordUtils.lsst_camera() sensors = [] for det in list(camera): if det.getType() != cameraGeom.SCIENCE: continue det_name = det.getName() corners = np.array(getCornerRaDec(det_name, camera, obs_md)) if (any([self.contains(*corner) for corner in corners]) or self.contains_region_corners(corners)): sensors.append(det_name) return sensors
def get_det_polygon(detector, camera, obs_md): """ Compute the convex polygon for a detector for a given observation. Parameters ---------- detector: lsst.afw.cameraGeom.detector.detector.Detector The detector at issue. camera: lsst.afw.cameraGeom.camera.Camera [None] Camera object that provides sensor locations in focalplane. If None, then lsst.obs.lsst.lsstCam.LsstCam is used. obs_md: lsst.sims.utils.ObservationMetaData The object containing the visit info. Returns ------- lsst.sphgeom.ConvexPolygon """ corners = getCornerRaDec(detector.getName(), camera, obs_md) vertices = [] for corner in corners: lonlat = lsst.sphgeom.LonLat.fromDegrees(*corner) vertices.append(lsst.sphgeom.UnitVector3d(lonlat)) return lsst.sphgeom.ConvexPolygon(vertices)
obs_metadata=obs, camera=camera) pix_x, pix_y = pixelCoordsFromRaDec(ra_grid, dec_grid, chipName=chip_name_grid, obs_metadata=obs, camera=camera) with open('lsst_pixel_data.txt', 'w') as out_file: out_file.write(header_msg) out_file.write('# ra dec chipName focal_x focal_y pix_x pix_y\n') for i_obj in range(len(ra_grid)): out_file.write('%.2f;%.2f;%s;%.5f;%.5f;%.5f;%.5f\n' % (ra_grid[i_obj], dec_grid[i_obj], chip_name_grid[i_obj], focal_x[i_obj], focal_y[i_obj], pix_x[i_obj], pix_y[i_obj])) detector_name_list = [dd.getName() for dd in camera] detector_name_list.sort() with open('lsst_camera_corners.txt', 'w') as out_file: out_file.write(header_msg) out_file.write('# chipName ra0 dec0 ra1 dec1 ra2 dec2 ra3 dec3\n') for detector_name in detector_name_list: corners = getCornerRaDec(detector_name, camera, obs) out_file.write('%s;%.4f;%.4f;%.4f;%.4f;%.4f;%.4f;%.4f;%.4f\n' % (detector_name, corners[0][0], corners[0][1], corners[1][0], corners[1][1], corners[2][0], corners[2][1], corners[3][0], corners[3][1]))
obs_metadata=obs, camera=camera) pix_x, pix_y = pixelCoordsFromRaDec(ra_grid, dec_grid, chipName=chip_name_grid, obs_metadata=obs, camera=camera) with open('lsst_pixel_data.txt', 'w') as out_file: out_file.write(header_msg) out_file.write('# ra dec chipName focal_x focal_y pix_x pix_y\n') for i_obj in range(len(ra_grid)): out_file.write( '%.2f;%.2f;%s;%.5f;%.5f;%.5f;%.5f\n' % (ra_grid[i_obj], dec_grid[i_obj], chip_name_grid[i_obj], focal_x[i_obj], focal_y[i_obj], pix_x[i_obj], pix_y[i_obj])) detector_name_list = [dd.getName() for dd in camera] detector_name_list.sort() with open('lsst_camera_corners.txt', 'w') as out_file: out_file.write(header_msg) out_file.write('# chipName ra0 dec0 ra1 dec1 ra2 dec2 ra3 dec3\n') for detector_name in detector_name_list: corners = getCornerRaDec(detector_name, camera, obs) out_file.write('%s;%.4f;%.4f;%.4f;%.4f;%.4f;%.4f;%.4f;%.4f\n' % (detector_name, corners[0][0], corners[0][1], corners[1][0], corners[1][1], corners[2][0], corners[2][1], corners[3][0], corners[3][1]))
def make_fov_plot(calcFill=False): # For the footprint generation. import lsst.sims.utils as sims_utils from lsst.obs.lsstSim import LsstSimMapper from lsst.sims.coordUtils import chipNameFromPupilCoords from lsst.sims.coordUtils import getCornerPixels, getCornerRaDec from lsst.afw.cameraGeom import SCIENCE mapper = LsstSimMapper() camera = mapper.camera obs = ObservationMetaData(pointingRA=0.0, pointingDec=0.0, rotSkyPos=0.0, mjd=59580.0) if calcFill: # Set up pupil coordinate points to iterate over (to calculate fill factor) testrange = 2.2 spacing = 0.01 xcen = 0 ycen = 0 xi = np.arange(xcen-np.radians(testrange), xcen+np.radians(testrange), np.radians(spacing)) yi = np.arange(ycen-np.radians(testrange), ycen+np.radians(testrange), np.radians(spacing)) x = [] y = [] for i in itertools.product(xi, yi): x.append(i[0]) y.append(i[1]) x = np.array(x) y = np.array(y) # Calculate 'visibility' chipNames = chipNameFromPupilCoords(x, y, camera=camera) vis = np.zeros(len(chipNames)) for i, chip in enumerate(chipNames): if chip is not None: vis[i] = 1 # Calculate fill factor area_degsq = 9.6 innerradius = 1.75 print('inner radius matching area_degsq for circle', innerradius) sep = np.degrees(sims_utils.haversine(x, y, xcen, ycen)) print('max distance from center used for chip calculation', sep.max()) incircle = np.where(sep < innerradius)[0] onchip = np.where(vis[incircle] == 1)[0] fillfactor = len(vis[onchip]) / float(len(vis[incircle])) print('fill factor', fillfactor) innerfillfactor = fillfactor outerradius = 2.06 print('outer radius', outerradius) sep = np.degrees(sims_utils.haversine(x, y, xcen, ycen)) print('max distance from center used for chip calculation', sep.max()) incircle = np.where(sep < outerradius)[0] onchip = np.where(vis[incircle] == 1)[0] fillfactor = len(vis[onchip]) / float(len(vis[incircle])) print('fill factor', fillfactor) else: innerradius = 1.75 outerradius = 2.06 innerffillfactor = 0.895 # Build locations of CCD corners. ccdnames = [] for det in camera: if det.getType() == SCIENCE: ccdnames.append(det.getName()) corners = [] for ccdname in ccdnames: corners.append(np.radians(getCornerRaDec(ccdname, camera, obs_metadata=obs))) plt.figure(figsize=(8, 6)) plt.axis('equal') #condition = np.where(vis == 1)[0] #plt.plot(np.degrees(x), np.degrees(y), 'g.', markersize=0.2) #plt.plot(np.degrees(x[condition]), np.degrees(y[condition]), 'b.', markersize=0.3) for cornerset in corners: cx = corners.swapaxes(0, 1)[0] cy = corners.swapaxes(0, 1)[1] plt.plot(0, 0, 'r.') plt.xlabel('x Pupil (deg)', fontsize='larger') plt.ylabel('y Pupil (deg))', fontsize='larger') theta = np.arange(0, 2*np.pi, 0.01) plt.plot(innerradius*np.cos(theta)+np.degrees(xcen), innerradius*np.sin(theta)+np.degrees(ycen), 'r-') plt.plot(outerradius*np.cos(theta)+np.degrees(xcen), outerradius*np.sin(theta)+np.degrees(ycen), 'r:') #plt.xlim(fieldra+offset-sep.max()/2.0, fieldra+offset+sep.max()/2.0) plt.ylim(np.degrees(xcen)-sep.max()*.7, np.degrees(ycen)+sep.max()*.7) xco = 0.74 plt.figtext(xco, 0.8, 'Inner circle') plt.figtext(xco, 0.75, r' r=%.2f$^\circ$' %(innerradius)) plt.figtext(xco, 0.7, ' %.0f%s fill factor' %(round(innerfillfactor*100), '%')) plt.figtext(xco, 0.6, 'Outer circle') plt.figtext(xco, 0.55, r' r=%.2f$^\circ$' %(outerradius)) plt.savefig('focalplane.' + figformat, format=figformat)