Skip to content

Commit 9f46139

Browse files
authored
Merge pull request #712 from sezelt/np2
Fix numpy 2 deprecated aliases
2 parents 597e5b1 + 2303563 commit 9f46139

File tree

4 files changed

+22
-22
lines changed

4 files changed

+22
-22
lines changed

py4DSTEM/io/legacy/legacy13/v13_emd_classes/io.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -127,61 +127,61 @@ def Metadata_to_h5(metadata, group):
127127
# None
128128
if v is None:
129129
v = "_None"
130-
v = np.string_(v) # convert to byte string
130+
v = np.bytes_(v) # convert to byte string
131131
dset = grp.create_dataset(k, data=v)
132-
dset.attrs["type"] = np.string_("None")
132+
dset.attrs["type"] = np.bytes_("None")
133133

134134
# strings
135135
elif isinstance(v, str):
136-
v = np.string_(v) # convert to byte string
136+
v = np.bytes_(v) # convert to byte string
137137
dset = grp.create_dataset(k, data=v)
138-
dset.attrs["type"] = np.string_("string")
138+
dset.attrs["type"] = np.bytes_("string")
139139

140140
# bools
141141
elif isinstance(v, bool):
142142
dset = grp.create_dataset(k, data=v, dtype=bool)
143-
dset.attrs["type"] = np.string_("bool")
143+
dset.attrs["type"] = np.bytes_("bool")
144144

145145
# numbers
146146
elif isinstance(v, Number):
147147
dset = grp.create_dataset(k, data=v, dtype=type(v))
148-
dset.attrs["type"] = np.string_("number")
148+
dset.attrs["type"] = np.bytes_("number")
149149

150150
# arrays
151151
elif isinstance(v, np.ndarray):
152152
dset = grp.create_dataset(k, data=v, dtype=v.dtype)
153-
dset.attrs["type"] = np.string_("array")
153+
dset.attrs["type"] = np.bytes_("array")
154154

155155
# tuples
156156
elif isinstance(v, tuple):
157157
# of numbers
158158
if isinstance(v[0], Number):
159159
dset = grp.create_dataset(k, data=v)
160-
dset.attrs["type"] = np.string_("tuple")
160+
dset.attrs["type"] = np.bytes_("tuple")
161161

162162
# of tuples
163163
elif any([isinstance(v[i], tuple) for i in range(len(v))]):
164164
dset_grp = grp.create_group(k)
165-
dset_grp.attrs["type"] = np.string_("tuple_of_tuples")
165+
dset_grp.attrs["type"] = np.bytes_("tuple_of_tuples")
166166
dset_grp.attrs["length"] = len(v)
167167
for i, x in enumerate(v):
168168
dset_grp.create_dataset(str(i), data=x)
169169

170170
# of arrays
171171
elif isinstance(v[0], np.ndarray):
172172
dset_grp = grp.create_group(k)
173-
dset_grp.attrs["type"] = np.string_("tuple_of_arrays")
173+
dset_grp.attrs["type"] = np.bytes_("tuple_of_arrays")
174174
dset_grp.attrs["length"] = len(v)
175175
for i, ar in enumerate(v):
176176
dset_grp.create_dataset(str(i), data=ar, dtype=ar.dtype)
177177

178178
# of strings
179179
elif isinstance(v[0], str):
180180
dset_grp = grp.create_group(k)
181-
dset_grp.attrs["type"] = np.string_("tuple_of_strings")
181+
dset_grp.attrs["type"] = np.bytes_("tuple_of_strings")
182182
dset_grp.attrs["length"] = len(v)
183183
for i, s in enumerate(v):
184-
dset_grp.create_dataset(str(i), data=np.string_(s))
184+
dset_grp.create_dataset(str(i), data=np.bytes_(s))
185185

