Bug #3295

Cannot access spatial model sky region attributes from Python

Added by Knödlseder Jürgen over 4 years ago. Updated over 4 years ago.

Status:ClosedStart date:08/02/2020
Priority:UrgentDue date:
Assigned To:Knödlseder Jürgen% Done:

100%

Category:-
Target version:1.7.1
Duration:

Description

Trying to access sky region attributes from within Python gives an error:

>>> import gammalib
>>> m=gammalib.GModelSky(gammalib.GModelSpatialPointSource(),gammalib.GModelSpectralPlaw())
>>> print(m.spatial().region())
<Swig Object of type 'GSkyRegionCircle *' at 0x1055168a0>
>>> print(m.spatial().region().centre())
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'SwigPyObject' object has no attribute 'centre'
while the following works
>>> r=gammalib.GSkyRegionCircle()
>>> print(r)
=== GSkyRegionCircle ===
 Right Ascension of centre .: 0 deg
 Declination of centre .....: 0 deg
 Radius ....................: 0 deg
>>> print(r.centre())
(RA,Dec)=(not initialised)

Note that I have seen the same problem for other classes.


Recurrence

No recurrence.

History

#1 Updated by Knödlseder Jürgen over 4 years ago

  • Status changed from New to Feedback
  • % Done changed from 0 to 90

Adding

%import(module="gammalib.sky") "GSkyRegionCircle.i";

in model.i fixed the issue. So it appears that all derived classes need to be added to a Python interface when doing automatic type casting across modules. Here is the list of what I have identified:
model.i:
%import(module="gammalib.sky") "GSkyRegionCircle.i";
%import(module="gammalib.sky") "GSkyRegionMap.i";

obs.i:
%import(module="gammalib.sky") "GModelSpatial.i";
%import(module="gammalib.sky") "GModelSpatialComposite.i";
%import(module="gammalib.sky") "GModelSpatialDiffuse.i";
%import(module="gammalib.sky") "GModelSpatialDiffuseConst.i";
%import(module="gammalib.sky") "GModelSpatialDiffuseCube.i";
%import(module="gammalib.sky") "GModelSpatialDiffuseMap.i";
%import(module="gammalib.sky") "GModelSpatialElliptical.i";
%import(module="gammalib.sky") "GModelSpatialEllipticalDisk.i";
%import(module="gammalib.sky") "GModelSpatialEllipticalGauss.i";
%import(module="gammalib.sky") "GModelSpatialPointSource.i";
%import(module="gammalib.sky") "GModelSpatialRadial.i";
%import(module="gammalib.sky") "GModelSpatialRadialDisk.i";
%import(module="gammalib.sky") "GModelSpatialRadialGauss.i";
%import(module="gammalib.sky") "GModelSpatialRadialRing.i";
%import(module="gammalib.sky") "GModelSpatialRadialShell.i";
%import(module="gammalib.sky") "GModelSpatialRadialProfile.i";
%import(module="gammalib.sky") "GModelSpatialRadialProfileDMBurkert.i";
%import(module="gammalib.sky") "GModelSpatialRadialProfileDMEinasto.i";
%import(module="gammalib.sky") "GModelSpatialRadialProfileDMZhao.i";
%import(module="gammalib.sky") "GModelSpatialRadialProfileGauss.i";

cta.i:
%import(module="gammalib.model") "GModelSpatial.i";
%import(module="gammalib.model") "GModelSpatialComposite.i";
%import(module="gammalib.model") "GModelSpatialDiffuse.i";
%import(module="gammalib.model") "GModelSpatialDiffuseConst.i";
%import(module="gammalib.model") "GModelSpatialDiffuseCube.i";
%import(module="gammalib.model") "GModelSpatialDiffuseMap.i";
%import(module="gammalib.model") "GModelSpatialElliptical.i";
%import(module="gammalib.model") "GModelSpatialEllipticalDisk.i";
%import(module="gammalib.model") "GModelSpatialEllipticalGauss.i";
%import(module="gammalib.model") "GModelSpatialPointSource.i";
%import(module="gammalib.model") "GModelSpatialRadial.i";
%import(module="gammalib.model") "GModelSpatialRadialDisk.i";
%import(module="gammalib.model") "GModelSpatialRadialGauss.i";
%import(module="gammalib.model") "GModelSpatialRadialRing.i";
%import(module="gammalib.model") "GModelSpatialRadialShell.i";
%import(module="gammalib.model") "GModelSpatialRadialProfile.i";
%import(module="gammalib.model") "GModelSpatialRadialProfileDMBurkert.i";
%import(module="gammalib.model") "GModelSpatialRadialProfileDMEinasto.i";
%import(module="gammalib.model") "GModelSpatialRadialProfileDMZhao.i";
%import(module="gammalib.model") "GModelSpatialRadialProfileGauss.i";
%import(module="gammalib.model") "GModelSpectral.i";
%import(module="gammalib.model") "GModelSpectralBrokenPlaw.i";
%import(module="gammalib.model") "GModelSpectralComposite.i";
%import(module="gammalib.model") "GModelSpectralConst.i";
%import(module="gammalib.model") "GModelSpectralExpInvPlaw.i";
%import(module="gammalib.model") "GModelSpectralExponential.i";
%import(module="gammalib.model") "GModelSpectralExpPlaw.i";
%import(module="gammalib.model") "GModelSpectralFunc.i";
%import(module="gammalib.model") "GModelSpectralGauss.i";
%import(module="gammalib.model") "GModelSpectralLogParabola.i";
%import(module="gammalib.model") "GModelSpectralMultiplicative.i";
%import(module="gammalib.model") "GModelSpectralNodes.i";
%import(module="gammalib.model") "GModelSpectralPlaw.i";
%import(module="gammalib.model") "GModelSpectralPlawEnergyFlux.i";
%import(module="gammalib.model") "GModelSpectralPlawPhotonFlux.i";
%import(module="gammalib.model") "GModelSpectralSmoothBrokenPlaw.i";
%import(module="gammalib.model") "GModelSpectralSuperExpPlaw.i";
%import(module="gammalib.model") "GModelSpectralTable.i";
%import(module="gammalib.model") "GModelTemporal.i";
%import(module="gammalib.model") "GModelTemporalConst.i";
%import(module="gammalib.model") "GModelTemporalLightCurve.i";
%import(module="gammalib.model") "GModelTemporalPhaseCurve.i";

Note that the corresponding header files needed to be included to enable the compilation of the Python wrapper.

#2 Updated by Knödlseder Jürgen over 4 years ago

  • Status changed from Feedback to Closed
  • % Done changed from 90 to 100

Also available in: Atom PDF