fermiPy / fermipy

Fermi-LAT Python Analysis Framework
http://fermipy.readthedocs.org/
BSD 3-Clause "New" or "Revised" License
51 stars 53 forks source link

ModuleNotFoundError: No module named 'astropy.coordinates.angle_utilities' #558

Closed astroSyvertHE closed 4 months ago

astroSyvertHE commented 9 months ago

Hi, I installed fermipy with mamba. When running gta.setup() an error occurs: 2023-12-23 11:16:42 INFO GTBinnedAnalysis.run_gtapp(): Finished gtexpcube2. Execution time: 1.41 s WARNING: FITSFixedWarning: RADECSYS= 'FK5 ' the RADECSYS keyword is deprecated, use RADESYSa. [astropy.wcs.wcs] WARNING: FITSFixedWarning: 'datfix' made the change 'Set DATEREF to '2001-01-01T00:01:04.184' from MJDREF. Set MJD-OBS to 54769.000000 from DATE-OBS. Set MJD-END to 60278.000000 from DATE-END'. [astropy.wcs.wcs]

The error is:


KeyError Traceback (most recent call last) File ~/miniforge3/envs/fermipy/lib/python3.9/site-packages/fermipy/gtanalysis.py:5196, in GTBinnedAnalysis.setup(self, overwrite, **kwargs) 5195 try: -> 5196 self._bexp = Map.read(self.files['bexpmap'], hdu=hpxhduname) 5197 except KeyError:

File ~/miniforge3/envs/fermipy/lib/python3.9/site-packages/gammapy/maps/core.py:240, in Map.read(filename, hdu, hdu_bands, map_type, format, colname) 239 with fits.open(str(make_path(filename)), memmap=False) as hdulist: --> 240 return Map.from_hdulist( 241 hdulist, hdu, hdu_bands, map_type, format=format, colname=colname 242 )

File ~/miniforge3/envs/fermipy/lib/python3.9/site-packages/gammapy/maps/core.py:308, in Map.from_hdulist(hdulist, hdu, hdu_bands, map_type, format, colname) 307 if map_type == "auto": --> 308 map_type = Map._get_map_type(hdulist, hdu) 309 cls_out = Map._get_map_cls(map_type)

File ~/miniforge3/envs/fermipy/lib/python3.9/site-packages/gammapy/maps/core.py:339, in Map._get_map_type(hdu_list, hdu_name) 338 else: --> 339 header = hdu_list[hdu_name].header 341 if ("PIXTYPE" in header) and (header["PIXTYPE"] == "HEALPIX"):

File ~/miniforge3/envs/fermipy/lib/python3.9/site-packages/astropy/io/fits/hdu/hdulist.py:390, in HDUList.getitem(self, key) 388 try: 389 return self._try_while_unread_hdus( --> 390 super().getitem, self._positive_index_of(key) 391 ) 392 except IndexError as e: 393 # Raise a more helpful IndexError if the file was not fully read.

File ~/miniforge3/envs/fermipy/lib/python3.9/site-packages/astropy/io/fits/hdu/hdulist.py:857, in HDUList._positive_index_of(self, key) 844 """ 845 Same as index_of, but ensures always returning a positive index 846 or zero. (...) 855 inefficient. 856 """ --> 857 index = self.index_of(key) 859 if index >= 0:

File ~/miniforge3/envs/fermipy/lib/python3.9/site-packages/astropy/io/fits/hdu/hdulist.py:839, in HDUList.index_of(self, key) 838 if found is None: --> 839 raise KeyError(f"Extension {key!r} not found.") 840 else:

KeyError: "Extension 'HPXEXPOSURES' not found."

During handling of the above exception, another exception occurred:

ModuleNotFoundError Traceback (most recent call last) Cell In[8], line 1 ----> 1 gta.setup()

File ~/miniforge3/envs/fermipy/lib/python3.9/site-packages/fermipy/gtanalysis.py:1087, in GTAnalysis.setup(self, init_sources, overwrite, **kwargs) 1085 # Run setup for each component 1086 for i, c in enumerate(self.components): -> 1087 c.setup(overwrite=overwrite) 1089 # Create likelihood 1090 self._create_likelihood()

