Skip to content

Commit

Permalink
Merge pull request #305 from volodia99/inconsistent-phi
Browse files Browse the repository at this point in the history
BUG: remove uniform convention for phi btw -pi and pi
  • Loading branch information
volodia99 authored Apr 5, 2024
2 parents ad038bf + 18e6b98 commit f45b87d
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 16 deletions.
30 changes: 19 additions & 11 deletions nonos/api/analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,17 +171,13 @@ def __init__(
self.r = x1
self.theta = x2
self.phi = x3
if self.phi.max() - np.pi > np.pi / 2:
self.phi -= np.pi
self.cube = ("r", "theta", "phi")
self.rmed = 0.5 * (self.r[1:] + self.r[:-1])
self.thetamed = 0.5 * (self.theta[1:] + self.theta[:-1])
self.phimed = 0.5 * (self.phi[1:] + self.phi[:-1])
if self.geometry == "polar":
self.R = x1
self.phi = x2
if self.phi.max() - np.pi > np.pi / 2:
self.phi -= np.pi
self.z = x3
self.cube = ("R", "phi", "z")
self.Rmed = 0.5 * (self.R[1:] + self.R[:-1])
Expand Down Expand Up @@ -540,11 +536,15 @@ def map(
ipi = find_nearest(phicoord, 2 * np.pi)
if self.native_geometry == "polar":
self.data = np.roll(
self.data, -ipi - self.coords.phi.shape[0] // 2 + 1, axis=1
self.data,
-ipi + 1,
axis=1,
)
elif self.native_geometry == "spherical":
self.data = np.roll(
self.data, -ipi - self.coords.phi.shape[0] // 2 + 1, axis=2
self.data,
-ipi + 1,
axis=2,
)
else:
raise NotImplementedError(
Expand Down Expand Up @@ -584,11 +584,15 @@ def map(
ipi = find_nearest(phicoord, 2 * np.pi)
if self.native_geometry == "polar":
self.data = np.roll(
self.data, -ipi - self.coords.phi.shape[0] // 2 + 1, axis=1
self.data,
-ipi + 1,
axis=1,
)
elif self.native_geometry == "spherical":
self.data = np.roll(
self.data, -ipi - self.coords.phi.shape[0] // 2 + 1, axis=2
self.data,
-ipi + 1,
axis=2,
)
else:
raise NotImplementedError(
Expand Down Expand Up @@ -734,7 +738,7 @@ def find_phip(
) -> float:
pd = self._load_planet(planet_number=planet_number, planet_file=planet_file)
ind_on = self._get_ind_output_number(pd.t)
return np.arctan2(pd.y, pd.x)[ind_on] % (2 * np.pi) - np.pi
return np.arctan2(pd.y, pd.x)[ind_on] % (2 * np.pi)

def latitudinal_projection(self, theta=None):
operation = self.operation + "_latitudinal_projection"
Expand Down Expand Up @@ -1483,14 +1487,18 @@ def rotate(
ipi = find_nearest(phicoord, 2 * np.pi)
if self.native_geometry == "polar":
ret_data = np.roll(
self.data, -ipi - self.coords.phi.shape[0] // 2 + 1, axis=1
self.data,
-ipi + 1,
axis=1,
)
ret_coords = Coordinates(
self.native_geometry, self.coords.R, self.coords.phi, self.coords.z
)
elif self.native_geometry == "spherical":
ret_data = np.roll(
self.data, -ipi - self.coords.phi.shape[0] // 2 + 1, axis=2
self.data,
-ipi + 1,
axis=2,
)
ret_coords = Coordinates(
self.native_geometry,
Expand Down
Binary file modified tests/pytest_mpl_baseline/test_2D_polar_plane.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/pytest_mpl_baseline/test_3D_vm_phiR.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/pytest_mpl_baseline/test_3D_vm_xy.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/pytest_mpl_baseline/test_symlog.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 3 additions & 5 deletions tests/test_plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def test_plot_planet_corotation(test_data_dir):

ds = GasDataSet(43, geometry="polar")
azimfield = ds["RHO"].radial_at_r().vertical_at_midplane().map("phi").data
assert find_nearest(azimfield, azimfield.max()) != ds["RHO"].shape[2] // 2
assert find_nearest(azimfield, azimfield.max()) != 0

azimfieldPlanet = (
ds["RHO"]
Expand All @@ -103,9 +103,7 @@ def test_plot_planet_corotation(test_data_dir):
.map("phi", rotate_with="planet0.dat")
.data
)
assert (
find_nearest(azimfieldPlanet, azimfieldPlanet.max()) == ds["RHO"].shape[2] // 2
)
assert find_nearest(azimfieldPlanet, azimfieldPlanet.max()) == 0


def test_unit_conversion(test_data_dir, temp_figure_and_axis):
Expand Down Expand Up @@ -185,7 +183,7 @@ def test_corotation_api_float(test_data_dir):
ds = GasDataSet(23)
case1 = ds["RHO"].map("x", "y", rotate_with="planet0.dat")
ds = GasDataSet(23)
case2 = ds["RHO"].map("x", "y", rotate_by=-1.2453036989845032)
case2 = ds["RHO"].map("x", "y", rotate_by=1.89628895460529)

npt.assert_array_equal(case1.data, case2.data)

Expand Down

0 comments on commit f45b87d

Please sign in to comment.