Пример #1
0
    def __init__(self, mit=False):
        
        dataInfo       = [['visit',1], ['ccd', 0]]

        if os.environ.has_key('OBS_SUBARU_DIR'):
            simdir         = os.environ['OBS_SUBARU_DIR']
            pafBase = "Full_Suprimecam_MIT_geom.paf" if mit else "Full_Suprimecam_geom.paf"
            cameraGeomPaf = os.path.join(simdir, "suprimecam", pafBase)
                                         
            if not os.path.exists(cameraGeomPaf):
                raise Exception("Unable to find cameraGeom Policy file: %s" % (cameraGeomPaf))
            
            cameraGeomPolicy = cameraGeomUtils.getGeomPolicy(cameraGeomPaf)
            camera           = cameraGeomUtils.makeCamera(cameraGeomPolicy)
        else:
            camera           = None

        CameraInfo.__init__(self, "suprimecam", dataInfo, camera)

        self.doLabel = True
        self.mit = mit

        self.dataIdTranslationMap = {
            # standard  : camera
            'visit'  : 'visit',
            'sensor' : 'ccd',
            }
        self.dataIdDbNames = {
            'visit' : 'visit',
            'ccd'   : 'ccdname',
            }
Пример #2
0
    def __init__(self):
        """ """
        dataInfo       = [['visit',1], ['ccd', 0]]

        if os.environ.has_key('OBS_SUBARU_DIR'):
            simdir         = os.environ['OBS_SUBARU_DIR']
            cameraGeomPaf = os.path.join(simdir, "hsc", "hsc_geom.paf")
            if not os.path.exists(cameraGeomPaf):
                cameraGeomPaf = os.path.join(simdir, "hsc", "description", "hsc_geom.paf")
                if not os.path.exists(cameraGeomPaf):
                    raise Exception("Unable to find cameraGeom Policy file: %s" % (cameraGeomPaf))
            cameraGeomPolicy = cameraGeomUtils.getGeomPolicy(cameraGeomPaf)
            camera           = cameraGeomUtils.makeCamera(cameraGeomPolicy)
        else:
            camera = None
            
        CameraInfo.__init__(self, "hsc", dataInfo, camera)

        self.dataIdTranslationMap = {
            'visit'  : 'visit',
            'sensor' : 'ccd',
            }

        self.dataIdDbNames = {
            'visit'  : 'visit',
            'ccd'    : 'ccdname',
            }

        
        self.doLabel = False
Пример #3
0
    def __init__(self):
        """ """
        dataInfo       = [['visit',1], ['snap', 0], ['raft',0], ['sensor',0]]

        if os.environ.has_key('OBS_LSSTSIM_DIR'):
            simdir        = os.environ['OBS_LSSTSIM_DIR']
            cameraGeomPaf = os.path.join(simdir, "description", "Full_STA_geom.paf")
            cameraGeomPolicy = cameraGeomUtils.getGeomPolicy(cameraGeomPaf)
            camera           = cameraGeomUtils.makeCamera(cameraGeomPolicy)
        else:
            camera = None
        
        CameraInfo.__init__(self, "lsstSim", dataInfo, camera)

        self.doLabel = False

        self.dataIdTranslationMap = {
            # input  : return
            'visit'  : 'visit',
            'snap'   : 'snap',
            'raft'   : 'raft',
            'sensor'    : 'sensor',
            }

        self.dataIdDbNames = {
            'visit' : 'visit',
            'raft'  : 'raftName',
            'sensor' : 'ccdName',
            'snap'  : 'snap',
            }
Пример #4
0
    def testDistortionInACamera(self):

	policyFile = cameraGeomUtils.getGeomPolicy(os.path.join(eups.productDir("afw"),
								"tests", "TestCameraGeom.paf"))
	pol = pexPolicy.Policy(policyFile)
	pol = cameraGeomUtils.getGeomPolicy(pol)
	cam = cameraGeomUtils.makeCamera(pol)

	# see if the distortion object made it into the camera object
	dist = cam.getDistortion()
	self.tryAFewCoords(dist, [1.0, 1.0, 0.1])

	# see if the distortion object is accessible in the ccds
	for raft in cam:
	    for ccd in cameraGeom.cast_Raft(raft):
		ccd = cameraGeom.cast_Ccd(ccd)
		if self.prynt:
		    print "CCD id: ", ccd.getId()
		ccdDist = ccd.getDistortion()
		self.tryAFewCoords(dist, [1.0, 1.0, 0.1])
