fermi-lat / Fermitools-conda

Conda recipe files for the Fermi Sciencetools software analysis package: Fermitools
https://fermi.gsfc.nasa.gov/ssc/data/analysis/
BSD 3-Clause "New" or "Revised" License
34 stars 17 forks source link

python core dump when doing import from UnbinnedAnalysis or BinnedAnalysys #103

Closed landriu closed 2 years ago

landriu commented 3 years ago

Hi all,

after having installed fermi-2.0.8, and working in python environment I met the following error :

[landriu@sappcfermi] ~ > python Python 3.7.9 | packaged by conda-forge | (default, Dec 9 2020, 21:08:20) [GCC 9.3.0] on linux Type "help", "copyright", "credits" or "license" for more information. Using startup saving python history in ~/.pyhistory

import astropy.coordinates as coords from UnbinnedAnalysis import * terminate called after throwing an instance of 'tip::TipException' what(): Cannot read keyword "TFORM" in extension "CIF" in file "/dsm/manip/glast/anaconda3/envs/fermi-2.0.8/share/fermitools/data/caldb/data/glast/lat/caldb.indx" (CFITSIO ERROR Aborted (core dumped)

[landriu@sappcfermi] ~ >

This occurs also when typing : from BinnedAnalysis import *

Cheers,

David Landriu

donhorner commented 3 years ago

I tried on several mac and linux installations of 2.0.8 but can't reproduce this error. The imports always work fine.

I wonder if something got corrupted in your install. Can you check if caldb.indx is a valid FITS file? Maybe run fverify on it or open it with fv?

landriu commented 3 years ago

Hello Don,

I have done fverify on caldb.indx and no error has been found with fverify :

[landriu@sappcfermi] ~ > fverify /dsm/manip/glast/anaconda3/envs/fermi-2.0.8/share/fermitools/data/caldb/data/glast/lat/caldb.indx

                  FVERIFY V4.18 (CFITSIO V3.440)
                  ------------------------------

HEASARC conventions are being checked.

File: /dsm/manip/glast/anaconda3/envs/fermi-2.0.8/share/fermitools/data/caldb/data/glast/lat/caldb.indx

2 Header-Data Units in this file.

=================== HDU 1: Primary Array ===================

7 header keywords

Null data array; NAXIS = 0

=================== HDU 2: BINARY Table ====================

72 header keywords

CIF (18 columns x 3268 rows)

Col# Name (Units) Format 1 TELESCOP 10A 2 INSTRUME 10A 3 DETNAM 20A 4 FILTER 10A 5 CAL_DEV 20A 6 CAL_DIR 70A 7 CAL_FILE 40A 8 CAL_CLAS 3A 9 CAL_DTYP 4A 10 CAL_CNAM 20A 11 CAL_CBD 630A70 12 CAL_XNO I 13 CAL_VSD 10A 14 CAL_VST 8A 15 REF_TIME D 16 CAL_QUAL I 17 CAL_DATE 10A 18 CAL_DESC 70A

++++++++++++++++++++++ Error Summary ++++++++++++++++++++++

HDU# Name (version) Type Warnings Errors 1 Primary Array 0 0 2 CIF Binary Table 0 0

Verification found 0 warning(s) and 0 error(s).

[landriu@sappcfermi] ~ >

jasercion commented 3 years ago

Hi @landriu, does the error provide a CFITSIO error code or any other traceback information? My quick read is that there is either an issue with the caldb index file itself or there's a cfitsio library problem. Are you able to perform any other fits file manipulations with just the Fermitools executables outside of the python interface? Also, can you directly perform any sort of binned or unbinned analysis calling CALDB as the irf selection using gtlike directly?

landriu commented 3 years ago

Hi Joe,

I could launch gtirfs, gtsrcmap and gtexpmap commands  without error message : 

[landriu@sappcfermi] ~/dev/TestFtoolsForFermi2.0.8 > gtirfs P7CLEAN_V6 ( = P7CLEAN_V6::BACK + P7CLEAN_V6::FRONT ) P7CLEAN_V6::BACK P7CLEAN_V6::FRONT P7REP_CLEAN_V10 ( = P7REP_CLEAN_V10::BACK + P7REP_CLEAN_V10::FRONT ) P7REP_CLEAN_V10::BACK P7REP_CLEAN_V10::FRONT .../... P8R3_ULTRACLEAN_V3::PSF0 P8R3_ULTRACLEAN_V3::PSF1 P8R3_ULTRACLEAN_V3::PSF2 P8R3_ULTRACLEAN_V3::PSF3

[landriu@sappcfermi] ~/dev/TestFtoolsForFermi2.0.8 >

..

[landriu@sappcfermi] ~/dev/TestFtoolsForFermi2.0.8 > which gtsrcmaps /dsm/manip/glast/anaconda3/envs/fermi-2.0.8/bin/fermitools/gtsrcmaps .. [landriu@sappcfermi] ~/dev/TestFtoolsForFermi2.0.8 > gtsrcmaps scfile=/dsm/saplxglast/glast/data/Flight2/june09/ft2_oneDay_new.fits expcube=/dsm/fermi/fermifast/glast/runs/tH/input/ltCube_100.fits cmap=/dsm/fermi/fermifast/glast/runs/tH/like/Rois/srcMap_1_E1.fits srcmdl=srcModel_1_E1.xml-initial bexpmap=/dsm/fermi/fermifast/glast/runs/tH/like/Rois/binned_exposure_E1.fits outfile=srcMap_1_E2.fits irfs=P7SOURCE_V6 ptsrc=no chatter=4 This is gtsrcmaps version HEAD ResponseFunctions::load: IRF used: P7SOURCE_V6 event_types: 0 1 Creating source named eg_v02 Creating source named gal_v02 Creating source named SunIC_v2 Creating source named EXTIC443 appending map for EXTIC443 appending map for SunIC_v2 appending map for eg_v02 appending map for gal_v02

.../... [landriu@sappcfermi] ~/dev/TestFtoolsForFermi2.0.8 > which gtexpmap /dsm/manip/glast/anaconda3/envs/fermi-2.0.8/bin/fermitools/gtexpmap .. [landriu@sappcfermi] ~/dev/TestFtoolsForFermi2.0.8 > gtexpmap evfile=/dsm/fermi/fermifast/glast/runs/tH/like/Rois/MergedEVENTS_1_E2.fits scfile=/dsm/fermi/fermifast/glast/runs/tH/input/ft2_july09_pass8.fits expcube=/dsm/fermi/fermifast/glast/runs/tH/input/ltCube_100.fits outfile=expMap_1_E2.fits irfs="CALDB" srcrad=30.3857 nlong=122 nlat=122 nenergies=11 The exposure maps generated by this tool are meant to be used for unbinned likelihood analysis only. Do not use them for binned analyses. Computing the ExposureMap using /dsm/fermi/fermifast/glast/runs/tH/input/ltCube_100.fits .....................!

** I could call also gtlike : unbinned analysis with CALDB as irf selection :

landriu@sappcfermi] ~/dev/TestFtoolsForFermi2.0.8 > which gtlike /dsm/manip/glast/anaconda3/envs/fermi-2.0.8/bin/fermitools/gtlike .. [landriu@sappcfermi] ~/dev/TestFtoolsForFermi2.0.8 > gtlike Statistic to use (BINNED|UNBINNED) [UNBINNED] Spacecraft file[/dsm/fermi/fermifast/glast/runs/tH/input/ft2_july09_pass8.fits] Event file[/dsm/fermi/fermifast/glast/runs/tH/like/Rois/MergedEVENTS_1_E2.fits] Unbinned exposure map[/dsm/fermi/fermifast/glast/runs/tH/like/Rois/expMap_1_E2.fits] Exposure hypercube file[none] Source model file[/dsm/fermi/fermifast/glast/runs/tH-20210126192336/like/Rois/srcModel_1.xml-Mixed] Response functions to use[CALDB] Optimizer (DRMNFB|NEWMINUIT|MINUIT|DRMNGB|LBFGS) [MINUIT]


1 SET PRINT .000



2 SET NOWARN


PARAMETER DEFINITIONS: NO. NAME VALUE STEP SIZE LIMITS 1 'Prefactor ' 8.7358 1.0000 .10000E-04 .10000E+06 2 'Index ' 1.9381 1.0000 .0000 5.0000
3 'norm ' 2.4452 1.0000 .0000 .10000E+06 4 'alpha ' 1.2889 1.0000 .0000 5.0000
5 'beta ' 4.3228 1.0000 -10.000 10.000
6 'Integral ' 7.6207 1.0000 .0000 100.00
7 'Index ' -2.0829 1.0000 -5.0000 .0000
8 'Normalizat' 1.3500 1.0000 .0000 100.00
9 'Value ' .98720 1.0000 .0000 10.000


3 SET ERR .5000



4 SET GRAD 1.000



5 MINIMIZE 1700. 2.000


MIGRAD MINIMIZATION HAS CONVERGED.

MIGRAD WILL VERIFY CONVERGENCE AND ERROR MATRIX.

MIGRAD MINIMIZATION HAS CONVERGED.

MIGRAD WILL VERIFY CONVERGENCE AND ERROR MATRIX. MIGRAD TERMINATED WITHOUT CONVERGENCE.

FCN= 5065.647 FROM MIGRAD STATUS=FAILED 310 CALLS 311 TOTAL EDM= .22E-02 STRATEGY= 1 ERR MATRIX NOT POS-DEF

