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

Marcosertoli/equilibrium not nan #334

Merged
merged 29 commits into from
Jul 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
f78d7c0
feat: first forays into updating Indica
Jun 18, 2024
4e27914
feat: 3.11 compatibility
Jun 20, 2024
2b35705
feat: passed precommit
Jun 20, 2024
49a5e14
fix: disabled mypy precommit due to system error
Jun 20, 2024
55e9ab8
readme: edited readme
Jun 20, 2024
216dfdf
fix: ppts reader data ambiguity
Jun 20, 2024
bdc6250
Fixed README.md for installation guidelines and consequent .lock file
marcosertoli Jun 20, 2024
bb998fa
Fixed 3.11 DataArray.data in another few instances
marcosertoli Jun 20, 2024
b16ed70
Deleted print statement
marcosertoli Jun 20, 2024
352046c
Upgraded default object .pkl to new versions.
marcosertoli Jun 20, 2024
9aea62b
Deleted print statement
marcosertoli Jun 20, 2024
cd6ce6c
feat: updated poetry
Jun 24, 2024
fcd5ff1
Merge branch 'jussihakosalo/indica311' of github.com:indica-mcf/Indic…
Jun 24, 2024
6e2ae84
feat: version fix
Jun 24, 2024
28ed998
Marcosertoli/311 further dataarray harmonisation (#329)
marcosertoli Jun 24, 2024
2daa0f8
Fixed bug in PPTS reader (#330)
marcosertoli Jun 24, 2024
4224e74
fix: rebuilt poetry lock
Jun 24, 2024
f840933
Merge branch 'jussihakosalo/indica311' of github.com:indica-mcf/Indic…
Jun 24, 2024
1bc63e8
Adding example runs for diagnostic models (#331)
marcosertoli Jun 24, 2024
a36533d
Upgraded python version in poetry dev dependencies & ipython
marcosertoli Jun 25, 2024
3f628a0
Previous implementation was returning rhos with NaNs as fill_value wh…
marcosertoli Jun 25, 2024
99ca1f5
Github CI workflows now asking for python 3.11
marcosertoli Jun 25, 2024
e026677
More R_shift fixing: (R,z) range of PSI and RHO must be restricted to…
marcosertoli Jun 26, 2024
a2287d7
Fixed revision reading across all methods
marcosertoli Jul 2, 2024
7b508c6
Changed R_midplane -> R, rpos -> R, zpos -> z for consistency across …
marcosertoli Jul 2, 2024
f4f63e7
Refactoring ASTRA available_quantities.py - reader also need reproces…
marcosertoli Jul 2, 2024
fba7bfb
Assigning PPTS z as additional coordinate to midplane fit
marcosertoli Jul 3, 2024
5490d6e
Merged main in.
marcosertoli Jul 3, 2024
f7ccce3
Fixed XRCS wavelength rescaling
marcosertoli Jul 4, 2024
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
24 changes: 3 additions & 21 deletions indica/converters/transect.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,35 +69,17 @@ def __init__(
self._machine_dims = machine_dimensions
self.x = xr.DataArray(
x_positions,
coords={
self.x1_name: self.x1.data
if isinstance(self.x1, xr.DataArray)
else self.x1
},
dims=self.x1_name,
coords={self.x1_name: self.x1.data},
)
self.y = xr.DataArray(
y_positions,
coords={
self.x1_name: self.x1.data
if isinstance(self.x1, xr.DataArray)
else self.x1
},
dims=self.x1.name,
coords={self.x1_name: self.x1.data},
)
self.z = xr.DataArray(
z_positions,
coords={
self.x1_name: self.x1.data
if isinstance(self.x1, xr.DataArray)
else self.x1
},
dims=self.x1_name,
coords={self.x1_name: self.x1.data},
)

# self.x: DataArray = DataArray(x_positions, coords=[(self.x1_name, self.x1)])
# self.y: DataArray = DataArray(y_positions, coords=[(self.x1_name, self.x1)])
# self.z: DataArray = DataArray(z_positions, coords=[(self.x1_name, self.x1)])
self.R: DataArray = np.sqrt(self.x**2 + self.y**2)
self.rho: DataArray
self.theta: DataArray
Expand Down
74 changes: 37 additions & 37 deletions indica/equilibrium.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,20 @@ def __init__(
self.rbnd = equilibrium_data["rbnd"]
self.zmag = equilibrium_data["zmag"]
self.zbnd = equilibrium_data["zbnd"]
if "rmji" and "rmjo" in equilibrium_data:
self.rmji = equilibrium_data["rmji"]
self.rmjo = equilibrium_data["rmjo"]
if "vjac" in equilibrium_data and "ajac" in equilibrium_data:
psin = equilibrium_data["vjac"].rho_poloidal ** 2
dpsin = psin[1] - psin[0]
self.volume = (equilibrium_data["vjac"] * dpsin).cumsum("rho_poloidal")
self.area = (equilibrium_data["ajac"] * dpsin).cumsum("rho_poloidal")
elif "volume" in equilibrium_data and "area" in equilibrium_data:
self.volume = equilibrium_data["volume"]
self.area = equilibrium_data["area"]
else:
raise ValueError("No volume or area information")

self.zx = self.zbnd.min("arbitrary_index")
self.rhotor = np.sqrt(
(self.ftor - self.ftor.sel(rho_poloidal=0.0))
Expand All @@ -72,7 +86,9 @@ def __init__(
self.psi = equilibrium_data["psi"]
self.rho = np.sqrt((self.psi - self.faxs) / (self.fbnd - self.faxs))

# Shift equilibrium
# TODO: shift of equilibrium is a bad idea, but useful...
# - psi (R, z) is restricted to new limits to avoid NaNs
# - volume is not changed so is inconsistent!
if isinstance(R_shift, float):
R_offset = xr.full_like(self.t, R_shift)
else:
Expand All @@ -81,45 +97,29 @@ def __init__(
z_offset = xr.full_like(self.t, z_shift)
else:
z_offset = z_shift.interp(t=self.t, kwargs={"fill_value": 0})
self.R_offset = R_offset
self.z_offset = z_offset

R_new = self.psi.R + self.R_offset
z_new = self.psi.z + self.z_offset
self.psi = self.psi.interp(R=R_new, z=z_new)
self.rho = self.rho.interp(
R=R_new, z=z_new, kwargs={"fill_value": self.rho.max()}
)
self.rmag -= self.R_offset
self.zmag -= self.z_offset
self.rbnd -= self.R_offset
self.zbnd -= self.z_offset
self.zx -= self.z_offset

# Including workaround in case faxs or fbnd had messy data
if np.any(np.isnan(self.rho.interp(R=self.rmag, z=self.zmag))):
self.faxs = self.psi.interp(R=self.rmag, z=self.zmag).drop(["R", "z"])
self.fbnd = self.psi.interp(R=self.rbnd, z=self.zbnd).mean(
"arbitrary_index"
)

self.R_offset = xr.where(np.isfinite(R_offset), R_offset, 0)
self.z_offset = xr.where(np.isfinite(z_offset), z_offset, 0)
if np.any(np.abs(R_offset) > 0) or np.any(np.abs(z_offset) > 0):
R_new = self.psi.R + self.R_offset
z_new = self.psi.z + self.z_offset
R_range = slice(R_new.min("R").max("t"), R_new.max("R").min("t"))
z_range = slice(z_new.min("z").max("t"), z_new.max("z").min("t"))
self.psi = self.psi.interp(R=R_new, z=z_new).sel(R=R_range, z=z_range)
self.rho = self.rho.interp(R=R_new, z=z_new).sel(R=R_range, z=z_range)
self.rmag -= self.R_offset
self.zmag -= self.z_offset
self.rbnd -= self.R_offset
self.zbnd -= self.z_offset
self.zx -= self.z_offset
if hasattr(self, "rmji"):
self.rmji -= self.R_offset
if hasattr(self, "rmjo"):
self.rmjo -= self.R_offset

if np.any(np.isnan(self.rho)):
self.rho = xr.where(self.rho > 0, self.rho, 0.0)

self.t = self.rho.t
if "vjac" in equilibrium_data and "ajac" in equilibrium_data:
psin = equilibrium_data["vjac"].rho_poloidal ** 2
dpsin = psin[1] - psin[0]
self.volume = (equilibrium_data["vjac"] * dpsin).cumsum("rho_poloidal")
self.area = (equilibrium_data["ajac"] * dpsin).cumsum("rho_poloidal")
elif "volume" in equilibrium_data and "area" in equilibrium_data:
self.volume = equilibrium_data["volume"]
self.area = equilibrium_data["area"]
else:
raise ValueError("No volume or area information")
if "rmji" and "rmjo" in equilibrium_data:
self.rmji = equilibrium_data["rmji"] - self.R_offset
self.rmjo = equilibrium_data["rmjo"] - self.R_offset

self.Rmin = min(self.rho.coords["R"])
self.Rmax = max(self.rho.coords["R"])
self.zmin = min(self.rho.coords["z"])
Expand Down
Loading
Loading