Python astropy.units.arcsec() Examples
The following are 30
code examples of astropy.units.arcsec().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
astropy.units
, or try the search function
.
Example #1
Source File: test_OpticalSystem.py From EXOSIMS with BSD 3-Clause "New" or "Revised" License | 7 votes |
def test_calc_dMag_per_intTime(self): """ Check calc_dMag_per_intTime i/o """ for mod in self.allmods: if 'calc_dMag_per_intTime' not in mod.__dict__: continue obj = mod(**copy.deepcopy(self.spec)) dMag = obj.calc_dMag_per_intTime(np.ones(self.TL.nStars)*u.day, self.TL, np.arange(self.TL.nStars), np.array([0]*self.TL.nStars)/(u.arcsec**2.),np.array([0]*self.TL.nStars)/(u.arcsec**2.), np.array([obj.WA0.value]*self.TL.nStars)*obj.WA0.unit,obj.observingModes[0]) self.assertEqual(dMag.shape,np.arange(self.TL.nStars).shape)
Example #2
Source File: test_altaz_icrs.py From Carnets with BSD 3-Clause "New" or "Revised" License | 6 votes |
def test_against_jpl_horizons(): """Check that Astropy gives consistent results with the JPL Horizons example. The input parameters and reference results are taken from this page: (from the first row of the Results table at the bottom of that page) http://ssd.jpl.nasa.gov/?horizons_tutorial """ obstime = Time('1998-07-28 03:00') location = EarthLocation(lon=Angle('248.405300d'), lat=Angle('31.9585d'), height=2.06 * u.km) # No atmosphere altaz_frame = AltAz(obstime=obstime, location=location) altaz = SkyCoord('143.2970d 2.6223d', frame=altaz_frame) radec_actual = altaz.transform_to('icrs') radec_expected = SkyCoord('19h24m55.01s -40d56m28.9s', frame='icrs') distance = radec_actual.separation(radec_expected).to('arcsec') # Current value: 0.238111 arcsec assert distance < 1 * u.arcsec
Example #3
Source File: test_OpticalSystem.py From EXOSIMS with BSD 3-Clause "New" or "Revised" License | 6 votes |
def test_init_psf(self): r"""Test of initialization and __init__ -- PSF Method: We instantiate OpticalSystem objects and verify that IWA and OWA vary as expected with the domain of WA of the throughput lookup table (from 0 to 1). """ filename = os.path.join(resource_path(), 'OpticalSystem', 'psf_5x5.fits') sampling = 1.234e-5 * u.arcsec # sampling rate keyword in above file for specs in [specs_default]: # the input dict is modified in-place -- so copy it our_specs = deepcopy(specs_default) for syst in our_specs['starlightSuppressionSystems']: syst['PSF'] = filename optsys = self.fixture(**deepcopy(our_specs)) # Check that the sampling rate is correct self.assertEqual(optsys.starlightSuppressionSystems[0]['samp'], sampling) # Check that the PSF is present and has right size # Values are checked elsewhere psf = optsys.starlightSuppressionSystems[0]['PSF'](1.0,1.0) self.assertIsInstance(psf, np.ndarray) self.assertEqual(psf.shape, (5,5))
Example #4
Source File: test_OpticalSystem.py From EXOSIMS with BSD 3-Clause "New" or "Revised" License | 6 votes |
def test_calc_intTime(self): """ Check calc_intTime i/o only """ for mod in self.allmods: if 'calc_intTime' not in mod.__dict__: continue obj = mod(**copy.deepcopy(self.spec)) #first check, infinite dMag should give zero C_p intTime = obj.calc_intTime(self.TL, np.arange(self.TL.nStars), np.array([0]*self.TL.nStars)/(u.arcsec**2.), np.array([0]*self.TL.nStars)/(u.arcsec**2.),np.ones(self.TL.nStars)*obj.dMag0, np.array([obj.WA0.value]*self.TL.nStars)*obj.WA0.unit,obj.observingModes[0]) self.assertEqual(len(intTime),self.TL.nStars)
Example #5
Source File: test_ZodiacalLight.py From EXOSIMS with BSD 3-Clause "New" or "Revised" License | 6 votes |
def test_calcfZmin(self): """ Test calcfZmin method """ for mod in self.allmods: if 'calcfZmin' in mod.__dict__: with RedirectStreams(stdout=self.dev_null): obj = mod() sInds = np.asarray([0]) currentTimeAbs = self.TK.currentTimeAbs OS = self.sim.OpticalSystem allModes = OS.observingModes mode = list(filter(lambda mode: mode['detectionMode'] == True, allModes))[0] hashname = self.sim.SurveySimulation.cachefname self.sim.ZodiacalLight.fZ_startSaved = obj.generate_fZ(self.Obs, self.TL, self.TK, mode, hashname) fZQuads = obj.calcfZmin(sInds, self.Obs, self.TL, self.TK, mode, hashname) [valfZmin, timefZmin] = obj.extractfZmin_fZQuads(fZQuads) self.assertTrue(len(valfZmin) == len(sInds)) self.assertTrue(len(timefZmin) == len(sInds)) self.assertTrue(valfZmin[0].unit == 1/u.arcsec**2) self.assertTrue(timefZmin[0].format == currentTimeAbs.format)
Example #6
Source File: test_ZodiacalLight.py From EXOSIMS with BSD 3-Clause "New" or "Revised" License | 6 votes |
def test_fEZ(self): """ Test that fEZ returns correct shape and units. """ exclude_mods=[] for mod in self.allmods: if mod.__name__ in exclude_mods: continue if 'fEZ' in mod.__dict__: obj = mod() # use 3 planets d = 10.*np.random.rand(3)*u.AU I = np.random.uniform(0.0, 180.0, 3)*u.deg fEZs = obj.fEZ(self.TL.MV[0], I, d) self.assertEqual(len(fEZs), 3, 'fEZ does not return same number of values as planets tested for {}'.format(mod.__name__)) self.assertEqual(fEZs.unit, self.unit, 'fEZ does not return 1/arcsec**2 for {}'.format(mod.__name__))
Example #7
Source File: test_PostProcessing.py From EXOSIMS with BSD 3-Clause "New" or "Revised" License | 6 votes |
def test_FAdMag0_fits(self): # get fits file path for FAdMag0 test classpath = os.path.split(inspect.getfile(self.__class__))[0] FAdMag0Path = os.path.join(classpath,'test_PostProcessing_FAdMag0.fits') # fits file has values for WA in [0.1, 0.2] and FAdMag0 in [10, 20] testWA = np.linspace(0.1, 0.2, 100)*u.arcsec for mod in self.allmods: with RedirectStreams(stdout=self.dev_null): obj = mod(FAdMag0=FAdMag0Path,**self.specs) vals = obj.FAdMag0(testWA) self.assertTrue(np.all(vals >= 10),'value below range of FAdMag0 for %s'%mod.__name__) self.assertTrue(np.all(vals <= 20),'value above range of FAdMag0 for %s'%mod.__name__)
Example #8
Source File: test_PostProcessing.py From EXOSIMS with BSD 3-Clause "New" or "Revised" License | 6 votes |
def test_ppFact_fits(self): # get fits file path for ppFact test classpath = os.path.split(inspect.getfile(self.__class__))[0] ppFactPath = os.path.join(classpath,'test_PostProcessing_ppFact.fits') # fits file has values for WA in [0.1,0.2] testWA = np.linspace(0.1,0.2,100)*u.arcsec for mod in self.allmods: with RedirectStreams(stdout=self.dev_null): obj = mod(ppFact=ppFactPath,**self.specs) vals = obj.ppFact(testWA) self.assertTrue(np.all(vals > 0),'negative value of ppFact for %s'%mod.__name__) self.assertTrue(np.all(vals <= 1),'ppFact > 1 for %s'%mod.__name__)
Example #9
Source File: test_OpticalSystem.py From EXOSIMS with BSD 3-Clause "New" or "Revised" License | 6 votes |
def test_ddMag_dt(self): """ Check ddMag_dt i/o """ for mod in self.allmods: if 'ddMag_dt' not in mod.__dict__: continue obj = mod(**copy.deepcopy(self.spec)) ddMag = obj.ddMag_dt(np.ones(self.TL.nStars)*u.day, self.TL, np.arange(self.TL.nStars), np.array([0]*self.TL.nStars)/(u.arcsec**2.),np.array([0]*self.TL.nStars)/(u.arcsec**2.), np.array([obj.WA0.value]*self.TL.nStars)*obj.WA0.unit,obj.observingModes[0]) self.assertEqual(ddMag.shape,np.arange(self.TL.nStars).shape)
Example #10
Source File: test_wcsapi.py From Carnets with BSD 3-Clause "New" or "Revised" License | 6 votes |
def test_sliced_ND_input(sub_wcs, wcs_slice): slices_wcsaxes = [0, 'x', 'y'] with warnings.catch_warnings(): warnings.filterwarnings('ignore', category=FutureWarning) _, coord_meta = transform_coord_meta_from_wcs(sub_wcs, RectangularFrame, slices=slices_wcsaxes) assert all(len(x) == 3 for x in coord_meta.values()) coord_meta['name'] = ['time', 'custom:pos.helioprojective.lat', 'custom:pos.helioprojective.lon'] coord_meta['type'] = ['scalar', 'latitude', 'longitude'] coord_meta['wrap'] = [None, None, 180.0] coord_meta['unit'] = [u.Unit("min"), u.Unit("deg"), u.Unit("deg")] coord_meta['visible'] = [False, True, True] coord_meta['format_unit'] = [u.Unit("min"), u.Unit("arcsec"), u.Unit("arcsec")] coord_meta['default_axislabel_position'] = ['', 'b', 't'] coord_meta['default_ticklabel_position'] = ['', 'b', 't'] coord_meta['default_ticks_position'] = ['', 'btlr', 'btlr'] # Validate the axes initialize correctly plt.subplot(projection=sub_wcs, slices=slices_wcsaxes) plt.close('all')
Example #11
Source File: test_Completeness.py From EXOSIMS with BSD 3-Clause "New" or "Revised" License | 6 votes |
def test_dcomp_dt(self): dt = self.fixture.dcomp_dt(np.ones(self.nStars)*u.d,self,np.arange(self.nStars),0/(u.arcsec**2),0/(u.arcsec**2),0*u.arcsec,{}) self.assertTrue(len(dt),self.nStars) with self.assertRaises(AssertionError): dt = self.fixture.dcomp_dt(np.ones(self.nStars-1)*u.d,self,np.arange(self.nStars),0/(u.arcsec**2),0/(u.arcsec**2),0*u.arcsec,{}) with self.assertRaises(AssertionError): dt = self.fixture.dcomp_dt(np.ones(self.nStars)*u.d,self,np.arange(self.nStars),np.zeros(2)/(u.arcsec**2),0/(u.arcsec**2),0*u.arcsec,{}) with self.assertRaises(AssertionError): dt = self.fixture.dcomp_dt(np.ones(self.nStars)*u.d,self,np.arange(self.nStars),0/(u.arcsec**2),np.zeros(2)/(u.arcsec**2),0*u.arcsec,{}) with self.assertRaises(AssertionError): dt = self.fixture.dcomp_dt(np.ones(self.nStars-1)*u.d,self,np.arange(self.nStars),0/(u.arcsec**2),0/(u.arcsec**2),np.zeros(2)*u.arcsec,{})
Example #12
Source File: KnownRVSurvey.py From EXOSIMS with BSD 3-Clause "New" or "Revised" License | 6 votes |
def __init__(self, **specs): # call prototype constructor SurveySimulation.__init__(self, **specs) TL = self.TargetList SU = self.SimulatedUniverse # reinitialize working angles and delta magnitudes used for integration self.WAint = np.zeros(TL.nStars)*u.arcsec self.dMagint = np.zeros(TL.nStars) # calculate estimates of shortest WAint and largest dMagint for each target for sInd in range(TL.nStars): pInds = np.where(SU.plan2star == sInd)[0] self.WAint[sInd] = np.arctan(np.min(SU.a[pInds])/TL.dist[sInd]).to('arcsec') phis = np.array([np.pi/2]*pInds.size) dMags = deltaMag(SU.p[pInds], SU.Rp[pInds], SU.a[pInds], phis) self.dMagint[sInd] = np.min(dMags) # populate outspec with arrays self._outspec['WAint'] = self.WAint.value self._outspec['dMagint'] = self.dMagint
Example #13
Source File: core.py From Carnets with BSD 3-Clause "New" or "Revised" License | 6 votes |
def arcsec_per_kpc_proper(self, z): """ Angular separation in arcsec corresponding to a proper kpc at redshift ``z``. Parameters ---------- z : array_like Input redshifts. Must be 1D or scalar. Returns ------- theta : `~astropy.units.Quantity` The angular separation in arcsec corresponding to a proper kpc at each input redshift. """ return u.arcsec / (self.angular_diameter_distance(z).to(u.kpc) * arcsec_in_radians)
Example #14
Source File: core.py From Carnets with BSD 3-Clause "New" or "Revised" License | 6 votes |
def arcsec_per_kpc_comoving(self, z): """ Angular separation in arcsec corresponding to a comoving kpc at redshift ``z``. Parameters ---------- z : array_like Input redshifts. Must be 1D or scalar. Returns ------- theta : `~astropy.units.Quantity` The angular separation in arcsec corresponding to a comoving kpc at each input redshift. """ return u.arcsec / (self.comoving_transverse_distance(z).to(u.kpc) * arcsec_in_radians)
Example #15
Source File: photoz.py From grizli with MIT License | 6 votes |
def show_from_ds9(ds9, self, zout, use_sky=True, **kwargs): import numpy as np if use_sky: xy = np.cast[float](ds9.get('pan fk5').split()) cosd = np.cos(xy[1]/180*np.pi) r = np.sqrt((self.cat['ra']-xy[0])**2*cosd**2 + (self.cat['dec']-xy[1])**2)*3600 runit = 'arcsec' if (not use_sky) | (xy.sum() == 0): xy = np.cast[float](ds9.get('pan image').split()) r = np.sqrt((self.cat['x_image']-xy[0])**2 + (self.cat['y_image']-xy[1])**2) runit = 'pix' ix = np.argmin(r) print('ID: {0}, r={1:.1f} {2}'.format(self.cat['id'][ix], r[ix], runit)) print(' z={0:.2f} logM={1:.2f}'.format(zout['z_phot'][ix], np.log10(zout['mass'][ix]))) fig = self.show_fit(self.cat['id'][ix], **kwargs) return fig, self.cat['id'][ix], zout['z_phot'][ix]
Example #16
Source File: test_sites.py From Carnets with BSD 3-Clause "New" or "Revised" License | 6 votes |
def test_EarthLocation_basic(): greenwichel = EarthLocation.of_site('greenwich') lon, lat, el = greenwichel.to_geodetic() assert_quantity_allclose(lon, Longitude('0:0:0', unit=u.deg), atol=10*u.arcsec) assert_quantity_allclose(lat, Latitude('51:28:40', unit=u.deg), atol=1*u.arcsec) assert_quantity_allclose(el, 46*u.m, atol=1*u.m) names = EarthLocation.get_site_names() assert 'greenwich' in names assert 'example_site' in names with pytest.raises(KeyError) as exc: EarthLocation.of_site('nonexistent site') assert exc.value.args[0] == "Site 'nonexistent site' not in database. Use EarthLocation.get_site_names to see available sites."
Example #17
Source File: test_sites.py From Carnets with BSD 3-Clause "New" or "Revised" License | 6 votes |
def test_builtin_sites(): reg = get_builtin_sites() greenwich = reg['greenwich'] lon, lat, el = greenwich.to_geodetic() assert_quantity_allclose(lon, Longitude('0:0:0', unit=u.deg), atol=10*u.arcsec) assert_quantity_allclose(lat, Latitude('51:28:40', unit=u.deg), atol=1*u.arcsec) assert_quantity_allclose(el, 46*u.m, atol=1*u.m) names = reg.names assert 'greenwich' in names assert 'example_site' in names with pytest.raises(KeyError) as exc: reg['nonexistent site'] assert exc.value.args[0] == "Site 'nonexistent site' not in database. Use the 'names' attribute to see available sites."
Example #18
Source File: test_frames.py From Carnets with BSD 3-Clause "New" or "Revised" License | 6 votes |
def test_component_names_repr(): from astropy.coordinates.baseframe import BaseCoordinateFrame, RepresentationMapping # Frame class with new component names that includes a name swap class NameChangeFrame(BaseCoordinateFrame): default_representation = r.PhysicsSphericalRepresentation frame_specific_representation_info = { r.PhysicsSphericalRepresentation: [ RepresentationMapping('phi', 'theta', u.deg), RepresentationMapping('theta', 'phi', u.arcsec), RepresentationMapping('r', 'JUSTONCE', u.AU)] } frame = NameChangeFrame(0*u.deg, 0*u.arcsec, 0*u.AU) # Check for the new names in the Frame repr assert "(theta, phi, JUSTONCE)" in repr(frame) # Check that the letter "r" has not been replaced more than once in the Frame repr assert repr(frame).count("JUSTONCE") == 1
Example #19
Source File: test_TargetList.py From EXOSIMS with BSD 3-Clause "New" or "Revised" License | 6 votes |
def test_outside_IWA_filter(self): n0 = self.targetlist.nStars #Test default IWA = 0 self.targetlist.outside_IWA_filter() n1 = self.targetlist.nStars self.assertEqual( n0, n1 ) #Test particular case self.opticalsystem.IWA = 10 * u.arcsec self.targetlist.outside_IWA_filter() #assert self.targetlist.nStars == 417 #not a useful test n1 = self.targetlist.nStars #reference #introduce two stars with planet below 10 arcsec. should be removed self.targetlist.dist[10] = 21 * u.pc #rrange is 1e-3 to 200au, so this planet is below the IWA of 10 arcsec self.targetlist.dist[12] = 22 * u.pc self.targetlist.outside_IWA_filter() self.assertEqual( self.targetlist.nStars , n1 - 2 ) #Test limiting case of IWA = PI/2 self.opticalsystem.IWA = 3.14/2 * u.rad with self.assertRaises(IndexError): self.targetlist.outside_IWA_filter() #self.assertEqual(targetlist.nStars, 0) #Note that nStars is now zero so I can no longer filter out stars. This is why the limiting case of dMagLim = 0 should be done last
Example #20
Source File: test_celestial_transformations.py From Carnets with BSD 3-Clause "New" or "Revised" License | 6 votes |
def test_m31_coord_transforms(fromsys, tosys, fromcoo, tocoo): """ This tests a variety of coordinate conversions for the Chandra point-source catalog location of M31 from NED. """ coo1 = fromsys(ra=fromcoo[0]*u.deg, dec=fromcoo[1]*u.deg, distance=m31_dist) coo2 = coo1.transform_to(tosys) if tosys is FK4: coo2_prec = coo2.transform_to(FK4(equinox=Time('B1950'))) assert (coo2_prec.spherical.lon - tocoo[0]*u.deg) < convert_precision # <1 arcsec assert (coo2_prec.spherical.lat - tocoo[1]*u.deg) < convert_precision else: assert (coo2.spherical.lon - tocoo[0]*u.deg) < convert_precision # <1 arcsec assert (coo2.spherical.lat - tocoo[1]*u.deg) < convert_precision assert coo1.distance.unit == u.kpc assert coo2.distance.unit == u.kpc assert m31_dist.unit == u.kpc assert (coo2.distance - m31_dist) < dist_precision # check round-tripping coo1_2 = coo2.transform_to(fromsys) assert (coo1_2.spherical.lon - fromcoo[0]*u.deg) < roundtrip_precision assert (coo1_2.spherical.lat - fromcoo[1]*u.deg) < roundtrip_precision assert (coo1_2.distance - m31_dist) < dist_precision
Example #21
Source File: test_formatter_locator.py From Carnets with BSD 3-Clause "New" or "Revised" License | 6 votes |
def test_values_unit(self): # Make sure that the intrinsic unit and format unit are correctly # taken into account when using the locator fl = AngleFormatterLocator(unit=u.arcsec, format_unit=u.arcsec, decimal=True) assert_quantity_allclose(fl.locator(850, 2150)[0], [1000., 1200., 1400., 1600., 1800., 2000.] * u.arcsec) fl = AngleFormatterLocator(unit=u.arcsec, format_unit=u.degree, decimal=False) assert_quantity_allclose(fl.locator(850, 2150)[0], [15., 20., 25., 30., 35.] * u.arcmin) fl = AngleFormatterLocator(unit=u.arcsec, format_unit=u.hourangle, decimal=False) assert_quantity_allclose(fl.locator(850, 2150)[0], [60., 75., 90., 105., 120., 135.] * (15 * u.arcsec)) fl = AngleFormatterLocator(unit=u.arcsec) fl.format = 'dd:mm:ss' assert_quantity_allclose(fl.locator(0.9, 1.1)[0], [1] * u.arcsec) fl = AngleFormatterLocator(unit=u.arcsec, spacing=0.2 * u.arcsec) assert_quantity_allclose(fl.locator(0.3, 0.9)[0], [0.4, 0.6, 0.8] * u.arcsec)
Example #22
Source File: test_utils.py From Carnets with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_size_pixel(self): """ Check size in derived pixel units. """ size = 0.3*u.arcsec / (0.1*u.arcsec/u.pixel) c = Cutout2D(self.data, (2, 2), size) assert c.data.shape == (3, 3) assert c.data[0, 0] == 5 assert c.slices_original == (slice(1, 4), slice(1, 4)) assert c.slices_cutout == (slice(0, 3), slice(0, 3))
Example #23
Source File: test_representation_arithmetic.py From Carnets with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_simple_differentials(self, omit_coslat): self._setup(omit_coslat) s, e, sf = self.s, self.e, self.sf o_lon = self.USD_cls(1.*u.arcsec, 0.*u.arcsec) o_lonc = o_lon.to_cartesian(base=s) o_lon2 = self.USD_cls.from_cartesian(o_lonc, base=s) assert_differential_allclose(o_lon, o_lon2) # simple check by hand for first element # (lat[0]=0, so works for both normal and CosLat differential) assert_quantity_allclose(o_lonc[0].xyz, [0., np.pi/180./3600., 0.]*u.one) # check all using unit vectors and scale factors. s_lon = s + 1.*u.arcsec * sf['lon'] * e['lon'] assert type(s_lon) is SphericalRepresentation assert_representation_allclose(o_lonc, s_lon - s, atol=1e-10*u.one) s_lon2 = s + o_lon assert_representation_allclose(s_lon2, s_lon, atol=1e-10*u.one) o_lat = self.USD_cls(0.*u.arcsec, 1.*u.arcsec) o_latc = o_lat.to_cartesian(base=s) assert_quantity_allclose(o_latc[0].xyz, [0., 0., np.pi/180./3600.]*u.one, atol=1e-10*u.one) s_lat = s + 1.*u.arcsec * sf['lat'] * e['lat'] assert type(s_lat) is SphericalRepresentation assert_representation_allclose(o_latc, s_lat - s, atol=1e-10*u.one) s_lat2 = s + o_lat assert_representation_allclose(s_lat2, s_lat, atol=1e-10*u.one)
Example #24
Source File: test_representation_arithmetic.py From Carnets with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_simple_differentials(self, omit_coslat): self._setup(omit_coslat) s, e, sf = self.s, self.e, self.sf o_lon = self.SD_cls(1.*u.arcsec, 0.*u.arcsec, 0.*u.kpc) o_lonc = o_lon.to_cartesian(base=s) o_lon2 = self.SD_cls.from_cartesian(o_lonc, base=s) assert_differential_allclose(o_lon, o_lon2) # simple check by hand for first element. # lat[0] is 0, so cos(lat) term doesn't matter. assert_quantity_allclose(o_lonc[0].xyz, [0., np.pi/180./3600., 0.]*u.kpc) # check all using unit vectors and scale factors. s_lon = s + 1.*u.arcsec * sf['lon'] * e['lon'] assert_representation_allclose(o_lonc, s_lon - s, atol=1*u.npc) s_lon2 = s + o_lon assert_representation_allclose(s_lon2, s_lon, atol=1*u.npc) o_lat = self.SD_cls(0.*u.arcsec, 1.*u.arcsec, 0.*u.kpc) o_latc = o_lat.to_cartesian(base=s) assert_quantity_allclose(o_latc[0].xyz, [0., 0., np.pi/180./3600.]*u.kpc, atol=1.*u.npc) s_lat = s + 1.*u.arcsec * sf['lat'] * e['lat'] assert_representation_allclose(o_latc, s_lat - s, atol=1*u.npc) s_lat2 = s + o_lat assert_representation_allclose(s_lat2, s_lat, atol=1*u.npc) o_distance = self.SD_cls(0.*u.arcsec, 0.*u.arcsec, 1.*u.mpc) o_distancec = o_distance.to_cartesian(base=s) assert_quantity_allclose(o_distancec[0].xyz, [1e-6, 0., 0.]*u.kpc, atol=1.*u.npc) s_distance = s + 1.*u.mpc * sf['distance'] * e['distance'] assert_representation_allclose(o_distancec, s_distance - s, atol=1*u.npc) s_distance2 = s + o_distance assert_representation_allclose(s_distance2, s_distance)
Example #25
Source File: test_formatter_locator.py From Carnets with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_incorrect_spacing(self): fl = AngleFormatterLocator() fl.spacing = 0.032 * u.deg with pytest.warns(UserWarning, match=r'Spacing is not a multiple of base spacing'): fl.format = 'dd:mm:ss' assert_almost_equal(fl.spacing.to_value(u.arcsec), 115.)
Example #26
Source File: test_sky_coord_velocities.py From Carnets with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_creation_attrs(): sc1 = SkyCoord(1*u.deg, 2*u.deg, pm_ra_cosdec=.2*u.mas/u.yr, pm_dec=.1*u.mas/u.yr, frame='fk5') assert_quantity_allclose(sc1.ra, 1*u.deg) assert_quantity_allclose(sc1.dec, 2*u.deg) assert_quantity_allclose(sc1.pm_ra_cosdec, .2*u.arcsec/u.kyr) assert_quantity_allclose(sc1.pm_dec, .1*u.arcsec/u.kyr) sc2 = SkyCoord(1*u.deg, 2*u.deg, pm_ra=.2*u.mas/u.yr, pm_dec=.1*u.mas/u.yr, differential_type=SphericalDifferential) assert_quantity_allclose(sc2.ra, 1*u.deg) assert_quantity_allclose(sc2.dec, 2*u.deg) assert_quantity_allclose(sc2.pm_ra, .2*u.arcsec/u.kyr) assert_quantity_allclose(sc2.pm_dec, .1*u.arcsec/u.kyr) sc3 = SkyCoord('1:2:3 4:5:6', pm_ra_cosdec=.2*u.mas/u.yr, pm_dec=.1*u.mas/u.yr, unit=(u.hour, u.deg)) assert_quantity_allclose(sc3.ra, 1*u.hourangle + 2*u.arcmin*15 + 3*u.arcsec*15) assert_quantity_allclose(sc3.dec, 4*u.deg + 5*u.arcmin + 6*u.arcsec) # might as well check with sillier units? assert_quantity_allclose(sc3.pm_ra_cosdec, 1.2776637006616473e-07 * u.arcmin / u.fortnight) assert_quantity_allclose(sc3.pm_dec, 6.388318503308237e-08 * u.arcmin / u.fortnight)
Example #27
Source File: test_images.py From Carnets with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_noncelestial_angular(self, tmpdir): # Regression test for a bug that meant that when passing a WCS that had # angular axes and using set_coord_type to set the coordinates to # longitude/latitude, but where the WCS wasn't recognized as celestial, # the WCS units are not converted to deg, so we can't assume that # transform will always return degrees. wcs = WCS(naxis=2) wcs.wcs.ctype = ['solar-x', 'solar-y'] wcs.wcs.cunit = ['arcsec', 'arcsec'] fig = plt.figure(figsize=(3, 3)) ax = fig.add_subplot(1, 1, 1, projection=wcs) ax.imshow(np.zeros([1024, 1024]), origin='lower') ax.coords[0].set_coord_type('longitude', coord_wrap=180) ax.coords[1].set_coord_type('latitude') ax.coords[0].set_major_formatter('s.s') ax.coords[1].set_major_formatter('s.s') ax.coords[0].set_format_unit(u.arcsec, show_decimal_unit=False) ax.coords[1].set_format_unit(u.arcsec, show_decimal_unit=False) ax.grid(color='white', ls='solid') # Force drawing (needed for format_coord) fig.savefig(tmpdir.join('nothing').strpath) assert ax.format_coord(512, 512) == '513.0 513.0 (world)' return fig
Example #28
Source File: test_images.py From Carnets with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_latex_labels(self): fig = plt.figure(figsize=(3, 3)) ax = fig.add_axes([0.3, 0.2, 0.65, 0.6], projection=WCS(self.twoMASS_k_header), aspect='equal') ax.set_xlim(-0.5, 0.5) ax.set_ylim(-0.5, 0.5) ax.coords[0].set_ticks(spacing=0.2 * 15 * u.arcsec) return fig
Example #29
Source File: test_intermediate_transformations.py From Carnets with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_earth_orientation_table(): """Check that we can set the IERS table used as Earth Reference. Use the here and now to be sure we get a difference. """ t = Time.now() location = EarthLocation(lat=0*u.deg, lon=0*u.deg) altaz = AltAz(location=location, obstime=t) sc = SkyCoord(1*u.deg, 2*u.deg) # Default: uses IERS_Auto, which will give a prediction. with catch_warnings() as w: altaz_auto = sc.transform_to(altaz) assert len(w) == 0 with iers.earth_orientation_table.set(iers.IERS_B.open()): with catch_warnings() as w: altaz_b = sc.transform_to(altaz) assert len(w) == 1 assert 'after IERS data' in str(w[0].message) sep_b_auto = altaz_b.separation(altaz_auto) assert_allclose(sep_b_auto, 0.0*u.deg, atol=1*u.arcsec) assert sep_b_auto > 10*u.microarcsecond # Check we returned to regular IERS system. altaz_auto2 = sc.transform_to(altaz) assert altaz_auto2.separation(altaz_auto) == 0.
Example #30
Source File: test_representation_arithmetic.py From Carnets with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_simple_differentials(self): s, e, sf = self.s, self.e, self.sf o_rho = CylindricalDifferential(1.*u.mpc, 0.*u.arcsec, 0.*u.kpc) o_rhoc = o_rho.to_cartesian(base=s) assert_quantity_allclose(o_rhoc[0].xyz, [1.e-6, 0., 0.]*u.kpc) s_rho = s + 1.*u.mpc * sf['rho'] * e['rho'] assert_representation_allclose(o_rhoc, s_rho - s, atol=1e-10*u.kpc) s_rho2 = s + o_rho assert_representation_allclose(s_rho2, s_rho) o_phi = CylindricalDifferential(0.*u.kpc, 1.*u.arcsec, 0.*u.kpc) o_phic = o_phi.to_cartesian(base=s) o_phi2 = CylindricalDifferential.from_cartesian(o_phic, base=s) assert_quantity_allclose(o_phi.d_rho, o_phi2.d_rho, atol=1.*u.npc) assert_quantity_allclose(o_phi.d_phi, o_phi2.d_phi, atol=1.*u.narcsec) assert_quantity_allclose(o_phi.d_z, o_phi2.d_z, atol=1.*u.npc) # simple check by hand for first element. assert_quantity_allclose(o_phic[0].xyz, [0., np.pi/180./3600., 0.]*u.kpc) # check all using unit vectors and scale factors. s_phi = s + 1.*u.arcsec * sf['phi'] * e['phi'] assert_representation_allclose(o_phic, s_phi - s, atol=1e-10*u.kpc) o_z = CylindricalDifferential(0.*u.kpc, 0.*u.arcsec, 1.*u.mpc) o_zc = o_z.to_cartesian(base=s) assert_quantity_allclose(o_zc[0].xyz, [0., 0., 1.e-6]*u.kpc) s_z = s + 1.*u.mpc * sf['z'] * e['z'] assert_representation_allclose(o_zc, s_z - s, atol=1e-10*u.kpc) s_z2 = s + o_z assert_representation_allclose(s_z2, s_z)