EXT PARAMETER APPROXIMATE STEP FIRST
NO. NAME VALUE ERROR SIZE DERIVATIVE 1 Prefactor 2.5682 1.7238 .91955E-05 -2.0169
2 Index 3.5167 .38314 .45534E-03 -.80596E-01 3 norm 5.0524 4.1694 .41360E-03 .13754E-01 4 alpha .31021 .96911 .89313E-02 .26668E-02 5 beta .44181 5.1902 .17699E-01 -.22082E-04 6 Integral 20.702 62.540 .75534E-01 -.57285E-01 7 Index -1.2909 3.9208 .59061E-02 .15149
8 Normalizat 1.2947 .26800 .10603E-03 -.20849
9 Value .85100 .99915E-01 .17154E-03 -.11421
ERR DEF= .500
START SIMPLEX MINIMIZATION. CONVERGENCE WHEN EDM .LT. .20E+01 SIMPLEX MINIMIZATION HAS CONVERGED.

FCN= 5065.647 FROM SIMPLEX STATUS=UNCHANGED 32 CALLS 343 TOTAL EDM= .14E+01 STRATEGY= 1 ERR MATRIX NOT POS-DEF

EXT PARAMETER APPROXIMATE STEP FIRST
NO. NAME VALUE ERROR SIZE DERIVATIVE 1 Prefactor 2.5682 1.7238 .54425E-03 -2.0169
2 Index 3.5167 .38314 .26841E-01 -.80596E-01 3 norm 5.0524 4.1694 .11424E-02 .13754E-01 4 alpha .31021 .96911 .20863 .26668E-02 5 beta .44181 5.1902 .16863 -.22082E-04 6 Integral 20.702 62.540 .35425 -.57285E-01 7 Index -1.2909 3.9208 .37950 .15149
8 Normalizat 1.2947 .26800 .45946E-02 -.20849
9 Value .85100 .99915E-01 .57293E-02 -.11421
ERR DEF= .500

MIGRAD MINIMIZATION HAS CONVERGED.

MIGRAD WILL VERIFY CONVERGENCE AND ERROR MATRIX.

FCN= 5065.646 FROM MIGRAD STATUS=CONVERGED 89 CALLS 432 TOTAL EDM= .33E-04 STRATEGY= 1 ERR MATRIX NOT POS-DEF

EXT PARAMETER APPROXIMATE STEP FIRST
NO. NAME VALUE ERROR SIZE DERIVATIVE 1 Prefactor 2.5499 1.7370 .18391E-05 2.0944
2 Index 3.5217 .38836 .91067E-04 .15186E-01 3 norm 5.0829 2.9082 .12038E-04 -.17493
4 alpha .30277 .76795 .35725E-03 -.72892E-03 5 beta .44204 5.2969 .70797E-03 .35707E-02 6 Integral 19.350 61.383 .72021E-01 .77589E-03 7 Index -1.3341 4.0031 .11812E-01 -.30473E-02 8 Normalizat 1.2921 .27497 .21205E-04 .37398E-01 9 Value .85175 .10123 .34307E-04 .28084E-01 ERR DEF= .500
Final values: Prefactor = 2.54994 Index = 3.52175 norm = 5.08295 alpha = 0.302771 beta = 0.44204 Integral = 19.3497 Index = -1.33406 Normalizat = 1.29215 Value = 0.851751


6 HESSE


FCN= 5065.646 FROM HESSE STATUS=OK 73 CALLS 505 TOTAL EDM= .28E-03 STRATEGY= 1 ERROR MATRIX ACCURATE

