dendrograms / astrodendro

Generate a dendrogram from a dataset
https://dendrograms.readthedocs.io/
Other
37 stars 36 forks source link

pp_catalog fails with ValueError related to astropy (5.3.1) units #191

Closed ajrigby closed 11 months ago

ajrigby commented 11 months ago

Just wanted to flag an issue I've encountered when trying to run a basic pp_catalog() on astropy 5.3.1. This must be an issue coming from the latest astropy release, because switching back to 5.2.2. solved the issue.

In [17]: d = Dendrogram.compute(dataG, min_value=6, min_delta=6, min_npix=10)

In [18]: cat = pp_catalog(d, metadata)
Computing catalog for 18517 structures
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Cell In[18], line 1
----> 1 cat = pp_catalog(d, metadata)

File ~/miniconda3/lib/python3.10/site-packages/astrodendro/analysis.py:758, in pp_catalog(structures, metadata, fields, verbose)
    756 with warnings.catch_warnings():
    757     warnings.simplefilter("once" if verbose else 'ignore', category=MissingMetadataWarning)
--> 758     return _make_catalog(structures, fields, metadata, PPStatistic, verbose)

File ~/miniconda3/lib/python3.10/site-packages/astrodendro/analysis.py:650, in _make_catalog(structures, fields, metadata, statistic, verbose)
    648 row = {}
    649 for lbl in fields:
--> 650     row[lbl] = getattr(stat, lbl)
    652 row = dict((lbl, getattr(stat, lbl))
    653            for lbl in fields)
    654 row.update(_idx=struct.idx)

File ~/miniconda3/lib/python3.10/site-packages/astrodendro/analysis.py:326, in SpatialBase.major_sigma(self)
    319 @property
    320 def major_sigma(self):
    321     """
    322     Major axis of the projection onto the position-position (PP) plane,
    323     computed from the intensity weighted second moment in direction of
    324     greatest elongation in the PP plane.
    325     """
--> 326     dx = self.spatial_scale or u.pixel
    327     a, b = self._sky_paxes()
    328     # We need to multiply the second moment by two to get the major axis
    329     # rather than the half-major axis.

File ~/miniconda3/lib/python3.10/site-packages/astropy/units/quantity.py:1334, in Quantity.__bool__(self)
   1330 def __bool__(self):
   1331     """This method raises ValueError, since truthiness of quantities is ambiguous,
   1332     especially for logarithmic units and temperatures. Use explicit comparisons.
   1333     """
-> 1334     raise ValueError(
   1335         f"{type(self).__name__} truthiness is ambiguous, especially for logarithmic units"
   1336         " and temperatures. Use explicit comparisons."
   1337     )

ValueError: Quantity truthiness is ambiguous, especially for logarithmic units and temperatures. Use explicit comparisons.
keflavich commented 11 months ago

this is likely a simple fix - something like self.spatial_scale if self.spatial_scale is not None else u.pixel. Want to try to implement that and make a PR?

ajrigby commented 11 months ago

That got it - thanks Adam. Pull request submitted.