from astropy.convolution import Gaussian2DKernel from astropy.modeling import models, fitting from astropy.stats import gaussian_fwhm_to_sigma, sigma_clipped_stats from photutils import (make_source_mask, MedianBackground, SigmaClip, Background2D) # Import plotting utilities from matplotlib import pyplot as plt # Add the AstroImage class import astroimage as ai # Add the header handler to the BaseImage class from Mimir_header_handler import Mimir_header_handler ai.reduced.ReducedScience.set_header_handler(Mimir_header_handler) ai.set_instrument('mimir') # Grad the assigned keyword for the airmass value airmassKeyword = ai.reduced.ReducedScience.headerKeywordDict['AIRMASS'] #============================================================================== # *********************** CUSTOM USER CODE ************************************ # this is where the user specifies where the raw data is stored # and some of the subdirectory structure to find the actual .FITS images #============================================================================== # This is where the associated PPOL directory is located PPOL_dir = 'C:\\Users\\Jordan\\FITS_data\\Mimir_data\\PPOL_Reduced\\201611' # The user must specify the *name* of the PPOL meta-groups associated with each # target-filter combination. This will allow the script to locate the computed
import glob import numpy as np from skimage import measure, morphology from astropy.table import Table, Column from astropy.stats import gaussian_fwhm_to_sigma, sigma_clipped_stats from astropy.convolution import convolve, convolve_fft, Gaussian2DKernel # For debugging import matplotlib.pyplot as plt # Add the AstroImage class import astroimage as ai # Add the header handler to the BaseImage class from Mimir_header_handler import Mimir_header_handler ai.set_instrument('2mass') # This script will read in the background level estimated for each on-target # image in the previous step. The background level in dimmest parts of the # on-target image will be directly computed, and the residual between the direct # estimate and the interpolation will be stored. The distribution of these # residual will be used to estimate which interpolated background levels can be # trusted. #============================================================================== # *********************** CUSTOM USER CODE ************************************ # this is where the user specifies where the raw data is stored # and some of the subdirectory structure to find the actual .FITS images #============================================================================== # This is the location of all PPOL reduction directory
# hack script to set the bad pixels to the right value for PPOL import os import glob import numpy as np import astroimage as ai ai.set_instrument('Mimir') bkgFreeDir = 'C:\\Users\\Jordan\\FITS_data\\Mimir_data\\pyPol_Reduced\\201611\\bkgFreeHWPimages' fileList = glob.glob(os.path.join(bkgFreeDir, '*.fits')) for file1 in fileList: print('processing {}'.format(os.path.basename(file1))) img = ai.reduced.ReducedScience.read(file1) # Capture NaNs and bad values and set them to -1e6 so that PPOL will # know what to do with those values. tmpData = img.data badPix = np.logical_not(np.isfinite(tmpData)) tmpData[np.where(badPix)] = -1e6 badPix = np.abs(tmpData) > 1e5 tmpData[np.where(badPix)] = -1e6 # Store the data in the image object img.data = tmpData # Write back to disk img.write(file1, dtype=np.float32, clobber=True) print('Done!')
import sys import time import numpy as np import matplotlib.pyplot as plt from astropy.table import Table, Column from astropy.coordinates import SkyCoord import astropy.units as u from scipy import stats # Add the AstroImage class import astroimage as ai # Add the header handler to the BaseImage class from Mimir_header_handler import Mimir_header_handler ai.reduced.ReducedScience.set_header_handler(Mimir_header_handler) ai.set_instrument('mimir') #============================================================================== # *********************** CUSTOM USER CODE ************************************ # this is where the user specifies where the raw data is stored # and some of the subdirectory structure to find the actual .FITS images #============================================================================== # Define the location of the PPOL reduced data to be read and worked on PPOL_data = 'C:\\Users\\Jordan\\FITS_data\\Mimir_data\\PPOL_Reduced\\201611\\' S3_dir = os.path.join(PPOL_data, 'S3_Astrometry') # This is the location where all pyPol data will be saved pyPol_data = 'C:\\Users\\Jordan\\FITS_data\\Mimir_data\\pyPol_Reduced\\201611' # Set the filename for the reduced data indexFile and read it in reducedFileIndexFile = os.path.join(pyPol_data, 'reducedFileIndex.csv')
# Short script to read in and display all the images in the diagnostic dir import glob import numpy as np import time from astropy.stats import sigma_clipped_stats, freedman_bin_width from scipy import ndimage import astroimage as ai ai.set_instrument('Mimir') fileList = glob.glob('*.fits') fileList = np.array(fileList) fileList.sort() # Define a quick mode function def mode(array): """An estimate of the statistical mode of this image""" # SUPER fast and sloppy mode estimate: mean, median, std = sigma_clipped_stats(array) quickModeEst = 3*median - 2*mean # Compute an approximately 3-sigma range about this modeRegion = quickModeEst + std*np.array([-1.5, +1.5]) # Now compute the number of bins to generate in this range binWidth = freedman_bin_width(array.flatten()) bins = np.arange(modeRegion[0], modeRegion[1], binWidth) # Loop through larger and larger binning until find unique solution foundMode = False while not foundMode:
os.mkdir(bkgFreeImagesDir, 0o755) # Read in the indexFile data and select the filenames indexFile = os.path.join(pyPol_data, 'reducedFileIndex.csv') fileIndex = Table.read(indexFile, format='csv') # Read in the kokopelli mask from astropy.io import fits kokopelliHDUlist = fits.open('kokopelliMask.fits') kokopelliMask = (kokopelliHDUlist[0].data > 0) # Read in the 2MASS masks TMASSdir = ".\\2MASSimages" # Set the instrument to 2MASS ai.set_instrument('2MASS') # Read in all the 2MASS images and store them in a dictionary for quick reference TMASS_Hfiles = np.array(glob.glob(os.path.join(TMASSdir, '*H_mask.fits'))) TMASS_Kfiles = np.array(glob.glob(os.path.join(TMASSdir, '*Ks_mask.fits'))) # Read in the 2MASS images TMASS_HmaskList = [ai.reduced.ReducedScience.read(f) for f in TMASS_Hfiles] TMASS_KmaskList = [ai.reduced.ReducedScience.read(f) for f in TMASS_Kfiles] # Parse the targets for each file TMASS_Htargets = [os.path.basename(f).split('_')[0] for f in TMASS_Hfiles] TMASS_Ktargets = [os.path.basename(f).split('_')[0] for f in TMASS_Kfiles] # Store these masks in a dictionary TMASS_HimgDict = dict(zip(TMASS_Htargets, TMASS_HmaskList))
os.mkdir(bkgFreeImagesDir, 0o755) # Read in the indexFile data and select the filenames indexFile = os.path.join(pyPol_data, 'reducedFileIndex.csv') fileIndex = Table.read(indexFile, format='csv') # Read in the kokopelli mask from astropy.io import fits kokopelliHDUlist = fits.open('kokopelliMask.fits') kokopelliMask = (kokopelliHDUlist[0].data > 0) # Read in the 2MASS masks TMASSdir = ".\\2MASSimages" # Set the instrument to 2MASS ai.set_instrument('2MASS') # Read in all the 2MASS images and store them in a dictionary for quick reference TMASS_Hfiles = np.array(glob.glob(os.path.join(TMASSdir, '*H_mask.fits'))) TMASS_Kfiles = np.array(glob.glob(os.path.join(TMASSdir, '*Ks_mask.fits'))) # Read in the 2MASS images TMASS_HmaskList = [ai.reduced.ReducedScience.read(f) for f in TMASS_Hfiles] TMASS_KmaskList = [ai.reduced.ReducedScience.read(f) for f in TMASS_Kfiles] # Parse the targets for each file TMASS_Htargets = [os.path.basename(f).split('_')[0] for f in TMASS_Hfiles] TMASS_Ktargets = [os.path.basename(f).split('_')[0] for f in TMASS_Kfiles] # Store these masks in a dictionary TMASS_HimgDict = dict(zip(