Skip to content
Draft
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
128 changes: 27 additions & 101 deletions nonos/api/analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,7 @@ def __init__(
code: str = "",
directory="",
rotate_grid: bool = False,
cell_selected=None,
):
self.field = field
self.operation = operation
Expand All @@ -389,6 +390,10 @@ def __init__(
self.code = code
self.directory = directory
self.rotate_grid = rotate_grid
if cell_selected is None:
self.cell_selected = np.ma.array(self.data, mask=True)
else:
self.cell_selected = cell_selected

@property
def shape(self) -> Tuple[Any, ...]:
Expand Down Expand Up @@ -590,6 +595,7 @@ def find_phip(self, planet_number: int = 0):
def latitudinal_projection(self, theta=None):
operation = self.operation + "_latitudinal_projection"
imid = self.find_imid()
cell_selected = np.ma.array(self.data, mask=False)
if self.native_geometry == "polar":
ret_coords = Coordinates(
self.native_geometry,
Expand All @@ -615,6 +621,8 @@ def latitudinal_projection(self, theta=None):
axis=1,
dtype="float64",
)
for iphi in range(self.shape[1]):
cell_selected[i, iphi, km : kp + 1] = np.ma.masked
# integral[i,km] = -1
# integral[i,kp] = 1
ret_data = integral.reshape(self.shape[0], self.shape[1], 1)
Expand All @@ -626,13 +634,13 @@ def latitudinal_projection(self, theta=None):
find_around(self.coords.theta, self.coords.thetamed[imid]),
self.coords.phi,
)
km = find_nearest(self.coords.theta, self.coords.theta.min())
kp = find_nearest(self.coords.theta, self.coords.theta.max())
km = find_nearest(self.coords.thetamed, self.coords.theta.min())
kp = find_nearest(self.coords.thetamed, self.coords.theta.max())
if theta is not None:
km = find_nearest(self.coords.theta, np.pi / 2 + theta)
kp = find_nearest(self.coords.theta, np.pi / 2 - theta)
km = find_nearest(self.coords.thetamed, np.pi / 2 - theta)
kp = find_nearest(self.coords.thetamed, np.pi / 2 + theta)
ret_data = (
np.sum(
np.nansum(
(
self.data
* self.coords.rmed[:, None, None]
Expand All @@ -643,6 +651,10 @@ def latitudinal_projection(self, theta=None):
dtype="float64",
)
).reshape(self.shape[0], 1, self.shape[2])
for ir in range(self.shape[0]):
for iphi in range(self.shape[2]):
cell_selected[ir, km : kp + 1, iphi] = np.ma.masked
cell_selected.mask = ~cell_selected.mask
return GasField(
self.field,
np.float32(ret_data),
Expand All @@ -654,107 +666,13 @@ def latitudinal_projection(self, theta=None):
code=self.code,
directory=self.directory,
rotate_grid=self.rotate_grid,
cell_selected=cell_selected,
)

# def latitudinal_projection(self, theta=None):
# operation = self.operation + "_latitudinal_projection"
# imid = self.find_imid()
# if self.native_geometry == "polar":
# ret_coords = Coordinates(
# self.native_geometry,
# self.coords.R,
# self.coords.phi,
# find_around(self.coords.z, self.coords.zmed[imid]),
# )
# # ret_coords = Coordinates(self.native_geometry, self.coords.R, find_around(self.coords.phi, self.coords.phimed[0]), self.coords.z)
# R = self.coords.Rmed
# z = self.coords.zmed
# kall = []
# iall = []
# integral = np.zeros((self.shape[0], self.shape[1]), dtype=">f4")
# for i in range(self.shape[0]):
# km = find_nearest(z, z.min())
# kp = find_nearest(z, z.max())
# if theta is not None:
# km = find_nearest(z, R[i] / np.tan(np.pi / 2 - theta))
# kp = find_nearest(z, R[i] / np.tan(np.pi / 2 + theta))
# for k in range(kp, km - 2, -1):
# kall.append(k)
# iall.append(find_nearest(R, np.sqrt(R[i] ** 2 - z[k] ** 2)))
# knall = np.array(kall)[
# np.where(
# (z[kall] < R[iall] / np.tan(np.pi / 2 - theta))
# & (z[kall] > R[iall] / np.tan(np.pi / 2 + theta))
# )[0]
# ]
# inall = np.array(iall)[
# np.where(
# (z[kall] < R[iall] / np.tan(np.pi / 2 - theta))
# & (z[kall] > R[iall] / np.tan(np.pi / 2 + theta))
# )[0]
# ]
# kall = knall
# iall = inall
# integral[i, :] = np.nansum(
# self.data[iall[:-1], :, kall[:-1]]
# * R[iall[:-1]][:, None]
# * np.ediff1d(np.arctan2(R[iall], z[kall]))[:, None],
# axis=0,
# dtype="float64",
# )
# iall = []
# kall = []
# # integral[i, :] = np.nansum(
# # (self.data[i, :, :] * np.ediff1d(self.coords.z)[None, :])[
# # :, km : kp + 1
# # ],
# # axis=1,
# # dtype="float64",
# # )
# # integral[i,km] = -1
# # integral[i,kp] = 1
# ret_data = integral.reshape(self.shape[0], self.shape[1], 1)
# # ret_data = integral.reshape(self.shape[0],1,self.shape[2])
# if self.native_geometry == "spherical":
# ret_coords = Coordinates(
# self.native_geometry,
# self.coords.r,
# find_around(self.coords.theta, self.coords.thetamed[imid]),
# self.coords.phi,
# )
# km = find_nearest(self.coords.thetamed, self.coords.theta.min())
# kp = find_nearest(self.coords.thetamed, self.coords.theta.max())
# if theta is not None:
# km = find_nearest(self.coords.thetamed, np.pi / 2 - theta)
# kp = find_nearest(self.coords.thetamed, np.pi / 2 + theta)
# ret_data = (
# np.nansum(
# (
# self.data
# * self.coords.rmed[:, None, None]
# * np.sin(self.coords.thetamed[None, :, None])
# * np.ediff1d(self.coords.theta)[None, :, None]
# )[:, km : kp + 1, :],
# axis=1,
# dtype="float64",
# )
# ).reshape(self.shape[0], 1, self.shape[2])
# return GasField(
# self.field,
# np.float32(ret_data),
# ret_coords,
# self.native_geometry,
# self.on,
# operation,
# inifile=self.inifile,
# code=self.code,
# directory=self.directory,
# rotate_grid=self.rotate_grid,
# )

def vertical_projection(self, z=None):
operation = self.operation + "_vertical_projection"
imid = self.find_imid()
cell_selected = np.ma.array(self.data, mask=False)
if self.native_geometry == "cartesian":
ret_coords = Coordinates(
self.native_geometry,
Expand All @@ -774,6 +692,9 @@ def vertical_projection(self, z=None):
dtype="float64",
)
).reshape(self.shape[0], self.shape[1], 1)
for ix in range(self.shape[0]):
for iy in range(self.shape[1]):
cell_selected[ix, iy, km : kp + 1] = np.ma.masked
if self.native_geometry == "polar":
ret_coords = Coordinates(
self.native_geometry,
Expand All @@ -793,13 +714,17 @@ def vertical_projection(self, z=None):
dtype="float64",
)
).reshape(self.shape[0], self.shape[1], 1)
for iR in range(self.shape[0]):
for iphi in range(self.shape[1]):
cell_selected[iR, iphi, km : kp + 1] = np.ma.masked
if self.native_geometry == "spherical":
raise NotImplementedError(
"""
vertical_projection(z) function not implemented in spherical coordinates.\n
Maybe you could use the function latitudinal_projection(theta)?
"""
)
cell_selected.mask = ~cell_selected.mask
return GasField(
self.field,
np.float32(ret_data),
Expand All @@ -811,6 +736,7 @@ def vertical_projection(self, z=None):
code=self.code,
directory=self.directory,
rotate_grid=self.rotate_grid,
cell_selected=cell_selected,
)

def vertical_at_midplane(self):
Expand Down