[Debian-astro-commits] [gyoto] 162/221: Python: add second python extension, gyoto_std, wrapping libgyoto-stdplug

Thibaut Jean-Claude Paumard thibaut at moszumanska.debian.org
Fri May 22 20:52:43 UTC 2015


This is an automated email from the git hooks/post-receive script.

thibaut pushed a commit to branch master
in repository gyoto.

commit b9f6e31e39057fcf175b112e19f79f7676b70001
Author: Thibaut Paumard <paumard at users.sourceforge.net>
Date:   Fri Dec 19 16:18:37 2014 +0100

    Python: add second python extension, gyoto_std, wrapping libgyoto-stdplug
---
 Makefile.in                   | 11 ++++---
 configure                     |  3 +-
 configure.ac                  |  2 +-
 include/GyotoAstrobj.h        |  2 +-
 include/GyotoKerrBL.h         |  7 +++--
 include/GyotoPageThorneDisk.h |  2 +-
 python/Makefile.in            | 12 ++++++--
 python/example.py             | 39 ++++++++++++++++++++++++
 python/gyoto.i                | 42 ++++++++++++++++++++++++++
 python/gyoto_std.i            | 69 +++++++++++++++++++++++++++++++++++++++++++
 python/setup_std.py.in        | 38 ++++++++++++++++++++++++
 11 files changed, 215 insertions(+), 12 deletions(-)

diff --git a/Makefile.in b/Makefile.in
index 9567fd1..cde6d73 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -91,9 +91,10 @@ DIST_COMMON = INSTALL NEWS README AUTHORS ChangeLog \
 	$(top_srcdir)/yorick/yorick1.in \
 	$(top_srcdir)/yorick/setpaths.i.in $(srcdir)/gyoto.in \
 	$(top_srcdir)/python/Makefile.in \
-	$(top_srcdir)/python/setup.py.in $(top_srcdir)/doc/doxyfile.in \
-	COPYING compile config.guess config.sub depcomp install-sh \
-	missing ltmain.sh
+	$(top_srcdir)/python/setup.py.in \
+	$(top_srcdir)/python/setup_std.py.in \
+	$(top_srcdir)/doc/doxyfile.in COPYING compile config.guess \
+	config.sub depcomp install-sh missing ltmain.sh
 ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
 am__aclocal_m4_deps = $(top_srcdir)/m4/ax_append_compile_flags.m4 \
 	$(top_srcdir)/m4/ax_append_flag.m4 \
@@ -113,7 +114,7 @@ CONFIG_HEADER = config.h $(top_builddir)/include/GyotoConfig.h
 CONFIG_CLEAN_FILES = doc/Makefile doc/user_guide/Makefile \
 	yorick/Makefile yorick/stdplug/Makefile yorick/gyoto.info \
 	yorick/yorick1 yorick/setpaths.i gyoto python/Makefile \
-	python/setup.py doc/doxyfile
+	python/setup.py python/setup_std.py doc/doxyfile
 CONFIG_CLEAN_VPATH_FILES =
 AM_V_P = $(am__v_P_ at AM_V@)
 am__v_P_ = $(am__v_P_ at AM_DEFAULT_V@)
@@ -479,6 +480,8 @@ python/Makefile: $(top_builddir)/config.status $(top_srcdir)/python/Makefile.in
 	cd $(top_builddir) && $(SHELL) ./config.status $@
 python/setup.py: $(top_builddir)/config.status $(top_srcdir)/python/setup.py.in
 	cd $(top_builddir) && $(SHELL) ./config.status $@
+python/setup_std.py: $(top_builddir)/config.status $(top_srcdir)/python/setup_std.py.in
+	cd $(top_builddir) && $(SHELL) ./config.status $@
 doc/doxyfile: $(top_builddir)/config.status $(top_srcdir)/doc/doxyfile.in
 	cd $(top_builddir) && $(SHELL) ./config.status $@
 
diff --git a/configure b/configure
index b74d667..60d22ba 100755
--- a/configure
+++ b/configure
@@ -19293,7 +19293,7 @@ if test "x$YORICK" != "x"; then :
 fi
 if test "x$PYTHON" != "x"; then :
 
-   ac_config_files="$ac_config_files python/Makefile python/setup.py"
+   ac_config_files="$ac_config_files python/Makefile python/setup.py python/setup_std.py"
 
 
 
@@ -20463,6 +20463,7 @@ do
     "gyoto") CONFIG_FILES="$CONFIG_FILES gyoto" ;;
     "python/Makefile") CONFIG_FILES="$CONFIG_FILES python/Makefile" ;;
     "python/setup.py") CONFIG_FILES="$CONFIG_FILES python/setup.py" ;;
