def transform_celestial(coords, systems): lons, lats = np.radians(coords['lon']), np.radians(coords['lat']) out = Table() out['lon'] = np.zeros(len(coords), dtype='float64') out['lat'] = np.zeros(len(coords), dtype='float64') for ii, (lon, lat) in enumerate(zip(lons, lats)): # First convert to FK5 J2000 in all cases if systems['in'] == 'fk4': lon, lat = slalib.sla_fk45z(lon, lat, 2000.0012775136652) elif systems['in'] == 'icrs': lon, lat = slalib.sla_hfk5z(lon, lat, 2000)[:2] elif systems['in'] == 'galactic': lon, lat = slalib.sla_galeq(lon, lat) elif systems['in'] == 'ecliptic': lon, lat = slalib.sla_ecleq(lon, lat, 51544) # Now convert from FK5 J2000 to out system if systems['out'] == 'fk4': # FK5 -> FK4 at BEPOCH 2000 assuming no proper motion or parallax lon, lat = slalib.sla_fk54z(lon, lat, 2000.0012775136652)[:2] elif systems['out'] == 'icrs': # FK5 -> Hipparcos (i.e. ICRF, which is as close as SLALIB # gets to ICRS) at epoch 2000 and with no proper motion lon, lat = slalib.sla_fk5hz(lon, lat, 2000) elif systems['out'] == 'galactic': # FK5 -> Galactic lon, lat = slalib.sla_eqgal(lon, lat) elif systems['out'] == 'ecliptic': # FK5 -> Ecliptic at TDB (MJD) 51544 (i.e. J2000) lon, lat = slalib.sla_eqecl(lon, lat, 51544) out[ii]['lon'] = np.degrees(lon) out[ii]['lat'] = np.degrees(lat) return out
def convert(coords, systems): if not set(systems.values()).issubset(SUPPORTED_SYSTEMS): return None lons, lats = np.radians(coords['lon']), np.radians(coords['lat']) for ii, (lon, lat) in enumerate(zip(lons, lats)): # First convert to FK5 J2000 in all cases if systems['in'] == 'fk4': lon, lat = slalib.sla_fk45z(lon, lat, 2000.0012775136652) elif systems['in'] == 'icrs': lon, lat = slalib.sla_hfk5z(lon, lat, 2000)[:2] elif systems['in'] == 'galactic': lon, lat = slalib.sla_galeq(lon, lat) elif systems['in'] == 'ecliptic': lon, lat = slalib.sla_ecleq(lon, lat, 51544) # Now convert from FK5 J2000 to out system if systems['out'] == 'fk4': # FK5 -> FK4 at BEPOCH 2000 assuming no proper motion or parallax lon, lat = slalib.sla_fk54z (lon, lat, 2000.0012775136652)[:2] elif systems['out'] == 'icrs': # FK5 -> Hipparcos (i.e. ICRF, which is as close as SLALIB # gets to ICRS) at epoch 2000 and with no proper motion lon, lat = slalib.sla_fk5hz(lon, lat, 2000) elif systems['out'] == 'galactic': # FK5 -> Galactic lon, lat = slalib.sla_eqgal(lon, lat) elif systems['out'] == 'ecliptic': # FK5 -> Ecliptic at TDB (MJD) 51544 (i.e. J2000) lon, lat = slalib.sla_eqecl(lon, lat, 51544) lons[ii], lats[ii] = lon, lat return dict(lon=np.degrees(lons), lat=np.degrees(lats))
import numpy as np from pyslalib import slalib as S # Read in initial coordinates as J2000 coordinates data_j2000 = np.radians(np.loadtxt('../initial_coords.txt')) ra_j2000_fk5, dec_j2000_fk5 = data_j2000[:, 0], data_j2000[:, 1] vals = {} for system in 'FK4', 'Ecliptic', 'Galactic', 'ICRS': vals[system] = [np.zeros_like(ra_j2000_fk5), np.zeros_like(dec_j2000_fk5)] for ii, (raj, decj) in enumerate(zip(ra_j2000_fk5, dec_j2000_fk5)): # FK5 -> FK4 at BEPOCH 2000.0 assuming no proper motion or parallax r1950, d1950, dr1950, dd1950 = S.sla_fk54z(raj, decj, 2000.0) vals['FK4'][0][ii], vals['FK4'][1][ii] = r1950, d1950 # FK5 -> Ecliptic at TDB (MJD) 51544.0 (i.e. J2000) dl, db = S.sla_eqecl(raj, decj, 51544.0) vals['Ecliptic'][0][ii], vals['Ecliptic'][1][ii] = dl, db # FK5 -> Galactic dl, db = S.sla_eqgal(raj, decj) vals['Galactic'][0][ii], vals['Galactic'][1][ii] = dl, db # FK5 -> Hipparcos (i.e. ICRF, which is as close as SLALIB # gets to ICRS) at epoch 2000.0 and with no proper motion rh, dh = S.sla_fk5hz(raj, decj, 2000.0) vals['ICRS'][0][ii], vals['ICRS'][1][ii] = rh, dh
import numpy as np from pyslalib import slalib as S # Read in initial coordinates as J2000 coordinates data_j2000 = np.radians(np.loadtxt('../initial_coords.txt')) ra_j2000_fk5, dec_j2000_fk5 = data_j2000[:,0], data_j2000[:,1] vals = {} for system in 'FK4', 'Ecliptic', 'Galactic', 'ICRS': vals[system] = [np.zeros_like(ra_j2000_fk5), np.zeros_like(dec_j2000_fk5)] for ii, (raj, decj) in enumerate(zip(ra_j2000_fk5, dec_j2000_fk5)): # FK5 -> FK4 at BEPOCH 2000.0 assuming no proper motion or parallax r1950, d1950, dr1950, dd1950 = S.sla_fk54z (raj, decj, 2000.0) vals['FK4'][0][ii],vals['FK4'][1][ii] = r1950, d1950 # FK5 -> Ecliptic at TDB (MJD) 51544.0 (i.e. J2000) dl, db = S.sla_eqecl(raj, decj, 51544.0) vals['Ecliptic'][0][ii],vals['Ecliptic'][1][ii] = dl, db # FK5 -> Galactic dl, db = S.sla_eqgal(raj, decj) vals['Galactic'][0][ii],vals['Galactic'][1][ii] = dl, db # FK5 -> Hipparcos (i.e. ICRF, which is as close as SLALIB # gets to ICRS) at epoch 2000.0 and with no proper motion rh, dh = S.sla_fk5hz(raj, decj, 2000.0) vals['ICRS'][0][ii],vals['ICRS'][1][ii] = rh, dh
def get_vobs(self, mjdtmp, xtmp, ytmp, mode, offx, offy, dcos, offmode): mode = mode.lower() offmode = offmode.lower() ### for 'coord == horizontal' skip try: mode = self.coord_dict[mode] except: xxtmp = xtmp yytmp = ytmp try: offmode = self.coord_dict[offmode] except: xxtmp = xtmp yytmp = ytmp if mode == 1: #j2000 if offmode == 0 or offmode == 1: #same or j2000 yytmp = ytmp + offy if dcos == 0: xxtmp = xtmp + offx else: xxtmp = xtmp + offx / math.cos(yytmp) elif offmode == 2: #b1950 ret = slalib.sla_fk54z(xtmp, ytmp, 2000) xtmp_b = ret[0] ytmp_b = ret[1] ytmp_b += offy if dcos == 0: xtmp_b += offx else: xtmp_b += offx / math.cos(ytmp_b) ret_1 = slalib.sla_fk45z(xtmp_b, ytmp_b, 1950) xxtmp = ret_1[0] yytmp = ret_1[1] elif offmode == 3: #lb,galactic,gal ret = slalib.sla_eqgal(xtmp, ytmp) xtmp_g = ret[0] ytmp_g = ret[1] ytmp_g += offy if dcos == 0: xtmp_g += offx else: xtmp_g += offx / math.cos(ytmp_g) ret_1 = slalib.sla_galeq(xtmp_g, ytmp_g) xxtmp = ret_1[0] yytmp = ret_1[1] if mode == 2: #b1950 if offmode == 1: #j2000 ret = slalib.sla_fk45z(xtmp, ytmp, 1950) xtmp_j = ret[0] ytmp_j = ret[1] yytmp = ytmp_j + offy if dcos == 0: xxtmp = xtmp_j + offx else: xxtmp = xtmp_j + offx / math.cos(ytmp_j) elif offmode == 2 or offmode == 0: #b1950 ytmp += offy if dcos == 0: xtmp += offx else: xtmp += offx / math.cos(ytmp) ret = slalib.sla_fk45z(xtmp, ytmp, 1950) xxtmp = ret[0] yytmp = ret[1] elif offmode == 3: #lb,galactic,gal ret = slalib.sla_eg50(xtmp, ytmp) xtmp_g = ret[0] ytmp_g = ret[1] ytmp_g += offy if dcos == 0: xtmp_g += offx else: xtmp_g += offx / math.cos(ytmp_g) ret = slalib.sla_galeq(xtmp_g, ytmp_g) xxtmp = ret[0] yytmp = ret[1] if mode == 3: #lb,galactic,gal if offmode == 1: #j2000 ret_2 = slalib.sla_galeq(xtmp, ytmp) xtmp_j = ret_2[0] ytmp_j = ret_2[1] yytmp = ytmp_j + offy if dcos == 0: xxtmp = xtmp_j + offx else: xxtmp = xtmp_j + offx / math.cos(ytmp_j) elif offmode == 2: #b1950 ret = slalib.sla_ge50(xtmp, ytmp) xtmp_b = ret[0] ytmp_b = ret[1] ytmp_b += offy if dcos == 0: xtmp_b += offx else: xtmp_b += offx / math.cos(ytmp_b) ret = slalib.sla_fk45z(xtmp_b, ytmp_b, 1950) xxtmp = ret[0] yytmp = ret[1] elif offmode == 0 or offmode == 3: #gal,lb,galactic ytmp += offy if dcos == 0: xtmp += offx else: xtmp += offx / math.cos(ytmp) ret = slalib.sla_galeq(xtmp, ytmp) xxtmp = ret[0] yytmp = ret[1] vobs = self.calc_vobs(mjdtmp + 2400000.5, xxtmp, yytmp) #print('vobs',vobs,type(vobs)) return vobs
def get_vobs(self, mjdtmp, xtmp, ytmp, mode, offx, offy, dcos, offmode): mode = mode.lower() offmode = offmode.lower() ### for 'coord == horizontal' skip try : mode = self.coord_dict[mode] except: xxtmp = xtmp yytmp = ytmp try: offmode = self.coord_dict[offmode] except: xxtmp = xtmp yytmp = ytmp if mode == 1:#j2000 if offmode == 0 or offmode == 1:#same or j2000 yytmp = ytmp+offy if dcos == 0 : xxtmp = xtmp+offx else : xxtmp = xtmp+offx/math.cos(yytmp) elif offmode == 2:#b1950 ret = slalib.sla_fk54z(xtmp, ytmp, 2000) xtmp_b = ret[0] ytmp_b = ret[1] ytmp_b += offy if dcos == 0 : xtmp_b += offx else : xtmp_b += offx/math.cos(ytmp_b) ret_1 = slalib.sla_fk45z(xtmp_b, ytmp_b,1950) xxtmp = ret_1[0] yytmp = ret_1[1] elif offmode == 3:#lb,galactic,gal ret = slalib.sla_eqgal(xtmp,ytmp) xtmp_g = ret[0] ytmp_g = ret[1] ytmp_g += offy if dcos == 0 : xtmp_g += offx else : xtmp_g += offx/math.cos(ytmp_g) ret_1 = slalib.sla_galeq(xtmp_g, ytmp_g) xxtmp = ret_1[0] yytmp = ret_1[1] if mode == 2:#b1950 if offmode == 1:#j2000 ret = slalib.sla_fk45z(xtmp, ytmp, 1950) xtmp_j = ret[0] ytmp_j = ret[1] yytmp = ytmp_j+offy if dcos == 0 : xxtmp = xtmp_j+offx else : xxtmp = xtmp_j+offx/math.cos(ytmp_j) elif offmode == 2 or offmode ==0:#b1950 ytmp += offy if dcos == 0 : xtmp += offx else: xtmp += offx/math.cos(ytmp) ret = slalib.sla_fk45z(xtmp, ytmp, 1950) xxtmp = ret[0] yytmp = ret[1] elif offmode == 3:#lb,galactic,gal ret = slalib.sla_eg50(xtmp,ytmp) xtmp_g = ret[0] ytmp_g = ret[1] ytmp_g += offy if dcos == 0 : xtmp_g += offx else : xtmp_g += offx/math.cos(ytmp_g) ret = slalib.sla_galeq(xtmp_g, ytmp_g) xxtmp = ret[0] yytmp = ret[1] if mode == 3:#lb,galactic,gal if offmode == 1:#j2000 ret_2 = slalib.sla_galeq(xtmp, ytmp) xtmp_j = ret_2[0] ytmp_j = ret_2[1] yytmp = ytmp_j+offy if dcos == 0 : xxtmp = xtmp_j+offx else : xxtmp = xtmp_j+offx/math.cos(ytmp_j) elif offmode == 2:#b1950 ret = slalib.sla_ge50(xtmp,ytmp) xtmp_b = ret[0] ytmp_b = ret[1] ytmp_b += offy if dcos == 0 : xtmp_b += offx else : xtmp_b += offx/math.cos(ytmp_b) ret = slalib.sla_fk45z(xtmp_b, ytmp_b, 1950) xxtmp = ret[0] yytmp = ret[1] elif offmode == 0 or offmode == 3:#gal,lb,galactic ytmp += offy if dcos == 0 : xtmp += offx else : xtmp += offx/math.cos(ytmp) ret = slalib.sla_galeq(xtmp, ytmp) xxtmp = ret[0] yytmp = ret[1] vobs = self.calc_vobs(mjdtmp+2400000.5, xxtmp, yytmp) #print('vobs',vobs,type(vobs)) return vobs