File ~/miniforge3/envs/fermipy/lib/python3.9/site-packages/fermipy/gtanalysis.py:5198, in GTBinnedAnalysis.setup(self, overwrite, **kwargs) 5196 self._bexp = Map.read(self.files['bexpmap'], hdu=hpxhduname) 5197 except KeyError: -> 5198 self._bexp = Map.read(self.files['bexpmap']) 5200 # Write ROI XML 5201 self.roi.write_xml(self.files['srcmdl'], self.config['model'])

File ~/miniforge3/envs/fermipy/lib/python3.9/site-packages/gammapy/maps/core.py:240, in Map.read(filename, hdu, hdu_bands, map_type, format, colname) 213 """Read a map from a FITS file. 214 215 Parameters (...) 237 Map object 238 """ 239 with fits.open(str(make_path(filename)), memmap=False) as hdulist: --> 240 return Map.from_hdulist( 241 hdulist, hdu, hdu_bands, map_type, format=format, colname=colname 242 )

File ~/miniforge3/envs/fermipy/lib/python3.9/site-packages/gammapy/maps/core.py:315, in Map.from_hdulist(hdulist, hdu, hdu_bands, map_type, format, colname) 311 return cls_out.from_hdulist( 312 hdulist, hdu=hdu, hdu_bands=hdu_bands, format=format, colname=colname 313 ) 314 else: --> 315 return cls_out.from_hdulist( 316 hdulist, hdu=hdu, hdu_bands=hdu_bands, format=format 317 )

File ~/miniforge3/envs/fermipy/lib/python3.9/site-packages/gammapy/maps/wcs/core.py:142, in WcsMap.from_hdulist(cls, hdu_list, hdu, hdu_bands, format) 138 hdu_bands = hdu_list[hdu_bands] 140 format = identify_wcs_format(hdu_bands) --> 142 wcs_map = cls.from_hdu(hdu, hdu_bands, format=format) 144 if wcs_map.unit.is_equivalent(""): 145 if format == "fgst-template":

File ~/miniforge3/envs/fermipy/lib/python3.9/site-packages/gammapy/maps/wcs/ndmap.py:88, in WcsNDMap.from_hdu(cls, hdu, hdu_bands, format) 70 @classmethod 71 def from_hdu(cls, hdu, hdu_bands=None, format=None): 72 """Make a WcsNDMap object from a FITS HDU. 73 74 Parameters (...) 86 Wcs map 87 """ ---> 88 geom = WcsGeom.from_header(hdu.header, hdu_bands, format=format) 89 shape = geom.axes.shape 90 shape_wcs = tuple([np.max(geom.npix[0]), np.max(geom.npix[1])])

File ~/miniforge3/envs/fermipy/lib/python3.9/site-packages/gammapy/maps/wcs/geom.py:485, in WcsGeom.from_header(cls, header, hdu_bands, format) 482 # TODO: see https://github.com/astropy/astropy/issues/9259 483 wcs._naxis = wcs._naxis[:2] --> 485 axes = MapAxes.from_table_hdu(hdu_bands, format=format) 486 shape = axes.shape 488 if hdu_bands is not None and "NPIX" in hdu_bands.columns.names:

File ~/miniforge3/envs/fermipy/lib/python3.9/site-packages/gammapy/maps/axes.py:1962, in MapAxes.from_table_hdu(cls, hdu, format) 1959 return cls([]) 1961 table = Table.read(hdu) -> 1962 return cls.from_table(table, format=format)

File ~/miniforge3/envs/fermipy/lib/python3.9/site-packages/gammapy/maps/axes.py:1980, in MapAxes.from_table(cls, table, format) 1964 @classmethod 1965 def from_table(cls, table, format="gadf"): 1966 """Create MapAxes from table 1967 1968 Parameters (...) 1978 Map axes object 1979 """ -> 1980 from gammapy.irf.io import IRF_DL3_AXES_SPECIFICATION 1982 axes = [] 1984 # Formats that support only one energy axis