Пример #5
0
    def testDistortionInACamera(self):

        policyFile = cameraGeomUtils.getGeomPolicy(
            os.path.join(eups.productDir("afw"), "tests",
                         "TestCameraGeom.paf"))
        pol = pexPolicy.Policy(policyFile)
        pol = cameraGeomUtils.getGeomPolicy(pol)
        cam = cameraGeomUtils.makeCamera(pol)

        # see if the distortion object made it into the camera object
        dist = cam.getDistortion()
        self.tryAFewCoords(dist, [1.0, 1.0, 0.1])

        # see if the distortion object is accessible in the ccds
        for raft in cam:
            for ccd in cameraGeom.cast_Raft(raft):
                ccd = cameraGeom.cast_Ccd(ccd)
                if self.prynt:
                    print "CCD id: ", ccd.getId()
                ccdDist = ccd.getDistortion()
                self.tryAFewCoords(dist, [1.0, 1.0, 0.1])
Пример #6
0
    def __init__(self):
        
        dataInfo       = [['visit',1], ['ccd', 0]]
        
        if os.environ.has_key('OBS_CFHT_DIR'):
            simdir         = os.environ['OBS_CFHT_DIR']
            cameraGeomPaf = os.path.join(simdir, "megacam", "description", "Full_Megacam_geom.paf")
            cameraGeomPolicy = cameraGeomUtils.getGeomPolicy(cameraGeomPaf)
            camera           = cameraGeomUtils.makeCamera(cameraGeomPolicy)
        else:
            camera = None

        CameraInfo.__init__(self, "cfht", dataInfo, camera)
        self.doLabel = True
Пример #7
0
 def setUp(self):
     policy = pexPolicy.Policy("tests/SuprimeCam_Geom.paf")
     geomPolicy = cameraGeomUtils.getGeomPolicy(policy)
     self.camera = cameraGeomUtils.makeCamera(geomPolicy)
     coeffs = list(COEFFS)
     coeffs.reverse(
     )  # NumPy's poly1d wants coeffs in descending order of powers
     coeffs.append(
         0.0)  # NumPy's poly1d goes all the way down to zeroth power
     self.config = pipConfig.Config()
     distConfig = pipConfig.Config()
     distConfig['coeffs'] = coeffs
     distConfig['actualToIdeal'] = True
     distConfig['step'] = 10.0
     self.config['radial'] = distConfig
Пример #8
0
    def __init__(self):
        dataInfo       = [['tract', 1], ['patch', 1], ['filterName', 1]]

        simdir        = os.environ['TESTING_PIPEQA_DIR']
        cameraGeomPaf = os.path.join(simdir, "policy", "Full_coadd_geom.paf")
        cameraGeomPolicy = cameraGeomUtils.getGeomPolicy(cameraGeomPaf)
        camera           = cameraGeomUtils.makeCamera(cameraGeomPolicy)

        CameraInfo.__init__(self, "coadd", dataInfo, camera)
        
        self.doLabel = True

        self.dataIdTranslationMap = {
            'visit' : ['tract','patch','filterName'],
            'raft'  : None,
            'sensor'   : None, #'filter',
            }

        self.dataIdDbNames = {
            'patch' : 'patch',
            'tract' : 'tract',
            'filterName' : 'filterName',
            }
 def std_camera(self, item, dataId):
     """Standardize a camera dataset by converting it to a camera
     object."""
     return cameraGeomUtils.makeCamera(cameraGeomUtils.getGeomPolicy(item))
