Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MNT: Avoid overwriting user's longitude values #63

Merged
merged 1 commit into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions pymsis/msis.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,9 +326,6 @@ def create_input(
# regression tests indicate it should still be integer DOY
# dyear += dseconds/86400
lons = np.atleast_1d(lons)
# If any longitudes were input as negatives, try to change them to
# the (0, 360) range
lons[lons < 0] += 360
lats = np.atleast_1d(lats)
alts = np.atleast_1d(alts)

Expand Down
11 changes: 8 additions & 3 deletions src/wrappers/msis00.F90
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,16 @@ subroutine pygtd7d(day, utsec, lon, lat, z, sflux, sfluxavg, ap, output, n)
real, intent(out) :: output(n, 1:11)

integer :: i
real :: t(2), d(9) ! Temporary to swap dimensions
real :: t(2), d(9), lon_tmp ! Temporary to swap dimensions

do i=1, n
call gtd7d(10000 + FLOOR(day(i)), utsec(i), z(i), lat(i), lon(i), &
utsec(i)/3600. + lon(i)/15., sfluxavg(i), &
if (lon(i) < 0) then
lon_tmp = lon(i) + 360
else
lon_tmp = lon(i)
endif
call gtd7d(10000 + FLOOR(day(i)), utsec(i), z(i), lat(i), lon_tmp, &
utsec(i)/3600. + lon_tmp/15., sfluxavg(i), &
sflux(i), ap(i, :), 48, d, t)
! O, H, and N are set to zero below 72.5 km
! Change them to NaN instead
Expand Down
6 changes: 6 additions & 0 deletions src/wrappers/msis2.F90
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,14 @@ subroutine pymsiscalc(day, utsec, lon, lat, z, sflux, sfluxavg, ap, output, n)
real(kind=rp), intent(out) :: output(n, 1:11)

integer :: i
real(kind=rp) :: lon_tmp

do i=1, n
if (lon(i) < 0) then
lon_tmp = lon(i) + 360
else
lon_tmp = lon(i)
endif
call msiscalc(day(i), utsec(i), z(i), lat(i), lon(i), sfluxavg(i), &
sflux(i), ap(i, :), output(i, 11), output(i, 1:10))
enddo
Expand Down
21 changes: 21 additions & 0 deletions tests/test_msis.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,27 @@ def test_create_input_multi_lon_lat(input_data, expected_input):
assert_array_equal(data, [expected_input] * 5 * 5)


@pytest.mark.parametrize("version", ["0", "2.0", "2.1"])
def test_create_input_lon_wrapping(input_data, expected_input, version):
date, lon, lat, alt, f107, f107a, ap = input_data
# Repeat 5 dates
lons = np.array([-90] * 5)
input_data = (date, lons, [lat] * 5, alt, f107, f107a, ap)
shape, data = msis.create_input(*input_data)
assert shape == (1, 5, 5, 1)
assert data.shape == (5 * 5, 14)
expected_input[2] = -90
assert_array_equal(data, [expected_input] * 5 * 5)
# Make sure that our input lons array wasn't transfomrmed inplace
assert_array_equal(lons, [-90] * 5)

# Test that -90 and 270 produce the same output
assert_array_equal(
msis.run(date, lons, [lat] * 5, alt, f107, f107a, ap, version=version),
msis.run(date, lons + 360, [lat] * 5, alt, f107, f107a, ap, version=version),
)


def test_run_options(input_data, expected_output):
# Default options is all 1's, so make sure they are equivalent
assert_allclose(
Expand Down
Loading