Skip to content

Commit

Permalink
Changed np.NaN -> np.nan for numpy 2.0 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
jameswilburlewis committed Sep 10, 2024
1 parent 3f707d8 commit 787c01c
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions pytplot/AncillaryPlots/spec_slicer.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def update(t, name):
data_at_slice = tplot_utilities.reduce_spec_dataset(tplot_dataset=y_values_avgd)
data_values_at_slice = data_at_slice.values
if y_axis_log:
data_values_at_slice[data_values_at_slice <= 0] = np.NaN
data_values_at_slice[data_values_at_slice <= 0] = np.nan

try:
plot_data.setData(bins, data_values_at_slice)
Expand All @@ -167,7 +167,7 @@ def update(t, name):

data_values_at_slice = data_at_slice.values
if y_axis_log:
data_values_at_slice[data_values_at_slice<=0] = np.NaN
data_values_at_slice[data_values_at_slice<=0] = np.nan
#Create a Mask for Nan Values
locations_where_nan = np.argwhere(np.isnan(data_values_at_slice))
if len(locations_where_nan) > 0:
Expand Down
6 changes: 3 additions & 3 deletions pytplot/QtPlotter/TVarFigureSpec.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ def _visdata(self):

# The the log of the z values if we are using a logarithmic x axis
if self._getzaxistype() == 'log':
data[data <= 0] = np.NaN
data[data <= 0] = np.nan
data = np.log10(data)
zmin = np.log10(self.zmin)
zmax = np.log10(self.zmax)
Expand Down Expand Up @@ -268,8 +268,8 @@ def _format_spec_data_as_image(self, x_pixel_length=1000, y_pixel_height=100):

# Try cutting the data off that is outside the bounds
try:
temp_data[yp < np.nanmin(y_values_at_xi)] = np.NaN
temp_data[yp > np.nanmax(y_values_at_xi)] = np.NaN
temp_data[yp < np.nanmin(y_values_at_xi)] = np.nan
temp_data[yp > np.nanmax(y_values_at_xi)] = np.nan
except RuntimeWarning:
# If the entire bin is NaN the above stuff fails, so just continue on
pass
Expand Down
4 changes: 2 additions & 2 deletions pytplot/tplot_math/clean_spikes.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,14 @@ def clean_spikes(names, nsmooth=10, thresh=0.3, sub_avg=False,
for i in range(dim[0]):
# compare smoothed out values to original values
if abs(d0[i] - ds[i]) > thresh * abs(ds[i]):
dn[i] = np.NaN # for spikes, set to NaN
dn[i] = np.nan # for spikes, set to NaN
else:
# More than one dim data.
for j in range(dim[1]):
for i in range(dim[0]):
# compare smoothed out values to original values
if abs(d0[i, j] - ds[i, j]) > thresh * abs(ds[i, j]):
dn[i, j] = np.NaN # for spikes, set to NaN
dn[i, j] = np.nan # for spikes, set to NaN

# pytplot.data_quants[new] = d
pytplot.replace_data(new, dn)
Expand Down
2 changes: 1 addition & 1 deletion pytplot/tplot_math/tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def test_tsmooth(self):
r = [1.0, 1.3333333333333333, 2.0, 3.0, 2.6666666666666665,
3.0, 2.6666666666666665, 3.0, 2.0, 1.3333333333333333, 1.0]
self.assertTrue(x == r)
b = [1.0, 1.0, 2.0, 3.0, np.NaN, np.NaN, np.NaN, np.NaN, 2.0, 1.0, 1.0]
b = [1.0, 1.0, 2.0, 3.0, np.nan, np.nan, np.nan, np.nan, 2.0, 1.0, 1.0]
y = smooth(b, width=3)
ry = [1.0, 1.3333333333333333, 2.0, 1.6666666666666665, 1.0,
np.nan, np.nan, 0.6666666666666666, 1.0, 1.3333333333333333, 1.0]
Expand Down
4 changes: 2 additions & 2 deletions pytplot/tplot_math/tsmooth.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@ def smooth(data, width=10, preserve_nans=None):

for i, d in enumerate(data):
if (i >= (width-1)/2) and (i <= N-(width+1)/2):
if (preserve_nans is not None) and data[i] is np.NaN:
if (preserve_nans is not None) and data[i] is np.nan:
continue
tsum = 0
count = 0
for j in range(int(width)):
idx = math.ceil(i+j-width/2)
if data[idx] is not np.NaN:
if data[idx] is not np.nan:
tsum += data[idx]
count += 1
if count > 0: # otherwise, all NaN
Expand Down

0 comments on commit 787c01c

Please sign in to comment.