2012年8月22日水曜日

pyephem

このエントリーをブックマークに追加 このエントリーを含むはてなブックマーク

pyephemを使って、hipparcosのdataをロードしようとしているのだが、角度関係が変。

ephem.degrees(x)のxにはradianを渡すらしい。

  ephem.degrees(degree2rad(entry["RAdeg"])),
  ephem.degrees(degree2rad(entry["DEdeg"])),
私の感覚だと、pythonでは普通、
def Angle(degree=None, hours=None, radian=None):
    ...
のようなインターフェースになると思うんだが・・・・・。(3つのうち同時に与えられるのは1つだけ)

in __init__.py of ephem

# We make available several basic types from _libastro.

Angle = _libastro.Angle
degrees = _libastro.degrees
hours = _libastro.hours

in astro.h

#define raddeg(x)   ((x)*180./PI)

in _libastro.c

static PyObject* build_degrees(double radians)
{
     return new_Angle(radians, raddeg(1));
}

static PyObject* build_degrees_from_degrees(double degrees)
{
     return build_degrees(degrees / raddeg(1));
}    

同じく _libastro.c

static PyObject* new_Angle(double radians, double factor)
{
     AngleObject *ea;
     ea = PyObject_NEW(AngleObject, &AngleType);
     if (ea) {
      ea->f.ob_fval = radians;
      ea->factor = factor;
     }
     return (PyObject*) ea;
}

こいつがephem.degrees()として公開されている。つーか、ea-<factorって何がやりたいの? radian固定ならfactorって何のためにあるのやら。

同じく _libastro.c

static PyObject *degrees(PyObject *self, PyObject *args)
{
     PyObject *o;
     double value;
     if (!PyArg_ParseTuple(args, "O:degrees", &o)) return 0;
     if (parse_angle(o, raddeg(1), &value) == -1) return 0;
     return new_Angle(value, raddeg(1));
}    

同じく _libastro.c

/*   
 * The global methods table and the module initialization function.
 */
     
static PyMethodDef libastro_methods[] = {
     
     {"degrees", degrees, METH_VARARGS, "build an angle measured in degrees"},
     {"hours", hours, METH_VARARGS, "build an angle measured in hours of arc"},
     {"now", (PyCFunction) build_now, METH_NOARGS, "Return the current time"},

0 件のコメント: