def dust_vals_disk(self,lcen,bcen,dist,radius): """ NAME: dust_vals_disk PURPOSE: return the distribution of extinction within a small disk as samples INPUT: lcen, bcen - Galactic longitude and latitude of the center of the disk (deg) dist - distance in kpc radius - radius of the disk (deg) OUTPUT: (pixarea,extinction) - arrays of pixel-area in sq rad and extinction value HISTORY: 2015-03-07 - Written - Bovy (IAS) """ # Find all of the (l,b) of the pixels within radius of (lcen,bcen) indx= cos_sphere_dist(self._sintheta,self._costheta, self._sinphi,self._cosphi, numpy.sin((90.-bcen)*_DEGTORAD), numpy.cos((90.-bcen)*_DEGTORAD), numpy.sin(lcen*_DEGTORAD), numpy.cos(lcen*_DEGTORAD)) \ >= numpy.cos(radius*_DEGTORAD) ll= self._saledata['GLON'][indx] bb= self._saledata['GLAT'][indx] # Now get the extinctions for these pixels pixarea= [] extinction= [] for l,b in zip(ll,bb): lbIndx= self._lbIndx(l,b) extinction.append(self._evaluate(l,b,dist,_lbIndx=lbIndx)) pixarea.append(self._dl[lbIndx]*self._db[lbIndx]*_DEGTORAD**2.) pixarea= numpy.array(pixarea) extinction= numpy.array(extinction) return (pixarea,extinction)
def dust_vals_disk(self, lcen, bcen, dist, radius): """ NAME: dust_vals_disk PURPOSE: return the distribution of extinction within a small disk as samples INPUT: lcen, bcen - Galactic longitude and latitude of the center of the disk (deg) dist - distance in kpc radius - radius of the disk (deg) OUTPUT: (pixarea,extinction) - arrays of pixel-area in sq rad and extinction value HISTORY: 2015-03-07 - Written - Bovy (IAS) """ # Find all of the (l,b) of the pixels within radius of (lcen,bcen) lmin = round((lcen - radius - self._dl) / self._dl) * self._dl lmax = round((lcen + radius + self._dl) / self._dl) * self._dl bmin = round((bcen - radius - self._db) / self._db) * self._db bmax = round((bcen + radius + self._db) / self._db) * self._db ls = numpy.arange(lmin, lmax + self._dl, self._dl) bs = numpy.arange(bmin, bmax + self._db, self._db) ll, bb = numpy.meshgrid(ls, bs, indexing='ij') ll = ll.flatten() bb = bb.flatten() indx= cos_sphere_dist(numpy.sin((90.-bb)*_DEGTORAD), numpy.cos((90.-bb)*_DEGTORAD), numpy.sin(ll*_DEGTORAD), numpy.cos(ll*_DEGTORAD), numpy.sin((90.-bcen)*_DEGTORAD), numpy.cos((90.-bcen)*_DEGTORAD), numpy.sin(lcen*_DEGTORAD), numpy.cos(lcen*_DEGTORAD)) \ >= numpy.cos(radius*_DEGTORAD) ll = ll[indx] bb = bb[indx] # Now get the extinctions for these pixels pixarea = self._dl * self._db * _DEGTORAD**2. + numpy.zeros( numpy.sum(indx)) extinction = [] for l, b in zip(ll, bb): extinction.append(self._evaluate(l, b, dist)) extinction = numpy.array(extinction) return (pixarea, extinction)
def dust_vals_disk(self,lcen,bcen,dist,radius): """ NAME: dust_vals_disk PURPOSE: return the distribution of extinction within a small disk as samples INPUT: lcen, bcen - Galactic longitude and latitude of the center of the disk (deg) dist - distance in kpc radius - radius of the disk (deg) OUTPUT: (pixarea,extinction) - arrays of pixel-area in sq rad and extinction value HISTORY: 2015-03-07 - Written - Bovy (IAS) """ # Find all of the (l,b) of the pixels within radius of (lcen,bcen) lmin= round((lcen-radius-self._dl)/self._dl)*self._dl lmax= round((lcen+radius+self._dl)/self._dl)*self._dl bmin= round((bcen-radius-self._db)/self._db)*self._db bmax= round((bcen+radius+self._db)/self._db)*self._db ls= numpy.arange(lmin,lmax+self._dl,self._dl) bs= numpy.arange(bmin,bmax+self._db,self._db) ll,bb= numpy.meshgrid(ls,bs,indexing='ij') ll= ll.flatten() bb= bb.flatten() indx= cos_sphere_dist(numpy.sin((90.-bb)*_DEGTORAD), numpy.cos((90.-bb)*_DEGTORAD), numpy.sin(ll*_DEGTORAD), numpy.cos(ll*_DEGTORAD), numpy.sin((90.-bcen)*_DEGTORAD), numpy.cos((90.-bcen)*_DEGTORAD), numpy.sin(lcen*_DEGTORAD), numpy.cos(lcen*_DEGTORAD)) \ >= numpy.cos(radius*_DEGTORAD) ll= ll[indx] bb= bb[indx] # Now get the extinctions for these pixels pixarea= self._dl*self._db*_DEGTORAD**2.+numpy.zeros(numpy.sum(indx)) extinction= [] for l,b in zip(ll,bb): extinction.append(self._evaluate(l,b,dist)) extinction= numpy.array(extinction) return (pixarea,extinction)
def _evaluate(self, l, b, d, norescale=False, _fd=1., _fs=1., _fo=1.): """ NAME: _evaluate PURPOSE: evaluate the dust-map INPUT: l- Galactic longitude (deg) b- Galactic latitude (deg) d- distance (kpc) can be array norescale= (False) if True, don't apply re-scalings _fd, _fs, _fo= (1.) amplitudes of the different components OUTPUT: extinction HISTORY: 2013-12-10 - Started - Bovy (IAS) """ if isinstance(l, numpy.ndarray) or isinstance(b, numpy.ndarray): raise NotImplementedError( "array input for l and b for Drimmel dust map not implemented") cl = numpy.cos(l * _DEGTORAD) sl = numpy.sin(l * _DEGTORAD) cb = numpy.cos(b * _DEGTORAD) sb = numpy.sin(b * _DEGTORAD) #Setup arrays avori = numpy.zeros_like(d) avspir = numpy.zeros_like(d) avdisk = numpy.zeros_like(d) #Find nearest pixel in COBE map for the re-scaling rfIndx = numpy.argmax( cos_sphere_dist(self._rf_sintheta, self._rf_costheta, self._rf_sinphi, self._rf_cosphi, numpy.sin(numpy.pi / 2. - b * _DEGTORAD), numpy.cos(numpy.pi / 2. - b * _DEGTORAD), sl, cl)) rfdisk, rfspir, rfori = 1., 1., 1, if self._drimmelMaps['rf_comp'][rfIndx] == 1 and not norescale: rfdisk = self._drimmelMaps['rf'][rfIndx] elif self._drimmelMaps['rf_comp'][rfIndx] == 2 and not norescale: rfspir = self._drimmelMaps['rf'][rfIndx] elif self._drimmelMaps['rf_comp'][rfIndx] == 3 and not norescale: rfori = self._drimmelMaps['rf'][rfIndx] #Find maximum distance dmax = 100. if b != 0.: dmax = .49999 / numpy.fabs(sb) - self._zsun / sb if cl != 0.: tdmax = (14.9999 / numpy.fabs(cl) - self._xsun / cl) if tdmax < dmax: dmax = tdmax if sl != 0.: tdmax = 14.9999 / numpy.fabs(sl) if tdmax < dmax: dmax = tdmax d = copy.copy(d) d[d > dmax] = dmax #Rectangular coordinates X = d * cb * cl Y = d * cb * sl Z = d * sb + self._zsun #Local grid #Orion locIndx = (numpy.fabs(X) < 1.) * (numpy.fabs(Y) < 2.) if numpy.sum(locIndx) > 0: xi = X[locIndx] / self._dx_ori2 + float(self._nx_ori2 - 1) / 2. yj = Y[locIndx] / self._dy_ori2 + float(self._ny_ori2 - 1) / 2. zk = Z[locIndx] / self._dz_ori2 + float(self._nz_ori2 - 1) / 2. avori[locIndx] = map_coordinates(self._drimmelMaps['avori2'], [xi, yj, zk], mode='constant', cval=0.) #local disk locIndx = (numpy.fabs(X) < 0.75) * (numpy.fabs(Y) < 0.75) if numpy.sum(locIndx) > 0: xi = X[locIndx] / self._dx_diskloc + float(self._nx_diskloc - 1) / 2. yj = Y[locIndx] / self._dy_diskloc + float(self._ny_diskloc - 1) / 2. zk = Z[locIndx] / self._dz_diskloc + float(self._nz_diskloc - 1) / 2. avdisk[locIndx] = map_coordinates(self._drimmelMaps['avdloc'], [xi, yj, zk], mode='constant', cval=0.) #Go to Galactocentric coordinates X = X + self._xsun #Stars beyond the local grid #Orion globIndx = True - (numpy.fabs(X - self._xsun) < 1.) * (numpy.fabs(Y) < 2.) if numpy.sum(globIndx) > 0: #Orion grid is different from other global grids, so has its own dmax dmax = 100. if b != 0.: dmax = .49999 / numpy.fabs(sb) - self._zsun / sb if cl > 0.: tdmax = (2.374999 / numpy.fabs(cl)) if tdmax < dmax: dmax = tdmax if cl < 0.: tdmax = (1.374999 / numpy.fabs(cl)) if tdmax < dmax: dmax = tdmax if sl != 0.: tdmax = (3.749999 / numpy.fabs(sl)) if tdmax < dmax: dmax = tdmax dori = copy.copy(d) dori[dori > dmax] = dmax Xori = dori * cb * cl + self._xsun Yori = dori * cb * sl Zori = dori * sb + self._zsun xi = Xori[globIndx] / self._dx_ori + 2.5 * float(self._nx_ori - 1) yj = Yori[globIndx] / self._dy_ori + float(self._ny_ori - 1) / 2. zk = Zori[globIndx] / self._dz_ori + float(self._nz_ori - 1) / 2. avori[globIndx] = map_coordinates(self._drimmelMaps['avori'], [xi, yj, zk], mode='constant', cval=0.) #disk & spir xi = X / self._dx_disk + float(self._nx_disk - 1) / 2. yj = Y / self._dy_disk + float(self._ny_disk - 1) / 2. zk = Z / self._dz_disk + float(self._nz_disk - 1) / 2. avspir = map_coordinates(self._drimmelMaps['avspir'], [xi, yj, zk], mode='constant', cval=0.) globIndx = True - (numpy.fabs(X - self._xsun) < 0.75) * (numpy.fabs(Y) < 0.75) if numpy.sum(globIndx) > 0: avdisk[globIndx] = map_coordinates(self._drimmelMaps['avdisk'], [xi, yj, zk], mode='constant', cval=0.)[globIndx] #Return out = _fd * rfdisk * avdisk + _fs * rfspir * avspir + _fo * rfori * avori if self._filter is None: # From Rieke & Lebovksy (1985); if sf10, first put ebv on SFD scale return out / 3.09 / ((1 - self._sf10) + self._sf10 * 0.86) else: return out/3.09/((1-self._sf10)+self._sf10*0.86)\ *aebv(self._filter,sf10=self._sf10)
def _evaluate(self,l,b,d,norescale=False, _fd=1.,_fs=1.,_fo=1.): """ NAME: _evaluate PURPOSE: evaluate the dust-map INPUT: l- Galactic longitude (deg) b- Galactic latitude (deg) d- distance (kpc) can be array norescale= (False) if True, don't apply re-scalings _fd, _fs, _fo= (1.) amplitudes of the different components OUTPUT: extinction HISTORY: 2013-12-10 - Started - Bovy (IAS) """ if isinstance(l,numpy.ndarray) or isinstance(b,numpy.ndarray): raise NotImplementedError("array input for l and b for Drimmel dust map not implemented") cl= numpy.cos(l*_DEGTORAD) sl= numpy.sin(l*_DEGTORAD) cb= numpy.cos(b*_DEGTORAD) sb= numpy.sin(b*_DEGTORAD) #Setup arrays avori= numpy.zeros_like(d) avspir= numpy.zeros_like(d) avdisk= numpy.zeros_like(d) #Find nearest pixel in COBE map for the re-scaling rfIndx= numpy.argmax(cos_sphere_dist(self._rf_sintheta, self._rf_costheta, self._rf_sinphi, self._rf_cosphi, numpy.sin(numpy.pi/2.-b*_DEGTORAD), numpy.cos(numpy.pi/2.-b*_DEGTORAD), sl,cl)) rfdisk, rfspir, rfori= 1., 1., 1, if self._drimmelMaps['rf_comp'][rfIndx] == 1 and not norescale: rfdisk= self._drimmelMaps['rf'][rfIndx] elif self._drimmelMaps['rf_comp'][rfIndx] == 2 and not norescale: rfspir= self._drimmelMaps['rf'][rfIndx] elif self._drimmelMaps['rf_comp'][rfIndx] == 3 and not norescale: rfori= self._drimmelMaps['rf'][rfIndx] #Find maximum distance dmax= 100. if b != 0.: dmax= .49999/numpy.fabs(sb) - self._zsun/sb if cl != 0.: tdmax= (14.9999/numpy.fabs(cl)-self._xsun/cl) if tdmax < dmax: dmax= tdmax if sl != 0.: tdmax = 14.9999/numpy.fabs(sl) if tdmax < dmax: dmax= tdmax d= copy.copy(d) d[d > dmax]= dmax #Rectangular coordinates X= d*cb*cl Y= d*cb*sl Z= d*sb+self._zsun #Local grid #Orion locIndx= (numpy.fabs(X) < 1.)*(numpy.fabs(Y) < 2.) if numpy.sum(locIndx) > 0: xi = X[locIndx]/self._dx_ori2+float(self._nx_ori2-1)/2. yj = Y[locIndx]/self._dy_ori2+float(self._ny_ori2-1)/2. zk = Z[locIndx]/self._dz_ori2+float(self._nz_ori2-1)/2. avori[locIndx]= map_coordinates(self._drimmelMaps['avori2'], [xi,yj,zk], mode='constant',cval=0.) #local disk locIndx= (numpy.fabs(X) < 0.75)*(numpy.fabs(Y) < 0.75) if numpy.sum(locIndx) > 0: xi = X[locIndx]/self._dx_diskloc+float(self._nx_diskloc-1)/2. yj = Y[locIndx]/self._dy_diskloc+float(self._ny_diskloc-1)/2. zk = Z[locIndx]/self._dz_diskloc+float(self._nz_diskloc-1)/2. avdisk[locIndx]= map_coordinates(self._drimmelMaps['avdloc'], [xi,yj,zk], mode='constant',cval=0.) #Go to Galactocentric coordinates X= X+self._xsun #Stars beyond the local grid #Orion globIndx= True-(numpy.fabs(X-self._xsun) < 1.)*(numpy.fabs(Y) < 2.) if numpy.sum(globIndx) > 0: #Orion grid is different from other global grids, so has its own dmax dmax= 100. if b != 0.: dmax= .49999/numpy.fabs(sb) - self._zsun/sb if cl > 0.: tdmax = (2.374999/numpy.fabs(cl)) if tdmax < dmax: dmax= tdmax if cl < 0.: tdmax = (1.374999/numpy.fabs(cl)) if tdmax < dmax: dmax= tdmax if sl != 0.: tdmax = (3.749999/numpy.fabs(sl)) if tdmax < dmax: dmax= tdmax dori= copy.copy(d) dori[dori > dmax]= dmax Xori= dori*cb*cl+self._xsun Yori= dori*cb*sl Zori= dori*sb+self._zsun xi = Xori[globIndx]/self._dx_ori + 2.5*float(self._nx_ori-1) yj = Yori[globIndx]/self._dy_ori + float(self._ny_ori-1)/2. zk = Zori[globIndx]/self._dz_ori + float(self._nz_ori-1)/2. avori[globIndx]= map_coordinates(self._drimmelMaps['avori'], [xi,yj,zk], mode='constant',cval=0.) #disk & spir xi = X/self._dx_disk+float(self._nx_disk-1)/2. yj = Y/self._dy_disk+float(self._ny_disk-1)/2. zk = Z/self._dz_disk+float(self._nz_disk-1)/2. avspir= map_coordinates(self._drimmelMaps['avspir'], [xi,yj,zk], mode='constant',cval=0.) globIndx= True-(numpy.fabs(X-self._xsun) < 0.75)*(numpy.fabs(Y) < 0.75) if numpy.sum(globIndx) > 0: avdisk[globIndx]= map_coordinates(self._drimmelMaps['avdisk'], [xi,yj,zk], mode='constant', cval=0.)[globIndx] #Return out=_fd*rfdisk*avdisk+_fs*rfspir*avspir+_fo*rfori*avori if self._filter is None: # From Rieke & Lebovksy (1985); if sf10, first put ebv on SFD scale return out/3.09/((1-self._sf10)+self._sf10*0.78) else: return out/3.09/((1-self._sf10)+self._sf10*0.78)\ *aebv(self._filter,sf10=self._sf10)