186186
else:
187187
er = f"Metadata only supports writing tuples with numeric and array-like arguments; found type {type(v[0])}"
@@ -192,23 +192,23 @@ def Metadata_to_h5(metadata, group):
192192
# of numbers
193193
if isinstance(v[0], Number):
194194
dset = grp.create_dataset(k, data=v)
195-
dset.attrs["type"] = np.string_("list")
195+
dset.attrs["type"] = np.bytes_("list")
196196

197197
# of arrays
198198
elif isinstance(v[0], np.ndarray):
199199
dset_grp = grp.create_group(k)
200-
dset_grp.attrs["type"] = np.string_("list_of_arrays")
200+
dset_grp.attrs["type"] = np.bytes_("list_of_arrays")
201201
dset_grp.attrs["length"] = len(v)
202202
for i, ar in enumerate(v):
203203
dset_grp.create_dataset(str(i), data=ar, dtype=ar.dtype)
204204

205205
# of strings
206206
elif isinstance(v[0], str):
207207
dset_grp = grp.create_group(k)
208-
dset_grp.attrs["type"] = np.string_("list_of_strings")
208+
dset_grp.attrs["type"] = np.bytes_("list_of_strings")
209209
dset_grp.attrs["length"] = len(v)
210210
for i, s in enumerate(v):
211-
dset_grp.create_dataset(str(i), data=np.string_(s))
211+
dset_grp.create_dataset(str(i), data=np.bytes_(s))
212212

213213
else:
214214
er = f"Metadata only supports writing lists with numeric and array-like arguments; found type {type(v[0])}"
@@ -490,7 +490,7 @@ def PointList_to_h5(pointlist, group):
490490
# Add data
491491
for f, t in zip(pointlist.fields, pointlist.types):
492492
group_current_field = grp.create_dataset(f, data=pointlist.data[f])
493-
group_current_field.attrs.create("dtype", np.string_(t))
493+
group_current_field.attrs.create("dtype", np.bytes_(t))
494494
# group_current_field.create_dataset(
495495
# "data",
496496
# data = pointlist.data[f]

py4DSTEM/process/classification/featurization.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -967,7 +967,7 @@ def _gmm_single(x, cv, components, num_models, random_seed=None, return_all=True
967967
gmm_list = []
968968
gmm_labels = []
969969
gmm_proba = []
970-
lowest_bic = np.infty
970+
lowest_bic = np.inf
971971
bic_temp = 0
972972
if random_seed is None:
973973
rng = np.random.RandomState(seed=42)

py4DSTEM/process/utils/elliptical_coords.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -320,8 +320,8 @@ def elliptical_resample(
320320

321321
# Get (qx,qy) corresponding to the coordinates distorted by the ellipse
322322
xr, yr = np.mgrid[0:Nx, 0:Ny]
323-
xr0 = xr.astype(np.float_) - qx0
324-
yr0 = yr.astype(np.float_) - qy0
323+
xr0 = xr.astype(np.float64) - qx0
324+
yr0 = yr.astype(np.float64) - qy0
325325
xr = xr0 * np.cos(-theta) - yr0 * np.sin(-theta)
326326
yr = xr0 * np.sin(-theta) + yr0 * np.cos(-theta)
327327
qx = qx0 + xr * np.cos(theta) - yr * (b / a) * np.sin(theta)

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@
2323
keywords="STEM,4DSTEM",
2424
python_requires=">=3.10",
2525
install_requires=[
26-
"numpy >= 1.19, < 2.0",
26+
"numpy >= 1.19",
2727
"scipy >= 1.5.2",
2828
"h5py >= 3.2.0",
2929
"hdf5plugin >= 4.1.3",
30-
"ncempy >= 1.8.1, <= 1.11.2",
30+
"ncempy >= 1.8.1",
3131
"matplotlib >= 3.2.2",
3232
"scikit-image >= 0.17.2",
3333
"scikit-learn >= 0.23.2, < 1.5",

0 commit comments

Comments
 (0)