def test_galacticFromEquatorial(self): ra = np.zeros((3), dtype=float) dec = np.zeros((3), dtype=float) ra[0] = 2.549091039839124218e+00 dec[0] = 5.198752733024248895e-01 ra[1] = 8.693375673649429425e-01 dec[1] = 1.038086165642298164e+00 ra[2] = 7.740864769302191473e-01 dec[2] = 2.758053025017753179e-01 glon, glat = utils._galacticFromEquatorial(ra, dec) self.assertIsInstance(glon, np.ndarray) self.assertIsInstance(glat, np.ndarray) self.assertAlmostEqual(glon[0], 3.452036693523627964e+00, 6) self.assertAlmostEqual(glat[0], 8.559512505657201897e-01, 6) self.assertAlmostEqual(glon[1], 2.455968474619387720e+00, 6) self.assertAlmostEqual(glat[1], 3.158563770667878468e-02, 6) self.assertAlmostEqual(glon[2], 2.829585540991265358e+00, 6) self.assertAlmostEqual(glat[2], -6.510790587552289788e-01, 6) # test passing in floats as args for ix, (rr, dd) in enumerate(zip(ra, dec)): gl, gb = utils._galacticFromEquatorial(rr, dd) self.assertIsInstance(rr, np.float) self.assertIsInstance(dd, np.float) self.assertIsInstance(gl, np.float) self.assertIsInstance(gb, np.float) self.assertAlmostEqual(gl, glon[ix], 10) self.assertAlmostEqual(gb, glat[ix], 10)
def _run(self, simData, cols_present=False): # raCol and DecCol in radians, gall/b in radians. if cols_present: # Column already present in data; assume it is correct and does not need recalculating. return simData if self.degrees: simData['gall'], simData['galb'] = _galacticFromEquatorial(np.radians(simData[self.raCol]), np.radians(simData[self.decCol])) else: simData['gall'], simData['galb'] = _galacticFromEquatorial(simData[self.raCol], simData[self.decCol]) return simData
def testGalacticStacker(self): """ Test the galactic coordinate stacker """ ra,dec = np.meshgrid(np.arange(0, 2.*np.pi, 0.1), np.arange(-np.pi, np.pi, 0.1) ) ra = np.ravel(ra) dec = np.ravel(dec) data = np.zeros(ra.size, dtype=zip(['ra','dec'],[float]*2)) data['ra'] += ra data['dec'] += dec s = stackers.GalacticStacker(raCol='ra', decCol='dec') newData = s.run(data) expectedL, expectedB = _galacticFromEquatorial(ra, dec) np.testing.assert_array_equal(newData['gall'], expectedL) np.testing.assert_array_equal(newData['galb'], expectedB) # Check that we have all the quadrants populated q1 = np.where((newData['gall'] < np.pi) & (newData['galb'] < 0.) )[0] q2 = np.where((newData['gall'] < np.pi) & (newData['galb'] > 0.) )[0] q3 = np.where((newData['gall'] > np.pi) & (newData['galb'] < 0.) )[0] q4 = np.where((newData['gall'] > np.pi) & (newData['galb'] > 0.) )[0] assert(q1.size > 0) assert(q2.size > 0) assert(q3.size > 0) assert(q4.size > 0)
def testGalacticFromEquatorial(self): raList = self.raList decList = self.decList lonRad, latRad = utils._galacticFromEquatorial(raList, decList) lonDeg, latDeg = utils.galacticFromEquatorial(np.degrees(raList), np.degrees(decList)) np.testing.assert_array_almost_equal(lonRad, np.radians(lonDeg), 10) np.testing.assert_array_almost_equal(latRad, np.radians(latDeg), 10) for ra, dec in zip(raList, decList): lonRad, latRad = utils._galacticFromEquatorial(ra, dec) lonDeg, latDeg = utils.galacticFromEquatorial(np.degrees(ra), np.degrees(dec)) self.assertAlmostEqual(lonRad, np.radians(lonDeg), 10) self.assertAlmostEqual(latRad, np.radians(latDeg), 10)
def testGalacticStacker(self): """ Test the galactic coordinate stacker """ ra, dec = np.degrees( np.meshgrid(np.arange(0, 2. * np.pi, 0.1), np.arange(-np.pi, np.pi, 0.1))) ra = np.ravel(ra) dec = np.ravel(dec) data = np.zeros(ra.size, dtype=list(zip(['ra', 'dec'], [float] * 2))) data['ra'] += ra data['dec'] += dec s = stackers.GalacticStacker(raCol='ra', decCol='dec') newData = s.run(data) expectedL, expectedB = _galacticFromEquatorial(np.radians(ra), np.radians(dec)) np.testing.assert_array_equal(newData['gall'], expectedL) np.testing.assert_array_equal(newData['galb'], expectedB) # Check that we have all the quadrants populated q1 = np.where((newData['gall'] < np.pi) & (newData['galb'] < 0.))[0] q2 = np.where((newData['gall'] < np.pi) & (newData['galb'] > 0.))[0] q3 = np.where((newData['gall'] > np.pi) & (newData['galb'] < 0.))[0] q4 = np.where((newData['gall'] > np.pi) & (newData['galb'] > 0.))[0] assert (q1.size > 0) assert (q2.size > 0) assert (q3.size > 0) assert (q4.size > 0)
def testGalacticFromEquatorial(self): raList = self.raList decList = self.decList lonRad, latRad = utils._galacticFromEquatorial(raList, decList) lonDeg, latDeg = utils.galacticFromEquatorial(np.degrees(raList), np.degrees(decList)) np.testing.assert_array_almost_equal(lonRad, np.radians(lonDeg), 10) np.testing.assert_array_almost_equal(latRad, np.radians(latDeg), 10) for ra, dec in zip(raList, decList): lonRad, latRad = utils._galacticFromEquatorial(ra, dec) lonDeg, latDeg = utils.galacticFromEquatorial( np.degrees(ra), np.degrees(dec)) self.assertAlmostEqual(lonRad, np.radians(lonDeg), 10) self.assertAlmostEqual(latRad, np.radians(latDeg), 10)
def get_galactic_coords(self): """ Getter for galactic coordinates, in case the catalog class does not provide that Reads in the ra and dec from the data base and returns columns with galactic longitude and latitude. All angles are in radians """ ra = self.column_by_name('raJ2000') dec = self.column_by_name('decJ2000') glon, glat = _galacticFromEquatorial(ra, dec) return np.array([glon, glat])
def get_galactic_coords(self): """ Getter for galactic coordinates, in case the catalog class does not provide that Reads in the ra and dec from the data base and returns columns with galactic longitude and latitude. All angles are in radians """ ra=self.column_by_name('raJ2000') dec=self.column_by_name('decJ2000') glon, glat = _galacticFromEquatorial(ra,dec) return numpy.array([glon,glat])
def test_galacticFromEquatorial(self): ra=numpy.zeros((3),dtype=float) dec=numpy.zeros((3),dtype=float) ra[0]=2.549091039839124218e+00 dec[0]=5.198752733024248895e-01 ra[1]=8.693375673649429425e-01 dec[1]=1.038086165642298164e+00 ra[2]=7.740864769302191473e-01 dec[2]=2.758053025017753179e-01 output=utils._galacticFromEquatorial(ra,dec) self.assertAlmostEqual(output[0][0],3.452036693523627964e+00,6) self.assertAlmostEqual(output[1][0],8.559512505657201897e-01,6) self.assertAlmostEqual(output[0][1],2.455968474619387720e+00,6) self.assertAlmostEqual(output[1][1],3.158563770667878468e-02,6) self.assertAlmostEqual(output[0][2],2.829585540991265358e+00,6) self.assertAlmostEqual(output[1][2],-6.510790587552289788e-01,6)
def calculateEbv(self, galacticCoordinates=None, equatorialCoordinates=None, northMap=None, southMap=None, interp=False): """ For an array of Gal long, lat calculate E(B-V) @param [in] galacticCoordinates is a numpy.array; the first row is galactic longitude, the second row is galactic latitude in radians @param [in] equatorialCoordinates is a numpy.array; the first row is RA, the second row is Dec in radians @param [in] northMap the northern dust map @param [in] southMap the southern dust map @param [in] interp is a boolean determining whether or not to interpolate the EBV value @param [out] ebv is a list of EBV values for all of the gLon, gLat pairs """ # raise an error if the coordinates are specified in both systems if galacticCoordinates is not None: if equatorialCoordinates is not None: raise RuntimeError("Specified both galacticCoordinates and " "equatorialCoordinates in calculateEbv") # convert (ra,dec) into gLon, gLat if galacticCoordinates is None: # raise an error if you did not specify ra or dec if equatorialCoordinates is None: raise RuntimeError("Must specify coordinates in calculateEbv") galacticCoordinates = numpy.array(_galacticFromEquatorial(equatorialCoordinates[0, :], equatorialCoordinates[1, :])) if northMap is None: if self.ebvMapNorth is None: self.load_ebvMapNorth() northMap = self.ebvMapNorth if southMap is None: if self.ebvMapSouth is None: self.load_ebvMapSouth() southMap = self.ebvMapSouth ebv = None if galacticCoordinates.shape[1] > 0: ebv = numpy.zeros(len(galacticCoordinates[0, :])) # identify (by index) which points are in the galactic northern hemisphere # and which points are in the galactic southern hemisphere # taken from # http://stackoverflow.com/questions/4578590/python-equivalent-of-filter-getting-two-output-lists-i-e-partition-of-a-list inorth, isouth = reduce(lambda x, y: x[not y[1] > 0.0].append(y[0]) or x, enumerate(galacticCoordinates[1, :]), ([], [])) nSet = galacticCoordinates[:, inorth] sSet = galacticCoordinates[:, isouth] ebvNorth = northMap.generateEbv(nSet[0, :], nSet[1, :], interpolate=interp) ebvSouth = southMap.generateEbv(sSet[0, :], sSet[1, :], interpolate=interp) for (i, ee) in zip(inorth, ebvNorth): ebv[i] = ee for (i, ee) in zip(isouth, ebvSouth): ebv[i] = ee return ebv
def calculateEbv(self, galacticCoordinates=None, equatorialCoordinates=None, northMap=None, southMap=None, interp=False): """ For an array of Gal long, lat calculate E(B-V) @param [in] galacticCoordinates is a numpy.array; the first row is galactic longitude, the second row is galactic latitude in radians @param [in] equatorialCoordinates is a numpy.array; the first row is RA, the second row is Dec in radians @param [in] northMap the northern dust map @param [in] southMap the southern dust map @param [in] interp is a boolean determining whether or not to interpolate the EBV value @param [out] ebv is a list of EBV values for all of the gLon, gLat pairs """ #raise an error if the coordinates are specified in both systems if galacticCoordinates is not None: if equatorialCoordinates is not None: raise RuntimeError( "Specified both galacticCoordinates and equatorialCoordinates in calculateEbv" ) #convert (ra,dec) into gLon, gLat if galacticCoordinates is None: #raise an error if you did not specify ra or dec if equatorialCoordinates is None: raise RuntimeError("Must specify coordinates in calculateEbv") galacticCoordinates = numpy.array( _galacticFromEquatorial(equatorialCoordinates[0, :], equatorialCoordinates[1, :])) if northMap is None: if self.ebvMapNorth is None: self.load_ebvMapNorth() northMap = self.ebvMapNorth if southMap is None: if self.ebvMapSouth is None: self.load_ebvMapSouth() southMap = self.ebvMapSouth ebv = None if galacticCoordinates.shape[1] > 0: ebv = numpy.zeros(len(galacticCoordinates[0, :])) #identify (by index) which points are in the galactic northern hemisphere #and which points are in the galactic southern hemisphere #taken from #http://stackoverflow.com/questions/4578590/python-equivalent-of-filter-getting-two-output-lists-i-e-partition-of-a-list inorth, isouth = reduce( lambda x, y: x[not y[1] > 0.0].append(y[0]) or x, enumerate(galacticCoordinates[1, :]), ([], [])) nSet = galacticCoordinates[:, inorth] sSet = galacticCoordinates[:, isouth] ebvNorth = northMap.generateEbv(nSet[0, :], nSet[1, :], interpolate=interp) ebvSouth = southMap.generateEbv(sSet[0, :], sSet[1, :], interpolate=interp) for (i, ee) in zip(inorth, ebvNorth): ebv[i] = ee for (i, ee) in zip(isouth, ebvSouth): ebv[i] = ee return ebv
def run(self, slicePoints): gall, galb = _galacticFromEquatorial(slicePoints['ra'], slicePoints['dec']) slicePoints['gall'] = gall slicePoints['galb'] = galb return slicePoints
def run(self, slicePoints): gall, galb = _galacticFromEquatorial(slicePoints['ra'],slicePoints['dec']) slicePoints['gall'] = gall slicePoints['galb'] = galb return slicePoints
def _run(self, simData): # raCol and DecCol in radians, gall/b in radians. simData['gall'], simData['galb'] = _galacticFromEquatorial( simData[self.raCol], simData[self.decCol]) return simData
def _run(self, simData): # raCol and DecCol in radians, gall/b in radians. simData['gall'], simData['galb'] = _galacticFromEquatorial(simData[self.raCol], simData[self.decCol]) return simData
def get_galacticCoords(self): return _galacticFromEquatorial(self.column_by_name('snra'), self.column_by_name('sndec'))