Skip to content

Commit 7d90a5d

Browse files
committed
Formatting requests from GitHub comments
1 parent 1d7c196 commit 7d90a5d

File tree

1 file changed

+8
-11
lines changed

1 file changed

+8
-11
lines changed

fitting_source/1D_fitting/plot_6_139La_Ext_Czjzek.py

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -94,14 +94,14 @@ def make_kernel(cq_range, eta_range, method, isotope):
9494

9595
spin_systems = [
9696
SpinSystem(sites=[Site(isotope=isotope, quadrupolar=dict(Cq=cq * 1e6, eta=e))])
97-
for cq, e in zip(Cq.flatten(), eta.flatten())
97+
for cq, e in zip(Cq.ravel(), eta.ravel())
9898
]
9999
sim = Simulator(spin_systems=spin_systems, methods=[method])
100100
sim.config.decompose_spectrum = "spin_system"
101-
sim.run(pack_as_csdm=False)
101+
sim.run(pack_as_csdm=False) # Will return spectrum as numpy array, not CSDM object
102102

103103
amp = sim.methods[0].simulation.real
104-
return np.swapaxes(amp, 0, 1)
104+
return amp.T
105105

106106

107107
# Create ranges to construct cq and eta grid points
@@ -127,7 +127,7 @@ def make_kernel(cq_range, eta_range, method, isotope):
127127
# {\bf s} = {\bf K \cdot f},
128128
#
129129
# A constant isotropic chemical shift, whose value is also in the Parameters object,
130-
# is applied to :math:`{\bf s}` using the `Fouier shift relation
130+
# is applied to :math:`{\bf s}` using the `Fourier shift relation
131131
# <https://en.wikipedia.org/wiki/Fourier_transform#Translation_/_time_shifting>`__.
132132
# Finally, the spectrum is scaled and returned.
133133
def make_spectrum_from_parameters(
@@ -156,7 +156,7 @@ def make_spectrum_from_parameters(
156156
_, _, amp = model_quad.pdf(pos=[cq_range, eta_range])
157157

158158
# Create spectra by dotting the amplitude distribution with the kernel
159-
dist = kernel.dot(amp.flatten())
159+
dist = kernel.dot(amp.ravel())
160160

161161
# Pack numpy array as csdm object and apply signal processing
162162
guess_dataset = cp.CSDM(
@@ -165,8 +165,8 @@ def make_spectrum_from_parameters(
165165
)
166166

167167
# Calculate isotropic shift in Hz
168-
ppm_to_hz_factor = Isotope(symbol="139La").gyromagnetic_ratio * 17.6
169-
iso_shift_in_hz = ppm_to_hz_factor * iso_shift
168+
larmor_freq = Isotope(symbol="139La").gyromagnetic_ratio * 17.6
169+
iso_shift_in_hz = larmor_freq * iso_shift
170170

171171
# Apply isotropic shift using FFT shift theorem
172172
guess_dataset = guess_dataset.fft()
@@ -235,9 +235,7 @@ def minimization_function(params, experiment, processor, kernel, sigma=sigma):
235235

236236
# %%
237237
# Create the Minimization object with all the functions and variables previously
238-
# created. Here the ``powell`` method is used for minimization since the
239-
# ``least_squares`` method will not optimize values due to no interpolation scheme
240-
# being used when creating the spectrum from the kernel and pdf.
238+
# created.
241239
minner = Minimizer(
242240
minimization_function, params, fcn_args=(experiment, processor, kernel)
243241
)
@@ -253,7 +251,6 @@ def minimization_function(params, experiment, processor, kernel, sigma=sigma):
253251
final_fit = make_spectrum_from_parameters(best_fit_params, kernel, processor)
254252
residual_spectrum = residuals(experiment, final_fit)
255253

256-
# plt.rcParams['figure.facecolor'] = 'white'
257254
plt.figure(figsize=(6, 4))
258255
ax = plt.subplot(projection="csdm")
259256
ax.plot(experiment, "k", alpha=0.5)

0 commit comments

Comments
 (0)