Skip to content

Commit c106712

Browse files
paulromanoGuySten
andauthored
Avoid deprecated numpy array shape assignment (#4104)
Co-authored-by: GuySten <guyste@post.bgu.ac.il>
1 parent e3bba4f commit c106712

15 files changed

Lines changed: 27 additions & 33 deletions

File tree

‎examples/custom_source/show_flux.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# Get the flux from the statepoint
55
with openmc.StatePoint('statepoint.10.h5') as sp:
66
flux = sp.tallies[1].mean
7-
flux.shape = (50, 50)
7+
flux = flux.reshape(50, 50)
88

99
# Plot the flux
1010
fig, ax = plt.subplots()

‎examples/parameterized_custom_source/show_flux.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# Get the flux from the statepoint
55
with openmc.StatePoint('statepoint.10.h5') as sp:
66
flux = sp.tallies[1].mean
7-
flux.shape = (50, 50)
7+
flux = flux.reshape(50, 50)
88

99
# Plot the flux
1010
fig, ax = plt.subplots()

‎openmc/data/angle_distribution.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ def from_ace(cls, ace, location_dist, location_start):
195195
n_points = int(ace.xss[idx + 1])
196196
# Data is given as rows of (values, PDF, CDF)
197197
data = ace.xss[idx + 2:idx + 2 + 3*n_points]
198-
data.shape = (3, n_points)
198+
data = data.reshape(3, n_points)
199199

200200
mu_i = Tabular(data[0], data[1], INTERPOLATION_SCHEME[intt])
201201
mu_i.c = data[2]

‎openmc/data/correlated.py‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ def from_ace(cls, ace, idx, ldis):
360360
# Secondary energy distribution
361361
n_energy_out = int(ace.xss[idx + 1])
362362
data = ace.xss[idx + 2:idx + 2 + 4*n_energy_out].copy()
363-
data.shape = (4, n_energy_out)
363+
data = data.reshape(4, n_energy_out)
364364
data[0,:] *= EV_PER_MEV
365365

366366
# Create continuous distribution
@@ -400,7 +400,7 @@ def from_ace(cls, ace, idx, ldis):
400400
intt = int(ace.xss[idx])
401401
n_cosine = int(ace.xss[idx + 1])
402402
data = ace.xss[idx + 2:idx + 2 + 3*n_cosine]
403-
data.shape = (3, n_cosine)
403+
data = data.reshape(3, n_cosine)
404404

405405
mu_ij = Tabular(data[0], data[1], INTERPOLATION_SCHEME[intt])
406406
mu_ij.c = data[2]
@@ -445,8 +445,7 @@ def from_endf(cls, file_obj):
445445
# TODO: separate out discrete lines
446446
n_angle = items[3]
447447
n_energy_out = items[5]
448-
values = np.asarray(values)
449-
values.shape = (n_energy_out, n_angle + 2)
448+
values = np.asarray(values).reshape(n_energy_out, n_angle + 2)
450449

451450
# Outgoing energy distribution at the i-th incoming energy
452451
eout_i = values[:,0]

‎openmc/data/energy_distribution.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1247,7 +1247,7 @@ def from_ace(cls, ace, idx, ldis):
12471247

12481248
n_energy_out = int(ace.xss[idx + 1])
12491249
data = ace.xss[idx + 2:idx + 2 + 3*n_energy_out].copy()
1250-
data.shape = (3, n_energy_out)
1250+
data = data.reshape(3, n_energy_out)
12511251
data[0,:] *= EV_PER_MEV
12521252

12531253
# Create continuous distribution

‎openmc/data/kalbach_mann.py‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -555,7 +555,7 @@ def from_ace(cls, ace, idx, ldis):
555555

556556
n_energy_out = int(ace.xss[idx + 1])
557557
data = ace.xss[idx + 2:idx + 2 + 5*n_energy_out].copy()
558-
data.shape = (5, n_energy_out)
558+
data = data.reshape(5, n_energy_out)
559559
data[0, :] *= EV_PER_MEV
560560

561561
# Create continuous distribution
@@ -637,8 +637,7 @@ def from_endf(cls, file_obj, za_emitted, za_target, projectile_mass):
637637
# TODO: split out discrete energies
638638
n_angle = items[3]
639639
n_energy_out = items[5]
640-
values = np.asarray(values)
641-
values.shape = (n_energy_out, n_angle + 2)
640+
values = np.asarray(values).reshape(n_energy_out, n_angle + 2)
642641

643642
# Outgoing energy distribution at the i-th incoming energy
644643
eout_i = values[:, 0]

‎openmc/data/thermal.py‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -796,12 +796,12 @@ def from_ace(cls, ace_or_filename, name=None):
796796
if not continuous:
797797
n_mu = ace.nxs[3]
798798
idx = ace.jxs[3]
799-
energy_out = ace.xss[idx:idx + n_energy * n_energy_out *
800-
(n_mu + 2): n_mu + 2]*EV_PER_MEV
801-
energy_out.shape = (n_energy, n_energy_out)
799+
n_values = n_energy * n_energy_out * (n_mu + 2)
800+
energy_out = ace.xss[idx:idx + n_values:n_mu + 2]*EV_PER_MEV
801+
energy_out = energy_out.reshape(n_energy, n_energy_out)
802802

803-
mu_out = ace.xss[idx:idx + n_energy * n_energy_out * (n_mu + 2)]
804-
mu_out.shape = (n_energy, n_energy_out, n_mu+2)
803+
mu_out = ace.xss[idx:idx + n_values]
804+
mu_out = mu_out.reshape(n_energy, n_energy_out, n_mu + 2)
805805
mu_out = mu_out[:, :, 1:]
806806
skewed = (ace.nxs[7] == 1)
807807
distribution = IncoherentInelasticAEDiscrete(energy_out, mu_out, skewed)
@@ -924,7 +924,7 @@ def from_ace(cls, ace_or_filename, name=None):
924924
assert n_mu > 0
925925
idx = ace.jxs[9] if mixed else ace.jxs[6]
926926
mu_out = ace.xss[idx:idx + n_energy * n_mu]
927-
mu_out.shape = (n_energy, n_mu)
927+
mu_out = mu_out.reshape(n_energy, n_mu)
928928
incoherent_dist = IncoherentElasticAEDiscrete(mu_out)
929929

930930
if ace.nxs[5] == 3:

‎openmc/data/urr.py‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,8 +205,7 @@ def from_ace(cls, ace):
205205
idx += N
206206

207207
# Get probability tables
208-
table = ace.xss[idx : idx+N*6*M].copy()
209-
table.shape = (N, 6, M)
208+
table = ace.xss[idx : idx+N*6*M].copy().reshape(N, 6, M)
210209

211210
# Convert units on heating numbers
212211
table[:,5,:] *= EV_PER_MEV

‎openmc/deplete/d1s.py‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ def apply_time_correction(
185185
tally_std_dev = new_tally.std_dev.reshape(shape)
186186

187187
# Apply TCF, broadcasting to the correct dimensions
188-
tcf.shape = (1, -1, 1, 1, 1)
188+
tcf = tcf.reshape(1, -1, 1, 1, 1)
189189
new_tally._mean = tally_mean * tcf
190190
new_tally._std_dev = tally_std_dev * tcf
191191

@@ -207,8 +207,8 @@ def apply_time_correction(
207207
# scores)
208208
new_tally._sum = (tally_sum * tcf).reshape(shape)
209209
new_tally._sum_sq = (tally_sum_sq * (tcf*tcf)).reshape(shape)
210-
new_tally._mean.shape = shape
211-
new_tally._std_dev.shape = shape
210+
new_tally._mean = new_tally._mean.reshape(shape)
211+
new_tally._std_dev = new_tally._std_dev.reshape(shape)
212212

213213
return new_tally
214214

‎openmc/lattice.py‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -969,8 +969,7 @@ def from_xml_element(cls, elem, get_universe):
969969
dimension = get_elem_list(elem, 'dimension', int)
970970
shape = np.array(dimension, dtype=int)[::-1]
971971
universes = get_elem_list(elem, 'universes', int)
972-
uarray = np.array([get_universe(u) for u in universes])
973-
uarray.shape = shape
972+
uarray = np.array([get_universe(u) for u in universes]).reshape(shape)
974973
lat.universes = uarray
975974
return lat
976975

0 commit comments

Comments
 (0)