Пример #10
0
def main(infile, ccds=None, camera="hsc", cmap="copper", cols=[0,1],
         nsig=3.0, percent=False, textcolor='k', out=None):

    ###########################
    # build the camera
    policy_file = {
        'hsc': os.path.join(os.getenv("OBS_SUBARU_DIR"), "hsc", "hsc_geom.paf"),
        'sc' : os.path.join(os.getenv("OBS_SUBARU_DIR"), "suprimecam", "Full_Suprimecam_geom.paf")
        }
    geomPolicy = afwCGU.getGeomPolicy(policy_file[camera.lower()])
    camera     = afwCGU.makeCamera(geomPolicy)

    
    ###########################
    # load the data
    data = {}
    if infile:
        load = numpy.loadtxt(infile)
        vals = load[:,cols[1]]
        for i in range(len(vals)):
            ccd = int(load[i,cols[0]])
            if len(cols) == 3:
                amp = int(load[i,cols[2]])
            else:
                amp = 0
            if ccd not in data:
                data[ccd] = {}
            data[ccd][amp] = vals[i]
    else:
        vals = []
        for r in camera:
            for c in afwCG.cast_Raft(r):
                ccd = afwCG.cast_Ccd(c)
                ccdId = ccd.getId().getSerial()
                data[ccdId] = {}
                val = 1.0
                if ccdId > 103:
                    val = 0.8
                for a in ccd:
                    amp = afwCG.cast_Amp(a)
                    ampId = amp.getId().getSerial() - 1
                    data[ccdId][ampId] = val
                    vals.append(val)
                if len(data[ccdId]) == 0:
                    data[ccdId][0] = val
                    vals.append(val)
        vals = numpy.array(vals)
        
    mean = vals.mean()
    med  = numpy.median(vals)
    std  = vals.std()
    vmin, vmax = med - nsig*std, med+nsig*std
    

    ###########################
    # make the plot
    fig = figure.Figure(figsize=(7,7))
    canvas = FigCanvas(fig)

    if infile:
        rect = (0.06, 0.12, 0.76, 0.76)
    else:
        rect = (0.06, 0.06, 0.88, 0.88)
        
    fpa_fig = hscUtil.FpaFigure(fig, camera, rect=rect)
    
    for i_ccd, amplist in data.items():

        hide = False
        if ccds and (i_ccd not in ccds):
            hide = True
        
        ax = fpa_fig.getAxes(i_ccd)
        fpa_fig.highlightAmp(i_ccd, 0)
        nq = fpa_fig.detectors[i_ccd].getOrientation().getNQuarter()
        nx, ny = 4, 8
        if nq % 2:
            ny, nx = nx, ny
        firstAmp = sorted(amplist.keys())[0]
        im = numpy.zeros((ny, nx)) + amplist[firstAmp]

        print i_ccd
        for amp, val in amplist.items():
            useVal = val
            if hide:
                useVal = 0.0
            if nq == 0:
                im[:,amp] = useVal
            if nq == 1 or nq == -3:
                im[3-amp,:] = useVal
            if nq == 2:
                im[:,3-amp] = useVal
            if nq == -1 or nq == 3:
                im[amp,:] = useVal
            
        im_ax = ax.imshow(im, cmap=cmap, vmax=vmax, vmin=vmin, interpolation='nearest')

        fpa_fig.addLabel(i_ccd, [str(i_ccd)], color=textcolor)


    #############################
    # the colorbar
    ylo, yhi = vmin, vmax

    if infile:
        rect = (0.91, 0.25, 0.02, 0.6)
        
        # real units
        cax  = fig.add_axes(rect)        
        cax.get_yaxis().get_major_formatter().set_useOffset(False)        
        cax.set_ylim([ylo, yhi])
        cax.get_xaxis().set_ticks([])
        cbar = fig.colorbar(im_ax, cax=cax)

        # mirror the values.  std or in percent (fractional) if requested
        caxp = cax.twinx()
        caxp.get_xaxis().set_ticks([])
        caxp.get_yaxis().get_major_formatter().set_useOffset(False)        
        if percent:
            caxp.set_ylim([(med-ylo)/(yhi-ylo), (yhi-med)/(yhi-ylo)])
        else:
            caxp.set_ylim([-nsig*std, nsig*std])


        for t in cax.get_yticklabels():
            t.set_size('small')
        for t in caxp.get_yticklabels():
            t.set_size("small")


    #################################
    # add stats
    if infile:
        stats = {"Mean":mean, "Med":med, "Std":std, "Max":vals.max(), "Min":vals.min()}
        order = ["Mean", "Med", "Std", "Min", "Max"]
        i = 0
        for k in order:
            v = stats[k]
            ax.text(0.8, 0.03+0.02*i, "%-10s %.3g"%(k+":",v), fontsize=9,
                    horizontalalignment='left', verticalalignment='center', transform=fig.transFigure)
            i += 1

    #################################
    # title and write it
    date = datetime.datetime.now().strftime("%Y-%m-%d_%H:%M:%S")
    title = "File: %s  Cols: %s  %s" % (infile, ":".join([str(x+1) for x in cols]), date) if infile else ""
    fig.suptitle(title)

    outfile = out if out else "camview-%s.png" % infile
    fig.savefig(outfile)
