Beispiel #1
0
 def _evaluate(self,l,b,d,_lbIndx=None):
     """
     NAME:
        _evaluate
     PURPOSE:
        evaluate the dust-map
     INPUT:
        l- Galactic longitude (deg)
        b- Galactic latitude (deg)
        d- distance (kpc) can be array
     OUTPUT:
        extinction
     HISTORY:
        2015-03-08 - Started - Bovy (IAS)
     """
     if isinstance(l,numpy.ndarray) or isinstance(b,numpy.ndarray):
         raise NotImplementedError("array input for l and b for Sale et al. (2014) dust map not implemented")
     if _lbIndx is None: lbIndx= self._lbIndx(l,b)
     else: lbIndx= _lbIndx
     if self._intps[lbIndx] != 0:
         out= self._intps[lbIndx](d)
     else:
         tlbData= self.lbData(l,b)
         interpData=\
             interpolate.InterpolatedUnivariateSpline(self._ds,
                                                      tlbData['a0'],
                                                      k=1)
         out= interpData(d)
         self._intps[lbIndx]= interpData
     if self._filter is None: # Sale et al. say A0/Aks = 11
         return out/11./aebv('2MASS Ks',sf10=self._sf10)
     else: # if sf10, first put ebv on SFD scale
         return out/11./aebv('2MASS Ks',sf10=self._sf10)\
             *aebv(self._filter,sf10=self._sf10)
Beispiel #2
0
 def _evaluate(self,l,b,d):
     """
     NAME:
        _evaluate
     PURPOSE:
        evaluate the dust-map
     INPUT:
        l- Galactic longitude (deg)
        b- Galactic latitude (deg)
        d- distance (kpc) can be array
     OUTPUT:
        extinction
     HISTORY:
        2013-12-12 - 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")
     lbIndx= self._lbIndx(l,b)
     if self._intps[lbIndx] != 0:
         out= self._intps[lbIndx](d)
     else:
         tlbData= self.lbData(l,b,addBC=True)
         interpData=\
             interpolate.InterpolatedUnivariateSpline(tlbData['dist'],
                                                      tlbData['aks'],
                                                      k=1)
         out= interpData(d)
         self._intps[lbIndx]= interpData
     if self._filter is None:
         return out/aebv('2MASS Ks',sf10=self._sf10)
     else:
         return out/aebv('2MASS Ks',sf10=self._sf10)\
             *aebv(self._filter,sf10=self._sf10)
Beispiel #3
0
 def _evaluate(self, l, b, d):
     """
     NAME:
        _evaluate
     PURPOSE:
        evaluate the dust-map
     INPUT:
        l- Galactic longitude (deg)
        b- Galactic latitude (deg)
        d- distance (kpc) can be array
     OUTPUT:
        extinction
     HISTORY:
        2013-12-12 - 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")
     lbIndx = self._lbIndx(l, b)
     if self._intps[lbIndx] != 0:
         out = self._intps[lbIndx](d)
     else:
         tlbData = self.lbData(l, b, addBC=True)
         interpData=\
             interpolate.InterpolatedUnivariateSpline(tlbData['dist'],
                                                      tlbData['aks'],
                                                      k=1)
         out = interpData(d)
         self._intps[lbIndx] = interpData
     if self._filter is None:
         return out / aebv('2MASS Ks', sf10=self._sf10)
     else:
         return out/aebv('2MASS Ks',sf10=self._sf10)\
             *aebv(self._filter,sf10=self._sf10)
Beispiel #4
0
 def plotData(self,l,b,*args,**kwargs):
     """
     NAME:
        plotData
     PURPOSE:
        plot the Marshall et al. (2006) extinction values 
        along a given line of sight as a function of 
        distance
     INPUT:
        l,b - Galactic longitude and latitude (degree)
        bovy_plot.bovy_plot args and kwargs
     OUTPUT:
        plot to output device
     HISTORY:
        2013-12-15 - Written - Bovy (IAS)
     """
     if not _BOVY_PLOT_LOADED:
         raise NotImplementedError("galpy.util.bovy_plot could not be loaded, so there is no plotting; might have to install galpy (http://github.com/jobovy/galpy) for plotting")
     #First get the data
     tdata= self.lbData(l,b)
     #Filter
     if self._filter is None:
         filterFac= 1./aebv('2MASS Ks',sf10=self._sf10)
     else:
         filterFac= 1./aebv('2MASS Ks',sf10=self._sf10)\
             *aebv(self._filter,sf10=self._sf10)
     #Plot
     out= bovy_plot.bovy_plot(tdata['dist'],tdata['aks']*filterFac,
                         *args,**kwargs)
     #uncertainties
     pyplot.errorbar(tdata['dist'],tdata['aks']*filterFac,
                     xerr=tdata['e_dist'],
                     yerr=tdata['e_aks']*filterFac,
                     ls='none',marker=None,color='k')
     return out
