Esempio n. 1
0
    "Orion_Cal_R_0117": {"night": 20150117, "numbers": (465, 488)},
    "Orion_Cal_V_0117": {"night": 20150117, "numbers": (489, 512)},
    "Taurus_Cal_V_0118": {"night": 20150118, "numbers": (277, 300)},
    "Taurus_Cal_R_0118": {"night": 20150118, "numbers": (301, 324)},
    "Orion_Cal_V_0119": {"night": 20150119, "numbers": (1, 24)},
    "Orion_Cal_R_0119": {"night": 20150119, "numbers": (25, 48)},
}

pyBDP_reduced = os.path.join(pyBDP_data, "pyBDP_reduced_images")

for group in groupDict.keys():
    print("Processing group {0}".format(group))
    night = "{0:d}".format(groupDict[group]["night"])
    startNum, stopNum = groupDict[group]["numbers"]
    # Loop through all the file numbers (be sure to include the LAST file!)
    for fileNum in range(startNum, stopNum + 1):
        # Construct the filename for this file
        strNum = "{0:03d}".format(fileNum)
        fileName = ".".join([str(night), strNum, "fits"])
        thisFile = os.path.join(pyBDP_reduced, fileName)

        if os.path.isfile(thisFile):
            # Read in the file
            thisImg = AstroImage(thisFile)

            # Modify the header to match the group name and re-write
            thisImg.header["OBJECT"] = group
            thisImg.write()

print("Done!")
            effective_gain = effective_gain,
            read_noise = read_noise)

    # It is only possible to "redo the astrometry" if the file on the disk
    # First make a copy of the average image
    tmpImg = avgImg.copy()
    # Replace NaNs with something finite and name the file "tmp.fits"
    tmpImg.arr = np.nan_to_num(tmpImg.arr)
    tmpImg.filename = 'tmp.fits'

    # Delete the sigma attribute
    if hasattr(tmpImg, 'sigma'):
        del tmpImg.sigma

    # Record the temporary file to disk for performing astrometry
    tmpImg.write()

    # Solve the stacked image astrometry
    avgImg1, success = image_tools.astrometry(tmpImg, override = True)

    # With successful astrometry, save result to disk
    if success:
        print('astrometry succeded')

        # Clean up temporary files
        # TODO update to by system independent
        # (use subprocess module and "del" command for Windows)
        # See AstroImage.astrometry for example

        del tmpImg
