def subtract_images_subroutine(name, dark): imA = pyfits.getdata(name) imAh = pyfits.getheader(name) imAh['SUBBED'] = 1 imB = np.subtract(imA, dark) sub_name = name.split(".")[0] new_name = "{0}_subDARK.fits".format(sub_name) pyfits.writeto(new_name, imB, imAh, overwrite=True) print "{0}, OK".format(new_name) #--------------------------------------- # Write to database cwd = os.getcwd() mysqlio_lib.save2sql_images(new_name, cwd) return new_name
def divide_images(image_list, flat_name): flat = pyfits.getdata(flat_name) new_image_list = [] for name in image_list: imA = pyfits.getdata(name) imAh = pyfits.getheader(name) imAh['FLATDIVED'] = 1 imB = np.divide(imA, flat) sub_name = name.split(".")[0] new_name = "{0}_divFLAT.fits".format(sub_name) new_image_list.append(new_name) pyfits.writeto(new_name, imB, imAh, overwrite=True) print "{0}, OK ".format(new_name) #--------------------------------------- # Write to database cwd = os.getcwd() mysqlio_lib.save2sql_images(new_name, cwd) return new_image_list
def subtract_images(image_list, dark_name): dark = pyfits.getdata(dark_name) new_image_list = [] print(len(image_list)) for name in image_list: try: imA = pyfits.getdata(name) imAh = pyfits.getheader(name) imAh['SUBBED'] = 1 imB = np.subtract(imA, dark) sub_name = name.split(".")[0] new_name = "{0}_subDARK.fits".format(sub_name) new_image_list.append(new_name) pyfits.writeto(new_name, imB, imAh, overwrite=True) print "{0}, OK".format(new_name) #--------------------------------------- # Write to database cwd = os.getcwd() mysqlio_lib.save2sql_images(new_name, cwd) except: print "{0} cannot be subtracted by dark".format(name) pass return new_image_list
#---------------------------------------- # Load arguments if len(argv) != 2: print 'The number of arguments is wrong.' print 'Usage: mask_image.py [a list of image name]' exit() list_name = argv[1] image_name_list = np.loadtxt(list_name, dtype=str) #--------------------------------------- for image_name in image_name_list: # Load data data = pyfits.getdata(image_name) header = pyfits.getheader(image_name) # Mask data[:200] = np.nan # Save data new_name = '{0}_mask.fits'.format(image_name[:-5]) pyfits.writeto(new_name, data, header, overwrite=True) print "{0}, done".format(new_name) #--------------------------------------- # Write to database cwd = os.getcwd() mysqlio_lib.save2sql_images(new_name, cwd) # Save the result as a list temp = "ls *_mask.fits > masked_image_list.txt" os.system(temp) #--------------------------------------- # Measure time elapsed_time = time.time() - start_time print "Exiting Main Program, spending ", elapsed_time, "seconds."