Beispiel #5
0
 def plotData(self,l,b,*args,**kwargs):
     """
     NAME:
        plotData
     PURPOSE:
        plot the Marshall et al. (2006) extinction values 
        along a given line of sight as a function of 
        distance
     INPUT:
        l,b - Galactic longitude and latitude (degree)
        bovy_plot.bovy_plot args and kwargs
     OUTPUT:
        plot to output device
     HISTORY:
        2013-12-15 - Written - Bovy (IAS)
     """
     if not _BOVY_PLOT_LOADED:
         raise NotImplementedError("galpy.util.bovy_plot could not be loaded, so there is no plotting; might have to install galpy (http://github.com/jobovy/galpy) for plotting")
     #First get the data
     tdata= self.lbData(l,b)
     #Filter
     if self._filter is None:
         filterFac= 1./aebv('2MASS Ks',sf10=self._sf10)
     else:
         filterFac= 1./aebv('2MASS Ks',sf10=self._sf10)\
             *aebv(self._filter,sf10=self._sf10)
     #Plot
     out= bovy_plot.bovy_plot(tdata['dist'],tdata['aks']*filterFac,
                         *args,**kwargs)
     #uncertainties
     pyplot.errorbar(tdata['dist'],tdata['aks']*filterFac,
                     xerr=tdata['e_dist'],
                     yerr=tdata['e_aks']*filterFac,
                     ls='none',marker=None,color='k')
     return out
Beispiel #6
0
 def _evaluate(self,l,b,d):
     """
     NAME:
        _evaluate
     PURPOSE:
        evaluate the dust-map
     INPUT:
        l- Galactic longitude (deg)
        b- Galactic latitude (deg)
        d- distance (kpc) can be array
     OUTPUT:
        extinction E(B-V)
     HISTORY:
        2015-03-02 - Started - Bovy (IAS)
     """
     distmod= 5.*numpy.log10(d)+10.
     if isinstance(l,numpy.ndarray) or isinstance(b,numpy.ndarray):
         raise NotImplementedError("array input for l and b for combined dust map not implemented")
     lbIndx= self._lbIndx(l,b)
     if self._intps[lbIndx] != 0:
         out= self._intps[lbIndx][0](distmod)
     else:
         interpData=\
             interpolate.InterpolatedUnivariateSpline(self._distmods,
                                                      self._best_fit[lbIndx],
                                                      k=self._interpk)
         out= interpData(distmod)
         self._intps[lbIndx]= interpData
     if self._filter is None:
         return out
     else:
         return out*aebv(self._filter,sf10=self._sf10)
Beispiel #7
0
 def _evaluate(self, l, b, d):
     """
     NAME:
        _evaluate
     PURPOSE:
        evaluate the dust-map
     INPUT:
        l- Galactic longitude (deg)
        b- Galactic latitude (deg)
        d- distance (kpc) can be array
     OUTPUT:
        extinction E(B-V)
     HISTORY:
        2015-03-02 - Started - Bovy (IAS)
     """
     distmod = 5. * numpy.log10(d) + 10.
     if isinstance(l, numpy.ndarray) or isinstance(b, numpy.ndarray):
         raise NotImplementedError(
             "array input for l and b for combined dust map not implemented"
         )
     lbIndx = self._lbIndx(l, b)
     if self._intps[lbIndx] != 0:
         out = self._intps[lbIndx][0](distmod)
     else:
         interpData=\
             interpolate.InterpolatedUnivariateSpline(self._distmods,
                                                      self._best_fit[lbIndx],
                                                      k=self._interpk)
         out = interpData(distmod)
         self._intps[lbIndx] = interpData
     if self._filter is None:
         return out
     else:
         return out * aebv(self._filter, sf10=self._sf10)
