Skip to content

Python read_geqdsk function interpolating incorrectly #331

Description

@shaunhaskey

The python read_geqdsk function seems to be interpolating incorrectly (probably since the change to using RegularGridInterpolator:

import fidasim
import matplotlib.pyplot as plt
import numpy as np
geqdsk_fname=f"/home/shaskey/code/FSIM_NN/sim_files/g164988.03525"
rmin, rmax= 100., 250.
zmin, zmax = -150., 150.
nr = 500
nz = 300
grid = fidasim.utils.rz_grid(rmin, rmax, nr, zmin, zmax, nz)
equil, rhop, btipsign = fidasim.utils.read_geqdsk(geqdsk_fname, grid, poloidal=True)
fig, ax = plt.subplots()
im = ax.pcolormesh(grid['r2d']/100, grid['z2d']/100, rhop)
im.set_clim([0, 1.5])
ax.contour(grid['r2d']/100, grid['z2d']/100, rhop, 8, colors='k')
ax.set_xlabel('R [m]')
ax.set_ylabel('Z [m]')
fig.canvas.draw();fig.show()

Produces an image that doesn't look correct:
Image

I think this is the source of the problem, due to a recent switch from interp2d to RegularGridInterpolator:
https://github.com/D3DEnergetic/FIDASIM/blame/d727862a6b897ecca70610a4964583079968f812/lib/python/fidasim/utils.py#L934

psirz_itp = RectBivariateSpline(r, z, g["psirz"])

RectBivariateSpline expects the third argument to be x.size, y.size so [R_index, Z_index], so a .T is missing for g["psirz"]

This makes sense according to this where we expect to need to include a .T
https://scipy.github.io/devdocs/tutorial/interpolate/interp_transition_guide.html

Screenshot:
Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions