def makeRadiusBins(galaxy, basemap, outDir, beam=15.0): ''' Create bins for the data basemap: map used to create bins (SpectralCube Projection) outDir: directory to write output bin image Date Programmer Description of Changes ---------------------------------------------------------------------- 10/29/2020 Yiqing Song Original Code 12/3/2020 A.A. Kepley Added more comments plus moved GCR map calculate up to other code. 4/15/2021 A.A. Kepley Changes bins to be beam width apart in radius. ''' minrad = 0.0 + beam / 2.0 maxrad = np.max( basemap).value + beam # want to add one bin beyond to capture max. binedge = np.arange(minrad, maxrad, beam) binedge = np.insert(binedge, 0, 0) binedge = binedge * basemap.unit bins = np.digitize(basemap.value, binedge.value) binlabels = ['{0:1.2f}'.format(i) + ' arcsec' for i in binedge] # make bins map binmap = Projection(bins, wcs=basemap.wcs, header=basemap.header) binmap.write(os.path.join(outDir, galaxy['NAME'].upper() + '_binsbyradius.fits'), overwrite=True) return binmap, binedge, binlabels
def makeBins(galaxy, basemap, bintype, outDir): ''' Create bins for the data basemap: map used to create bins (SpectralCube Projection) bintype: type of bins ('intensity','stellarmass', 'radius') outDir: directory to write output bin image Date Programmer Description of Changes ---------------------------------------------------------------------- 10/29/2020 Yiqing Song Original Code 12/3/2020 A.A. Kepley Added more comments plus moved GCR map calculate up to other code. ''' if bintype == 'intensity' or bintype == 'stellarmass': #Bin the basemap by brightness binnum = int( np.log(np.nanmax(basemap.value) / np.nanmin(basemap.value))) + 1 binedge = np.nanmin(basemap.value) * np.logspace( 0, binnum, num=binnum + 1, base=np.e) #create bins based on dynamic range of mom0 bins = np.digitize( basemap.value, binedge ) #this will automatically add an extra bin in the end for nan values binlabels = [""] + [ '{0:1.2f}'.format(i) + basemap.unit.to_string() for i in binedge ] #need to add units to stellarmass map!! elif bintype == 'radius': binnum = 5 binedge = np.zeros(binnum + 1) binedge[1:] = np.logspace(-1, np.log10(0.5), num=binnum, base=10) #create bins based on r25 bins = np.digitize( basemap, binedge ) #this will automatically add an extra bin in the end for nan values binlabels = [""] + ['{0:1.2f}'.format(i) + 'R25' for i in binedge] else: raise Exception( "bintype should either be 'radius' or 'intensity' or 'stellarmass' " ) # Blank NaN values bins[bins == len(binedge)] = 0 # make bins map binmap = Projection(bins, wcs=basemap.wcs, header=basemap.header) binmap.write(os.path.join( outDir, galaxy['NAME'].upper() + '_binsby' + bintype + '.fits'), overwrite=True) return binmap, binedge, binlabels
def makeBins(galaxy, basemap, bintype): if bintype=='intensity' or bintype=='stellarmass': #Bin the basemap by brightness binnum=int(np.log(np.nanmax(basemap.value)/np.nanmin(basemap.value)))+1 binedge = np.nanmin(basemap.value)*np.logspace(0, binnum, num=binnum+1, base=np.e) #create bins based on dynamic range of mom0 bins = np.digitize(basemap.value, binedge) #this will automatically add an extra bin in the end for nan values binlabels=[""]+['{0:1.2f}'.format(i)+basemap.unit.to_string() for i in binedge] #need to add units to stellarmass map!! elif bintype=='radius': R_arcmin, R_kpc, R_r25=mapGCR(galaxy,basemap) #can choose from 3 different Rmaps binnum=5 binedge = np.zeros(binnum+1) binedge[1:]=np.logspace(-1, np.log10(0.5), num=binnum,base=10)#create bins based on r25 bins = np.digitize(R_r25, binedge) #this will automatically add an extra bin in the end for nan values binlabels=[""]+['{0:1.2f}'.format(i)+'R25' for i in binedge] else: raise Exception ("bintype should either be 'radius' or 'intensity' or 'stellarmass' ") # Blank NaN values bins[bins==len(binedge)] = 0 # make bins map binmap=Projection(bins,wcs=basemap.wcs,header=basemap.header) binmap.write(datadir+galaxy.upper()+'_binsby'+bintype+'.fits', overwrite=True) return binmap, binedge, binlabels
def makeMap(cubeFile, outDir, baseName=None,maskFile='',maptype='peakIntensity',order=0 ): """ Create peak intensity map from a cube Parameters cubeFile: str FITS filename of the cube outDir: str Directory in which to place the output FITS file maskFile: str FITS filename of the mask. Should have same geometry as cube. If not use routines in analysis_setup.py to regrid. maptype: str type of map to make. Options are peakIntensity, peakVelocity, linewidth, moment, and mask2D. order: int order for moment map """ if not baseName: baseName=os.path.basename(cubeFile).replace('.fits','') cube = SpectralCube.read(cubeFile).with_spectral_unit(u.km/u.s, velocity_convention='radio') if maskFile: maskCube = SpectralCube.read(maskFile).with_spectral_unit(u.km/u.s, velocity_convention='radio') mask = (maskCube.unitless_filled_data[:,:,:] > 0.5) maskedCube = cube.with_mask(mask) else: maskedCube = cube if maptype is 'peakIntensity': mymap = maskedCube.max(axis=0) outname = baseName+'_peakInt.fits' elif maptype is 'mask2D': mymap = maskedCube.max(axis=0) outname = baseName+'_mask2D.fits' elif maptype is 'linewidth': mymap = maskedCube.linewidth_fwhm() outname = baseName+'_linewidth.fits' elif maptype is 'moment': mymap = maskedCube.moment(order=order) outname = baseName+'_mom'+str(order)+'.fits' elif maptype is 'peakVelocity': velocity = maskedCube.spectral_axis mask = np.sum(maskedCube.get_mask_array(),axis=0) > 1.0 newwcs = maskedCube.wcs.dropaxis(2) peakind = maskedCube.argmax(axis=0) peakvel = velocity[peakind] peakvel[peakvel==velocity[0]] = np.nan mymap = Projection(peakvel, wcs=newwcs, mask=mask) outname = baseName + '_peakVelocity.fits' else: print('Map type unknown. Options are peakIntensity, linewidth, moment') return mymap.meta['MASK'] = maskFile mymap.write(os.path.join(outDir,outname),overwrite=True)