EXT PARAMETER INTERNAL INTERNAL
NO. NAME VALUE ERROR STEP SIZE VALUE
1 Prefactor 2.5499 4.0852 .37210E-06 -1.5607
2 Index 3.5217 .89468 .18213E-04 .42103
3 norm 5.0829 21.584 .24076E-05 -1.5565
4 alpha .30277 2.6348 .71450E-04 -1.0735
5 beta .44204 13.092 .14159E-03 .44218E-01 6 Integral 19.350 57.908 .13731E-02 -.65986
7 Index -1.3341 1.4736 .47249E-03 .48519
8 Normalizat 1.2921 .28884 .42411E-05 -1.3430
9 Value .85175 .11200 .68615E-05 -.97848
ERR DEF= .500
Minuit fit quality: 3 estimated distance: 0.000280862 Minuit parameter uncertainties: 1 4.08523 2 0.919358 3 20.9499 4 8.28026 5 39.0639 6 50.9248 7 1.61279 8 0.288871 9 0.112025 Computing TS values for each source (7 total) .......!

Photon fluxes are computed for the energy range 100 to 300 MeV

EXTIC443: Prefactor: 2.54994 +/- 4.08523 Index: 3.52175 +/- 0.919358 Scale: 783.211 Npred: 41.008 Flux: 2.13387e-06 +/- 6.09134e-07 photons/cm^2/s

LAT0004: norm: 5.08295 +/- 20.9499 alpha: 0.302771 +/- 8.28026 beta: 0.44204 +/- 39.0639 Eb: 0.549281 Npred: 38.1539 ROI distance: 3.7254 TS value: 34.5373 Flux: 1.32922e-06 +/- 4.34657e-07 photons/cm^2/s

LAT0005: Integral: 19.3497 +/- 50.9248 Index: -1.33406 +/- 1.61279 LowerLimit: 100 UpperLimit: 200000 Npred: 16.3111 ROI distance: 7.01219 TS value: 11.5304 Flux: 6.45343e-07 +/- 3.55671e-07 photons/cm^2/s

PSRJ0534+2200: Prefactor: 5.26674 Index: -2.41162 Scale: 282.493 Npred: 55.1313 Flux: 2.40552e-06 photons/cm^2/s

SunIC_v2: Value: 1 Npred: 3.18734 Flux: 3.23534e-06 photons/cm^2/s

eg_v02: Normalization: 1.29215 +/- 0.288871 Npred: 151.692 Flux: 0.000199271 +/- 4.45487e-05 photons/cm^2/s

gal_v02: Value: 0.851751 +/- 0.112025 Npred: 273.865 Flux: 0.000273764 +/- 3.60064e-05 photons/cm^2/s

WARNING: Fit may be bad in range [182.986, 193.318] (MeV) WARNING: Fit may be bad in range [215.767, 227.951] (MeV)

Total number of observed counts: 580 Total number of model events: 579.348

-log(Likelihood): 5065.646396

Elapsed CPU time: 19.46

[landriu@sappcfermi] ~/dev/TestFtoolsForFermi2.0.8 >

Cheers,

David Landriu

landriu commented 3 years ago

I should add that when writing first : "from UnbinnedAnalysis import " or "from BinnedAnalysis import " no core dump appears, and it is possible to define then : "import astropy.coordinates as coords".

[landriu@sappcfermi] ~ > python Python 3.7.9 | packaged by conda-forge | (default, Dec 9 2020, 21:08:20) [GCC 9.3.0] on linux Type "help", "copyright", "credits" or "license" for more information. Using startup saving python history in ~/.pyhistory

from BinnedAnalysis import * import astropy.coordinates as coords

The core dump occurs when calling astropy first .

jasercion commented 3 years ago

I'm almost certain that what is happening here is that there is a collision between libraries that are installed both by Fermitools and Astropy, likely cfitsio or a related lib, and that Fermitools is panicking when it attempts to identify and use on import the library imported by Astropy. I'll keep poking at this to see if I can come up with a good solution to this, but for now unless it affects your analysis in a negative way I'd suggest continuing to enforce the initial import of the Fermitools modules before Astropy.

jasercion commented 3 years ago

I'll also add this + your workaround to our known issues page.

jasercion commented 2 years ago

As of the 2.2.0 release this issue is resolved. Closing.