[Debian-astro-commits] [gyoto] 161/221: Fix Screen::Bucket::Bucket to work with pixel-type Coord2dSets; more Python examples

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 f104a3bf96f73c4ee1fb8fa15f24a931b0962b67
Author: Thibaut Paumard <paumard at users.sourceforge.net>
Date:   Fri Dec 19 13:18:19 2014 +0100

    Fix Screen::Bucket::Bucket to work with pixel-type Coord2dSets; more Python examples
---
 lib/Screen.C      |  2 +-
 python/example.py | 88 +++++++++++++++++++++++++++++++++++++++++++++++++++++--
 python/gyoto.i    | 11 ++++---
 3 files changed, 94 insertions(+), 7 deletions(-)

diff --git a/lib/Screen.C b/lib/Screen.C
index 5096ed4..3ecc470 100644
--- a/lib/Screen.C
+++ b/lib/Screen.C
@@ -1423,7 +1423,7 @@ double Screen::RepeatAngle::angle() const {return val_;}
 Screen::Bucket::Bucket (Coord1dSet &alp, Coord1dSet &del)
   : Coord2dSet(alp.kind), alpha_(alp), delta_(del)
 {
-  if (alp.kind != angle || alp.kind != angle)
+  if (alp.kind != del.kind)
     throwError("both specifiers must be of same kind");
   if (alp.size() != del.size())
     throwError("alpha and delta should be of same size"); 
diff --git a/python/example.py b/python/example.py
index 94e1ef5..b6a055b 100644
--- a/python/example.py
+++ b/python/example.py
@@ -1,3 +1,5 @@
+#/bin/env python
+# -*- coding: utf-8 -*-
 import numpy
 import matplotlib as ml
 import matplotlib.pyplot as plt
@@ -73,7 +75,7 @@ aop.MinDistance(distance)
 
 ii=gyoto.Range(1, res, 1)
 jj=gyoto.Range(1, res, 1)
-grid=gyoto.Grid(ii, jj)
+grid=gyoto.Grid(ii, jj, "\rj = ")
 
 sc.rayTrace(grid, aop)
 
@@ -93,7 +95,7 @@ spectrum=numpy.zeros((ns, res, res), dtype=float)
 
 ii=gyoto.Range(1, res, 1)
 jj=gyoto.Range(1, res, 1)
-grid=gyoto.Grid(ii, jj)
+grid=gyoto.Grid(ii, jj, "\rj = ")
 
 aop=gyoto.Properties()
 aop.Spectrum(spectrum)
@@ -103,3 +105,85 @@ sc.rayTrace(grid, aop)
 
 plt.imshow(spectrum[1,:,:])
 plt.show()
+
+# Another Scenery, with impact coords, created from within Python
+
+met=gyoto.Metric("KerrBL")
+met.mass(4e6, "sunmass")
+ao=gyoto.Astrobj("PageThorneDisk")
+ao.metric(met)
+ao.opticallyThin(False)
+ao.rMax(100)
+screen=gyoto.Screen()
+screen.distance(8, "kpc")
+screen.time(8, "kpc")
+screen.resolution(64)
+screen.inclination(numpy.pi/4)
+screen.PALN(numpy.pi)
+screen.time(8, "kpc")
+screen.fieldOfView(100, "µas")
+sc=gyoto.Scenery()
+sc.metric(met)
+sc.astrobj(ao)
+sc.screen(screen)
+sc.delta(1, "kpc")
+sc.adaptive(True)
+sc.nThreads(8)
+
+res=sc.screen().resolution()
+
+ii=gyoto.Range(1, res, 1)
+jj=gyoto.Range(1, res, 1)
+grid=gyoto.Grid(ii, jj, "\rj = ")
+
+ipct=numpy.zeros((res, res, 16), dtype=float)
+
+aop=gyoto.Properties()
+aop.ImpactCoords(ipct)
+aop.offset=res*res
+
+sc.rayTrace(grid, aop)
+
+plt.imshow(ipct[:,:,0], interpolation="nearest", vmin=-100, vmax=0)
+plt.show()
+
+# Trace one line of the above using alpha and delta
+
+N=10
+
+buf=numpy.linspace(screen.fieldOfView()*-0.5, screen.fieldOfView()*0.5, N)
+a=gyoto.Angles(buf)
+d=gyoto.RepeatAngle(screen.fieldOfView()*-0.5, N)
+bucket=gyoto.Bucket(a, d)
+
+ipct=numpy.zeros((N, 1, 16), dtype=float)
+
+aop=gyoto.Properties()
+aop.ImpactCoords(ipct)
+aop.offset=N
+
+sc.rayTrace(bucket, aop)
+plt.plot(buf, ipct[:,0,0])
+plt.show()
+
+# Trace the diagonal of the above using i and j. The Range and Indices
+# definitions below are equivalent.  Range is more efficient for a
+# range, Indices can hold arbitrary indices.
+
+ind=numpy.arange(1, res+1, dtype=numpy.uintp) # on 64bit arch...
+
+ii=gyoto.Indices(ind)
+jj=gyoto.Range(1, res, 1)
+bucket=gyoto.Bucket(ii, jj)
+
+ipct=numpy.zeros((res, 1, 16), dtype=float)
+
+aop=gyoto.Properties()
+aop.ImpactCoords(ipct)
+aop.offset=res
+
+sc.rayTrace(bucket, aop)
+
+t=numpy.clip(ipct[:,0,0], a_min=-200, a_max=0)
+plt.plot(t)
+plt.show()
diff --git a/python/gyoto.i b/python/gyoto.i
index ab5b987..6999d4c 100644
--- a/python/gyoto.i
+++ b/python/gyoto.i
@@ -71,7 +71,10 @@ using namespace Gyoto;
 %template(vector_unsigned_long) std::vector<unsigned long>;
 %include "carrays.i"
 %array_class(double, array_double)
+%array_class(double, array_unsigned_long)
 %include "numpy.i"
+%numpy_typemaps(size_t, NPY_ULONG , size_t)
+%numpy_typemaps(double, NPY_DOUBLE, size_t)
 
 %init {
   Gyoto::Register::init();
@@ -106,12 +109,12 @@ GyotoSmPtrClassGeneric(Astrobj)
 
 
 %define _PAccessor2(member, setter)
-  void setter(double *IN_ARRAY2, int DIM1, int DIM2) {
+  void setter(double *IN_ARRAY2, size_t DIM1, size_t DIM2) {
     $self->member = IN_ARRAY2;
   }
 %enddef
 %define _PAccessor3(member, setter)
-void setter(double *IN_ARRAY3, int DIM1, int DIM2, int DIM3) {
+void setter(double *IN_ARRAY3, size_t DIM1, size_t DIM2, size_t DIM3) {
     $self->member = IN_ARRAY3;
   }
 %enddef
@@ -238,7 +241,7 @@ protected:
   size_t const sz_;
   size_t i_;
 public:
-  Indices (unsigned long * IN_ARRAY1, unsigned long DIM1);
+  Indices (size_t *IN_ARRAY1, size_t DIM1);
   void begin();
   bool valid();
   size_t size();
@@ -252,7 +255,7 @@ protected:
   size_t const sz_;
   size_t i_;
 public:
-  Angles (double const*const buf, size_t sz);
+  Angles (double * IN_ARRAY1, size_t DIM1);
   void begin();
   bool valid();
   size_t size();

-- 
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