Skip to content

Commit

Permalink
fix wavex_setup and dmwavex_setup
Browse files Browse the repository at this point in the history
  • Loading branch information
abhisrkckl committed Oct 9, 2023
1 parent 0bb171d commit 2e17704
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/pint/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1328,8 +1328,9 @@ def wavex_setup(model, T_span, freqs=None, n_freqs=None):
"Both freqs and n_freqs are specified. Only one or the other should be used"
)

if n_freqs <= 0:
if n_freqs is not None and n_freqs <= 0:
raise ValueError("Must use a non-zero number of wave frequencies")

model.add_component(WaveX())
if isinstance(T_span, u.quantity.Quantity):
T_span.to(u.d)
Expand All @@ -1356,11 +1357,11 @@ def wavex_setup(model, T_span, freqs=None, n_freqs=None):

if n_freqs is not None:
if n_freqs == 1:
wave_freq = 2.0 * np.pi / T_span
wave_freq = 1 / T_span

Check warning on line 1360 in src/pint/utils.py

View check run for this annotation

Codecov / codecov/patch

src/pint/utils.py#L1360

Added line #L1360 was not covered by tests
model.WXFREQ_0001.quantity = wave_freq
else:
wave_numbers = np.arange(1, n_freqs + 1)
wave_freqs = 2.0 * np.pi * wave_numbers / T_span
wave_freqs = wave_numbers / T_span

Check warning on line 1364 in src/pint/utils.py

View check run for this annotation

Codecov / codecov/patch

src/pint/utils.py#L1364

Added line #L1364 was not covered by tests
model.WXFREQ_0001.quantity = wave_freqs[0]
model.components["WaveX"].add_wavex_components(wave_freqs[1:])
return model.components["WaveX"].get_indices()
Expand Down Expand Up @@ -1408,8 +1409,9 @@ def dmwavex_setup(model, T_span, freqs=None, n_freqs=None):
"Both freqs and n_freqs are specified. Only one or the other should be used"
)

if n_freqs <= 0:
if n_freqs is not None and n_freqs <= 0:
raise ValueError("Must use a non-zero number of wave frequencies")

model.add_component(DMWaveX())
if isinstance(T_span, u.quantity.Quantity):
T_span.to(u.d)
Expand All @@ -1436,11 +1438,11 @@ def dmwavex_setup(model, T_span, freqs=None, n_freqs=None):

if n_freqs is not None:
if n_freqs == 1:
wave_freq = 2.0 * np.pi / T_span
wave_freq = 1 / T_span

Check warning on line 1441 in src/pint/utils.py

View check run for this annotation

Codecov / codecov/patch

src/pint/utils.py#L1441

Added line #L1441 was not covered by tests
model.DMWXFREQ_0001.quantity = wave_freq
else:
wave_numbers = np.arange(1, n_freqs + 1)
wave_freqs = 2.0 * np.pi * wave_numbers / T_span
wave_freqs = wave_numbers / T_span
model.DMWXFREQ_0001.quantity = wave_freqs[0]
model.components["DMWaveX"].add_dmwavex_components(wave_freqs[1:])
return model.components["DMWaveX"].get_indices()
Expand Down

0 comments on commit 2e17704

Please sign in to comment.