+    "python/setup_std.py") CONFIG_FILES="$CONFIG_FILES python/setup_std.py" ;;
     "doc/doxyfile") CONFIG_FILES="$CONFIG_FILES doc/doxyfile" ;;
 
   *) as_fn_error $? "invalid argument: \`$ac_config_target'" "$LINENO" 5;;
diff --git a/configure.ac b/configure.ac
index b2f849f..2c8812e 100644
--- a/configure.ac
+++ b/configure.ac
@@ -764,7 +764,7 @@ AS_IF([test "x$YORICK" != "x"],
 )
 AS_IF([test "x$PYTHON" != "x"],
   [
-   AC_CONFIG_FILES([python/Makefile python/setup.py])
+   AC_CONFIG_FILES([python/Makefile python/setup.py python/setup_std.py])
   ]
 )
 AS_IF([test "x$DOXYGEN" != "x" && test "x$mkdoc" == "xyes"],
diff --git a/include/GyotoAstrobj.h b/include/GyotoAstrobj.h
index c5ee028..588f7c1 100644
--- a/include/GyotoAstrobj.h
+++ b/include/GyotoAstrobj.h
@@ -349,7 +349,7 @@ class Gyoto::Astrobj::Generic
    * quantities to compute for this object. The default of these
    * defaults GYOTO_QUANTITY_INTENSITY.
    */
-  virtual Quantity_t getDefaultQuantities();
+  virtual Gyoto::Quantity_t getDefaultQuantities();
   ///< Which quantities to compute if know was requested
 
   //XML I/O
diff --git a/include/GyotoKerrBL.h b/include/GyotoKerrBL.h
index 3db0924..c7150de 100644
--- a/include/GyotoKerrBL.h
+++ b/include/GyotoKerrBL.h
@@ -135,14 +135,15 @@ class Gyoto::Metric::KerrBL : public Metric::Generic {
    */
   int myrk4(Worldline * line, const double coordin[8], double h, double res[8]) const; //external-use RK4
   
- private:
+ public:
   int myrk4(const double coor[8], const double cst[5], double h, double res[8]) const;///< Internal-use RK4 proxy
-  int myrk4_adaptive(Gyoto::Worldline* line, const double coor[8], double lastnorm, double normref, double coor1[8], double h0, double& h1, double h1max) const; ///< Internal-use adaptive RK4 proxy
+  int myrk4_adaptive(Gyoto::Worldline* line, const double coor[8], double lastnorm, double normref, double coor1[8], double h0, double& h1, double h1max=GYOTO_DEFAULT_DELTA_MAX) const; ///< Internal-use adaptive RK4 proxy
   /**
    * \brief Ensure conservation of the constants of motion
    *
    * Tweak thetadot if necessary.
    */
+ private:
   int CheckCons(const double coor_init[8], const double cst[5], double coor_fin[8]) const;
 
   /**
@@ -152,9 +153,11 @@ class Gyoto::Metric::KerrBL : public Metric::Generic {
    */
   void Normalize4v(double coord[8], const double part_mass) const;
 
+ public:
   /** F function such as dy/dtau=F(y,cst)
    */
   using Metric::Generic::diff;
+ private:
   /** 
    * \brief Used in RK4 proxies.
    */
diff --git a/include/GyotoPageThorneDisk.h b/include/GyotoPageThorneDisk.h
index e2c2284..646a67c 100644
--- a/include/GyotoPageThorneDisk.h
+++ b/include/GyotoPageThorneDisk.h
@@ -137,7 +137,7 @@ virtual double bolometricEmission(double nuem, double dsem,
                                    double* coord_obj_hit, double dt,
                                    Astrobj::Properties* data) const;
 
-  Quantity_t getDefaultQuantities();
+  Gyoto::Quantity_t getDefaultQuantities();
 
   // Hook::Listener API //
  public:
diff --git a/python/Makefile.in b/python/Makefile.in
index 3fd26b5..fb89c1b 100644
--- a/python/Makefile.in
+++ b/python/Makefile.in
@@ -81,17 +81,24 @@ export CPPFLAGS
 export CXXFLAGS
 export CC
 
-all: gyoto.py _gyoto$(PYTHON_EXTENSION_SUFFIX)
+all: gyoto.py gyoto_std.py _gyoto$(PYTHON_EXTENSION_SUFFIX) \
+	_gyoto_std$(PYTHON_EXTENSION_SUFFIX)
 
 _gyoto$(PYTHON_EXTENSION_SUFFIX): gyoto_wrap.cxx
 	$(PYTHON) $(srcdir)/setup.py build_ext
 
+_gyoto_std$(PYTHON_EXTENSION_SUFFIX): gyoto_std_wrap.cxx
+	$(PYTHON) $(srcdir)/setup_std.py build_ext
+
 gyoto.py gyoto_wrap.cxx: gyoto.i header.py
 	swig2.0 -I$(srcdir)/../include -c++ -python  $(srcdir)/gyoto.i
 	mv gyoto.py trailer.py
 	cat header.py trailer.py > gyoto.py
 	rm trailer.py
 
+gyoto_std.py gyoto_std_wrap.cxx: gyoto_std.i gyoto.i
+	swig2.0 -I$(srcdir)/../include -c++ -python  $(srcdir)/gyoto_std.i
+
 .PHONY: all install uninstall distclean info install-html html install-pdf pdf install-dvi dvi install-ps ps clean dist check installdirs
 
 
@@ -100,6 +107,7 @@ gyoto.py gyoto_wrap.cxx: gyoto.i header.py
 # install as usual from setup.py
 install: installdirs
 	$(PYTHON) $(srcdir)/setup.py install
+	$(PYTHON) $(srcdir)/setup_std.py install
 ifneq ($(VIRTUALENV),no)
 	$(VIRTUALENV) $(VIRTUALENV_FLAGS) $(DESTDIR)$(prefix) || $(VIRTUALENV) $(DESTDIR)$(prefix)
 	$(DESTDIR)$(prefix)/bin/python $(srcdir)/setup.py install --prefix=$(DESTDIR)$(prefix)
@@ -125,7 +133,7 @@ uninstall:
 clean:
 	$(PYTHON) setup.py clean
 	-rm -Rf build
-	-rm gyoto.py gyoto_wrap.cxx
+	-rm gyoto.py gyoto_wrap.cxx gyoto_std.py gyoto_std_wrap.cxx
 
 # Clean up the output of configure
 distclean: 
diff --git a/python/example.py b/python/example.py
index b6a055b..bf03fb1 100644
--- a/python/example.py
+++ b/python/example.py
@@ -1,9 +1,16 @@
 #/bin/env python
 # -*- coding: utf-8 -*-
+# Example file for gyoto
+# Before loading the gyoto_std extension:
+#  - gyoto must be imported;
+#  - the stdplug Gyoto plug-in must be loaded. This normally happens
+#    automatically, unless the user has set her environment otherwise.
 import numpy
 import matplotlib as ml
 import matplotlib.pyplot as plt
 import gyoto
+gyoto.loadPlugin("stdplug")
+import gyoto_std
 
 a=gyoto.Factory("../doc/examples/example-moving-star.xml")
 sc=a.getScenery()
@@ -187,3 +194,35 @@ sc.rayTrace(bucket, aop)
 t=numpy.clip(ipct[:,0,0], a_min=-200, a_max=0)
 plt.plot(t)
 plt.show()
+
+# Instanciate and manipulate derived classes from the standard
+# plug-in: Note that objects from gyoto_std needs to be downcast to
+# the relevant base before the can be used in gyoto:
+# e.g. AstrobjPtr(obj.__deref__()). The opposite is not (yet)
+# possible: you can't cast the Astrobj from sc.astrobj() up to a
+# StarPtr or TorusPtr. That's where the Object/Value/Property
+# mechanism comes into play, since you don't need to cast an object to
+# set a property:
+
+# By creating an object from gyoto_std, we have full access to its methods:
+tr=gyoto_std.Torus()
+tr.smallRadius(0.1)
+
+# Before feeding it to a function that expects a SmartPointer<Astrobj>,
+# we nee to cast it:
+tt=gyoto.AstrobjPtr(tr.__deref__())
+
+# We can still use the Torus methods on tr, but not on tt.  However,
+# the Property mechanism gives access to the members that can be set
+# from XML:
+p=tt.property("SmallRadius")
+tt.set(p, gyoto.Value(0.2))
+tt.get(p).Double == tr.smallRadius()
+
+# Etc:
+cplx=gyoto_std.ComplexAstrobj()
+cplx.append(gyoto.AstrobjPtr(tr.__deref__()))
+cplx.append(sc.astrobj())
+sc.astrobj(gyoto.AstrobjPtr(cplx.__deref__()))
+
+cplx.rMax(100)
diff --git a/python/gyoto.i b/python/gyoto.i
index 6999d4c..ac5ea79 100644
--- a/python/gyoto.i
+++ b/python/gyoto.i
@@ -33,6 +33,26 @@ Gyoto::SmartPointer<Gyoto::klass::Generic> pyGyoto ## klass (std::string const&s
 }
 %enddef
 
+%define GyotoSmPtrClassDerivedPtrHdr(nspace, klass, nick, hdr)
+%template(nick ## Ptr) Gyoto::SmartPointer<Gyoto::nspace::klass>;
+%ignore Gyoto::nspace::klass;
+%include hdr
+%rename(nick) pyGyoto ## nick;
+%inline {
+Gyoto::SmartPointer<Gyoto::nspace::klass> pyGyoto ## nick () {
+  return new Gyoto::nspace::klass();
+}
+}
+%enddef
+
+%define GyotoSmPtrClassDerivedHdr(nspace, klass, hdr)
+GyotoSmPtrClassDerivedPtrHdr(nspace, klass, klass, hdr)
+%enddef
+
+%define GyotoSmPtrClassDerived(nspace, klass)
+GyotoSmPtrClassDerivedHdr(nspace, klass, Gyoto ## klass ## .h)
+%enddef
+
 %{
 #define SWIG_FILE_WITH_INIT
   //#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION
@@ -48,6 +68,13 @@ Gyoto::SmartPointer<Gyoto::klass::Generic> pyGyoto ## klass (std::string const&s
 #include "GyotoWorldline.h"
 #include "GyotoPhoton.h"
 #include "GyotoScreen.h"
+#include "GyotoStandardAstrobj.h"
+#include "GyotoUniformSphere.h"
+#include "GyotoThinDisk.h"
+#include "GyotoSpectrometer.h"
+#include "GyotoComplexSpectrometer.h"
+#include "GyotoUniformSpectrometer.h"
+#include "GyotoRegister.h"
 using namespace Gyoto;
 
 %}
@@ -81,6 +108,12 @@ using namespace Gyoto;
   import_array();
  }
 
+%ignore Gyoto::Register::Entry;
+%ignore Gyoto::Register::init;
+%rename(listRegister) Gyoto::Register::list;
+%include GyotoRegister.h
+
+
 %include "GyotoSmartPointer.h"
 
 %include "GyotoValue.h"
@@ -107,6 +140,12 @@ GyotoSmPtrClass(Scenery)
 GyotoSmPtrClass(Photon)
 GyotoSmPtrClassGeneric(Astrobj)
 
+%ignore Gyoto::Astrobj::Standard;
+%ignore Gyoto::Astrobj::UniformSphere;
+%ignore Gyoto::Astrobj::ThinDisk;
+%include GyotoStandardAstrobj.h
+%include GyotoUniformSphere.h
+%include GyotoThinDisk.h
 
 %define _PAccessor2(member, setter)
   void setter(double *IN_ARRAY2, size_t DIM1, size_t DIM2) {
@@ -138,6 +177,9 @@ GyotoSmPtrClassGeneric(Metric)
 GyotoSmPtrClassGeneric(Spectrum)
 GyotoSmPtrClassGeneric(Spectrometer)
 
+GyotoSmPtrClassDerivedPtrHdr(Spectrometer, Complex, ComplexSpectrometer, GyotoComplexSpectrometer.h)
+GyotoSmPtrClassDerivedPtrHdr(Spectrometer, Uniform, UniformSpectrometer, GyotoUniformSpectrometer.h)
+
 %include "GyotoConfig.h"
 %include "GyotoDefs.h"
 %include "GyotoUtils.h"
diff --git a/python/gyoto_std.i b/python/gyoto_std.i
new file mode 100644
index 0000000..c7d1c73
--- /dev/null
+++ b/python/gyoto_std.i
@@ -0,0 +1,69 @@
+%module(docstring="The Gyoto standard plug-in") gyoto_std
+%import gyoto.i
+%{
+#include "GyotoWorldline.h"
+#include "GyotoPhoton.h"
+#include "GyotoUniformSphere.h"
+#include "GyotoPhoton.h"
+#include "GyotoScenery.h"
+#include "GyotoSpectrometer.h"
+#include "GyotoComplexSpectrometer.h"
+#include "GyotoValue.h"
+
+  // include Metric headers
+#include "GyotoKerrBL.h"
+#include "GyotoKerrKS.h"
+#include "GyotoMinkowski.h"
+// include Astrobj headers
+#include "GyotoComplexAstrobj.h"
+#include "GyotoStar.h"
+#include "GyotoStarTrace.h"
+#include "GyotoFixedStar.h"
+#include "GyotoTorus.h"
+#include "GyotoThinDisk.h"
+#include "GyotoPageThorneDisk.h"
+#include "GyotoThinDiskPL.h"
+#include "GyotoPolishDoughnut.h"
+#include "GyotoThinDiskIronLine.h"
+
+#include "GyotoPatternDisk.h"
+#include "GyotoPatternDiskBB.h"
+#include "GyotoDynamicalDisk.h"
+#include "GyotoDisk3D.h"
+#include "GyotoDynamicalDisk3D.h"
+#include "GyotoDirectionalDisk.h"
+
+// include Spectrum headers
+#include "GyotoPowerLawSpectrum.h"
+#include "GyotoBlackBodySpectrum.h"
+#include "GyotoThermalBremsstrahlungSpectrum.h"
+%}
+
+%array_class(double, array_double)
+%array_class(double, array_unsigned_long)
+
+%rename(ComplexAstrobjPtr) ComplexPtr;
+GyotoSmPtrClassDerivedPtrHdr(Astrobj, Complex, ComplexAstrobj, GyotoComplexAstrobj.h)
+GyotoSmPtrClassDerived(Astrobj, Star)
+GyotoSmPtrClassDerived(Astrobj, StarTrace)
+GyotoSmPtrClassDerived(Astrobj, FixedStar)
+GyotoSmPtrClassDerived(Astrobj, Torus)
+GyotoSmPtrClassDerived(Astrobj, PageThorneDisk)
+GyotoSmPtrClassDerived(Astrobj, ThinDiskPL)
+GyotoSmPtrClassDerived(Astrobj, PolishDoughnut)
+GyotoSmPtrClassDerived(Astrobj, ThinDiskIronLine)
+GyotoSmPtrClassDerived(Astrobj, PatternDisk)
+GyotoSmPtrClassDerived(Astrobj, PatternDiskBB)
+GyotoSmPtrClassDerived(Astrobj, DynamicalDisk)
+GyotoSmPtrClassDerived(Astrobj, Disk3D)
+GyotoSmPtrClassDerived(Astrobj, DynamicalDisk3D)
+GyotoSmPtrClassDerived(Astrobj, DirectionalDisk)
+
+GyotoSmPtrClassDerived(Metric, KerrBL)
+GyotoSmPtrClassDerived(Metric, KerrKS)
+GyotoSmPtrClassDerived(Metric, Minkowski)
+
+GyotoSmPtrClassDerivedHdr(Spectrum, PowerLaw, GyotoPowerLawSpectrum.h)
+GyotoSmPtrClassDerivedHdr(Spectrum, BlackBody, GyotoBlackBodySpectrum.h)
+GyotoSmPtrClassDerivedHdr(Spectrum, ThermalBremsstrahlung, GyotoThermalBremsstrahlungSpectrum.h)
+
diff --git a/python/setup_std.py.in b/python/setup_std.py.in
new file mode 100644
index 0000000..81ac8cc
--- /dev/null
+++ b/python/setup_std.py.in
@@ -0,0 +1,38 @@
+#!/usr/bin/env python
+
+# setup.py.in.distutils
+#
+# Copyright 2012, 2013 Brandon Invergo <brandon at invergo.net>
+# Copyright 2014 Thibaut Paumard
+#
+# Copying and distribution of this file, with or without modification,
+# are permitted in any medium without royalty provided the copyright
+# notice and this notice are preserved.  This file is offered as-is,
+# without any warranty.
+
+
+from distutils.core import setup, Extension
+import platform
+
+
+if platform.system() == 'Linux':
+    doc_dir = '@prefix@/share/doc/@PACKAGE_TARNAME@'
+else:
+    try:
+        from win32com.shell import shellcon, shell
+        homedir = shell.SHGetFolderPath(0, shellcon.CSIDL_APPDATA, 0, 0)
+        appdir = '@PACKAGE_TARNAME@'
+        doc_dir = os.path.join(homedir, appdir)
+    except:
+        pass
+
+gyoto_std_module = Extension('_gyoto_std',
+                         sources=['gyoto_std_wrap.cxx']
+                         )
+
+setup(name='@PACKAGE_NAME@'+'_std',
+      version='@PACKAGE_VERSION@',
+      author_email='@PACKAGE_BUGREPORT@',
+      py_modules=["gyoto_std"],
+      ext_modules=[gyoto_std_module]
+     )

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-astro/packages/gyoto.git



More information about the Debian-astro-commits mailing list