pyephem-logo-short.png

References

Install

mkdir -p /home/user/make/pyephem
cd /home/user/make/pyephem
wget http://pypi.python.org/packages/source/p/pyephem/pyephem-3.7.4.1.tar.gz
cd pyephem-3.7.4.1
mkdir -p /home/user/opt/pkgs/pyephem-3.7.4.1/lib/python2.6/site-packages/
ln -sf /home/user/opt/pkgs/pyephem-3.7.4.1/lib/python2.6/site-packages/ /home/user/opt/pyephem
export PYTHONPATH=/home/user/opt/pyephem:${PYTHONPATH}
python setup.py install --prefix=/Users/chinoney/opt/pkgs/pyephem-3.7.4.1
python -c 'import ephem; print ephem.__version__'
3.7.4.1

Tips

Angle

  • Most angles are measured in degrees.
  • Each angle acts like a Python float.
ephem.degrees(ephem.pi / 32)
ephem.degrees('5.625')
ephem.degrees('5:37.5')
ephem.degrees('5:37:30')
ephem.degrees('5:37:30.0')

Date

The dates are encoded as the Dublin Julian Day, which is the number of days (including any fraction) that have passed since the last day of 1899, at noon.

  • Dates are stored and returned as floats.
  • Dates always use Universal Time, never your local time zone.
ephem.Date(35497.7197916667)
ephem.Date('1997/3/10.2197916667')
ephem.Date('1997/3/10 05.275')
ephem.Date('1997/3/10 05:16.5')
ephem.Date('1997/3/10 05:16:30')
ephem.Date('1997/3/10 05:16:30.0')
ephem.Date((1997, 3, 10.2197916667))
ephem.Date((1997, 3, 10, 5, 16, 30.0))

MJD to DJD

pyephemのdefault date formatは「DJD(Dublin Julian Day)」。「MJD(Modified Julian Day)」では無い。

ephem.julian_date(0)
Out[1]: 2415020.0
MJD_TO_JD = 2400000.5
JD_TO_DJD = -2415020.0
MJD_TO_DJD = MJD_TO_JD + JD_TO_DJD
def mjd_to_djd(mjd):
    return mjd + MJD_TO_DJD

Fixed Body

Each Fixed Body' has only three necessary elements:

_ra, _dec
Position
_epoch
The epoch of the position

RA/Dec to Az/El back to RA/Dec to Az/El

import ephem

obs = ephem.Observer()
obs.long = ephem.degrees('-67.75920')
obs.lat = ephem.degrees('-23.00577')
obs.elevation = 5150.
obs.date = 55927. - 15019.5

targets = ["TauA,f|J,05:34:32.00,+22:00:52.0,1",
           "CMB-1,f|J,12:04:00,-39:00:00,1"]
srcs = [ephem.readdb(t) for t in targets]

GOOD

Input:

for t, s in zip(targets, srcs):
       print 'input source: %s' % t
       s.compute(obs)
       print 'computed(Az, El): %s, %s' % (s.az, s.alt)
       ra, dec = obs.radec_of(s.az, s.alt)
       print 'Back to RA, Dec: %s, %s' % (ra, dec)

       o = ephem.FixedBody()
       o._ra, o._dec = ephem.degrees(ra), ephem.degrees(dec)
       o.compute(obs)
       print 'computed(Az. El) w/ FixedBody from (RA, Dec): (%s, %s)' % (o.az, o.alt)
       ra, dec = obs.radec_of(o.az, o.alt)
       print 'computed(Az, El) again: %s, %s (%s, %s), (%s, %s)' % (ra, dec, o.ra, o.dec, o._ra, o._dec)
       print ''

Output:

input source: TauA,f|J,05:34:32.00,+22:00:52.0,1
computed(Az, El): 51:49:28.0, 22:38:47.1
Back to RA, Dec: 5:34:32.00, 22:00:52.0
computed(Az. El) w/ FixedBody from (RA, Dec): (51:49:28.0, 22:38:47.1)
computed(Az, El) again: 5:34:32.00, 22:00:52.0 (5:35:17.99, 22:01:16.7), (5:34:32.00, 22:00:52.0)
input source: CMB-1,f|J,12:04:00,-39:00:00,1
computed(Az, El): 154:26:38.9, -21:25:48.2
Back to RA, Dec: 12:04:00.00, -39:00:00.0
computed(Az. El) w/ FixedBody from (RA, Dec): (154:26:38.9, -21:25:48.2)
computed(Az, El) again: 12:04:00.00, -39:00:00.0 (12:04:38.60, -39:03:55.5), (12:04:00.00, -39:00:00.0)

BAD

Input:

for t, s in zip(targets, srcs):
       print 'input source: %s' % t
       s.compute(obs)
       print 'computed(Az, El): %s, %s' % (s.az, s.alt)
       ra, dec = obs.radec_of(s.az, s.alt)
       print 'Back to RA, Dec: %s, %s' % (ra, dec)

       o = ephem.FixedBody(ra, dec)
       o.compute(obs)
       print 'computed(Az. El) w/ FixedBody from (RA, Dec): (%s, %s)' % (o.az, o.alt)
       ra, dec = obs.radec_of(o.az, o.alt)
       print 'computed(Az, El) again: %s, %s (%s, %s), (%s, %s)' % (ra, dec, o.ra, o.dec, o._ra, o._dec)
       print ''

