Skip to content

Commit 711ed76

Browse files
authored
Merge pull request #24 from jagar2/main
Update for modern Numpy
2 parents 5864d59 + 11822e4 commit 711ed76

26 files changed

+165
-152
lines changed

BGlib/__version__.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
version = '0.0.4'
2-
time = '2023-08-24 16:00:00'
1+
version = '0.0.6'
2+
time = '2024-06-10 12:00:00'

BGlib/be/analysis/be_loop_fitter.py

+12-12
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,17 @@
3939
'''
4040
loop_metrics32 = np.dtype({'names': ['Area', 'Centroid x', 'Centroid y',
4141
'Rotation Angle [rad]', 'Offset'],
42-
'formats': [np.float32, np.float32, np.float32,
43-
np.float32, np.float32]})
42+
'formats': [float, float, float,
43+
float, float]})
4444

4545
crit32 = np.dtype({'names': ['AIC_loop', 'BIC_loop', 'AIC_line', 'BIC_line'],
46-
'formats': [np.float32, np.float32, np.float32,
47-
np.float32]})
46+
'formats': [float, float, float,
47+
float]})
4848

4949
__field_names = ['a_0', 'a_1', 'a_2', 'a_3', 'a_4', 'b_0', 'b_1', 'b_2', 'b_3',
5050
'R2 Criterion']
5151
loop_fit32 = np.dtype({'names': __field_names,
52-
'formats': [np.float32 for name in __field_names]})
52+
'formats': [float for name in __field_names]})
5353

5454

5555
class BELoopFitter(Fitter):
@@ -217,7 +217,7 @@ def _create_projection_datasets(self):
217217

218218
# Write datasets
219219
self.h5_projected_loops = create_empty_dataset(self.h5_main,
220-
np.float32,
220+
float,
221221
'Projected_Loops',
222222
h5_group=self.h5_results_grp)
223223

@@ -351,7 +351,7 @@ def _read_data_chunk(self):
351351
0]
352352
else:
353353
this_forc_spec_inds = np.ones(
354-
shape=self.h5_main.h5_spec_inds.shape[1], dtype=np.bool)
354+
shape=self.h5_main.h5_spec_inds.shape[1], dtype=bool)
355355

356356
if self._num_forcs:
357357
this_forc_dc_vec = get_unit_values(
@@ -495,7 +495,7 @@ def _read_guess_chunk(self):
495495
np.where(self._h5_guess.h5_spec_inds[forc_pos] == forc_ind)[0]
496496
else:
497497
this_forc_spec_inds = np.ones(
498-
shape=self._h5_guess.h5_spec_inds.shape[1], dtype=np.bool)
498+
shape=self._h5_guess.h5_spec_inds.shape[1], dtype=bool)
499499

500500
this_forc_2d = self._guess[:, this_forc_spec_inds]
501501
if self.verbose and self.mpi_rank == 0:
@@ -532,7 +532,7 @@ def _read_guess_chunk(self):
532532
# TODO: avoid memory copies!
533533
float_mat = np.zeros(shape=list(dc_rest_2d.shape) +
534534
[len(loop_fit32.names)-1],
535-
dtype=np.float32)
535+
dtype=float)
536536
if self.verbose and self.mpi_rank == 0:
537537
print('Created empty float matrix of shape: {}'
538538
'.'.format(float_mat.shape))
@@ -569,7 +569,7 @@ def _project_loop(sho_response, dc_offset):
569569
ancillary : numpy.ndarray
570570
Metrics for the loop projection
571571
"""
572-
# projected_loop = np.zeros(shape=sho_response.shape, dtype=np.float32)
572+
# projected_loop = np.zeros(shape=sho_response.shape, dtype=float)
573573
ancillary = np.zeros(shape=1, dtype=loop_metrics32)
574574

575575
pix_dict = projectLoop(np.squeeze(dc_offset),
@@ -683,7 +683,7 @@ def _unit_compute_guess(self):
683683
print('Unzipping loop projection results')
684684
loop_mets = np.zeros(shape=len(results), dtype=loop_metrics32)
685685
proj_loops = np.zeros(shape=(len(results), self.data[0][0].shape[1]),
686-
dtype=np.float32)
686+
dtype=float)
687687

688688
if self.verbose and self.mpi_rank == 0:
689689
print(
@@ -1302,7 +1302,7 @@ def _loop_fit_tree(tree, guess_mat, fit_results, vdc_shifted,
13021302
num_nodes = len(cluster_tree.nodes)
13031303

13041304
# prepare the guess and fit matrices
1305-
loop_guess_mat = np.zeros(shape=(num_nodes, 9), dtype=np.float32)
1305+
loop_guess_mat = np.zeros(shape=(num_nodes, 9), dtype=float)
13061306
# loop_fit_mat = np.zeros(shape=loop_guess_mat.shape, dtype=loop_guess_mat.dtype)
13071307
loop_fit_results = list(
13081308
np.arange(num_nodes, dtype=np.uint16)) # temporary placeholder

BGlib/be/analysis/be_relax_fit.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ def __init__(self, h5_main, variables=None, fit_method='Exponential', sens=1, ph
9797
self.write_dc_offset_values = self.all_dc_offset_values[::2]
9898

9999
#if there is only one RS spectrum
100-
if type(self.write_dc_offset_values) == np.float32:
100+
if type(self.write_dc_offset_values) == float:
101101
self.write_dc_offset_values = [self.write_dc_offset_values]
102102

103103
if self.starts_with == 'read':
@@ -107,7 +107,7 @@ def __init__(self, h5_main, variables=None, fit_method='Exponential', sens=1, ph
107107
np.argwhere(self.h5_main.h5_spec_vals[
108108
0] == self.no_read_steps)]
109109
# if there is only one RS spectrum
110-
if type(self.write_dc_offset_values) == np.float32:
110+
if type(self.write_dc_offset_values) == float:
111111
self.write_dc_offset_values = [self.write_dc_offset_values]
112112

113113
self.no_read_offset = len(self.all_dc_offset_values) - self.no_rs_spectra
@@ -248,7 +248,7 @@ def _create_results_datasets(self):
248248
results_units = 'pm'
249249

250250
berelaxfit32 = np.dtype({'names': field_names,
251-
'formats': [np.float32 for name in field_names]})
251+
'formats': [float for name in field_names]})
252252
self.h5_results = usid.hdf_utils.write_main_dataset(self.h5_results_grp, results_shape, results_dset_name,
253253
results_quantity, results_units, pos_dims, spec_dims,
254254
dtype=berelaxfit32, h5_pos_inds=self.h5_main.h5_pos_inds,
@@ -292,7 +292,7 @@ def _write_results_chunk(self):
292292
if self.fit_method == 'Logistic':
293293
field_names = ['A', 'K', 'B', 'v', 'Q', 'C']
294294
berelaxfit32 = np.dtype({'names': field_names,
295-
'formats': [np.float32 for name in field_names]})
295+
'formats': [float for name in field_names]})
296296
# write and flush results
297297
results = usid.io.dtype_utils.stack_real_to_compound(self._results, compound_type=berelaxfit32)
298298
results = results.reshape(self.h5_results.shape[0], -1)

BGlib/be/analysis/be_sho_fitter.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
_field_names = ['Amplitude [V]', 'Frequency [Hz]', 'Quality Factor',
3030
'Phase [rad]', 'R2 Criterion']
3131
sho32 = np.dtype({'names': _field_names,
32-
'formats': [np.float32 for name in _field_names]})
32+
'formats': [float for name in _field_names]})
3333

3434

3535
class SHOGuessFunc(Enum):

BGlib/be/analysis/utils/be_loop.py

+13-13
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,19 @@
1818
from scipy.special import erf, erfinv
1919
import warnings
2020

21-
# switching32 = np.dtype([('V+', np.float32),
22-
# ('V-', np.float32),
23-
# ('Imprint', np.float32),
24-
# ('R+', np.float32),
25-
# ('R-', np.float32),
26-
# ('Switchable Polarization', np.float32),
27-
# ('Work of Switching', np.float32),
28-
# ('Nucleation Bias 1', np.float32),
29-
# ('Nucleation Bias 2', np.float32)])
21+
# switching32 = np.dtype([('V+', float),
22+
# ('V-', float),
23+
# ('Imprint', float),
24+
# ('R+', float),
25+
# ('R-', float),
26+
# ('Switchable Polarization', float),
27+
# ('Work of Switching', float),
28+
# ('Nucleation Bias 1', float),
29+
# ('Nucleation Bias 2', float)])
3030
field_names = ['V+', 'V-', 'Imprint', 'R+', 'R-', 'Switchable Polarization',
3131
'Work of Switching', 'Nucleation Bias 1', 'Nucleation Bias 2']
3232
switching32 = np.dtype({'names': field_names,
33-
'formats': [np.float32 for name in field_names]})
33+
'formats': [float for name in field_names]})
3434

3535

3636
###############################################################################
@@ -309,7 +309,7 @@ def loop_fit_jacobian(vdc, coef_vec):
309309
vdc = np.squeeze(np.array(vdc))
310310
num_steps = vdc.size
311311

312-
J = np.zeros([num_steps, 9], dtype=np.float32)
312+
J = np.zeros([num_steps, 9], dtype=float)
313313

314314
V1 = vdc[:int(num_steps / 2)]
315315
V2 = vdc[int(num_steps / 2):]
@@ -602,8 +602,8 @@ def intersection(L1, L2):
602602
return intersection(line(A, B), line(C, D))
603603

604604
# start and end coordinates of each line segment defining the convex hull
605-
outline_1 = np.zeros((hull.simplices.shape[0], 2), dtype=np.float)
606-
outline_2 = np.zeros((hull.simplices.shape[0], 2), dtype=np.float)
605+
outline_1 = np.zeros((hull.simplices.shape[0], 2), dtype=float)
606+
outline_2 = np.zeros((hull.simplices.shape[0], 2), dtype=float)
607607
for index, pair in enumerate(hull.simplices):
608608
outline_1[index, :] = points[pair[0]]
609609
outline_2[index, :] = points[pair[1]]

BGlib/be/translators/be_odf.py

+11-11
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ def translate(self, file_path, show_plots=True, save_plots=True,
377377
UDVS_labs = ['step_num', 'dc_offset', 'ac_amp', 'wave_type', 'wave_mod', 'be-line']
378378
UDVS_units = ['', 'V', 'A', '', '', '']
379379
UDVS_mat = np.array([1, 0, parm_dict['BE_amplitude_[V]'], 1, 1, 1],
380-
dtype=np.float32).reshape(1, len(UDVS_labs))
380+
dtype=float).reshape(1, len(UDVS_labs))
381381

382382
old_spec_inds = np.vstack((np.arange(tot_bins, dtype=INDICES_DTYPE),
383383
np.zeros(tot_bins, dtype=INDICES_DTYPE)))
@@ -396,20 +396,20 @@ def translate(self, file_path, show_plots=True, save_plots=True,
396396
band_width = parm_dict['BE_band_width_[Hz]'] * (0.5 - parm_dict['BE_band_edge_trim'])
397397
st_f = parm_dict['BE_center_frequency_[Hz]'] - band_width
398398
en_f = parm_dict['BE_center_frequency_[Hz]'] + band_width
399-
bin_freqs = np.linspace(st_f, en_f, bins_per_step, dtype=np.float32)
399+
bin_freqs = np.linspace(st_f, en_f, bins_per_step, dtype=float)
400400

401401
if verbose:
402402
print('\tGenerating BE arrays of length: '
403403
'{}'.format(bins_per_step))
404404
bin_inds = np.zeros(shape=bins_per_step, dtype=np.int32)
405405
bin_FFT = np.zeros(shape=bins_per_step, dtype=np.complex64)
406-
ex_wfm = np.zeros(shape=bins_per_step, dtype=np.float32)
406+
ex_wfm = np.zeros(shape=bins_per_step, dtype=float)
407407

408408
# Forcing standardized datatypes:
409409
bin_inds = np.int32(bin_inds)
410-
bin_freqs = np.float32(bin_freqs)
410+
bin_freqs = float(bin_freqs)
411411
bin_FFT = np.complex64(bin_FFT)
412-
ex_wfm = np.float32(ex_wfm)
412+
ex_wfm = float(ex_wfm)
413413

414414
self.FFT_BE_wave = bin_FFT
415415

@@ -711,8 +711,8 @@ def _read_beps_data(self, path_dict, udvs_steps, mode, add_pixel=False):
711711
take_conjugate = requires_conjugate(rand_spectra, cores=self._cores)
712712

713713
self.mean_resp = np.zeros(shape=(self.h5_raw.shape[1]), dtype=np.complex64)
714-
self.max_resp = np.zeros(shape=(self.h5_raw.shape[0]), dtype=np.float32)
715-
self.min_resp = np.zeros(shape=(self.h5_raw.shape[0]), dtype=np.float32)
714+
self.max_resp = np.zeros(shape=(self.h5_raw.shape[0]), dtype=float)
715+
self.min_resp = np.zeros(shape=(self.h5_raw.shape[0]), dtype=float)
716716

717717
numpix = self.h5_raw.shape[0]
718718
"""
@@ -945,7 +945,7 @@ def _read_secondary_channel(self, h5_meas_group, aux_file_path):
945945
h5_pos_vals=self.h5_raw.h5_pos_vals,
946946
h5_spec_inds=h5_current_spec_inds,
947947
h5_spec_vals=h5_current_spec_values,
948-
dtype=np.float32, # data type / precision
948+
dtype=float, # data type / precision
949949
main_dset_attrs={'IO_rate': 4E+6, 'Amplifier_Gain': 9},
950950
verbose=self._verbose)
951951

@@ -961,7 +961,7 @@ def _read_secondary_channel(self, h5_meas_group, aux_file_path):
961961
spectral_len = spectral_len // 2
962962

963963
# calculate the # positions that can be stored in memory in one go.
964-
b_per_position = np.float32(0).itemsize * spectral_len
964+
b_per_position = np.dtype('float32').itemsize * spectral_len
965965

966966
max_pos_per_read = int(np.floor((get_available_memory()) / b_per_position))
967967

@@ -1565,7 +1565,7 @@ def translate_val(target, strvals, numvals):
15651565
'wave_type', 'wave_mod', 'in-field',
15661566
'out-of-field']
15671567
UD_VS_table_unit = ['', 'V', 'A', '', '', 'V', 'V']
1568-
udvs_table = np.zeros(shape=(num_VS_steps, 7), dtype=np.float32)
1568+
udvs_table = np.zeros(shape=(num_VS_steps, 7), dtype=float)
15691569

15701570
udvs_table[:, 0] = np.arange(0, num_VS_steps) # Python base 0
15711571
udvs_table[:, 1] = UD_dc_vec
@@ -1606,7 +1606,7 @@ def translate_val(target, strvals, numvals):
16061606
UD_dc_vec = VS_offset * np.ones(num_VS_steps)
16071607
UD_VS_table_label = ['step_num', 'dc_offset', 'ac_amp', 'wave_type', 'wave_mod', 'forward', 'reverse']
16081608
UD_VS_table_unit = ['', 'V', 'A', '', '', 'A', 'A']
1609-
udvs_table = np.zeros(shape=(num_VS_steps, 7), dtype=np.float32)
1609+
udvs_table = np.zeros(shape=(num_VS_steps, 7), dtype=float)
16101610
udvs_table[:, 0] = np.arange(1, num_VS_steps + 1)
16111611
udvs_table[:, 1] = UD_dc_vec
16121612
udvs_table[:, 2] = vs_amp_vec

BGlib/be/translators/be_odf_relaxation.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -115,13 +115,13 @@ def translate(self, file_path, show_plots=True, save_plots=True, do_histogram=Fa
115115
band_width = parm_dict['BE_band_width_[Hz]'] * (0.5 - parm_dict['BE_band_edge_trim'])
116116
st_f = parm_dict['BE_center_frequency_[Hz]'] - band_width
117117
en_f = parm_dict['BE_center_frequency_[Hz]'] + band_width
118-
bin_freqs = np.linspace(st_f, en_f, len(bin_inds), dtype=np.float32)
118+
bin_freqs = np.linspace(st_f, en_f, len(bin_inds), dtype=float)
119119

120120
# Forcing standardized datatypes:
121121
bin_inds = np.int32(bin_inds)
122-
bin_freqs = np.float32(bin_freqs)
122+
bin_freqs = float(bin_freqs)
123123
bin_FFT = np.complex64(bin_FFT)
124-
ex_wfm = np.float32(ex_wfm)
124+
ex_wfm = float(ex_wfm)
125125

126126
self.FFT_BE_wave = bin_FFT
127127

@@ -188,7 +188,7 @@ def translate(self, file_path, show_plots=True, save_plots=True, do_histogram=Fa
188188
udvs_slices[col_name] = (slice(None), slice(col_ind, col_ind + 1))
189189
h5_UDVS = chan_grp.create_dataset('UDVS',
190190
data=UDVS_mat,
191-
dtype=np.float32)
191+
dtype=float)
192192
write_simple_attrs(h5_UDVS, {'labels': UDVS_labs, 'units': UDVS_units})
193193

194194
h5_bin_steps = chan_grp.create_dataset('Bin_Steps',
@@ -206,7 +206,7 @@ def translate(self, file_path, show_plots=True, save_plots=True, do_histogram=Fa
206206
dtype=np.uint32)
207207
h5_bin_freq = chan_grp.create_dataset('Bin_Frequencies',
208208
data=bin_freqs,
209-
dtype=np.float32)
209+
dtype=float)
210210
h5_bin_FFT = chan_grp.create_dataset('Bin_FFT',
211211
data=bin_FFT,
212212
dtype=np.complex64)
@@ -262,8 +262,8 @@ def translate(self, file_path, show_plots=True, save_plots=True, do_histogram=Fa
262262
compression='gzip')
263263

264264
self.mean_resp = np.zeros(shape=(self.ds_main.shape[1]), dtype=np.complex64)
265-
self.max_resp = np.zeros(shape=(self.ds_main.shape[0]), dtype=np.float32)
266-
self.min_resp = np.zeros(shape=(self.ds_main.shape[0]), dtype=np.float32)
265+
self.max_resp = np.zeros(shape=(self.ds_main.shape[0]), dtype=float)
266+
self.min_resp = np.zeros(shape=(self.ds_main.shape[0]), dtype=float)
267267

268268
# Now read the raw data files:
269269
self._read_data(path_dict['read_real'], path_dict['read_imag'], parm_dict)
@@ -594,7 +594,7 @@ def translateVal(target, strvals, numvals):
594594
num_VS_steps = total_steps * 2 # To account for IF and OOF
595595

596596
UD_VS_table_label = ['step_num', 'dc_offset', 'ac_amp', 'wave_type', 'wave_mod', 'in-field', 'out-of-field']
597-
UD_VS_table = np.zeros(shape=(num_VS_steps, 7), dtype=np.float32)
597+
UD_VS_table = np.zeros(shape=(num_VS_steps, 7), dtype=float)
598598
UD_VS_table_unit = ['', 'V', 'A', '', '', 'V', 'V']
599599

600600
UD_VS_table[:, 0] = np.arange(0, num_VS_steps) # Python base 0

BGlib/be/translators/beps_data_generator.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -564,7 +564,7 @@ def _calc_sho(self, coef_OF_mat, coef_IF_mat, amp_noise=0.1, phase_noise=0.1, q_
564564
sho_if_inds = sho_field == 1
565565

566566
# determine how many pixels can be read at once
567-
mem_per_pix = vdc_vec.size * np.float32(0).itemsize
567+
mem_per_pix = vdc_vec.size * float(0).itemsize
568568
#free_mem = self.max_ram - vdc_vec.size * vdc_vec.dtype.itemsize * 6
569569
free_mem = 1024
570570
batch_size = int(free_mem / mem_per_pix)

0 commit comments

Comments
 (0)