Beispiel #8
0
 def _evaluate(self, l, b, d):
     """
     NAME:
        _evaluate
     PURPOSE:
        evaluate the dust-map
     INPUT:
        l- Galactic longitude (deg)
        b- Galactic latitude (deg)
        d- distance (kpc)
     OUTPUT:
        extinction
     HISTORY:
        2013-11-24 - Started - Bovy (IAS)
     """
     tebv = read_SFD_EBV(l,
                         b,
                         interp=self._interp,
                         noloop=self._noloop,
                         verbose=False)
     if self._filter is None:
         return tebv * numpy.ones_like(d)
     else:
         return tebv * aebv(self._filter,
                            sf10=self._sf10) * numpy.ones_like(d)
Beispiel #9
0
 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-06 - Written - Bovy (IAS)
     """
     # Convert the disk center to a HEALPIX vector
     vec = healpy.pixelfunc.ang2vec((90. - bcen) * _DEGTORAD,
                                    lcen * _DEGTORAD)
     distmod = 5. * numpy.log10(dist) + 10.
     # Query the HEALPIX map for pixels that lie within the disk
     pixarea = []
     extinction = []
     for nside in self._nsides:
         # Find the pixels at this resolution that fall within the disk
         ipixs = healpy.query_disc(nside,
                                   vec,
                                   radius * _DEGTORAD,
                                   inclusive=False,
                                   nest=True)
         # Get indices of all pixels within the disk at current nside level
         nsideindx = self._pix_info['nside'] == nside
         potenIndxs = self._indexArray[nsideindx]
         nsidepix = self._pix_info['healpix_index'][nsideindx]
         # Loop through the pixels in the (small) disk
         tout = []
         for ii, ipix in enumerate(ipixs):
             lbIndx = potenIndxs[ipix == nsidepix]
             if numpy.sum(lbIndx) == 0: continue
             if self._intps[lbIndx] != 0:
                 tout.append(self._intps[lbIndx][0](distmod))
             else:
                 interpData=\
                     interpolate.InterpolatedUnivariateSpline(self._distmods,
                                                              self._best_fit[lbIndx],
                                                              k=self._interpk)
                 tout.append(interpData(distmod))
                 self._intps[lbIndx] = interpData
         tarea = healpy.pixelfunc.nside2pixarea(nside)
         tarea = [tarea for ii in range(len(tout))]
         pixarea.extend(tarea)
         extinction.extend(tout)
     pixarea = numpy.array(pixarea)
     extinction = numpy.array(extinction)
     if not self._filter is None:
         extinction = extinction * aebv(self._filter, sf10=self._sf10)
     return (pixarea, extinction)
Beispiel #10
0
 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-06 - Written - Bovy (IAS)
     """
     # Convert the disk center to a HEALPIX vector
     vec= healpy.pixelfunc.ang2vec((90.-bcen)*_DEGTORAD,lcen*_DEGTORAD)
     distmod= 5.*numpy.log10(dist)+10.
     # Query the HEALPIX map for pixels that lie within the disk
     pixarea= []
     extinction= []
     for nside in self._nsides:
         # Find the pixels at this resolution that fall within the disk
         ipixs= healpy.query_disc(nside,vec,radius*_DEGTORAD,
                                 inclusive=False,nest=True)
         # Get indices of all pixels within the disk at current nside level
         nsideindx= self._pix_info['nside'] == nside
         potenIndxs= self._indexArray[nsideindx]
         nsidepix= self._pix_info['healpix_index'][nsideindx]
         # Loop through the pixels in the (small) disk
         tout= []
         for ii,ipix in enumerate(ipixs):
             lbIndx= potenIndxs[ipix == nsidepix]
             if numpy.sum(lbIndx) == 0: continue
             if self._intps[lbIndx] != 0:
                 tout.append(self._intps[lbIndx][0](distmod))
             else:
                 interpData=\
                     interpolate.InterpolatedUnivariateSpline(self._distmods,
                                                              self._best_fit[lbIndx],
                                                              k=self._interpk)
                 tout.append(interpData(distmod))
                 self._intps[lbIndx]= interpData
         tarea= healpy.pixelfunc.nside2pixarea(nside)
         tarea= [tarea for ii in range(len(tout))]
         pixarea.extend(tarea)
         extinction.extend(tout)
     pixarea= numpy.array(pixarea)
     extinction= numpy.array(extinction)
     if not self._filter is None:
         extinction= extinction*aebv(self._filter,sf10=self._sf10)        
     return (pixarea,extinction)
