def test_names(): # First check that sesame is up if urllib.request.urlopen("http://cdsweb.u-strasbg.fr/cgi-bin/nph-sesame").getcode() != 200: pytest.skip("SESAME appears to be down, skipping test_name_resolve.py:test_names()...") with pytest.raises(NameResolveError): get_icrs_coordinates("m87h34hhh") try: icrs = get_icrs_coordinates("NGC 3642") except NameResolveError: ra, dec = _parse_response(_cached_ngc3642["all"]) icrs = SkyCoord(ra=float(ra)*u.degree, dec=float(dec)*u.degree) icrs_true = SkyCoord(ra="11h 22m 18.014s", dec="59d 04m 27.27s") # use precision of only 1 decimal here and below because the result can # change due to Sesame server-side changes. np.testing.assert_almost_equal(icrs.ra.degree, icrs_true.ra.degree, 1) np.testing.assert_almost_equal(icrs.dec.degree, icrs_true.dec.degree, 1) try: icrs = get_icrs_coordinates("castor") except NameResolveError: ra, dec = _parse_response(_cached_castor["all"]) icrs = SkyCoord(ra=float(ra)*u.degree, dec=float(dec)*u.degree) icrs_true = SkyCoord(ra="07h 34m 35.87s", dec="+31d 53m 17.8s") np.testing.assert_almost_equal(icrs.ra.degree, icrs_true.ra.degree, 1) np.testing.assert_almost_equal(icrs.dec.degree, icrs_true.dec.degree, 1)
def test_names(): # First check that sesame is up if urllib.request.urlopen( "http://cdsweb.u-strasbg.fr/cgi-bin/nph-sesame").getcode() != 200: pytest.skip( "SESAME appears to be down, skipping test_name_resolve.py:test_names()..." ) with pytest.raises(NameResolveError): get_icrs_coordinates("m87h34hhh") try: icrs = get_icrs_coordinates("NGC 3642") except NameResolveError: ra, dec = _parse_response(_cached_ngc3642["all"]) icrs = SkyCoord(ra=float(ra) * u.degree, dec=float(dec) * u.degree) icrs_true = SkyCoord(ra="11h 22m 18.014s", dec="59d 04m 27.27s") # use precision of only 1 decimal here and below because the result can # change due to Sesame server-side changes. np.testing.assert_almost_equal(icrs.ra.degree, icrs_true.ra.degree, 1) np.testing.assert_almost_equal(icrs.dec.degree, icrs_true.dec.degree, 1) try: icrs = get_icrs_coordinates("castor") except NameResolveError: ra, dec = _parse_response(_cached_castor["all"]) icrs = SkyCoord(ra=float(ra) * u.degree, dec=float(dec) * u.degree) icrs_true = SkyCoord(ra="07h 34m 35.87s", dec="+31d 53m 17.8s") np.testing.assert_almost_equal(icrs.ra.degree, icrs_true.ra.degree, 1) np.testing.assert_almost_equal(icrs.dec.degree, icrs_true.dec.degree, 1)
def test_name_resolve_cache(tmpdir): from astropy.utils.data import _get_download_cache_locs, get_cached_urls import shelve target_name = "castor" temp_cache_dir = str(tmpdir.mkdir('cache')) with paths.set_temp_cache(temp_cache_dir, delete=True): download_dir, urlmapfn = _get_download_cache_locs() with shelve.open(urlmapfn) as url2hash: assert len(url2hash) == 0 icrs1 = get_icrs_coordinates(target_name, cache=True) # This is a weak test: we just check to see that a url is added to the # cache! with shelve.open(urlmapfn) as url2hash: assert len(url2hash) == 1 url = get_cached_urls()[0] assert 'http://cdsweb.u-strasbg.fr/cgi-bin/nph-sesame/' in url # Try reloading coordinates, now should just reload cached data: with no_internet(): icrs2 = get_icrs_coordinates(target_name, cache=True) with shelve.open(urlmapfn) as url2hash: assert len(url2hash) == 1 assert u.allclose(icrs1.ra, icrs2.ra) assert u.allclose(icrs1.dec, icrs2.dec)
def __init__(self, pqr_to_itrs_matrix, observing_location_itrs, sources=None): r''' sources: dict Name: ICRS SkyCoord. ''' if sources is None: source_names = [ 'Cas A', 'Cyg A', 'Vir A', 'Her A', 'Tau A', 'Per A', '3C 353', '3C 123', '3C 295', '3C 196', 'DR 4', 'DR 23', 'DR 21' ] source_icrs = [ get_icrs_coordinates(source) for source in source_names ] self.sources = { name: icrs for name, icrs in zip(source_names, source_icrs) } else: self.sources = sources self.pqr_to_itrs_matrix = pqr_to_itrs_matrix xyz = observing_location_itrs self.obsgeoloc = acc.CartesianRepresentation(x=xyz[0], y=xyz[1], z=xyz[2], unit='m')
def resolve(name=None): """Resolve object name to coordinates. Parameters ---------- name : str or None If str, it is the name of the object to resolve. If None (default), a primpt for the object name will be presented. Returns ------- sc : instance Instance of SkyCoord from astropy. Get e.g. RA via sc.ra (with units), or sc.ra.value (without units). Or explictly in a different coordinate system, e.g. sc.galactic.b, etc. """ if name is None: name = input("Object name (+ENTER): ") try: coords = name_resolve.get_icrs_coordinates(name) except Exception as e: raise return coords
def test_names_parse(): # a few test cases for parsing embedded coordinates from object name test_names = [ 'CRTS SSS100805 J194428-420209', 'MASTER OT J061451.7-272535.5', '2MASS J06495091-0737408', '1RXS J042555.8-194534', 'SDSS J132411.57+032050.5', 'DENIS-P J203137.5-000511', '2QZ J142438.9-022739', 'CXOU J141312.3-652013' ] for name in test_names: sc = get_icrs_coordinates(name, parse=True)
def test_names_parse(): # a few test cases for parsing embedded coordinates from object name test_names = ['CRTS SSS100805 J194428-420209', 'MASTER OT J061451.7-272535.5', '2MASS J06495091-0737408', '1RXS J042555.8-194534', 'SDSS J132411.57+032050.5', 'DENIS-P J203137.5-000511', '2QZ J142438.9-022739', 'CXOU J141312.3-652013'] for name in test_names: sc = get_icrs_coordinates(name, parse=True)
def test_name_resolve_cache(tmpdir): from astropy.utils.data import get_cached_urls target_name = "castor" temp_cache_dir = str(tmpdir.mkdir('cache')) with paths.set_temp_cache(temp_cache_dir, delete=True): assert len(get_cached_urls()) == 0 icrs1 = get_icrs_coordinates(target_name, cache=True) urls = get_cached_urls() assert len(urls) == 1 assert 'http://cdsweb.u-strasbg.fr/cgi-bin/nph-sesame/' in urls[0] # Try reloading coordinates, now should just reload cached data: with no_internet(): icrs2 = get_icrs_coordinates(target_name, cache=True) assert len(get_cached_urls()) == 1 assert u.allclose(icrs1.ra, icrs2.ra) assert u.allclose(icrs1.dec, icrs2.dec)
def test_name_resolve_cache(tmpdir): from astropy.utils.data import get_cached_urls target_name = "castor" temp_cache_dir = str(tmpdir.mkdir('cache')) with paths.set_temp_cache(temp_cache_dir, delete=True): assert len(get_cached_urls()) == 0 icrs1 = get_icrs_coordinates(target_name, cache=True) urls = get_cached_urls() assert len(urls) == 1 expected_urls = sesame_url.get() assert any([urls[0].startswith(x) for x in expected_urls]), f'{urls[0]} not in {expected_urls}' # Try reloading coordinates, now should just reload cached data: with no_internet(): icrs2 = get_icrs_coordinates(target_name, cache=True) assert len(get_cached_urls()) == 1 assert u.allclose(icrs1.ra, icrs2.ra) assert u.allclose(icrs1.dec, icrs2.dec)
def search_around_source(self, source_name, radius): """ Search for sources around the named source. The coordinates of the provided source are resolved using the astropy.coordinates.name_resolve facility. :param source_name: name of the source, like "Crab" :param radius: radius of the search, in degrees :return: (ra, dec, table), where ra,dec are the coordinates of the source as resolved by astropy, and table is a table with the list of sources """ sky_coord = get_icrs_coordinates(source_name) ra, dec = (sky_coord.fk5.ra.value, sky_coord.fk5.dec.value) return ra, dec, self.cone_search(ra, dec, radius)
def search_around_source(self, source_name, radius): """ Search for sources around the named source. The coordinates of the provided source are resolved using the astropy.coordinates.name_resolve facility. :param source_name: name of the source, like "Crab" :param radius: radius of the search, in degrees :return: (ra, dec, table), where ra,dec are the coordinates of the source as resolved by astropy, and table is a table with the list of sources """ sky_coord = get_icrs_coordinates(source_name) ra, dec = (sky_coord.fk5.ra.value, sky_coord.fk5.dec.value) return ra, dec, self.cone_search(ra, dec, radius)
def object_az_el(source, site, year, doy): """ Compute object's position in alt-az for a given site and time Also returns the source's apparent coordinates @param source : a source name recognized by Simbad @type source : str @param site : DSN station number @type site : int @param year : four digit year @type year : int @param doy : DOY with UT as a fraction of a day @type doy : float """ try: coords = APcn.get_icrs_coordinates(source) except APcn.NameResolveError as details: raise APcn.NameResolveError(details) module_logger.debug("Sky coords: %s", coords) try: dss = C.DSS(site) module_logger.debug("DSS-%d: %f, %f", site, dss.long * 180 / pi, dss.lat * 180 / pi) except KeyError: raise KeyError('%d is not a valid DSS station' % site) loc = APc.EarthLocation(dss.long * u.rad, dss.lat * u.rad) module_logger.debug("Site coords: %s", loc) if doy: mjd = DT.MJD(year, doy) else: raise RuntimeError("no DOY given") tt = APt.Time(mjd, format='mjd') module_logger.debug("ISO time = %s", tt.iso) tt.delta_ut1_utc = 0 coords.obstime = tt coords.location = loc return coords.altaz
elif object_name.startswith('IRAS'): object_name = object_name.replace('IRAS', 'IRAS ') object_name = object_name.replace('p', '+') elif object_name.startswith('B86'): object_name = object_name.replace('B86', '[B86] ') else: pass change1_cards.append('OBJECT') change1_values.append(object_name) change1_comments.append('Target designation') msgs.warning( 'The object name is taken from the file_name and is: {}'.format( object_name)) # RA Dec radec = name_resolve.get_icrs_coordinates(object_name).transform_to( FK5(equinox='J2000')) msgs.warning( 'The coordinates of the object are taken from an online archive:') msgs.warning('RA={}, Dec={}'.format(radec.ra, radec.dec)) """ result_from_query = download_archive.query_from_radec(radec, radius=600., instrument='MUSE') download_archive.download(result_from_query['dp_id']) """ change1_cards.append('RA') change1_values.append(radec.ra.value) change1_comments.append('[deg] Spectroscopic target position (J2000.0)') change1_cards.append('DEC') change1_values.append(radec.dec.value) change1_comments.append('[deg] Spectroscopic target position (J2000.0)')
def PulsarVis(sourcename, times): if sourcename in {'PSRJ0030+0451', 'PSRJ0437-4715'}: SunAvoidance = 55.0 * u.deg else: SunAvoidance = 45.0 * u.deg print("Sun Avoidance: {0:.3f}".format(SunAvoidance)) MoonAvoidance = 15.0 * u.deg # Each pulsar's feasible observation range based on ISS hardware data if sourcename in 'PSRB1821-24': #Analysis ticket 890 HardwareUpperAvoidance = 120 * u.deg #360*u.deg HardwareLowerAvoidance = 88 * u.deg #0*u.deg elif sourcename in 'PSRB1937+21': HardwareUpperAvoidance = 142.0 * u.deg #360*u.deg HardwareLowerAvoidance = 91.0 * u.deg #0*u.deg elif sourcename in 'PSRJ0218+4232': HardwareUpperAvoidance = 156.0 * u.deg #360*u.deg HardwareLowerAvoidance = 88.0 * u.deg #0*u.deg elif sourcename in 'PSRJ0030+0451': HardwareUpperAvoidance = 148.0 * u.deg #360*u.deg HardwareLowerAvoidance = 95.0 * u.deg #0*u.deg elif sourcename in 'PSRJ0437-4715': HardwareUpperAvoidance = 95.0 * u.deg #360*u.deg HardwareLowerAvoidance = 35.0 * u.deg #0*u.deg else: HardwareUpperAvoidance = 360.0 * u.deg #360*u.deg HardwareLowerAvoidance = 0.0 * u.deg #0*u.deg print("ISS Upper:", HardwareUpperAvoidance, "Lower:", HardwareLowerAvoidance, "\n".format(HardwareLowerAvoidance, HardwareUpperAvoidance)) tle160lines = [ '1 25544U 98067A 17160.91338884 +.00001442 +00000-0 +29152-4 0 9993', '2 25544 051.6425 074.5823 0004493 253.3640 193.9362 15.54003243060621' ] tle167lines = [ '1 25544U 98067A 17167.53403196 +.00002711 +00000-0 +48329-4 0 9994', '2 25544 051.6431 041.5846 0004445 283.0899 147.8207 15.54043876061656' ] platform = 'ISS (ZARYA)' # Set up two TLEs so we can compute the precession rate from the # change of RA of ascending node with time tle1 = tlefile.read(platform, line1=tle160lines[0], line2=tle160lines[1]) tle2 = tlefile.read(platform, line1=tle167lines[0], line2=tle167lines[1]) # print(platform) ISSInclination = tle2.inclination * u.deg # print("Inclination = {0:.3f}".format(ISSInclination)) StarboardPoleDec0 = -1 * (90.0 * u.deg - ISSInclination) PortPoleDec0 = -1 * StarboardPoleDec0 #print("Starboard Orbit Pole Declination {0:.2f}".format(StarboardPoleDec0)) # print("Port Orbit Pole Declination {0:.2f}".format(PortPoleDec0)) # Compute ISS precession rate in degrees per day ISSPrecessionRate = (tle2.right_ascension - tle1.right_ascension) / ( tle2.epoch_day - tle1.epoch_day) * u.deg / u.d # print("ISS Precession Rate {0:.3f} ({1:.3f} period)".format(ISSPrecessionRate, # np.abs(360.0*u.deg/ISSPrecessionRate))) ttle2 = Time("{0:4d}-01-01T00:00:00".format(int(tle2.epoch_year) + 2000), format='isot', scale='utc') + tle2.epoch_day * u.d # print("ttle2 = ",ttle2.isot) StarboardPoleRA0 = np.fmod(tle2.right_ascension + 90.0, 360.0) * u.deg PortPoleRA0 = np.fmod(StarboardPoleRA0 + 180.0 * u.deg, 360.0 * u.deg) # print("Starboard Pole RA @ ttle2 = {0:.3f}".format(StarboardPoleRA0)) # print("Port Pole RA @ ttle2 = {0:.3f}".format(PortPoleRA0)) def StarboardPoleDec(t): return np.ones_like(t) * StarboardPoleDec0 def PortPoleDec(t): return np.ones_like(t) * StarboardPoleDec0 def StarboardPoleRA(t): return np.fmod( StarboardPoleRA0 + (t - ttle2).to(u.d) * ISSPrecessionRate, 360.0 * u.deg) def PortPoleRA(t): return np.fmod(StarboardPoleRA(t) + 180.0 * u.deg, 360.0 * u.deg) def StarboardPoleCoord(t): return SkyCoord(StarboardPoleRA(t).value, StarboardPoleDec(t).value, unit=u.deg, frame="icrs") def PortPoleCoord(t): return SkyCoord(PortPoleRA(t).value, PortPoleDec(t).value, unit=u.deg, frame="icrs") now = Time.now() doy_now = np.float(now.yday.split(':')[1]) # print("Current DOY = {0}".format(np.int(doy_now))) #print("StarboardPoleRA (now) = {0:.3f}".format(StarboardPoleRA(now))) #print("PortPoleRA (now) = {0:.3f}".format(PortPoleRA(now))) if sourcename[0:2] != 'PSR': SourcePos = get_icrs_coordinates(sourcename) else: splitstr = sourcename.split(',') SourcePos = ICRS(ra=Angle(double(splitstr[0])), dec=Angle(double(splitstr[1]))) #print("\nSource: {0} at {1}, {2}".format(sourcename,SourcePos.ra, SourcePos.dec)) #print("Separation from Starboard Pole = {0:.3f}".format(SourcePos.separation(StarboardPoleCoord(now)))) #print("Separation from Port Pole = {0:.3f}".format(SourcePos.separation(PortPoleCoord(now)))) #Calculate terms and references to do check #doy2XXX = np.arange(365.0) #times = doy2XXX*u.d + startepoch issseps = SourcePos.separation(StarboardPoleCoord(times)).to(u.deg) # The Sun and Moon positions are returned in the GCRS frame # Convert them to ICRS so .separation doesn't go insane when # comparing different frames with different obstimes. SunPos = get_sun(times) SunPos = SkyCoord(SunPos.ra, SunPos.dec, frame='icrs') MoonPos = get_moon(times) MoonPos = SkyCoord(MoonPos.ra, MoonPos.dec, frame='icrs') # Hold indicies when Sun and Moon cause constraint violation sunseps = SourcePos.separation(SunPos).to(u.deg) idxsun = sunseps < SunAvoidance moonseps = SourcePos.separation(MoonPos).to(u.deg) idxmoon = moonseps < MoonAvoidance # Hold indicies when sep is outside of 91 to 142 deg due to hardware violation (KWood analysis 10/27/2017) idxang = ~((issseps > HardwareLowerAvoidance) & (issseps < HardwareUpperAvoidance)) # Apply all vis constraints indxall = idxsun | idxmoon | idxang #true when constraint is violated # Generate and populate signal output vis = np.ones(len(doy2XXX)) vis[indxall] = float('NaN') #Return result return vis
def PortPoleCoord(t): return SkyCoord(PortPoleRA(t).value, PortPoleDec(t).value, unit=u.deg, frame="icrs") now = Time.now() doy_now = np.float(now.yday.split(':')[1]) print("Current DOY = {0}".format(np.int(doy_now))) print("StarboardPoleRA (now) = {0:.3f}".format(StarboardPoleRA(now))) print("PortPoleRA (now) = {0:.3f}".format(PortPoleRA(now))) if args.ra is None or args.dec is None: SourcePos = get_icrs_coordinates(args.sourcename) else: SourcePos = ICRS(ra=Angle(args.ra), dec=Angle(args.dec)) print("\nSource: {0} at {1}, {2}".format(args.sourcename, SourcePos.ra, SourcePos.dec)) print("Separation from Starboard Pole = {0:.3f}".format( SourcePos.separation(StarboardPoleCoord(now)))) print("Separation from Port Pole = {0:.3f}".format( SourcePos.separation(PortPoleCoord(now)))) # Plot separation from orbit pole for all of 2017 and beyond doy2017 = np.arange(600.0) times = doy2017 * u.d + Time("2017-01-01T00:00:00", format='isot', scale='utc') fig, ax = plt.subplots() seps = SourcePos.separation(StarboardPoleCoord(times))