Treat numbers in IRF table columns as `ndmin=1`
See original GitHub issueIt is currently impossible using astropy to read or write 1d arrays with a single entry. They will be written and read as single numbers instead of 1d arrays of length 1.
This means, that IRFs cannot be written with single bins in any of the dimensions, which is most important for the FOV offset angle for point-like IRFs.
Issue at astropy: https://github.com/astropy/astropy/issues/10765
Gammapy should treat single numbers in columns like THETA_LOW
, THETA_HI
as 1d arrays with a single entry, e.g. by calling
something like u.Quantity(table['THETA_LO'], ndmin=1)
.
CUrrently this fails due to len being called on a scalar:
In [5]: EffectiveAreaTable2D.read('./pyirf_eventdisplay.fits.gz', hdu='EFFECTIVE_AREA')
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-5-1f951cbdf154> in <module>
----> 1 EffectiveAreaTable2D.read('./pyirf_eventdisplay.fits.gz', hdu='EFFECTIVE_AREA')
~/.local/anaconda/envs/pyirf-dev/lib/python3.7/site-packages/gammapy/irf/effective_area.py in read(cls, filename, hdu)
413 """Read from file."""
414 with fits.open(make_path(filename), memmap=False) as hdulist:
--> 415 return cls.from_hdulist(hdulist, hdu=hdu)
416
417 def to_effective_area_table(self, offset, energy=None):
~/.local/anaconda/envs/pyirf-dev/lib/python3.7/site-packages/gammapy/irf/effective_area.py in from_hdulist(cls, hdulist, hdu)
407 def from_hdulist(cls, hdulist, hdu="EFFECTIVE AREA"):
408 """Create from `~astropy.io.fits.HDUList`."""
--> 409 return cls.from_table(Table.read(hdulist[hdu]))
410
411 @classmethod
~/.local/anaconda/envs/pyirf-dev/lib/python3.7/site-packages/gammapy/irf/effective_area.py in from_table(cls, table)
401 offset_hi=table["THETA_HI"].quantity[0],
402 data=table["EFFAREA"].quantity[0].transpose(),
--> 403 meta=table.meta,
404 )
405
~/.local/anaconda/envs/pyirf-dev/lib/python3.7/site-packages/gammapy/irf/effective_area.py in __init__(self, energy_lo, energy_hi, offset_lo, offset_hi, data, meta, interp_kwargs)
369 offset_axis = MapAxis.from_nodes(offset_lo, interp="lin", name="offset")
370 else:
--> 371 offset_edges = edges_from_lo_hi(offset_lo, offset_hi)
372 offset_axis = MapAxis.from_edges(offset_edges, interp="lin", name="offset")
373
~/.local/anaconda/envs/pyirf-dev/lib/python3.7/site-packages/gammapy/maps/utils.py in edges_from_lo_hi(edges_lo, edges_hi)
153 edges = edges_lo.copy()
154 try:
--> 155 edges = edges.insert(len(edges), edges_hi[-1])
156 except AttributeError:
157 edges = np.insert(edges, len(edges), edges_hi[-1])
~/.local/anaconda/envs/pyirf-dev/lib/python3.7/site-packages/astropy/units/quantity.py in __len__(self)
1064 if self.isscalar:
1065 raise TypeError("'{cls}' object with a scalar value has no "
-> 1066 "len()".format(cls=self.__class__.__name__))
1067 else:
1068 return len(self.value)
TypeError: 'Quantity' object with a scalar value has no len()
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (4 by maintainers)
Top Results From Across the Web
Tables of IRFs, dynamic-multiplier functions, and FEVDs - Stata
irf table makes a table of the values of the requested statistics at each time since impulse. Each column represents a combination of...
Read more >Populating Interaction Resource Data - Genesys Documentation
Genesys Info Mart creates a row in the IRF table whenever an existing interaction terminates while in a mediation resource, such as a...
Read more >Using structured references with Excel tables - Microsoft Support
Structured references make it easier to use formulas with Excel tables by ... That combination of table and column names is called a...
Read more >Show, hide, or edit a table title in Numbers on Mac
When you add a table, its title (Table 1, for example) is shown by default. You can edit the title or hide it....
Read more >Table setup - APA Style
Tables are visual displays composed of columns and rows in which numbers, text, or a combination of numbers and text are presented.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
ACtually the fix is about to be merged and should be released with astropy 4.0.2
@adonath since the fix is now published in astropy 4.0.2, I will close this as not a gammapy issue.
If you want to support older gammapy versions, you could implement something, but I wouldn’t.