Beispiel #11
0
 def _evaluate(self,l,b,d):
     """
     NAME:
        _evaluate
     PURPOSE:
        evaluate the dust-map
     INPUT:
        l- Galactic longitude (deg)
        b- Galactic latitude (deg)
        d- distance (kpc)
     OUTPUT:
        extinction
     HISTORY:
        2013-11-24 - Started - Bovy (IAS)
     """
     tebv= read_SFD_EBV(l,b,interp=self._interp,
                        noloop=self._noloop,verbose=False)
     if self._filter is None:
         return tebv*numpy.ones_like(d)
     else:
         return tebv*aebv(self._filter,sf10=self._sf10)*numpy.ones_like(d)
Beispiel #12
0
    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)
Beispiel #13
0
    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)
Beispiel #14
0
    def plot_mollweide(self, d, **kwargs):
        """
        NAME:
           plot_mollweide
        PURPOSE:
           plot the extinction across the sky in Galactic coordinates  out to a given distance using a Mollweide projection
        INPUT:
           d - distance in kpc (nearest distance to this in the map is plotted)
           nside_plot= (2048) nside of the plotted map
           healpy.visufunc.mollview kwargs
        OUTPUT:
           plot to output device
        HISTORY:
           2019-12-06 - Written - Bovy (UofT)
        """
        # Distance modulus
        dm = 5. * numpy.log10(d) + 10.
        # Get factor to apply to map to obtain extinction in object's filter
        filter_fac= aebv(self._filter,sf10=self._sf10) \
                    if not self._filter is None else 1.
        # Map the dust map to a common nside, first find nearest distance pixel
        tpix = numpy.argmin(numpy.fabs(dm - self._distmods))
        # Construct an empty map at the highest HEALPix resolution present in the map; code snippets adapted from http://argonaut.skymaps.info/usage
        nside_max = numpy.max(self._pix_info['nside'])
        npix = healpy.pixelfunc.nside2npix(nside_max)
        pix_val = numpy.empty(npix, dtype='f8')
        pix_val[:] = healpy.UNSEEN
        # Fill the upsampled map
        for nside in numpy.unique(self._pix_info['nside']):
            # Get indices of all pixels at current nside level
            indx = self._pix_info['nside'] == nside
            # Extract A_X of each selected pixel
            pix_val_n = filter_fac * self._best_fit[indx, tpix]
            # Determine nested index of each selected pixel in upsampled map
            mult_factor = (nside_max // nside)**2
            pix_idx_n = self._pix_info['healpix_index'][indx] * mult_factor
            # Write the selected pixels into the upsampled map
            for offset in range(mult_factor):
                pix_val[pix_idx_n + offset] = pix_val_n[:]
        # If the desired nside is less than the maximum nside in the map, degrade
        nside_plot = kwargs.get('nside_plot', 2048)
        if not nside_plot is None and nside_plot < nside_max:
            pix_val = healpy.pixelfunc.ud_grade(pix_val,
                                                nside_plot,
                                                pess=False,
                                                order_in='NEST',
                                                order_out='NEST')
        pix_val[pix_val == healpy.UNSEEN] = -1.

        if not self._filter is None:
            kwargs['unit'] = r'$A_{%s}\,(\mathrm{mag})$' % (
                self._filter.split(' ')[-1])
        else:
            kwargs['unit'] = r'$E(B-V)\,(\mathrm{mag})$'
        kwargs['title'] = kwargs.get('title', "")
        healpy.visufunc.mollview(pix_val,
                                 nest=True,
                                 xsize=4000,
                                 min=0.,
                                 max=numpy.quantile(pix_val, 0.99),
                                 format=r'$%g$',
                                 cmap='gist_yarg',
                                 **kwargs)
        return None