File ~/miniforge3/envs/fermipy/lib/python3.9/site-packages/gammapy/irf/init.py:6 2 """ 3 Instrument response functions (IRFs). 4 """ 5 from gammapy.utils.registry import Registry ----> 6 from .background import Background2D, Background3D 7 from .core import FoVAlignment, IRFMap 8 from .edisp import EDispKernel, EDispKernelMap, EDispMap, EnergyDispersion2D

File ~/miniforge3/envs/fermipy/lib/python3.9/site-packages/gammapy/irf/background.py:10 8 from gammapy.maps import MapAxes, MapAxis 9 from gammapy.maps.axes import UNIT_STRING_FORMAT ---> 10 from .core import IRF 11 from .io import gadf_is_pointlike 13 all = ["Background3D", "Background2D"]

File ~/miniforge3/envs/fermipy/lib/python3.9/site-packages/gammapy/irf/core.py:17 12 from gammapy.utils.interpolation import ( 13 ScaledRegularGridInterpolator, 14 interpolation_scale, 15 ) 16 from gammapy.utils.scripts import make_path ---> 17 from .io import IRF_DL3_HDU_SPECIFICATION, IRF_MAP_HDU_SPECIFICATION, gadf_is_pointlike 19 log = logging.getLogger(name) 22 class FoVAlignment(str, Enum):

File ~/miniforge3/envs/fermipy/lib/python3.9/site-packages/gammapy/irf/io.py:4 2 import logging 3 from astropy.io import fits ----> 4 from gammapy.data.hdu_index_table import HDUIndexTable 5 from gammapy.utils.deprecation import deprecated 6 from gammapy.utils.fits import HDULocation

File ~/miniforge3/envs/fermipy/lib/python3.9/site-packages/gammapy/data/init.py:3 1 # Licensed under a 3-clause BSD style license - see LICENSE.rst 2 """Data and observation handling.""" ----> 3 from .data_store import DataStore 4 from .event_list import EventList 5 from .filters import ObservationFilter

File ~/miniforge3/envs/fermipy/lib/python3.9/site-packages/gammapy/data/data_store.py:15 13 from .hdu_index_table import HDUIndexTable 14 from .obs_table import ObservationTable, ObservationTableChecker ---> 15 from .observations import Observation, ObservationChecker, Observations 17 all = ["DataStore"] 19 ALL_IRFS = ["aeff", "edisp", "psf", "bkg", "rad_max"]

File ~/miniforge3/envs/fermipy/lib/python3.9/site-packages/gammapy/data/observations.py:22 20 from gammapy.utils.testing import Checker 21 from gammapy.utils.time import time_ref_to_dict, time_relative_to_ref ---> 22 from .event_list import EventList, EventListChecker 23 from .filters import ObservationFilter 24 from .gti import GTI

File ~/miniforge3/envs/fermipy/lib/python3.9/site-packages/gammapy/data/event_list.py:8 6 from astropy import units as u 7 from astropy.coordinates import AltAz, Angle, SkyCoord ----> 8 from astropy.coordinates.angle_utilities import angular_separation 9 from astropy.io import fits 10 from astropy.table import Table

ModuleNotFoundError: No module named 'astropy.coordinates.angle_utilities'

I noted that this module is in python2. I'm running the code in jupyterlab with python2, but with the command !which python the output is python3.9.

How can I solve that? Thank you very much for your help!

Best,

sofiav

NithyaSathyan commented 9 months ago

Hii.. I have installed fermipy using conda. When running the script for FERMI LAT analysis i get the error message as follows :

2023-12-27 18:16:09 INFO GTAnalysis.init():