Пример #11
0
    def setUp(self):
        CameraGeomTestCase.ampSerial = [0] # an array so we pass the value by reference

        self.geomPolicy = cameraGeomUtils.getGeomPolicy(os.path.join(eups.productDir("afw"),
                                                                     "tests", "TestCameraGeom.paf"))
Пример #12
0
def verifySkyTiles(cursor, qsp, kind, wcsMap, wcsList, inButler):
    """Verifies that the sky-tile to CCD mapping in the registry used by inButler
    is correct. Also computes statistics on the angular separation between amp
    corners pre and post WCS determination.
    """
    if kind == 'imsim':
        geomPolicy = cameraGeomUtils.getGeomPolicy(
            pexPolicy.Policy.createPolicy(
                pexPolicy.DefaultPolicyFile("obs_lsstSim", "Full_STA_geom.paf",
                                            "description")))
    else:
        geomPolicy = cameraGeomUtils.getGeomPolicy(
            pexPolicy.Policy.createPolicy(
                pexPolicy.DefaultPolicyFile("obs_cfht",
                                            "Full_Megacam_geom.paf",
                                            "megacam/description")))
    camera = cameraGeomUtils.makeCamera(geomPolicy)
    ampDiskLayout = {}
    for p in geomPolicy.get("CcdDiskLayout").getArray("Amp"):
        ampDiskLayout[p.get("serial")] = (p.get("flipLR"), p.get("flipTB"))
    actualTiles = set(wcsMap.keys())
    processedTiles = set(inButler.queryMetadata("raw", "skyTile"))
    emptyTiles = processedTiles - actualTiles
    missedTiles = actualTiles - processedTiles
    if len(emptyTiles) > 0:
        print dedent("""\
            %d tiles not overlapping any Science CCDs (calexps) were found. This can
            happen if the run didn't span all the input amps in the registry, or
            when a raw amp gets shifted off a tile after WCS determination. So this
            is normal, but note that empty sky-tiles should not contain any
            SourceAssoc output.""" % len(emptyTiles))
    for tile in emptyTiles:
        print "\t%d" % tile
    if len(missedTiles) > 0:
        print dedent("""\
            %d tiles overlapping Science CCDs (calexps) were not processed.
            This indicates the raw amp padding radius used by the registry
            creation script is too small!""" % len(missedTiles))
    for tile in missedTiles:
        print "\t%d" % tile
    print "----"
    missedAmps = set()
    for tile in actualTiles:
        tileGeom = qsp.getGeometry(tile)
        tileAmps = set()
        if kind == "imsim":
            for visit, raft, sensor, channel in inButler.queryMetadata(
                    "raw",
                    "channel", ("visit", "raft", "sensor", "channel"),
                    skyTile=tile,
                    snap=0):
                s1, comma, s2 = sensor
                c1, comma, c2 = channel
                raftNum = lsstSimRafts.index(raft)
                ccdNum = int(s1) * 3 + int(s2)
                ampNum = (int(c2) << 3) + int(c1)
                tileAmps.add((long(visit), raftNum, ccdNum, ampNum))
        else:
            for visit, ccd, amp in inButler.queryMetadata(
                    "raw", "amp", ("visit", "ccd", "amp"), skyTile=tile):
                tileAmps.add((long(visit), 0, int(ccd), int(amp)))
        for ccdData in wcsMap[tile]:
            amps = getAmps(ccdData, camera, ampDiskLayout, cursor, kind)
            for ampData in amps:
                sciCoords = [
                    ccdData[0].pixelToSky(c[0], c[1]) for c in ampData[2]
                ]
                # find amps that should have been included in tile
                ampSerial = ampData[0].getId().getSerial()
                if (tile in missedTiles
                        or not (ccdData[2], ccdData[3], ccdData[4], ampSerial)
                        in tileAmps):
                    if tileGeom.intersects(coordsToPolygon(sciCoords)):
                        print(
                            "Tile %d missing visit %s raft %s ccd %s amp %d" %
                            (tile, str(ccdData[1]), str(
                                ccdData[2]), str(ccdData[3]), ampSerial))
                        missedAmps.add((ccdData[1], ampSerial))
    print "----"
    print "Computing statistics on angular separation between"
    print "science corners and raw corners/edges..."
    nSamples = 0
    maxDist, maxEdgeDist, maxMissEdgeDist = 0.0, 0.0, 0.0
    meanDist, meanEdgeDist, meanMissEdgeDist = 0.0, 0.0, 0.0
    minDist, minEdgeDist, minMissEdgeDist = 180.0, 180.0, 180.0
    for ccdData in wcsList:
        amps = getAmps(ccdData, camera, ampDiskLayout, cursor, kind)
        for ampData in amps:
            sciCoords = [ccdData[0].pixelToSky(c[0], c[1]) for c in ampData[2]]
            rawCoords = [ampData[1].pixelToSky(c[0], c[1]) for c in ampData[3]]
            rawPoly = coordsToPolygon(rawCoords)
            v = rawPoly.getVertices()
            e = rawPoly.getEdges()
            for raw, sci in izip(rawCoords, sciCoords):
                sciPos = tuple(sci.getVector())
                dist = geom.cartesianAngularSep(tuple(raw.getVector()),
                                                tuple(sciPos))
                minDist = min(dist, minDist)
                maxDist = max(dist, maxDist)
                meanDist += dist
                edgeDist = 180.0
                for i in xrange(len(v)):
                    edgeDist = min(
                        edgeDist, geom.minEdgeSep(sciPos, e[i], v[i - 1],
                                                  v[i]))
                minEdgeDist = min(edgeDist, minEdgeDist)
                maxEdgeDist = max(edgeDist, maxEdgeDist)
                meanEdgeDist += edgeDist
                nSamples += 1
                if (ccdData[1], ampData[0].getId().getSerial()) in missedAmps:
                    minMissEdgeDist = min(edgeDist, minMissEdgeDist)
                    maxMissEdgeDist = max(edgeDist, maxMissEdgeDist)
                    meanMissEdgeDist += edgeDist
    meanDist /= nSamples
    meanEdgeDist /= nSamples
    print "----"
    print "Number of amps examined: %d" % nSamples
    print "Min  raw to science corner distance: %.6f deg" % minDist
    print "Max  raw to science corner distance: %.6f deg" % maxDist
    print "Mean raw to science corner distance: %.6f deg" % meanDist
    print "Min  min science corner to raw amp edge distance: %.6f deg" % minEdgeDist
    print "Max  min science corner to raw amp edge distance: %.6f deg" % maxEdgeDist
    print "Mean min science corner to raw amp edge distance: %.6f deg" % meanEdgeDist
    print "Number of amps missed: %d" % len(missedAmps)
    if len(missedAmps) > 0:
        meanMissEdgeDist /= len(missedAmps)
        print "Min  min science corner to missed raw amp edge distance: %.6f deg" % minMissEdgeDist
        print "Max  min science corner to missed raw amp edge distance: %.6f deg" % maxMissEdgeDist
        print "Mean min science corner to missed raw amp edge distance: %.6f deg" % meanMissEdgeDist
