-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Marcosertoli/separate examples (#342)
* New files with example models and transforms - moved from model files * Adapting all files to new example folder/file structure * Fixed transform plotting for both transect and los * Fixed linting
- Loading branch information
1 parent
cd74a9b
commit d056440
Showing
16 changed files
with
326 additions
and
716 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
from pathlib import Path | ||
import pickle | ||
from typing import Tuple | ||
|
||
import numpy as np | ||
|
||
from indica.models import Plasma | ||
from indica.models.plasma import PlasmaProfiles | ||
|
||
|
||
def example_plasma( | ||
machine: str = "st40", | ||
pulse: int = None, | ||
tstart=0.02, | ||
tend=0.1, | ||
dt=0.01, | ||
main_ion="h", | ||
impurities: Tuple[str, ...] = ("c", "ar", "he"), | ||
load_from_pkl: bool = True, | ||
**kwargs, | ||
): | ||
default_plasma_file = ( | ||
f"{Path(__file__).parent.parent}/data/{machine}_default_plasma_phantom.pkl" | ||
) | ||
|
||
if load_from_pkl and pulse is not None: | ||
try: | ||
print(f"\n Loading phantom plasma class from {default_plasma_file}. \n") | ||
return pickle.load(open(default_plasma_file, "rb")) | ||
except FileNotFoundError: | ||
print( | ||
f"\n\n No phantom plasma class file {default_plasma_file}. \n" | ||
f" Building it and saving to file. \n\n" | ||
) | ||
|
||
plasma = Plasma( | ||
tstart=tstart, | ||
tend=tend, | ||
dt=dt, | ||
main_ion=main_ion, | ||
impurities=impurities, | ||
**kwargs, | ||
) | ||
plasma.build_atomic_data() | ||
|
||
update_profiles = PlasmaProfiles(plasma) | ||
|
||
# Assign profiles to time-points | ||
nt = len(plasma.t) | ||
ne_peaking = np.linspace(1, 2, nt) | ||
te_peaking = np.linspace(1, 2, nt) | ||
_y0 = update_profiles.profilers["toroidal_rotation"].y0 | ||
vrot0 = np.linspace( | ||
_y0 * 1.1, | ||
_y0 * 2.5, | ||
nt, | ||
) | ||
vrot_peaking = np.linspace(1, 2, nt) | ||
|
||
_y0 = update_profiles.profilers["ion_temperature"].y0 | ||
ti0 = np.linspace(_y0 * 1.1, _y0 * 2.5, nt) | ||
|
||
_y0 = update_profiles.profilers[f"impurity_density:{impurities[0]}"].y0 | ||
nimp_y0 = _y0 * 5 * np.linspace(1, 8, nt) | ||
nimp_peaking = np.linspace(1, 5, nt) | ||
nimp_wcenter = np.linspace(0.4, 0.1, nt) | ||
for i, t in enumerate(plasma.t): | ||
parameters = { | ||
"electron_temperature.peaking": te_peaking[i], | ||
"ion_temperature.peaking": te_peaking[i], | ||
"ion_temperature.y0": ti0[i], | ||
"toroidal_rotation.peaking": vrot_peaking[i], | ||
"toroidal_rotation.y0": vrot0[i], | ||
"electron_density.peaking": ne_peaking[i], | ||
"impurity_density:ar.peaking": nimp_peaking[i], | ||
"impurity_density:ar.y0": nimp_y0[i], | ||
"impurity_density:ar.wcenter": nimp_wcenter[i], | ||
} | ||
update_profiles(parameters, t=t) | ||
|
||
if load_from_pkl and pulse is not None: | ||
print(f"\n Saving phantom plasma class in {default_plasma_file} \n") | ||
pickle.dump(plasma, open(default_plasma_file, "wb")) | ||
|
||
return plasma |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import numpy as np | ||
|
||
from indica.converters import LineOfSightTransform | ||
from indica.converters import TransectCoordinates | ||
|
||
|
||
def pi_transform_example(nchannels: int): | ||
x_positions = np.linspace(0.2, 0.8, nchannels) | ||
y_positions = np.linspace(0.0, 0.0, nchannels) | ||
z_positions = np.linspace(0.0, 0.0, nchannels) | ||
|
||
transect_transform = TransectCoordinates( | ||
x_positions, | ||
y_positions, | ||
z_positions, | ||
"pi", | ||
machine_dimensions=((0.15, 0.95), (-0.7, 0.7)), | ||
) | ||
return transect_transform | ||
|
||
|
||
def helike_transform_example(nchannels): | ||
los_end = np.full((nchannels, 3), 0.0) | ||
los_end[:, 0] = 0.17 | ||
los_end[:, 1] = 0.0 | ||
los_end[:, 2] = np.linspace(0.2, -0.5, nchannels) | ||
los_start = np.array([[0.9, 0, 0]] * los_end.shape[0]) | ||
los_start[:, 2] = -0.1 | ||
origin = los_start | ||
direction = los_end - los_start | ||
|
||
los_transform = LineOfSightTransform( | ||
origin[0:nchannels, 0], | ||
origin[0:nchannels, 1], | ||
origin[0:nchannels, 2], | ||
direction[0:nchannels, 0], | ||
direction[0:nchannels, 1], | ||
direction[0:nchannels, 2], | ||
name="xrcs", | ||
machine_dimensions=((0.15, 0.95), (-0.7, 0.7)), | ||
passes=1, | ||
) | ||
return los_transform | ||
|
||
|
||
def smmh1_transform_example(nchannels): | ||
los_start = np.array([[0.8, 0, 0]]) * np.ones((nchannels, 3)) | ||
los_start[:, 2] = np.linspace(0, -0.2, nchannels) | ||
los_end = np.array([[0.17, 0, 0]]) * np.ones((nchannels, 3)) | ||
los_end[:, 2] = np.linspace(0, -0.2, nchannels) | ||
origin = los_start | ||
direction = los_end - los_start | ||
los_transform = LineOfSightTransform( | ||
origin[:, 0], | ||
origin[:, 1], | ||
origin[:, 2], | ||
direction[:, 0], | ||
direction[:, 1], | ||
direction[:, 2], | ||
name="smmh1", | ||
machine_dimensions=((0.15, 0.95), (-0.7, 0.7)), | ||
passes=2, | ||
) | ||
return los_transform | ||
|
||
|
||
def ts_transform_example(nchannels): | ||
x_positions = np.linspace(0.2, 0.8, nchannels) | ||
y_positions = np.linspace(0.0, 0.0, nchannels) | ||
z_positions = np.linspace(0.0, 0.0, nchannels) | ||
transform = TransectCoordinates( | ||
x_positions, | ||
y_positions, | ||
z_positions, | ||
"ts", | ||
machine_dimensions=((0.15, 0.95), (-0.7, 0.7)), | ||
) | ||
return transform |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.