threeML / hawc_hal

HAWC Accelerated Likelihood - python-only framework for HAWC data analysis
BSD 3-Clause "New" or "Revised" License
11 stars 21 forks source link

Writing model/residual map when using HealpixMapROI #55

Closed hayalaso closed 3 years ago

hayalaso commented 3 years ago

I'm trying to save the residual and model maps of my analysis. I wasn't able due to the following error

tables.exceptions.HDF5ExtError: HDF5 error back trace

  File "H5A.c", line 259, in H5Acreate2
    unable to create attribute
  File "H5Aint.c", line 280, in H5A_create
    unable to create attribute in object header
  File "H5Oattribute.c", line 347, in H5O_attr_create
    unable to create new attribute in header
  File "H5Omessage.c", line 224, in H5O_msg_append_real
    unable to create new message
  File "H5Omessage.c", line 1945, in H5O_msg_alloc
    unable to allocate space for message
  File "H5Oalloc.c", line 1142, in H5O_alloc
    object header message is too large

End of HDF5 error back trace

Can't set attribute 'metadata' in node:
 /ROI (Group) ''.

It looks like the header of the ROI object is too large.

I did a quick test, using HealpixConeROI, and my program was able to run fine.

I printed the information of the ROI. When using the Healpix Map one:

{'roifile': '../../FitsFiles/data_roi_aquila.fits', 'model_radius_deg': 19.0, 'ra': 267.63, 'roimap': array([0., 0., 0., ..., 0., 0., 0.]), 'threshold': 0.5, 'dec': -3.72, 'ROI type': 'HealpixMapROI'}

and when using Healpix Cone:

{'model_radius_deg': 19.0, 'dec': -3.72, 'ra': 267.63, 'ROI type': 'HealpixConeROI', 'data_radius_deg': 10.0}

It looks like the header is trying to save the roimap, which might cause the problem?

henrikef commented 3 years ago

Yes, I see how that might be a problem.

I have two ideas how this could be done instead:

  1. Only write the roifile property, not the roimap one, and make sure that HAL reads the actual ROI map from the ROI file when e.g. a model map hd5 file with a map ROI is read in. Probably less work but dangerous because a. The roifile is not always guaranteed to still exist (e.g. if a file is copied to a different file system) b. It's currently not mandated that the roifile exists at all, users are free to use a healpix map in memory when setting up the ROI.
  2. Write the ROI map into the hd5 file itself, not in the header (and make sure that it is being read in correctly as well).

Thoughts?

hayalaso commented 3 years ago

I was actually starting to look into something like point 2, to save the ROI map in the hd5 file.

hayalaso commented 3 years ago

I see from here, that the dictionary with the ROI information is created. Is the roimap necessary to be here for other functions? Otherwise, I was thinking of adding a try/exception in the class method from_dict of HealpixMapROI when trying to read a hdf5 file.

hayalaso commented 3 years ago

Fixed by #56