Output:

input source: TauA,f|J,05:34:32.00,+22:00:52.0,1
computed(Az, El): 51:49:28.0, 22:38:47.1
Back to RA, Dec: 5:34:32.00, 22:00:52.0
computed(Az. El) w/ FixedBody from (RA, Dec): (301:57:40.1, 51:10:11.6)
computed(Az, El) again: 24:00:00.00, -0:00:00.0 (0:00:37.72, 0:04:05.8), (0:00:00.00, 0:00:00.0)
input source: CMB-1,f|J,12:04:00,-39:00:00,1
computed(Az, El): 154:26:38.9, -21:25:48.2
Back to RA, Dec: 12:04:00.00, -39:00:00.0
computed(Az. El) w/ FixedBody from (RA, Dec): (301:57:40.1, 51:10:11.6)
computed(Az, El) again: 24:00:00.00, -0:00:00.0 (0:00:37.72, 0:04:05.8), (0:00:00.00, 0:00:00.0)

Az/El to RA/Dec

#!/usr/bin/env python
  
import numpy as np
import ephem

CEDAR_FLAT_LONGITUDE = '-118.143657'
CEDAR_FLAT_LATITUDE  = '37.279435'
LONGITUDE = CEDAR_FLAT_LONGITUDE
LATITUDE = CEDAR_FLAT_LATITUDE

MJD_TO_JD = 2400000.5
JD_TO_DJD = -2415020.0
MJD_TO_DJD = MJD_TO_JD + JD_TO_DJD
def mjd_to_djd(mjd):
    return mjd + MJD_TO_DJD


mjd = np.load(filename)

filename = 'run0907.071/az.npy'
az = np.load(filename)
filename = 'run0907.071/el.npy'
el = np.load(filename)
filename = 'run0907.071/ra.npy'
ra = np.load(filename)
filename = 'run0907.071/dec.npy'
dec = np.load(filename)

obs = ephem.Observer()
obs.long = LONGITUDE
obs.lat = LATITUDE

for i in xrange(len(mjd)):
    obs.date = float(mjd_to_djd(mjd[i]))
    tmp_ra, tmp_dec = obs.radec_of(az[i], el[i])
    print np.degrees([float(tmp_ra)-ra[i], float(tmp_dec)-dec[i]])

RA/Dec to Az/El

obs = ephem.Observer()
obs.long = LONGITUDE
obs.lat = LATITUDE
obs.elevation = ALTITUDE
srcs = []
srcs.append(ephem.readdb("TauA,f|J,05:34:32.00,+22:00:52.0,1"))
srcs.append(ephem.readdb("CMB-1,f|J,12:04:00,-39:00:00,1"))
srcs.append(ephem.readdb("CMB-2,f|J,05:12:00,-39:00:00,1"))
srcs.append(ephem.readdb("CMB-3,f|J,00:48:00,-48:00:00,1"))
srcs.append(ephem.readdb("CMB-4,f|J,22:44:00,-36:00:00,1"))

mjd = 55927.000000000000 # 2012
djd = mjd_to_djd(mjd)
obs.date = djd

for src in srcs:
       src.compute(obs)
       az = float(src.az)
       el = float(src.alt)

angle from the Sun

#!/usr/bin/env python

import math
from math import sin, cos, acos
import numpy as np
import ephem

CEDAR_FLAT_LONGITUDE = '-118.143657'
CEDAR_FLAT_LATITUDE  = '37.279435'
LONGITUDE = CEDAR_FLAT_LONGITUDE
LATITUDE = CEDAR_FLAT_LATITUDE

MJD_TO_JD = 2400000.5
JD_TO_DJD = -2415020.0
MJD_TO_DJD = MJD_TO_JD + JD_TO_DJD
def mjd_to_djd(mjd):
    return mjd + MJD_TO_DJD

def sun_dist(mjd, az, el):
    obs = ephem.Observer()
    obs.long = LONGITUDE
    obs.lat = LATITUDE

    az0 = az
    el0 = el
    p_0 = [cos(az0)*cos(el0), -sin(az0)*cos(el0),  sin(el0)]

    sun = ephem.Sun()
    djd = mjd_to_djd(mjd)
    obs.date = djd
    sun.compute(obs)
    az_sun, el_sun = float(sun.az), float(sun.alt)
    p_sun = [cos(az_sun)*cos(el_sun), -sin(az_sun)*cos(el_sun),  sin(el_sun)]

    theta = acos( np.dot(p_sun,p_0) )
    return theta


filename = 'run0907.071/antenna_time.npy'
antenna_time = np.load(filename)
filename = 'run0907.071/bolo_time.npy'
mjd = np.load(filename)

filename = 'run0907.071/az.npy'
az = np.load(filename)
filename = 'run0907.071/el.npy'
el = np.load(filename)
filename = 'run0907.071/ra.npy'

for i in xrange(len(mjd)):
    print np.degrees(sun_dist(mjd[i], az[i], el[i]))

添付ファイル: filepyephem-logo-short.png 320件 [詳細]