Пример #13
0
def verifySkyTiles(cursor, qsp, kind, wcsMap, wcsList, inButler):
    """Verifies that the sky-tile to CCD mapping in the registry used by inButler
    is correct. Also computes statistics on the angular separation between amp
    corners pre and post WCS determination.
    """
    if kind == 'imsim':
        geomPolicy = cameraGeomUtils.getGeomPolicy(pexPolicy.Policy.createPolicy(
            pexPolicy.DefaultPolicyFile("obs_lsstSim", "Full_STA_geom.paf", "description")))
    else:
        geomPolicy =  cameraGeomUtils.getGeomPolicy(pexPolicy.Policy.createPolicy(
            pexPolicy.DefaultPolicyFile("obs_cfht", "Full_Megacam_geom.paf", "megacam/description")))
    camera = cameraGeomUtils.makeCamera(geomPolicy)
    ampDiskLayout = {}
    for p in geomPolicy.get("CcdDiskLayout").getArray("Amp"):
        ampDiskLayout[p.get("serial")] = (p.get("flipLR"), p.get("flipTB"))
    actualTiles = set(wcsMap.keys())
    processedTiles = set(inButler.queryMetadata("raw", "skyTile"))
    emptyTiles = processedTiles - actualTiles
    missedTiles = actualTiles - processedTiles
    if len(emptyTiles) > 0:
        print dedent("""\
            %d tiles not overlapping any Science CCDs (calexps) were found. This can
            happen if the run didn't span all the input amps in the registry, or
            when a raw amp gets shifted off a tile after WCS determination. So this
            is normal, but note that empty sky-tiles should not contain any
            SourceAssoc output.""" % len(emptyTiles))
    for tile in emptyTiles:
        print "\t%d" % tile
    if len(missedTiles) > 0:
        print dedent("""\
            %d tiles overlapping Science CCDs (calexps) were not processed.
            This indicates the raw amp padding radius used by the registry
            creation script is too small!""" % len(missedTiles))
    for tile in missedTiles:
        print "\t%d" % tile
    print "----"
    missedAmps = set()
    for tile in actualTiles:
        tileGeom = qsp.getGeometry(tile)
        tileAmps = set()
        if kind == "imsim":
            for visit, raft, sensor, channel in inButler.queryMetadata(
                    "raw", "channel", ("visit", "raft", "sensor", "channel"),
                    skyTile=tile, snap=0):
                s1, comma, s2 = sensor
                c1, comma, c2 = channel
                raftNum = lsstSimRafts.index(raft)
                ccdNum = int(s1) * 3 + int(s2)
                ampNum = (int(c2) << 3) + int(c1)
                tileAmps.add((long(visit), raftNum, ccdNum, ampNum))
        else:
            for visit, ccd, amp in inButler.queryMetadata(
                    "raw", "amp", ("visit", "ccd", "amp"), skyTile=tile):
                tileAmps.add((long(visit), 0, int(ccd), int(amp)))
        for ccdData in wcsMap[tile]:
            amps = getAmps(ccdData, camera, ampDiskLayout, cursor, kind)
            for ampData in amps:
               sciCoords = [ccdData[0].pixelToSky(c[0], c[1]) for c in ampData[2]]
               # find amps that should have been included in tile
               ampSerial = ampData[0].getId().getSerial()
               if (tile in missedTiles or not
                   (ccdData[2], ccdData[3], ccdData[4], ampSerial) in tileAmps):
                   if tileGeom.intersects(coordsToPolygon(sciCoords)):
                       print ("Tile %d missing visit %s raft %s ccd %s amp %d" %
                             (tile, str(ccdData[1]), str(ccdData[2]), str(ccdData[3]), ampSerial))
                       missedAmps.add((ccdData[1], ampSerial))
    print "----"
    print "Computing statistics on angular separation between"
    print "science corners and raw corners/edges..."
    nSamples = 0
    maxDist, maxEdgeDist, maxMissEdgeDist = 0.0, 0.0, 0.0
    meanDist, meanEdgeDist, meanMissEdgeDist = 0.0, 0.0, 0.0
    minDist, minEdgeDist, minMissEdgeDist = 180.0, 180.0, 180.0
    for ccdData in wcsList:
        amps = getAmps(ccdData, camera, ampDiskLayout, cursor, kind)
        for ampData in amps:
           sciCoords = [ccdData[0].pixelToSky(c[0], c[1]) for c in ampData[2]]
           rawCoords = [ampData[1].pixelToSky(c[0], c[1]) for c in ampData[3]]
           rawPoly = coordsToPolygon(rawCoords)
           v = rawPoly.getVertices()
           e = rawPoly.getEdges()
           for raw, sci in izip(rawCoords, sciCoords):
              sciPos = tuple(sci.getVector())
              dist = geom.cartesianAngularSep(tuple(raw.getVector()),
                                              tuple(sciPos))
              minDist = min(dist, minDist)
              maxDist = max(dist, maxDist)
              meanDist += dist
              edgeDist = 180.0
              for i in xrange(len(v)):
                  edgeDist = min(edgeDist, geom.minEdgeSep(sciPos, e[i], v[i - 1], v[i]))
              minEdgeDist = min(edgeDist, minEdgeDist)
              maxEdgeDist = max(edgeDist, maxEdgeDist)
              meanEdgeDist += edgeDist
              nSamples += 1
              if (ccdData[1], ampData[0].getId().getSerial()) in missedAmps:
                  minMissEdgeDist = min(edgeDist, minMissEdgeDist)
                  maxMissEdgeDist = max(edgeDist, maxMissEdgeDist)
                  meanMissEdgeDist += edgeDist
    meanDist /= nSamples
    meanEdgeDist /= nSamples
    print "----"
    print "Number of amps examined: %d" % nSamples
    print "Min  raw to science corner distance: %.6f deg" % minDist
    print "Max  raw to science corner distance: %.6f deg" % maxDist
    print "Mean raw to science corner distance: %.6f deg" % meanDist
    print "Min  min science corner to raw amp edge distance: %.6f deg" % minEdgeDist
    print "Max  min science corner to raw amp edge distance: %.6f deg" % maxEdgeDist
    print "Mean min science corner to raw amp edge distance: %.6f deg" % meanEdgeDist
    print "Number of amps missed: %d" % len(missedAmps)
    if len(missedAmps) > 0:
        meanMissEdgeDist /= len(missedAmps)
        print "Min  min science corner to missed raw amp edge distance: %.6f deg" % minMissEdgeDist
        print "Max  min science corner to missed raw amp edge distance: %.6f deg" % maxMissEdgeDist
        print "Mean min science corner to missed raw amp edge distance: %.6f deg" % meanMissEdgeDist
