Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Notebook update #46

Merged
merged 16 commits into from
May 27, 2024
Merged

Notebook update #46

merged 16 commits into from
May 27, 2024

Conversation

samanthalwong
Copy link
Collaborator

Implemented the corrected significance and alpha outputs from ExcessMapEstimator using correlate_off = False (see gammapy/gammapy#5245).

This will create artifacts in sky maps unless you are using the maps.py file in gammapy that is currently part of gammapy/gammapy#5270. The fix should be "officially" implemented in gammapy 1.3 (coming very soon).

Additionally, some bug & docs fixes to the notebook.

Copy link
Collaborator

@steob92 steob92 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added some comments. It's all minor stuff that I can do

type : "PL"
#array of [normalization, spectral index]
# Spectral fit parameters (initial guess) - for power law: array of [normalization, spectral index]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: Add units to normalization (I'll do this)

aeff_max_percent: 0.01
offset_max: 1.75
# Safe energy threshold (as a %) for effective area - ED doesn't use this, so it's set fairly small
aeff_max_percent: 0.1
#exclusion regions are lists of lists of [[SkyCoord, radius], [SkyCoord, radius], ...]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll add a comment to explicitly say degrees

gammapy_tools/analysis/rbm.py Outdated Show resolved Hide resolved
@steob92
Copy link
Collaborator

steob92 commented May 27, 2024

I'm getting an error when running the analysis notebook on this cell:

from gammapy.data import DataStore

my_data = DataStore.from_dir(config["io"]["out_dir"])
my_observations = my_data.get_observations()

for obs in my_observations:
    print(obs.obs_id)
    #obs.peek()
    obs.bkg.plot_at_energy([0.12 * u.TeV,0.5*u.TeV,4*u.TeV,6*u.TeV,10*u.TeV,30*u.TeV])
    # plt.show()
    break
---------------------------------------------------------------------------
UnitConversionError                       Traceback (most recent call last)
File ~/mambaforge/envs/gammapy-tools/lib/python3.11/site-packages/astropy/units/quantity.py:982, in Quantity.to_value(self, unit, equivalencies)
    981 try:
--> 982     scale = self.unit._to(unit)
    983 except Exception:
    984     # Short-cut failed; try default (maybe equivalencies help).

File ~/mambaforge/envs/gammapy-tools/lib/python3.11/site-packages/astropy/units/core.py:1159, in UnitBase._to(self, other)
   1157         return self_decomposed.scale / other_decomposed.scale
-> 1159 raise UnitConversionError(f"'{self!r}' is not a scaled version of '{other!r}'")

UnitConversionError: 'Unit("1 / (TeV s sr)")' is not a scaled version of 'Unit(dimensionless)'

During handling of the above exception, another exception occurred:

UnitConversionError                       Traceback (most recent call last)
File ~/mambaforge/envs/gammapy-tools/lib/python3.11/site-packages/astropy/units/quantity.py:1350, in Quantity.__float__(self)
   1349 try:
-> 1350     return float(self.to_value(dimensionless_unscaled))
   1351 except (UnitsError, TypeError):

File ~/mambaforge/envs/gammapy-tools/lib/python3.11/site-packages/astropy/units/quantity.py:985, in Quantity.to_value(self, unit, equivalencies)
    983 except Exception:
    984     # Short-cut failed; try default (maybe equivalencies help).
--> 985     value = self._to_value(unit, equivalencies)
    986 else:

File ~/mambaforge/envs/gammapy-tools/lib/python3.11/site-packages/astropy/units/quantity.py:891, in Quantity._to_value(self, unit, equivalencies)
    889 if not self.dtype.names or isinstance(self.unit, StructuredUnit):
    890     # Standard path, let unit to do work.
--> 891     return self.unit.to(
    892         unit, self.view(np.ndarray), equivalencies=equivalencies
    893     )
    895 else:
    896     # The .to() method of a simple unit cannot convert a structured
    897     # dtype, so we work around it, by recursing.
    898     # TODO: deprecate this?
    899     # Convert simple to Structured on initialization?

File ~/mambaforge/envs/gammapy-tools/lib/python3.11/site-packages/astropy/units/core.py:1195, in UnitBase.to(self, other, value, equivalencies)
   1194 else:
-> 1195     return self._get_converter(Unit(other), equivalencies)(value)

File ~/mambaforge/envs/gammapy-tools/lib/python3.11/site-packages/astropy/units/core.py:1124, in UnitBase._get_converter(self, other, equivalencies)
   1122                 return lambda v: b(converter(v))
-> 1124 raise exc

File ~/mambaforge/envs/gammapy-tools/lib/python3.11/site-packages/astropy/units/core.py:1107, in UnitBase._get_converter(self, other, equivalencies)
   1106 try:
-> 1107     return self._apply_equivalencies(
   1108         self, other, self._normalize_equivalencies(equivalencies)
   1109     )
   1110 except UnitsError as exc:
   1111     # Last hope: maybe other knows how to do it?
   1112     # We assume the equivalencies have the unit itself as first item.
   1113     # TODO: maybe better for other to have a `_back_converter` method?

File ~/mambaforge/envs/gammapy-tools/lib/python3.11/site-packages/astropy/units/core.py:1085, in UnitBase._apply_equivalencies(self, unit, other, equivalencies)
   1083 other_str = get_err_str(other)
-> 1085 raise UnitConversionError(f"{unit_str} and {other_str} are not convertible")

UnitConversionError: '1 / (TeV s sr)' and '' (dimensionless) are not convertible

During handling of the above exception, another exception occurred:

TypeError                                 Traceback (most recent call last)
Cell In[23], line 9
      7 print(obs.obs_id)
      8 #obs.peek()
----> 9 obs.bkg.plot_at_energy([0.12 * u.TeV,0.5*u.TeV,4*u.TeV,6*u.TeV,10*u.TeV,30*u.TeV])
     10 # plt.show()
     11 break

File ~/mambaforge/envs/gammapy-tools/lib/python3.11/site-packages/gammapy/irf/background.py:284, in Background2D.plot_at_energy(self, energy, add_cbar, ncols, figsize, **kwargs)
    268 """Plot the background rate in Field of view coordinates at a given energy.
    269 
    270 Parameters
   (...)
    281     Keyword arguments passed to `~matplotlib.pyplot.pcolormesh`.
    282 """
    283 bkg_3d = self.to_3d()
--> 284 bkg_3d.plot_at_energy(
    285     energy=energy, add_cbar=add_cbar, ncols=ncols, figsize=figsize, **kwargs
    286 )

File ~/mambaforge/envs/gammapy-tools/lib/python3.11/site-packages/gammapy/irf/background.py:211, in Background3D.plot_at_energy(self, energy, add_cbar, ncols, figsize, **kwargs)
    209 if add_cbar:
    210     label = f"Background [{bkg.unit.to_string(UNIT_STRING_FORMAT)}]"
--> 211     cbar = ax.figure.colorbar(caxes, ax=ax, label=label, fraction=cfraction)
    212     cbar.formatter.set_powerlimits((0, 0))
    214 row, col = np.unravel_index(i, shape=(rows, cols))

File ~/mambaforge/envs/gammapy-tools/lib/python3.11/site-packages/matplotlib/figure.py:1310, in FigureBase.colorbar(self, mappable, cax, ax, use_gridspec, **kwargs)
   1306     cax.grid(visible=False, which='both', axis='both')
   1308 NON_COLORBAR_KEYS = [  # remove kws that cannot be passed to Colorbar
   1309     'fraction', 'pad', 'shrink', 'aspect', 'anchor', 'panchor']
-> 1310 cb = cbar.Colorbar(cax, mappable, **{
   1311     k: v for k, v in kwargs.items() if k not in NON_COLORBAR_KEYS})
   1312 cax.figure.stale = True
   1313 return cb

File ~/mambaforge/envs/gammapy-tools/lib/python3.11/site-packages/matplotlib/colorbar.py:395, in Colorbar.__init__(self, ax, mappable, cmap, norm, alpha, values, boundaries, orientation, ticklocation, extend, spacing, ticks, format, drawedges, extendfrac, extendrect, label, location)
    392 self.ticklocation = ticklocation
    394 self.set_label(label)
--> 395 self._reset_locator_formatter_scale()
    397 if np.iterable(ticks):
    398     self._locator = ticker.FixedLocator(ticks, nbins=len(ticks))

File ~/mambaforge/envs/gammapy-tools/lib/python3.11/site-packages/matplotlib/colorbar.py:1159, in Colorbar._reset_locator_formatter_scale(self)
   1153 def _reset_locator_formatter_scale(self):
   1154     """
   1155     Reset the locator et al to defaults.  Any user-hardcoded changes
   1156     need to be re-entered if this gets called (either at init, or when
   1157     the mappable normal gets changed: Colorbar.update_normal)
   1158     """
-> 1159     self._process_values()
   1160     self._locator = None
   1161     self._minorlocator = None

File ~/mambaforge/envs/gammapy-tools/lib/python3.11/site-packages/matplotlib/colorbar.py:1093, in Colorbar._process_values(self)
   1091     self.norm.vmin = 0
   1092     self.norm.vmax = 1
-> 1093 self.norm.vmin, self.norm.vmax = mtransforms.nonsingular(
   1094     self.norm.vmin, self.norm.vmax, expander=0.1)
   1095 if (not isinstance(self.norm, colors.BoundaryNorm) and
   1096         (self.boundaries is None)):
   1097     b = self.norm.inverse(b)

File ~/mambaforge/envs/gammapy-tools/lib/python3.11/site-packages/matplotlib/transforms.py:2855, in nonsingular(vmin, vmax, expander, tiny, increasing)
   2851     swapped = True
   2853 # Expand vmin, vmax to float: if they were integer types, they can wrap
   2854 # around in abs (abs(np.int8(-128)) == -128) and vmax - vmin can overflow.
-> 2855 vmin, vmax = map(float, [vmin, vmax])
   2857 maxabsvalue = max(abs(vmin), abs(vmax))
   2858 if maxabsvalue < (1e6 / tiny) * np.finfo(float).tiny:

File ~/mambaforge/envs/gammapy-tools/lib/python3.11/site-packages/astropy/units/quantity.py:1352, in Quantity.__float__(self)
   1350     return float(self.to_value(dimensionless_unscaled))
   1351 except (UnitsError, TypeError):
-> 1352     raise TypeError(
   1353         "only dimensionless scalar quantities can be "
   1354         "converted to Python scalars"
   1355     )

TypeError: only dimensionless scalar quantities can be converted to Python scalars

Error in callback <function _draw_all_if_interactive at 0x779398066d40> (for post_execute), with arguments args (),kwargs {}:

---------------------------------------------------------------------------
UnitConversionError                       Traceback (most recent call last)
File ~/mambaforge/envs/gammapy-tools/lib/python3.11/site-packages/astropy/units/quantity.py:982, in Quantity.to_value(self, unit, equivalencies)
    981 try:
--> 982     scale = self.unit._to(unit)
    983 except Exception:
    984     # Short-cut failed; try default (maybe equivalencies help).

File ~/mambaforge/envs/gammapy-tools/lib/python3.11/site-packages/astropy/units/core.py:1159, in UnitBase._to(self, other)
   1157         return self_decomposed.scale / other_decomposed.scale
-> 1159 raise UnitConversionError(f"'{self!r}' is not a scaled version of '{other!r}'")

UnitConversionError: 'Unit("1 / (TeV s sr)")' is not a scaled version of 'Unit(dimensionless)'

During handling of the above exception, another exception occurred:

UnitConversionError                       Traceback (most recent call last)
File ~/mambaforge/envs/gammapy-tools/lib/python3.11/site-packages/astropy/units/quantity.py:1350, in Quantity.__float__(self)
   1349 try:
-> 1350     return float(self.to_value(dimensionless_unscaled))
   1351 except (UnitsError, TypeError):

File ~/mambaforge/envs/gammapy-tools/lib/python3.11/site-packages/astropy/units/quantity.py:985, in Quantity.to_value(self, unit, equivalencies)
    983 except Exception:
    984     # Short-cut failed; try default (maybe equivalencies help).
--> 985     value = self._to_value(unit, equivalencies)
    986 else:

File ~/mambaforge/envs/gammapy-tools/lib/python3.11/site-packages/astropy/units/quantity.py:891, in Quantity._to_value(self, unit, equivalencies)
    889 if not self.dtype.names or isinstance(self.unit, StructuredUnit):
    890     # Standard path, let unit to do work.
--> 891     return self.unit.to(
    892         unit, self.view(np.ndarray), equivalencies=equivalencies
    893     )
    895 else:
    896     # The .to() method of a simple unit cannot convert a structured
    897     # dtype, so we work around it, by recursing.
    898     # TODO: deprecate this?
    899     # Convert simple to Structured on initialization?

File ~/mambaforge/envs/gammapy-tools/lib/python3.11/site-packages/astropy/units/core.py:1195, in UnitBase.to(self, other, value, equivalencies)
   1194 else:
-> 1195     return self._get_converter(Unit(other), equivalencies)(value)

File ~/mambaforge/envs/gammapy-tools/lib/python3.11/site-packages/astropy/units/core.py:1124, in UnitBase._get_converter(self, other, equivalencies)
   1122                 return lambda v: b(converter(v))
-> 1124 raise exc

File ~/mambaforge/envs/gammapy-tools/lib/python3.11/site-packages/astropy/units/core.py:1107, in UnitBase._get_converter(self, other, equivalencies)
   1106 try:
-> 1107     return self._apply_equivalencies(
   1108         self, other, self._normalize_equivalencies(equivalencies)
   1109     )
   1110 except UnitsError as exc:
   1111     # Last hope: maybe other knows how to do it?
   1112     # We assume the equivalencies have the unit itself as first item.
   1113     # TODO: maybe better for other to have a `_back_converter` method?

File ~/mambaforge/envs/gammapy-tools/lib/python3.11/site-packages/astropy/units/core.py:1085, in UnitBase._apply_equivalencies(self, unit, other, equivalencies)
   1083 other_str = get_err_str(other)
-> 1085 raise UnitConversionError(f"{unit_str} and {other_str} are not convertible")

UnitConversionError: '1 / (TeV s sr)' and '' (dimensionless) are not convertible

During handling of the above exception, another exception occurred:

TypeError                                 Traceback (most recent call last)
File ~/mambaforge/envs/gammapy-tools/lib/python3.11/site-packages/matplotlib/pyplot.py:197, in _draw_all_if_interactive()
    195 def _draw_all_if_interactive() -> None:
    196     if matplotlib.is_interactive():
--> 197         draw_all()

File ~/mambaforge/envs/gammapy-tools/lib/python3.11/site-packages/matplotlib/_pylab_helpers.py:132, in Gcf.draw_all(cls, force)
    130 for manager in cls.get_all_fig_managers():
    131     if force or manager.canvas.figure.stale:
--> 132         manager.canvas.draw_idle()

File ~/mambaforge/envs/gammapy-tools/lib/python3.11/site-packages/matplotlib/backend_bases.py:1893, in FigureCanvasBase.draw_idle(self, *args, **kwargs)
   1891 if not self._is_idle_drawing:
   1892     with self._idle_draw_cntx():
-> 1893         self.draw(*args, **kwargs)

File ~/mambaforge/envs/gammapy-tools/lib/python3.11/site-packages/matplotlib/backends/backend_agg.py:388, in FigureCanvasAgg.draw(self)
    385 # Acquire a lock on the shared font cache.
    386 with (self.toolbar._wait_cursor_for_draw_cm() if self.toolbar
    387       else nullcontext()):
--> 388     self.figure.draw(self.renderer)
    389     # A GUI class may be need to update a window using this draw, so
    390     # don't forget to call the superclass.
    391     super().draw()

File ~/mambaforge/envs/gammapy-tools/lib/python3.11/site-packages/matplotlib/artist.py:95, in _finalize_rasterization.<locals>.draw_wrapper(artist, renderer, *args, **kwargs)
     93 @wraps(draw)
     94 def draw_wrapper(artist, renderer, *args, **kwargs):
---> 95     result = draw(artist, renderer, *args, **kwargs)
     96     if renderer._rasterizing:
     97         renderer.stop_rasterizing()

File ~/mambaforge/envs/gammapy-tools/lib/python3.11/site-packages/matplotlib/artist.py:72, in allow_rasterization.<locals>.draw_wrapper(artist, renderer)
     69     if artist.get_agg_filter() is not None:
     70         renderer.start_filter()
---> 72     return draw(artist, renderer)
     73 finally:
     74     if artist.get_agg_filter() is not None:

File ~/mambaforge/envs/gammapy-tools/lib/python3.11/site-packages/matplotlib/figure.py:3154, in Figure.draw(self, renderer)
   3151         # ValueError can occur when resizing a window.
   3153 self.patch.draw(renderer)
-> 3154 mimage._draw_list_compositing_images(
   3155     renderer, self, artists, self.suppressComposite)
   3157 for sfig in self.subfigs:
   3158     sfig.draw(renderer)

File ~/mambaforge/envs/gammapy-tools/lib/python3.11/site-packages/matplotlib/image.py:132, in _draw_list_compositing_images(renderer, parent, artists, suppress_composite)
    130 if not_composite or not has_images:
    131     for a in artists:
--> 132         a.draw(renderer)
    133 else:
    134     # Composite any adjacent images together
    135     image_group = []

File ~/mambaforge/envs/gammapy-tools/lib/python3.11/site-packages/matplotlib/artist.py:72, in allow_rasterization.<locals>.draw_wrapper(artist, renderer)
     69     if artist.get_agg_filter() is not None:
     70         renderer.start_filter()
---> 72     return draw(artist, renderer)
     73 finally:
     74     if artist.get_agg_filter() is not None:

File ~/mambaforge/envs/gammapy-tools/lib/python3.11/site-packages/matplotlib/axes/_base.py:3070, in _AxesBase.draw(self, renderer)
   3067 if artists_rasterized:
   3068     _draw_rasterized(self.figure, artists_rasterized, renderer)
-> 3070 mimage._draw_list_compositing_images(
   3071     renderer, self, artists, self.figure.suppressComposite)
   3073 renderer.close_group('axes')
   3074 self.stale = False

File ~/mambaforge/envs/gammapy-tools/lib/python3.11/site-packages/matplotlib/image.py:132, in _draw_list_compositing_images(renderer, parent, artists, suppress_composite)
    130 if not_composite or not has_images:
    131     for a in artists:
--> 132         a.draw(renderer)
    133 else:
    134     # Composite any adjacent images together
    135     image_group = []

File ~/mambaforge/envs/gammapy-tools/lib/python3.11/site-packages/matplotlib/artist.py:72, in allow_rasterization.<locals>.draw_wrapper(artist, renderer)
     69     if artist.get_agg_filter() is not None:
     70         renderer.start_filter()
---> 72     return draw(artist, renderer)
     73 finally:
     74     if artist.get_agg_filter() is not None:

File ~/mambaforge/envs/gammapy-tools/lib/python3.11/site-packages/matplotlib/collections.py:2197, in QuadMesh.draw(self, renderer)
   2194     ys = self.convert_yunits(offsets[:, 1])
   2195     offsets = np.column_stack([xs, ys])
-> 2197 self.update_scalarmappable()
   2199 if not transform.is_affine:
   2200     coordinates = self._coordinates.reshape((-1, 2))

File ~/mambaforge/envs/gammapy-tools/lib/python3.11/site-packages/matplotlib/collections.py:920, in Collection.update_scalarmappable(self)
    918         # pcolormesh, scatter, maybe others flatten their _A
    919         self._alpha = self._alpha.reshape(self._A.shape)
--> 920     self._mapped_colors = self.to_rgba(self._A, self._alpha)
    922 if self._face_is_mapped:
    923     self._facecolors = self._mapped_colors

File ~/mambaforge/envs/gammapy-tools/lib/python3.11/site-packages/matplotlib/cm.py:513, in ScalarMappable.to_rgba(self, x, alpha, bytes, norm)
    511 x = ma.asarray(x)
    512 if norm:
--> 513     x = self.norm(x)
    514 rgba = self.cmap(x, alpha=alpha, bytes=bytes)
    515 return rgba

File ~/mambaforge/envs/gammapy-tools/lib/python3.11/site-packages/matplotlib/colors.py:1357, in Normalize.__call__(self, value, clip)
   1355     self.autoscale_None(result)
   1356 # Convert at least to float, without losing precision.
-> 1357 (vmin,), _ = self.process_value(self.vmin)
   1358 (vmax,), _ = self.process_value(self.vmax)
   1359 if vmin == vmax:

File ~/mambaforge/envs/gammapy-tools/lib/python3.11/site-packages/matplotlib/colors.py:1318, in Normalize.process_value(value)
   1316 if is_scalar:
   1317     value = [value]
-> 1318 dtype = np.min_scalar_type(value)
   1319 if np.issubdtype(dtype, np.integer) or dtype.type is np.bool_:
   1320     # bool_/int8/int16 -> float32; int32/int64 -> float64
   1321     dtype = np.promote_types(dtype, np.float32)

File ~/mambaforge/envs/gammapy-tools/lib/python3.11/site-packages/astropy/units/quantity.py:1352, in Quantity.__float__(self)
   1350     return float(self.to_value(dimensionless_unscaled))
   1351 except (UnitsError, TypeError):
-> 1352     raise TypeError(
   1353         "only dimensionless scalar quantities can be "
   1354         "converted to Python scalars"
   1355     )

TypeError: only dimensionless scalar quantities can be converted to Python scalars

---------------------------------------------------------------------------
UnitConversionError                       Traceback (most recent call last)
File ~/mambaforge/envs/gammapy-tools/lib/python3.11/site-packages/astropy/units/quantity.py:982, in Quantity.to_value(self, unit, equivalencies)
    981 try:
--> 982     scale = self.unit._to(unit)
    983 except Exception:
    984     # Short-cut failed; try default (maybe equivalencies help).

File ~/mambaforge/envs/gammapy-tools/lib/python3.11/site-packages/astropy/units/core.py:1159, in UnitBase._to(self, other)
   1157         return self_decomposed.scale / other_decomposed.scale
-> 1159 raise UnitConversionError(f"'{self!r}' is not a scaled version of '{other!r}'")

UnitConversionError: 'Unit("1 / (TeV s sr)")' is not a scaled version of 'Unit(dimensionless)'

During handling of the above exception, another exception occurred:

UnitConversionError                       Traceback (most recent call last)
File ~/mambaforge/envs/gammapy-tools/lib/python3.11/site-packages/astropy/units/quantity.py:1350, in Quantity.__float__(self)
   1349 try:
-> 1350     return float(self.to_value(dimensionless_unscaled))
   1351 except (UnitsError, TypeError):

File ~/mambaforge/envs/gammapy-tools/lib/python3.11/site-packages/astropy/units/quantity.py:985, in Quantity.to_value(self, unit, equivalencies)
    983 except Exception:
    984     # Short-cut failed; try default (maybe equivalencies help).
--> 985     value = self._to_value(unit, equivalencies)
    986 else:

File ~/mambaforge/envs/gammapy-tools/lib/python3.11/site-packages/astropy/units/quantity.py:891, in Quantity._to_value(self, unit, equivalencies)
    889 if not self.dtype.names or isinstance(self.unit, StructuredUnit):
    890     # Standard path, let unit to do work.
--> 891     return self.unit.to(
    892         unit, self.view(np.ndarray), equivalencies=equivalencies
    893     )
    895 else:
    896     # The .to() method of a simple unit cannot convert a structured
    897     # dtype, so we work around it, by recursing.
    898     # TODO: deprecate this?
    899     # Convert simple to Structured on initialization?

File ~/mambaforge/envs/gammapy-tools/lib/python3.11/site-packages/astropy/units/core.py:1195, in UnitBase.to(self, other, value, equivalencies)
   1194 else:
-> 1195     return self._get_converter(Unit(other), equivalencies)(value)

File ~/mambaforge/envs/gammapy-tools/lib/python3.11/site-packages/astropy/units/core.py:1124, in UnitBase._get_converter(self, other, equivalencies)
   1122                 return lambda v: b(converter(v))
-> 1124 raise exc

File ~/mambaforge/envs/gammapy-tools/lib/python3.11/site-packages/astropy/units/core.py:1107, in UnitBase._get_converter(self, other, equivalencies)
   1106 try:
-> 1107     return self._apply_equivalencies(
   1108         self, other, self._normalize_equivalencies(equivalencies)
   1109     )
   1110 except UnitsError as exc:
   1111     # Last hope: maybe other knows how to do it?
   1112     # We assume the equivalencies have the unit itself as first item.
   1113     # TODO: maybe better for other to have a `_back_converter` method?

File ~/mambaforge/envs/gammapy-tools/lib/python3.11/site-packages/astropy/units/core.py:1085, in UnitBase._apply_equivalencies(self, unit, other, equivalencies)
   1083 other_str = get_err_str(other)
-> 1085 raise UnitConversionError(f"{unit_str} and {other_str} are not convertible")

UnitConversionError: '1 / (TeV s sr)' and '' (dimensionless) are not convertible

During handling of the above exception, another exception occurred:

TypeError                                 Traceback (most recent call last)
File ~/mambaforge/envs/gammapy-tools/lib/python3.11/site-packages/IPython/core/formatters.py:340, in BaseFormatter.__call__(self, obj)
    338     pass
    339 else:
--> 340     return printer(obj)
    341 # Finally look for special method names
    342 method = get_real_method(obj, self.print_method)

File ~/mambaforge/envs/gammapy-tools/lib/python3.11/site-packages/IPython/core/pylabtools.py:152, in print_figure(fig, fmt, bbox_inches, base64, **kwargs)
    149     from matplotlib.backend_bases import FigureCanvasBase
    150     FigureCanvasBase(fig)
--> 152 fig.canvas.print_figure(bytes_io, **kw)
    153 data = bytes_io.getvalue()
    154 if fmt == 'svg':

File ~/mambaforge/envs/gammapy-tools/lib/python3.11/site-packages/matplotlib/backend_bases.py:2164, in FigureCanvasBase.print_figure(self, filename, dpi, facecolor, edgecolor, orientation, format, bbox_inches, pad_inches, bbox_extra_artists, backend, **kwargs)
   2161     # we do this instead of `self.figure.draw_without_rendering`
   2162     # so that we can inject the orientation
   2163     with getattr(renderer, "_draw_disabled", nullcontext)():
-> 2164         self.figure.draw(renderer)
   2165 if bbox_inches:
   2166     if bbox_inches == "tight":

File ~/mambaforge/envs/gammapy-tools/lib/python3.11/site-packages/matplotlib/artist.py:95, in _finalize_rasterization.<locals>.draw_wrapper(artist, renderer, *args, **kwargs)
     93 @wraps(draw)
     94 def draw_wrapper(artist, renderer, *args, **kwargs):
---> 95     result = draw(artist, renderer, *args, **kwargs)
     96     if renderer._rasterizing:
     97         renderer.stop_rasterizing()

File ~/mambaforge/envs/gammapy-tools/lib/python3.11/site-packages/matplotlib/artist.py:72, in allow_rasterization.<locals>.draw_wrapper(artist, renderer)
     69     if artist.get_agg_filter() is not None:
     70         renderer.start_filter()
---> 72     return draw(artist, renderer)
     73 finally:
     74     if artist.get_agg_filter() is not None:

File ~/mambaforge/envs/gammapy-tools/lib/python3.11/site-packages/matplotlib/figure.py:3154, in Figure.draw(self, renderer)
   3151         # ValueError can occur when resizing a window.
   3153 self.patch.draw(renderer)
-> 3154 mimage._draw_list_compositing_images(
   3155     renderer, self, artists, self.suppressComposite)
   3157 for sfig in self.subfigs:
   3158     sfig.draw(renderer)

File ~/mambaforge/envs/gammapy-tools/lib/python3.11/site-packages/matplotlib/image.py:132, in _draw_list_compositing_images(renderer, parent, artists, suppress_composite)
    130 if not_composite or not has_images:
    131     for a in artists:
--> 132         a.draw(renderer)
    133 else:
    134     # Composite any adjacent images together
    135     image_group = []

File ~/mambaforge/envs/gammapy-tools/lib/python3.11/site-packages/matplotlib/artist.py:72, in allow_rasterization.<locals>.draw_wrapper(artist, renderer)
     69     if artist.get_agg_filter() is not None:
     70         renderer.start_filter()
---> 72     return draw(artist, renderer)
     73 finally:
     74     if artist.get_agg_filter() is not None:

File ~/mambaforge/envs/gammapy-tools/lib/python3.11/site-packages/matplotlib/axes/_base.py:3070, in _AxesBase.draw(self, renderer)
   3067 if artists_rasterized:
   3068     _draw_rasterized(self.figure, artists_rasterized, renderer)
-> 3070 mimage._draw_list_compositing_images(
   3071     renderer, self, artists, self.figure.suppressComposite)
   3073 renderer.close_group('axes')
   3074 self.stale = False

File ~/mambaforge/envs/gammapy-tools/lib/python3.11/site-packages/matplotlib/image.py:132, in _draw_list_compositing_images(renderer, parent, artists, suppress_composite)
    130 if not_composite or not has_images:
    131     for a in artists:
--> 132         a.draw(renderer)
    133 else:
    134     # Composite any adjacent images together
    135     image_group = []

File ~/mambaforge/envs/gammapy-tools/lib/python3.11/site-packages/matplotlib/artist.py:72, in allow_rasterization.<locals>.draw_wrapper(artist, renderer)
     69     if artist.get_agg_filter() is not None:
     70         renderer.start_filter()
---> 72     return draw(artist, renderer)
     73 finally:
     74     if artist.get_agg_filter() is not None:

File ~/mambaforge/envs/gammapy-tools/lib/python3.11/site-packages/matplotlib/collections.py:2197, in QuadMesh.draw(self, renderer)
   2194     ys = self.convert_yunits(offsets[:, 1])
   2195     offsets = np.column_stack([xs, ys])
-> 2197 self.update_scalarmappable()
   2199 if not transform.is_affine:
   2200     coordinates = self._coordinates.reshape((-1, 2))

File ~/mambaforge/envs/gammapy-tools/lib/python3.11/site-packages/matplotlib/collections.py:920, in Collection.update_scalarmappable(self)
    918         # pcolormesh, scatter, maybe others flatten their _A
    919         self._alpha = self._alpha.reshape(self._A.shape)
--> 920     self._mapped_colors = self.to_rgba(self._A, self._alpha)
    922 if self._face_is_mapped:
    923     self._facecolors = self._mapped_colors

File ~/mambaforge/envs/gammapy-tools/lib/python3.11/site-packages/matplotlib/cm.py:513, in ScalarMappable.to_rgba(self, x, alpha, bytes, norm)
    511 x = ma.asarray(x)
    512 if norm:
--> 513     x = self.norm(x)
    514 rgba = self.cmap(x, alpha=alpha, bytes=bytes)
    515 return rgba

File ~/mambaforge/envs/gammapy-tools/lib/python3.11/site-packages/matplotlib/colors.py:1357, in Normalize.__call__(self, value, clip)
   1355     self.autoscale_None(result)
   1356 # Convert at least to float, without losing precision.
-> 1357 (vmin,), _ = self.process_value(self.vmin)
   1358 (vmax,), _ = self.process_value(self.vmax)
   1359 if vmin == vmax:

File ~/mambaforge/envs/gammapy-tools/lib/python3.11/site-packages/matplotlib/colors.py:1318, in Normalize.process_value(value)
   1316 if is_scalar:
   1317     value = [value]
-> 1318 dtype = np.min_scalar_type(value)
   1319 if np.issubdtype(dtype, np.integer) or dtype.type is np.bool_:
   1320     # bool_/int8/int16 -> float32; int32/int64 -> float64
   1321     dtype = np.promote_types(dtype, np.float32)

File ~/mambaforge/envs/gammapy-tools/lib/python3.11/site-packages/astropy/units/quantity.py:1352, in Quantity.__float__(self)
   1350     return float(self.to_value(dimensionless_unscaled))
   1351 except (UnitsError, TypeError):
-> 1352     raise TypeError(
   1353         "only dimensionless scalar quantities can be "
   1354         "converted to Python scalars"
   1355     )

TypeError: only dimensionless scalar quantities can be converted to Python scalars

<Figure size 1200x600 with 7 Axes>

@steob92 steob92 changed the base branch from main to 1.1_rc May 27, 2024 16:08
@steob92 steob92 merged commit 17e8f26 into 1.1_rc May 27, 2024
@matthew-w-lundy matthew-w-lundy deleted the notebook-update branch November 1, 2024 17:35
@matthew-w-lundy matthew-w-lundy restored the notebook-update branch November 1, 2024 17:35
@matthew-w-lundy matthew-w-lundy deleted the notebook-update branch November 1, 2024 17:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants