Skip to content

Commit

Permalink
Fixing flipping of arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
“Emily committed Oct 9, 2024
1 parent 6951008 commit dfbb025
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 13 deletions.
15 changes: 6 additions & 9 deletions lasy/profiles/longitudinal/longitudinal_profile_from_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,18 +65,15 @@ def __init__(self, data, lo, hi):
assert np.all(np.diff(wavelength) > 0) or np.all(
np.diff(wavelength) < 0
), 'data["axis"] must be in monotonically increasing or decreasing order.'
if np.all(np.diff(wavelength) < 0):
wavelength = wavelength[::-1]
spectral_intensity = data["intensity"][::-1]
else:
spectral_intensity = data["intensity"]
spectral_intensity = data["intensity"]
if data.get("phase") is None:
spectral_phase = np.zeros_like(wavelength)
else:
if np.all(np.diff(wavelength) < 0):
spectral_phase = data["phase"][::-1]
else:
spectral_phase = data["phase"]
spectral_phase = data["phase"]
if np.all(np.diff(wavelength) < 0: # Flip arrays
wavelength = wavelength[::-1]
spectral_intensity = spectral_intensity[::-1]
spectral_phase = spectral_phase[::-1]
dt = data["dt"]
cwl = np.sum(spectral_intensity * wavelength) / np.sum(spectral_intensity)
cfreq = c / cwl
Expand Down
6 changes: 2 additions & 4 deletions tests/test_laser_profiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,11 +240,9 @@ def test_longitudinal_profiles():

# LongitudinalProfileFromData
print("LongitudinalProfileFromData")
data = {}
data = {} # Generate spectral data assuming analytic ft of GaussianLongitudinalProfile
data["datatype"] = "spectral"
data["dt"] = np.abs(
t[1] - t[0]
) # Generate spectral data assuming analytic ft of GaussianLongitudinalProfile
data["dt"] = 1e-15
profile = np.exp(
-(tau**2) * ((omega - omega_0) ** 2) / 4.0 + 1.0j * (cep_phase + omega * t_peak)
)
Expand Down

0 comments on commit dfbb025

Please sign in to comment.