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

Modif correct distortion #17

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
6 changes: 6 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"[python]": {
"editor.defaultFormatter": "ms-python.autopep8"
},
"python.formatting.provider": "none"
}
Binary file modified INGRID/.DS_Store
Binary file not shown.
4 changes: 2 additions & 2 deletions INGRID/OMFITgeqdsk.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,12 @@ def merge(inv):
try:
# official gEQDSK file format saves PSIRZ as a single flat array of size rowsXcols
nlNWNH = int(np.ceil(self['NW'] * self['NH'] / 5.))
self['PSIRZ'] = np.reshape(np.fromiter(splitter(''.join(EQDSK[offset:offset + nlNWNH])), dtype=np.float64),(self['NH'], self['NW']))
self['PSIRZ'] = np.reshape(np.fromiter(splitter(''.join(EQDSK[offset:offset + nlNWNH])), dtype=float),(self['NH'], self['NW']))
offset = offset + nlNWNH
except ValueError:
# sometimes gEQDSK files save row by row of the PSIRZ grid (eg. FIESTA code)
nlNWNH = self['NH'] * nlNW
self['PSIRZ'] = np.reshape(np.fromiter(splitter(''.join(EQDSK[offset:offset + nlNWNH])), dtype=np.float64),(self['NH'], self['NW']))
self['PSIRZ'] = np.reshape(np.fromiter(splitter(''.join(EQDSK[offset:offset + nlNWNH])), dtype=float),(self['NH'], self['NW']))
offset = offset + nlNWNH
self['QPSI'] = np.array(list(map(np.float64, splitter(merge(EQDSK[offset:offset + nlNW])))))
offset = offset + nlNW
Expand Down
495 changes: 406 additions & 89 deletions INGRID/geometry.py

Large diffs are not rendered by default.

29 changes: 18 additions & 11 deletions INGRID/interpol.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from scipy.ndimage import zoom
from scipy.interpolate import RectBivariateSpline as rbs


class EfitData:
"""
Structure to store the rectangular grid of psi data. It uses
Expand Down Expand Up @@ -71,9 +72,9 @@ def __init__(self, rmin=0.0, rmax=1.0, nr=10, zmin=0.0, zmax=2.0, nz=20,
self.parent = parent
self.psi_levels = {}

def init_bivariate_spline(self, r: 'np.ndarray',
z: 'np.ndarray',
v: 'np.ndarray') -> None:
def init_bivariate_spline(self, r: 'np.ndarray',
z: 'np.ndarray',
v: 'np.ndarray') -> None:
""" Initialize scipy.interpolate.RectBivariateSpline
object for Bicubic interpolation.

Expand Down Expand Up @@ -162,7 +163,7 @@ def get_psi(self, r0, z0, tag='v'):

lookup = {'v': (0, 0), 'vr': (1, 0), 'vrr': (2, 0),
'vz': (0, 1), 'vzz': (0, 2), 'vrz': (1, 1)
}
}

dx, dy = lookup[tag]
return self.rbs(r0, z0, dx, dy)[0]
Expand All @@ -188,7 +189,7 @@ def plot_levels(self, level=1.0, color='red'):
self.ax.contour(self.r, self.z, self.v, level, colors=color)

def PlotLevel(self: object, level: float = 1.0, color: str = 'red', label: str = '', linestyles: str = 'solid',
refined: bool = True, refine_factor: int = 10) -> None:
refined: bool = True, refine_factor: int = 20) -> None:
"""
Plot a psi level and provide it a label.

Expand Down Expand Up @@ -219,14 +220,17 @@ def PlotLevel(self: object, level: float = 1.0, color: str = 'red', label: str =
if refined is True:
data = zoom(input=self.v, zoom=refine_factor)
rgrid, zgrid = np.meshgrid(np.linspace(self.rmin, self.rmax, data.shape[0]),
np.linspace(self.zmin, self.zmax, data.shape[1]),
np.linspace(
self.zmin, self.zmax, data.shape[1]),
indexing='ij')
try:
self.psi_levels[label].collections[0].remove()
self.psi_levels[label] = plt.contour(rgrid, zgrid, data, [float(level)], colors=color, label=label, linestyles=linestyles)
self.psi_levels[label] = plt.contour(rgrid, zgrid, data, [float(
level)], colors=color, label=label, linestyles=linestyles)
self.psi_levels[label].collections[0].set_label(label)
except:
self.psi_levels[label] = plt.contour(rgrid, zgrid, data, [float(level)], colors=color, label=label, linestyles=linestyles)
self.psi_levels[label] = plt.contour(rgrid, zgrid, data, [float(
level)], colors=color, label=label, linestyles=linestyles)
self.psi_levels[label].collections[0].set_label(label)

def plot_data(self: object, nlevs: int = 30, interactive: bool = True, fig: object = None,
Expand Down Expand Up @@ -256,8 +260,10 @@ def plot_data(self: object, nlevs: int = 30, interactive: bool = True, fig: obje
Refinement factor for to be passed to SciPy zoom method
"""

lev = self.v.min() + (self.v.max() - self.v.min()) * np.arange(nlevs) / (nlevs - 1)
self.fig = fig if fig is not None else plt.figure('INGRID: ' + self.name, figsize=(8, 10))
lev = self.v.min() + (self.v.max() - self.v.min()) * \
np.arange(nlevs) / (nlevs - 1)
self.fig = fig if fig is not None else plt.figure(
'INGRID: ' + self.name, figsize=(8, 10))
self.fig.subplots_adjust(bottom=0.075)
self.ax = ax if ax is not None else self.fig.add_subplot(111)

Expand All @@ -268,7 +274,8 @@ def plot_data(self: object, nlevs: int = 30, interactive: bool = True, fig: obje
if refined is True:
data = zoom(input=self.v, zoom=refine_factor)
rgrid, zgrid = np.meshgrid(np.linspace(self.rmin, self.rmax, data.shape[0]),
np.linspace(self.zmin, self.zmax, data.shape[1]),
np.linspace(
self.zmin, self.zmax, data.shape[1]),
indexing='ij')
if view_mode == 'lines':
self.ax.contour(rgrid, zgrid, data, lev, cmap='gist_gray')
Expand Down
Loading