Пример #14
0
def main(figname, camera='hsc', output=None):

    # build a camera
    if camera == 'hsc':
        simdir = os.environ['OBS_SUBARU_DIR']
        cameraGeomPaf = os.path.join(simdir, "hsc", "hsc_geom.paf")
        if not os.path.exists(cameraGeomPaf):
            cameraGeomPaf = os.path.join(simdir, "hsc", "description",
                                         "hsc_geom.paf")
            if not os.path.exists(cameraGeomPaf):
                raise Exception("Unable to find cameraGeom Policy file: %s" %
                                (cameraGeomPaf))
        cameraGeomPolicy = camGeomUtils.getGeomPolicy(cameraGeomPaf)
        camera = camGeomUtils.makeCamera(cameraGeomPolicy)

    if not camera:
        raise ValueError("Camera must be ... uhm ... 'hsc'")

    ###########################
    # make RBG arrays with FpaImage objects
    # The FpaImage objects have a method to extract pixels from one CCD
    # So we'll create a dummy image and put the whole user image in it,
    # then we'll copy each CCD into the final image
    ###########################
    bin = 16
    fpa_img = [
        hscUtil.FpaImage(camera, scale=bin),
        hscUtil.FpaImage(camera, scale=bin),
        hscUtil.FpaImage(camera, scale=bin),
    ]
    fpa_dum = [
        hscUtil.FpaImage(camera, scale=bin),
        hscUtil.FpaImage(camera, scale=bin),
        hscUtil.FpaImage(camera, scale=bin),
    ]
    ny, nx = fpa_img[0].image.shape

    ###########################
    # Load the image the user provided.
    # figure out how much to scale things so it fits in our FpaImage
    ###########################
    img0 = PIL.Image.open(figname)
    h, w = img0.size
    if h >= w:
        scale = 1.0 * ny / h
    else:
        scale = 1.0 * nx / w
    img = numpy.array(
        img0.resize((int(scale * h), int(scale * w)), PIL.Image.ANTIALIAS))
    subw = int(scale * w)
    subh = int(scale * h)
    x0 = int(0.5 * (nx - subw))
    y0 = int(0.5 * (ny - subh))

    fpa_dum[0].image += 100
    for i in 0, 1, 2:
        fpa_dum[i].image[y0:y0 + subh, x0:x0 + subw] = img[:, :, i]

    ###########################
    # Now copy each CCD from the dummy to the original
    ###########################
    for i in 0, 1, 2:  #, 1, 2:
        for i_ccd in range(104):
            img2 = fpa_dum[i].getPixels(i_ccd)
            print i_ccd, img2.shape
            fpa_img[i].insert(i_ccd, img2)

    ###########################
    # convert this to an RBG image
    # we don't need to worry about uint8 with range 256, matplotlib will handle normalization.
    ###########################
    color_img = numpy.ones((ny, nx, 3), dtype=numpy.uint8)
    for i in range(3):
        color_img[:, :, i] = fpa_img[i].image

    ###########################
    # plot it
    ###########################
    fig = figure.Figure()
    canvas = FigCanvas(fig)
    ax = fig.add_subplot(111)
    ax.imshow(color_img)
    ax.get_xaxis().set_ticks([])
    ax.get_yaxis().set_ticks([])
    fig.savefig(output)