Beispiel #1
0
def compute_ecliptic_location(date, site_code):
    '''Calculate and return two 4000 element long arrays giving the location of the ecliptic
    for the passed <date> (as a UTC datetime) in J2000 RA, Dec co-ordinates'''

    # Compute date as MJD_TDB
    (site_name, site_long, site_lat, site_hgt) = get_sitepos(site_code)
    mjd_tdb = datetime2mjd_tdb(date, site_long, site_lat, site_hgt, False)

    # Ecliptic plane
    ecl_lon = np.linspace(0,360,4000)
    ecl_lat = np.zeros(ecl_lon.shape)
    ecliptic_ra_list = []
    ecliptic_dec_list = []
    for elong,elat in zip(ecl_lon, ecl_lat):
        ecl_ra, ecl_dec = S.sla_ecleq(radians(elong), radians(elat), mjd_tdb)
        ecliptic_ra_list.append(ecl_ra)
        ecliptic_dec_list.append(ecl_dec)
    ecliptic_ra  = coord.Angle(ecliptic_ra_list * u.radian)
    ecliptic_dec = coord.Angle(ecliptic_dec_list * u.radian)

    return ecliptic_ra, ecliptic_dec
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
Beispiel #3
0
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
Beispiel #4
0
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))
Beispiel #5
0
    def read(self, parfilenm):
        self.FILE = parfilenm
        pf = open(parfilenm)
        for line in pf.readlines():
            # Convert any 'D-' or 'D+' to 'E-' or 'E+'
            line = line.replace("D-", "E-")
            line = line.replace("D+", "E+")
            try:
                splitline = line.split()
                key = splitline[0]
                if key in str_keys:
                    setattr(self, key, splitline[1])
                elif key in float_keys:
                    try:
                        setattr(self, key, float(splitline[1]))
                    except ValueError:
                        pass
                if len(
                        splitline
                ) == 3:  # Some parfiles don't have flags, but do have errors
                    if splitline[2] not in ['0', '1']:
                        setattr(self, key + '_ERR', float(splitline[2]))
                if len(splitline) == 4:
                    setattr(self, key + '_ERR', float(splitline[3]))
            except:
                print ''

# Read PSR name
        if hasattr(self, 'PSR'):
            setattr(self, 'PSR', self.PSR)
        if hasattr(self, 'PSRJ'):
            setattr(self, 'PSRJ', self.PSRJ)
        # Deal with Ecliptic coords
        if (hasattr(self, 'BETA') and hasattr(self, 'LAMBDA')):
            self.use_eclip = True
            setattr(self, 'ELAT', self.BETA)
            setattr(self, 'ELONG', self.LAMBDA)
        if (slalib and hasattr(self, 'ELAT') and hasattr(self, 'ELONG')):
            self.use_eclip = True
            if hasattr(self, 'POSEPOCH'):
                epoch = self.POSEPOCH
            else:
                epoch = self.PEPOCH
            ra_rad, dec_rad = sla_ecleq(self.ELONG * pu.DEGTORAD,
                                        self.ELAT * pu.DEGTORAD, epoch)
            rstr = pu.coord_to_string(*pu.rad_to_hms(ra_rad))
            dstr = pu.coord_to_string(*pu.rad_to_dms(dec_rad))
            setattr(self, 'RAJ', rstr)
            setattr(self, 'DECJ', dstr)
        if hasattr(self, 'RAJ'):
            setattr(self, 'RA_RAD', pu.ra_to_rad(self.RAJ))
        if hasattr(self, 'DECJ'):
            setattr(self, 'DEC_RAD', pu.dec_to_rad(self.DECJ))
        # Compute the Galactic coords
        if (slalib and hasattr(self, 'RA_RAD') and hasattr(self, 'DEC_RAD')):
            l, b = sla_eqgal(self.RA_RAD, self.DEC_RAD)
            setattr(self, 'GLONG', l * pu.RADTODEG)
            setattr(self, 'GLAT', b * pu.RADTODEG)
        # Compute the Ecliptic coords
        if (slalib and hasattr(self, 'RA_RAD') and hasattr(self, 'DEC_RAD')):
            if hasattr(self, 'POSEPOCH'):
                epoch = self.POSEPOCH
            else:
                epoch = self.PEPOCH
            elon, elat = sla_eqecl(self.RA_RAD, self.DEC_RAD, epoch)
            setattr(self, 'ELONG', elon * pu.RADTODEG)
            setattr(self, 'ELAT', elat * pu.RADTODEG)
        if hasattr(self, 'P'):
            setattr(self, 'P0', self.P)
        if hasattr(self, 'P0'):
            setattr(self, 'F0', 1.0 / self.P0)
        if hasattr(self, 'F0'):
            setattr(self, 'P0', 1.0 / self.F0)
        if hasattr(self, 'F1'):
            setattr(self, 'P1', -self.F1 / (self.F0 * self.F0))
        if hasattr(self, 'FB0'):
            setattr(self, 'PB', (1.0 / self.FB0) / 86400.0)
        if hasattr(self, 'P0_ERR'):
            if hasattr(self, 'P1_ERR'):
                f, ferr, fd, fderr = pu.pferrs(self.P0, self.P0_ERR, self.P1,
                                               self.P1_ERR)
                setattr(self, 'F0_ERR', ferr)
                setattr(self, 'F1', fd)
                setattr(self, 'F1_ERR', fderr)
            else:
                f, fd, = pu.p_to_f(self.P0, self.P1)
                setattr(self, 'F0_ERR', self.P0_ERR / (self.P0 * self.P0))
                setattr(self, 'F1', fd)
        if hasattr(self, 'F0_ERR'):
            if hasattr(self, 'F1_ERR'):
                p, perr, pd, pderr = pu.pferrs(self.F0, self.F0_ERR, self.F1,
                                               self.F1_ERR)
                setattr(self, 'P0_ERR', perr)
                setattr(self, 'P1', pd)
                setattr(self, 'P1_ERR', pderr)
            else:
                p, pd, = pu.p_to_f(self.F0, self.F1)
                setattr(self, 'P0_ERR', self.F0_ERR / (self.F0 * self.F0))
                setattr(self, 'P1', pd)
        if hasattr(self, 'DM'):
            setattr(self, 'DM', self.DM)
        if hasattr(self, 'EPS1') and hasattr(self, 'EPS2'):
            self.use_ell = True
            ecc = math.sqrt(self.EPS1 * self.EPS1 + self.EPS2 * self.EPS2)
            omega = math.atan2(self.EPS1, self.EPS2)
            setattr(self, 'ECC', ecc)
            setattr(self, 'OM', omega)
        if hasattr(self, 'PB') and hasattr(self,
                                           'A1') and not hasattr(self, 'ECC'):
            setattr(self, 'ECC', 0.0)
        pf.close()