Beispiel #1
0
 def calcPos(self, mjd, config):
     """Calculate the moon's ecliptic lon/lat and geocentric RA/Dec, for the given MJD(s)."""
     self.mjd = numpy.copy(mjd)
     self.ra = numpy.zeros(len(mjd), 'float')
     self.dec = numpy.zeros(len(mjd), 'float')
     for i in range(len(mjd)):
         # Calculate moon's position. 
         ra_RAD, dec_RAD, diam = slalib.sla_rdplan(mjd[i], 3,
                                                   config['longitude']*_deg2rad, config['latitude']*_deg2rad)             
         self.ra[i] = ra_RAD * _rad2deg
         self.dec[i] = dec_RAD * _rad2deg
     # Calculate the lunar phase. 
     eclon = numpy.zeros(len(mjd), 'float')
     eclat = numpy.zeros(len(mjd), 'float')
     for i in range(len(mjd)):
         eclon[i], eclat[i] = slalib.sla_eqecl(self.ra[i]*_deg2rad, self.dec[i]*_deg2rad, self.mjd[i])            
     # Calculate the solar longitude. 
     sun = Sun()
     lon_sun = sun.getLon(self.mjd)*_deg2rad
     # Calculate the solar elongation of the Moon.
     solarelong = numpy.arccos(numpy.cos((lon_sun - eclon)) * numpy.cos(eclat))
     # Calculate the phase of the moon. This is the 0-180 degrees phase. 
     self.phase = 180.0 - solarelong*_rad2deg
     # Calculate the illumination of the Moon. This is between 0 - 100, and is what Opsim calls 'moonPhase'.
     self.illum = ( 1 + numpy.cos(self.phase*_deg2rad) )/2.0 * 100.0
     return
Beispiel #2
0
 def calcPos(self, mjd, config):
     """Calculate the moon's ecliptic lon/lat and geocentric RA/Dec, for the given MJD(s)."""
     self.mjd = numpy.copy(mjd)
     self.ra = numpy.zeros(len(mjd), 'float')
     self.dec = numpy.zeros(len(mjd), 'float')
     for i in range(len(mjd)):
         # Calculate moon's position.
         ra_RAD, dec_RAD, diam = slalib.sla_rdplan(
             mjd[i], 3, config['longitude'] * _deg2rad,
             config['latitude'] * _deg2rad)
         self.ra[i] = ra_RAD * _rad2deg
         self.dec[i] = dec_RAD * _rad2deg
     # Calculate the lunar phase.
     eclon = numpy.zeros(len(mjd), 'float')
     eclat = numpy.zeros(len(mjd), 'float')
     for i in range(len(mjd)):
         eclon[i], eclat[i] = slalib.sla_eqecl(self.ra[i] * _deg2rad,
                                               self.dec[i] * _deg2rad,
                                               self.mjd[i])
     # Calculate the solar longitude.
     sun = Sun()
     lon_sun = sun.getLon(self.mjd) * _deg2rad
     # Calculate the solar elongation of the Moon.
     solarelong = numpy.arccos(
         numpy.cos((lon_sun - eclon)) * numpy.cos(eclat))
     # Calculate the phase of the moon. This is the 0-180 degrees phase.
     self.phase = 180.0 - solarelong * _rad2deg
     # Calculate the illumination of the Moon. This is between 0 - 100, and is what Opsim calls 'moonPhase'.
     self.illum = (1 + numpy.cos(self.phase * _deg2rad)) / 2.0 * 100.0
     return
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 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 #5
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 #6
0
# 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

glon = vals['Galactic'][0]
glat = vals['Galactic'][1]
np.savetxt('coords_galactic.txt',
           zip(np.degrees(glon), np.degrees(glat)),
# 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


glon = vals['Galactic'][0]
glat = vals['Galactic'][1]
np.savetxt('coords_galactic.txt', zip(np.degrees(glon), 
Beispiel #8
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()