Esempio n. 3
0
def on_key(event):
    global fileList, targetList, fig, imgNum, brushSize
    global maskDir, maskImg
    global prevImg,   thisImg,   nextImg
    global prevAxImg, thisAxImg, nextAxImg
    global prevTarget, thisTarget, nextTarget
    global prevMin,   thisMin,   nextMin
    global prevMax,   thisMax,   nextMax
    global prevLabel, thisLabel, nextLabel

    # Handle brush sizing
    if event.key == '1':
        brushSize = 1
    elif event.key == '2':
        brushSize = 2
    elif event.key == '3':
        brushSize = 3
    elif event.key == '4':
        brushSize = 4
    elif event.key == '5':
        brushSize = 5
    elif event.key == '6':
        brushSize = 6

    # Increment the image number
    if event.key == 'right' or event.key == 'left':
        if event.key == 'right':
            #Advance to the next image
            imgNum += 1

            # Read in the new files
            prevImg = thisImg
            thisImg = nextImg
            nextImg = AstroImage(fileList[(imgNum + 1) % len(fileList)])

            # Update target info
            prevTarget = thisTarget
            thisTarget = nextTarget
            nextTarget = targetList[(imgNum + 1) % len(fileList)]

            # Compute new image display minima
            prevMin = thisMin
            thisMin = nextMin
            nextMin = np.median(nextImg.arr) - 0.25*np.std(nextImg.arr)

            # Compute new image display maxima
            prevMax = thisMax
            thisMax = nextMax
            nextMax = np.median(nextImg.arr) + 2*np.std(nextImg.arr)

        if event.key == 'left':
            #Move back to the previous image
            imgNum -= 1

            # Read in the new files
            nextImg = thisImg
            thisImg = prevImg
            prevImg = AstroImage(fileList[(imgNum - 1) % len(fileList)])

            # Update target info
            nextTarget = thisTarget
            thisTarget = prevTarget
            prevTarget = targetList[(imgNum - 1) % len(fileList)]

            # Compute new image display minima
            nextMin = thisMin
            thisMin = prevMin
            prevMin = np.median(prevImg.arr) - 0.25*np.std(prevImg.arr)

            # Compute new image display maxima
            nextMax = thisMax
            thisMax = prevMax
            prevMax = np.median(prevImg.arr) + 2*np.std(prevImg.arr)

        #*******************************
        # Update the displayed mask
        #*******************************

        # Check which mask files might be usable...
        prevMaskFile = os.path.join(maskDir,
            os.path.basename(prevImg.filename))
        thisMaskFile = os.path.join(maskDir,
            os.path.basename(thisImg.filename))
        nextMaskFile = os.path.join(maskDir,
            os.path.basename(nextImg.filename))
        if os.path.isfile(thisMaskFile):
            # If the mask for this file exists, use it
            print('using this mask: ',os.path.basename(thisMaskFile))
            maskImg = AstroImage(thisMaskFile)
        elif os.path.isfile(prevMaskFile) and (prevTarget == thisTarget):
            # Otherwise check for the mask for the previous file
            print('using previous mask: ',os.path.basename(prevMaskFile))
            maskImg = AstroImage(prevMaskFile)
        elif os.path.isfile(nextMaskFile) and (nextTarget == thisTarget):
            # Then check for the mask of the next file
            print('using next mask: ',os.path.basename(nextMaskFile))
            maskImg = AstroImage(nextMaskFile)
        else:
            # If none of those files exist, build a blank slate
            # Build a mask template (0 = not masked, 1 = masked)
            maskImg       = thisImg.copy()
            maskImg.filename = thisMaskFile
            maskImg.arr   = maskImg.arr.astype(np.int16) * np.int16(0)
            maskImg.dtype = np.byte
            maskImg.header['BITPIX'] = 16

        # Update contour plot (clear old lines redo contouring)
        axarr[1].collections = []
        axarr[1].contour(xx, yy, maskImg.arr, levels=[0.5], colors='white', alpha = 0.2)

        # Reassign image display limits
        prevAxImg.set_clim(vmin = prevMin, vmax = prevMax)
        thisAxImg.set_clim(vmin = thisMin, vmax = thisMax)
        nextAxImg.set_clim(vmin = nextMin, vmax = nextMax)

        # Display the new images
        prevAxImg.set_data(prevImg.arr)
        thisAxImg.set_data(thisImg.arr)
        nextAxImg.set_data(nextImg.arr)

        # Update the annotation
        axList = fig.get_axes()
        axList[1].set_title(os.path.basename(thisImg.filename))

        prevStr   = (str(prevImg.header['OBJECT']) + '\n' +
                     str(prevImg.header['FILTNME3'] + '\n' +
                     str(prevImg.header['POLPOS'])))
        thisStr   = (str(thisImg.header['OBJECT']) + '\n' +
                     str(thisImg.header['FILTNME3'] + '\n' +
                     str(thisImg.header['POLPOS'])))
        nextStr   = (str(nextImg.header['OBJECT']) + '\n' +
                     str(nextImg.header['FILTNME3'] + '\n' +
                     str(nextImg.header['POLPOS'])))
        prevLabel.set_text(prevStr)
        thisLabel.set_text(thisStr)
        nextLabel.set_text(nextStr)

        # Update the display
        fig.canvas.draw()

    # Save the generated mask
    if event.key == 'enter':
        # Make sure the header has the right values
        maskImg.header = thisImg.header

        # Write the mask to disk
        print('Writing mask for file ', os.path.basename(maskImg.filename))
        maskImg.write()

    # Clear out the mask values
    if event.key == 'backspace':
        # Clear out the mask array
        maskImg.arr = maskImg.arr * np.byte(0)

        # Update contour plot (clear old lines redo contouring)
        axarr[1].collections = []
        axarr[1].contour(xx, yy, maskImg.arr, levels=[0.5], colors='white', alpha = 0.2)

        # Update the display
        fig.canvas.draw()