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

Numpy no longer includes warnings module as attribute as of numpy v1.24.3 #89

Merged
merged 10 commits into from
Jun 7, 2023
77 changes: 43 additions & 34 deletions hawc_hal/healpix_handling/gnomonic_projection.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import numpy as np
import warnings

from healpy import projaxes as PA
import matplotlib.pyplot as plt


def get_gnomonic_projection(figure, hpx_map, **kwargs):
Expand All @@ -16,23 +16,23 @@ def get_gnomonic_projection(figure, hpx_map, **kwargs):
:return: the array containing the projection.
"""

defaults = {'coord': 'C',
'rot': None,
'format': '%g',
'flip': 'astro',
'xsize': 200,
'ysize': None,
'reso': 1.5,
'nest': False,
'min': None,
'max': None,
'cmap': None,
'norm': None}
defaults = {
"coord": "C",
"rot": None,
"format": "%g",
"flip": "astro",
"xsize": 200,
"ysize": None,
"reso": 1.5,
"nest": False,
"min": None,
"max": None,
"cmap": None,
"norm": None,
}

for key, default_value in list(defaults.items()):

if key not in kwargs:

kwargs[key] = default_value

## Colas, 2018-07-11: The following fails for really tall figures,
Expand All @@ -47,26 +47,35 @@ def get_gnomonic_projection(figure, hpx_map, **kwargs):
# extent[3] - margins[3] - margins[1])
extent = (0.05, 0.05, 0.9, 0.9)

ax = PA.HpxGnomonicAxes(figure, extent,
coord=kwargs['coord'],
rot=kwargs['rot'],
format=kwargs['format'],
flipconv=kwargs['flip'])
ax = PA.HpxGnomonicAxes(
figure,
extent,
coord=kwargs["coord"],
rot=kwargs["rot"],
format=kwargs["format"],
flipconv=kwargs["flip"],
)

# Suppress warnings about nans
with np.warnings.catch_warnings():

np.warnings.filterwarnings('ignore')
# ! numpy does not contain the warnings module as of v1.24.3
# TODO: remove this when numpy is updated
# with np.warnings.catch_warnings():
#
# np.warnings.filterwarnings('ignore')

img = ax.projmap(hpx_map,
nest=kwargs['nest'],
coord=kwargs['coord'],
vmin=kwargs['min'],
vmax=kwargs['max'],
xsize=kwargs['xsize'],
ysize=kwargs['ysize'],
reso=kwargs['reso'],
cmap=kwargs['cmap'],
norm=kwargs['norm'])
with warnings.catch_warnings():
warnings.filterwarnings("ignore")
img = ax.projmap(
hpx_map,
nest=kwargs["nest"],
coord=kwargs["coord"],
vmin=kwargs["min"],
vmax=kwargs["max"],
xsize=kwargs["xsize"],
ysize=kwargs["ysize"],
reso=kwargs["reso"],
cmap=kwargs["cmap"],
norm=kwargs["norm"],
)

return img