def rf_equitorial(input_coord_sys, average_velocities=None): """ Convert to reference frame of stellar group after subtraction of LSR (U,V,W) = (11.1,12.24,7.25) kms^-1 defined in Schönrich et al. (2010) and convert it back to equitorial coordinates. Parameters ---------- input_coord_sys : ICRS ICRS input of group for analysis average_velocity : tuple average cartesian velocity to be subtracted if known, else computes it here Returns ------- ICRS ICRS frame """ cartesian_representation, center = rf_cartesian(input_coord_sys) revert = cartesian_representation.transform_to(ICRS) revert.representation_type = 'spherical' revert.differential_type = 'spherical' galactic_revert = Galactic(l=revert.ra, b=revert.dec, distance=revert.distance, pm_l_cosb=revert.pm_ra, pm_b=revert.pm_dec, radial_velocity=revert.radial_velocity) rf_lsr_equitorial = galactic_revert.transform_to(ICRS) return rf_lsr_equitorial
def genGalPlane(): #building galactic plane in ICRS coordinates """Generates galactic plane line to plot on sky map output: galicrs ndarray(SkyCoord) """ galcoords = Galactic(l=np.arange(0, 360, 1) * u.deg, b=np.zeros(360) * u.deg) galicrs = galcoords.transform_to(coordinates.ICRS) galicrs.dec[117] = np.nan * u.deg return galicrs
def CheckCoord(Coord, CoordType): degtorad = math.pi/180 Coord = Coord.strip() if "," in Coord: lon = Coord.split(",")[0].strip() lat = Coord.split(",")[1].strip() if len(lon.split()) == 3: lon_hr = float (lon.split()[0]) lon_min = float (lon.split()[1]) lon_sec = float (lon.split()[2]) lat_deg = float (lat.split()[0]) lat_min = float (lat.split()[1]) lat_sec = float (lat.split()[2]) lon = lon_hr*15. + lon_min/60. + lon_sec/3600. lat = lat_deg + lat_min/60. + lat_sec/3600. else: lon = float(lon) lat = float(lat) else: lon = Coord.split()[0] lat = Coord.split()[1] lon = float (lon) lat = float (lat) if CoordType == "J2000": #mjd for 2000-01-01 #(elon,elat) = slalib.sla_eqecl(lon*degtorad, lat*degtorad, 51544.0) gc = FK5(ra=lon*u.degree, dec=lat*u.degree) hec = gc.transform_to(BarycentricTrueEcliptic) (elon,elat) = (hec.lon.value*degtorad, hec.lat.value*degtorad) elif CoordType == "Galactic": #(ra,dec) = slalib.sla_galeq(lon*degtorad, lat*degtorad) #(elon,elat) = slalib.sla_eqecl(ra,dec,51544.0) gc = Galactic(l=lon*u.degree,b=lat*u.degree) hec = gc.transform_to(BarycentricTrueEcliptic) (elon,elat) = (hec.lon.value*degtorad, hec.lat.value*degtorad) else: elon = lon*degtorad elat = lat*degtorad # return (elon, elat) return (elon, elat)
def gal2fk5(l, b): c = Galactic(l * u.deg, b * u.deg) out = c.transform_to(FK5) return out.ra.degree, out.dec.degree
''' Coordinates ''' #leo.lat = 37.9183 #leo.lon = -122.1067 ''' Galactic Coordinates ''' from astropy.coordinates import ICRS from astropy.coordinates import SkyCoord import astropy.units as u from astropy.coordinates import Galactic l = 120 b = 0 gal = Galactic(l*u.degree,b*u.degree) eq = gal.transform_to(ICRS) _jd = ugradio.timing.julian_date() alt,az = ugradio.coord.get_altaz(6.45083114, 62.72572675 ,_jd,leo.lat,leo.lon,leo.alt,equinox='J2019') ''' Read spectrometer ''' spec = leuschner.Spectrometer('10.0.1.2') #instantiates an interface to the spectrometer at the specified IP address. #spec.int_time #tells you how long each spectrum is integrated for '''Take data ''' '''Will read N spectra and store the output in a FITS file, writing the ra/dec coordinates into the header of the file. Note that this does not point the telescope; it just documents where it is pointed in the file. ''' #spec.read_spec('_test_.fits', N, (ra, dec), 'eq') #e.g. spec.read_spec('compas.fits',10,(50,60),'eq')
# frame or representation class. # Local Standard of Rest LSRD = Galactic(u=0.1 * u.km, v=0.1 * u.km, w=0.1 * u.km, U=9 * u.km / u.s, V=12 * u.km / u.s, W=7 * u.km / u.s, representation_type='cartesian', differential_type='cartesian') LSRD_EQUIV = [ LSRD, SkyCoord(LSRD), # as a SkyCoord LSRD.transform_to(ICRS()), # different frame LSRD.transform_to(ICRS()).transform_to( Galactic()) # different representation ] @pytest.fixture(params=[None] + LSRD_EQUIV) def observer(request): return request.param # Target located in direction of motion of LSRD with no velocities LSRD_DIR_STATIONARY = Galactic(u=9 * u.km, v=12 * u.km, w=7 * u.km, representation_type='cartesian')
def get_footprint_object(self): """Returns footprint object 'sfd'""" # work with SFD map and Decals/Mzls tiles # lonlat from SFD healpix is in galactic coords, convert this to Celestial hdu = fitsio.FITS(os.path.join(self.map_dir, 'lambda_sfd_ebv.fits')) sfd = EmptyClass() temp = hdu[1].read() sfd.temp = temp['TEMPERATURE'] npix = Healpix().get_nside(len(sfd.temp)) assert (npix == 512) sfd.l_indeg, sfd.b_indeg = hp.pix2ang(512, np.where(sfd.temp > 0)[0], nest=True, lonlat=True) #inPlane= np.where((sfd_gal_dec > -20) & (sfd_gal_dec < 20))[0] trans = Galactic(l=sfd.l_indeg * units.degree, b=sfd.b_indeg * units.degree) radec = trans.transform_to(ICRS) sfd.ra, sfd.dec = radec.ra.value, radec.dec.value all_tiles = fits_table( os.path.join(self.tile_dir, 'mosaic-tiles_obstatus.fits')) wdes_tiles = fits_table( os.path.join(self.tile_dir, 'decam-tiles_obstatus.fits')) inDESI = ((all_tiles.in_desi_orig == 1) | (all_tiles.in_desi == 1)) inDecals = ((inDESI) & (all_tiles.dec <= 30.)) #(mzls_decals.in_des == 0)) inMzls = ((inDESI) & (all_tiles.dec > 30.)) #(mzls_decals.in_des == 0)) inDes = ((wdes_tiles.in_desi_orig == 1) | (wdes_tiles.in_desi == 1)) inDes = ((inDes) & (wdes_tiles.in_des == 1)) #above30= mzls.dec > 30. #inDESI= ( (mzls.in_desi_orig == 1) | # (mzls.in_desi == 1)) #inMzls= ( (above30) & # (inDESI)) #desi= merge_tables([mzls,decals],columns='fillzero') des = wdes_tiles.copy() del wdes_tiles des.cut(inDes) mzls = all_tiles.copy() decals = all_tiles.copy() del all_tiles mzls.cut(inMzls) decals.cut(inDecals) ps = Healpix().get_pixscale(len(sfd.temp), unit='deg') # match_radec(ref,obs): for each point in ref, return matching point in obs print('matching tiles to healpix centers') I, J, d = match_radec(mzls.ra, mzls.dec, sfd.ra, sfd.dec, ps * 8) sfd.ipix_mzls = list(set(J)) I, J, d = match_radec(decals.ra, decals.dec, sfd.ra, sfd.dec, ps * 8) sfd.ipix_decals = list(set(J)) I, J, d = match_radec(des.ra, des.dec, sfd.ra, sfd.dec, ps * 8) sfd.ipix_des = list(set(J)) return sfd # legasurvey pts fill in in ps*3 I, J, d = match_radec(legsurvey.ra, legsurvey.dec, sfd.ra, sfd.dec, ps * 3) sfd.ipix_legsurvey = set(J) # des fills in with ps*8 I, J, d = match_radec(des.ra, des.dec, sfd.ra, sfd.dec, ps * 8) sfd.ipix_legsurvey.union(set(J)) sfd.ipix_legsurvey = list(sfd.ipix_legsurvey) return sfd
""" Resample test.hpx into Galactic coordinates, and create test_gal.hpx """ import numpy as np import healpy as hp from astropy.coordinates import Galactic, FK5 import astropy.units as u nest = True map = hp.read_map('test.hpx', nest=nest) theta, phi = hp.pix2ang(64, np.arange(map.size), nest) l, b = phi, np.pi / 2 - theta g = Galactic(l, b, unit=(u.rad, u.rad)) f = g.transform_to(FK5) ra, dec = f.ra.rad, f.dec.rad map = hp.get_interp_val(map, np.pi / 2 - dec, ra, nest) hp.write_map('test_gal.hpx', map, nest=nest, coord='G', fits_IDL=False)