threeML / hawc_hal

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

Old maptrees unable to open #21

Closed cbrisboi closed 5 years ago

cbrisboi commented 5 years ago

Previously, we used integers, rather than strings to refer to the bins. They were labeled 'id' rather than 'name' as we have now. I can manually overcome this label switch, however due to the type difference, a fascinating error message occurs.

This was while running the example to extract an ROI 3 degrees around the crab, from the example in hal already (but for Mrk 421).

Traceback (most recent call last): File "make_crab_set.py", line 18, in <module> m.write("crab_maptree.hd5") File "/Users/chad/hawc/chad_hal/hawc_hal/maptree/map_tree.py", line 171, in write 'Bin name inconsistency: {} != {}'.format(bin_id, analysis_bin.name) AssertionError: Bin name inconsistency: 0 != 0

cbrisboi commented 5 years ago

Additionally, it may be a good idea for backward compatibility to add logic to account for older maps to avoid this kind of problem

Traceback (most recent call last):
  File "./fitModel.py", line 513, in <module>
    like = HAL("HAWC", map_tree, det_res, roi, options.pixelwidth)
  File "/Users/chad/hawc/chad_hal/hawc_hal/HAL.py", line 57, in __init__
    self._maptree = map_tree_factory(maptree, roi=roi)
  File "/Users/chad/hawc/chad_hal/hawc_hal/maptree/map_tree.py", line 22, in map_tree_factory
    return MapTree.from_root_file(map_tree_file, roi)
  File "/Users/chad/hawc/chad_hal/hawc_hal/maptree/map_tree.py", line 53, in from_root_file
    data_analysis_bins = from_root_file(map_tree_file, roi)
  File "/Users/chad/hawc/chad_hal/hawc_hal/maptree/from_root_file.py", line 70, in from_root_file
    data_bins_labels = list(root_numpy.tree2array(f.Get("BinInfo"), "id"))
cbrisboi commented 5 years ago

Here is the script used to reproduce the error I posted in the beginning. In this case, I used the map corresponding to the 2HWC catalog. As stated previously, it is the example script modified for the crab, rather than Mrk 421

from hawc_hal import HealpixConeROI

root_map_tree = "ADD A MAP HERE"

# Export only the ROI. This is a file only a few Mb in size                                                                                                                          
# that can be provided as dataset to journals, for example                                                                                                           
ra_crab, dec_crab = 83.63, 22.02
data_radius = 3.0
model_radius = 8.0

roi = HealpixConeROI(data_radius=data_radius,
                     model_radius=model_radius,
                     ra=ra_crab,
                     dec=dec_crab)

m = map_tree_factory(root_map_tree, roi)
m.write("crab_maptree.hd5")