fermipy version 1.2.0 ScienceTools version 2.2.0 2023-12-27 18:16:10 INFO GTAnalysis.setup(): Running setup. 2023-12-27 18:16:10 INFO GTBinnedAnalysis.setup(): Running setup for component 00 2023-12-27 18:16:10 INFO GTBinnedAnalysis._select_data(): Skipping data selection. 2023-12-27 18:16:10 INFO GTBinnedAnalysis._create_ltcube(): Skipping LT Cube. 2023-12-27 18:16:12 INFO GTBinnedAnalysis._create_expcube(): Skipping gtexpcube. WARNING: FITSFixedWarning: RADECSYS= 'FK5 ' the RADECSYS keyword is deprecated, use RADESYSa. [astropy.wcs.wcs] WARNING: FITSFixedWarning: 'datfix' made the change 'Set DATEREF to '2001-01-01T00:01:04.184' from MJDREF. Set MJD-OBS to 54682.655283 from DATE-OBS. Set MJD-END to 59852.000000 from DATE-END'. [astropy.wcs.wcs] Traceback (most recent call last): File "/home/dell/anaconda3/envs/fermipy/lib/python3.9/site-packages/fermipy/gtanalysis.py", line 5196, in setup self._bexp = Map.read(self.files['bexpmap'], hdu=hpxhduname) File "/home/dell/anaconda3/envs/fermipy/lib/python3.9/site-packages/gammapy/maps/core.py", line 240, in read return Map.from_hdulist( File "/home/dell/anaconda3/envs/fermipy/lib/python3.9/site-packages/gammapy/maps/core.py", line 308, in from_hdulist map_type = Map._get_map_type(hdulist, hdu) File "/home/dell/anaconda3/envs/fermipy/lib/python3.9/site-packages/gammapy/maps/core.py", line 339, in _get_map_type header = hdu_list[hdu_name].header File "/home/dell/anaconda3/envs/fermipy/lib/python3.9/site-packages/astropy/io/fits/hdu/hdulist.py", line 390, in getitem super().getitem, self._positive_index_of(key) File "/home/dell/anaconda3/envs/fermipy/lib/python3.9/site-packages/astropy/io/fits/hdu/hdulist.py", line 857, in _positive_index_of index = self.index_of(key) File "/home/dell/anaconda3/envs/fermipy/lib/python3.9/site-packages/astropy/io/fits/hdu/hdulist.py", line 839, in index_of raise KeyError(f"Extension {key!r} not found.") KeyError: "Extension 'HPXEXPOSURES' not found."

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/home/dell/data backup ubuntu dell mint/Documents/low_z_BLLACs/1ES0647+250/xx.py", line 3, in gta.setup() File "/home/dell/anaconda3/envs/fermipy/lib/python3.9/site-packages/fermipy/gtanalysis.py", line 1087, in setup c.setup(overwrite=overwrite) File "/home/dell/anaconda3/envs/fermipy/lib/python3.9/site-packages/fermipy/gtanalysis.py", line 5198, in setup self._bexp = Map.read(self.files['bexpmap']) File "/home/dell/anaconda3/envs/fermipy/lib/python3.9/site-packages/gammapy/maps/core.py", line 240, in read return Map.from_hdulist( File "/home/dell/anaconda3/envs/fermipy/lib/python3.9/site-packages/gammapy/maps/core.py", line 315, in from_hdulist return cls_out.from_hdulist( File "/home/dell/anaconda3/envs/fermipy/lib/python3.9/site-packages/gammapy/maps/wcs/core.py", line 142, in from_hdulist wcs_map = cls.from_hdu(hdu, hdu_bands, format=format) File "/home/dell/anaconda3/envs/fermipy/lib/python3.9/site-packages/gammapy/maps/wcs/ndmap.py", line 88, in from_hdu geom = WcsGeom.from_header(hdu.header, hdu_bands, format=format) File "/home/dell/anaconda3/envs/fermipy/lib/python3.9/site-packages/gammapy/maps/wcs/geom.py", line 485, in from_header axes = MapAxes.from_table_hdu(hdu_bands, format=format) File "/home/dell/anaconda3/envs/fermipy/lib/python3.9/site-packages/gammapy/maps/axes.py", line 1962, in from_table_hdu return cls.from_table(table, format=format) File "/home/dell/anaconda3/envs/fermipy/lib/python3.9/site-packages/gammapy/maps/axes.py", line 1980, in from_table from gammapy.irf.io import IRF_DL3_AXES_SPECIFICATION File "/home/dell/anaconda3/envs/fermipy/lib/python3.9/site-packages/gammapy/irf/init.py", line 6, in from .background import Background2D, Background3D File "/home/dell/anaconda3/envs/fermipy/lib/python3.9/site-packages/gammapy/irf/background.py", line 10, in from .core import IRF File "/home/dell/anaconda3/envs/fermipy/lib/python3.9/site-packages/gammapy/irf/core.py", line 17, in from .io import IRF_DL3_HDU_SPECIFICATION, IRF_MAP_HDU_SPECIFICATION, gadf_is_pointlike File "/home/dell/anaconda3/envs/fermipy/lib/python3.9/site-packages/gammapy/irf/io.py", line 4, in from gammapy.data.hdu_index_table import HDUIndexTable File "/home/dell/anaconda3/envs/fermipy/lib/python3.9/site-packages/gammapy/data/init.py", line 3, in from .data_store import DataStore File "/home/dell/anaconda3/envs/fermipy/lib/python3.9/site-packages/gammapy/data/data_store.py", line 15, in from .observations import Observation, ObservationChecker, Observations File "/home/dell/anaconda3/envs/fermipy/lib/python3.9/site-packages/gammapy/data/observations.py", line 22, in from .event_list import EventList, EventListChecker File "/home/dell/anaconda3/envs/fermipy/lib/python3.9/site-packages/gammapy/data/event_list.py", line 8, in from astropy.coordinates.angle_utilities import angular_separation ModuleNotFoundError: No module named 'astropy.coordinates.angle_utilities'

How to fix this error?

NithyaSathyan commented 9 months ago

Hii @astroSyvertHE Could you solve this issue related to ModuleNotFoundError: No module named 'astropy.coordinates.angle_utilities'

astroSyvertHE commented 9 months ago

Hi @NithyaSathyan, at the beginning I asked for help to fix this issue related with this module that is in the python2 version but not in the third version. I have not the answer, I'm just waiting us help me to fix it.

Thanks,

cheers

NithyaSathyan commented 9 months ago

But I was working with python 3.9 version and it worked perfectly fine. The problem arose when I had to reinstall fermipy recently.

On Tue, 2 Jan, 2024, 1:12 pm Sofia Ventura, @.***> wrote:

Hi @NithyaSathyan https://github.com/NithyaSathyan, at the beginning I asked for help to fix this issue related with this module that is in the python2 version but not in the third version. I have not the answer, I'm just waiting us help me to fix it.

Thanks,

cheers

— Reply to this email directly, view it on GitHub https://github.com/fermiPy/fermipy/issues/558#issuecomment-1873698576, or unsubscribe https://github.com/notifications/unsubscribe-auth/BE6FP4MN6OMABEOIOC33XT3YMO27RAVCNFSM6AAAAABBAW6OOOVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQNZTGY4TQNJXGY . You are receiving this because you were mentioned.Message ID: @.***>

clodoN1109 commented 8 months ago

Hi @NithyaSathyan. I ran into the same problem today, with exactly the same error log. Changing Astropy from version 6.0.0 to 5.3.3 resolved the issue for me. I'm still going to try with version 5.3.4, that is the last release on PyPi before 6.0.0.

NithyaSathyan commented 8 months ago

Thanks for the reply. I could fix the issue in the same manner.

On Sat, Jan 20, 2024 at 3:49 AM clodo @.***> wrote:

Hi @NithyaSathyan https://github.com/NithyaSathyan. I ran into the same problem today, with exactly the same error log. Changing Astropy from version 6.0.0 to 5.3.3 resolved the issue for me.

— Reply to this email directly, view it on GitHub https://github.com/fermiPy/fermipy/issues/558#issuecomment-1901204473, or unsubscribe https://github.com/notifications/unsubscribe-auth/BE6FP4LNJIQRRKPAGBIPRS3YPLWQVAVCNFSM6AAAAABBAW6OOOVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSMBRGIYDINBXGM . You are receiving this because you were mentioned.Message ID: @.***>

astroSyvertHE commented 7 months ago

Thanks! Now it's work!