def make_column_density(wavelength, files): ''' This function uses wavelengths and images at those wavelengths to generate column density and temperature after properly convolving and regriding the images. This uses following functions: resconvolve and regrid from required_functions make_maps and make_colour_map from colden_functions Parameters ---------- wavelengths : 1-D array array of all the wavelength in micron file: 1-D array of srings Path and name of all the required flux files Returns ------- Temperature : 2-D array map of temerature in Kelvin C_D : 2-D array map of column density in cm^-2 MassCD : 2-D array map of column density in M_sun/pc^2 fitheader : header header needed for final images ''' print print "Total number of files:", len(files) # store all the images in one list im = [] # resolution for each wavelength original_res = [beamsize['160'], beamsize['250'], beamsize['350'], beamsize['500']] # get the template wavelength and file name # template is the one that is not changed in the end template_wavelength = wavelength[-1] template_map_name = files[-1] print "Template wavelength:", template_wavelength print "Template image name:", template_map_name # get the resolution of the template file if template_wavelength == 160.: required_res = original_res[0] elif template_wavelength == 250.: required_res = original_res[1] elif template_wavelength == 350.: required_res = original_res[2] elif template_wavelength == 500.: required_res = original_res[3] print "Template resolution:", required_res print # this loops goes though each file for i in range(len(files)): print wavelength[i] # if the file is not the template file then # 1) it is convolved to the resolution of template map # 2) it is regrid to the shape and size of template # 3) saved into an array if wavelength[i] != template_wavelength: # file names used conv_file = files[i][:-5]+'.conv.fits' # convolve file resamp_file = conv_file[:-5]+'.resamp.fits' # resampled image print conv_file print resamp_file # remove if these files are already there os.system("rm {0}".format(conv_file)) os.system("rm {0}".format(resamp_file)) # convolve the image rf.resconvolve(files[i],required_res,original_res[i], resultimage = conv_file) # resample image rf.regrid(conv_file, template_map_name, resultimage = resamp_file, header = None) print # 3) open the resample file and store the data into the bigger list (im) image = fits.getdata(resamp_file) im.append(image) print "shape:", np.shape(image) # else if, the file is the template file then # saved into an array without alteration elif wavelength[i] == template_wavelength: image, fitheader= fits.getdata(files[i], header = True) im.append(image) print "shape:", np.shape(image) print # make wavelength 0 for column density and temp dont have wavelength try: fitheader.remove(keyword='WAVELNTH') except: print fitheader['FREQ_0'] = (nu0/1e9, '[GHz] frequency at which the opacity power law is locked') fitheader['KAPPA_0'] = (kappa0, '[cm^2/g] dust opacity at FREQ_0') fitheader['BETA'] = (beta, 'Dust emissivity') fitheader['GAS2DUST'] = (gastodust, 'gas to dus ratio') #fitheader['AUTHOR'] = ('Ayushi Singh') # run this function that will make column-density and temperature maps # parameters are: wavelength [micron], im: all the images in an array [MJy/sr], pixelsize used to calculate radius # Dataset: used for the title, plots: this is false unless want plot at every 1000 value if len(files) > 2: Temperature, C_D, MassCD = cf.make_SED_maps(wavelength, im) elif len(files) ==2 : Temperature, C_D, MassCD = cf.make_colour_map(wavelength, im) return Temperature, C_D, MassCD, fitheader
fits.writeto(T_250,Temperature_250,fithead_250) fithead_250['BUNIT'] = 'cm^-2' fithead_250['HEADER'] = 'Column Density' fits.writeto(CD_250,C_D_250,fithead_250) fithead_250['BUNIT'] = 'Msun/pc^2' fithead_250['HEADER'] = 'Column Density' fits.writeto(CD_M_250,CD_Msun_250,fithead_250) ################################################################################################## # convolve the real file to a given resolution print "Final convolving started." rf.resconvolve(CD_350,beamsize['500'],beamsize['350'], resultimage = CD_350_conv) rf.resconvolve(CD_250,beamsize['350'],beamsize['250'], resultimage = CD_250_conv) rf.resconvolve(T_350,beamsize['500'],beamsize['350'], resultimage = T_350_conv) rf.resconvolve(T_250,beamsize['350'],beamsize['250'], resultimage = T_250_conv) print "Final convolving ended. \n" # resisze these image to the 3" template # using 160 as a guideline for the template image. guide, guideheader = fits.getdata(file160, header = True) high_res_template = np.zeros([np.shape(guide)[0],np.shape(guide)[1]]) #editing the template header try: quideheader.remove(keyword='WAVELNTH') quideheader.remove(keyword='OFFSET')