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
guideheader['NAXIS1'] = np.shape(high_res_template )[1] guideheader['NAXIS2'] = np.shape(high_res_template )[0] guideheader['META_1'] = np.shape(high_res_template )[1] guideheader['META_1'] = np.shape(high_res_template )[0] guideheader['FREQ_0'] = (nu0/1e9, '[GHz] frequency at which the opacity power law is locked') guideheader['KAPPA_0'] = (kappa0, '[cm^2/g] dust opacity at FREQ_0') guideheader['BETA'] = (beta, 'Dust emissivity') guideheader['GAS2DUST'] = (gastodust, 'gas to dus ratio') #guideheader['AUTHOR'] = ('Ayushi Singh') os.system("rm {0}".format(template)) fits.writeto(template, high_res_template , guideheader) # regriding all the image to a corresponding variable print "Final regriging started." C_D_250 = rf.regrid(CD_250, template, savefile = False) C_D_350 = rf.regrid(CD_350, template, savefile = False) C_D_500 = rf.regrid(CD_500, template, savefile = False) C_D_250_conv = rf.regrid(CD_250_conv, template, savefile = False) C_D_350_conv = rf.regrid(CD_350_conv, template, savefile = False) Temperature_250 = rf.regrid(T_250, template, savefile = False) Temperature_350 = rf.regrid(T_350, template, savefile = False) Temperature_500 = rf.regrid(T_500, template, savefile = False) Temperature_250_conv = rf.regrid(T_250_conv, template, savefile = False) Temperature_350_conv = rf.regrid(T_350_conv, template, savefile = False) print "Final regriding ended. \n" ################################# high resolution CD map ########################################## # calculating high resolution column density hold1 = (C_D_350)-(C_D_350_conv)