@@ -174,10 +174,11 @@ def rV_vol_average(quant, r_V):
174174
175175
176176def rad_coord_transform (x , name_in , name_out , geqdsk ):
177- """Transform from one radial coordinate to another. Note that this coordinate conversion is only
177+ """
178+ Transform from one radial coordinate to another. Note that this coordinate conversion is only
178179 strictly valid inside of the LCFS. A number of common coordinate nomenclatures are accepted, but
179180 it is recommended to use one of the coordinate names indicated in the input descriptions below.
180-
181+
181182 Parameters
182183 ----------
183184 x: array or float
@@ -188,17 +189,18 @@ def rad_coord_transform(x, name_in, name_out, geqdsk):
188189 input x coordinate ('rhon','psin','rvol', 'rhop','rhov','Rmid','rmid','r/a')
189190 geqdsk: dict
190191 gEQDSK dictionary, as obtained from the omfit-eqdsk package.
191-
192+
192193 Returns
193194 -------
194195 array
195196 Conversion of `x` input for the requested radial grid coordinate.
196197 """
197198 if name_in == name_out :
198199 return x
200+
199201 x = copy .deepcopy (x )
200202
201- # avoid confusion with name conventions
203+ #hopefully avoid confusion with name conventions
202204 conventions = {
203205 "rvol" : "rvol" ,
204206 "r_vol" : "rvol" ,
@@ -222,6 +224,8 @@ def rad_coord_transform(x, name_in, name_out, geqdsk):
222224 name_in = conventions [name_in ]
223225 name_out = conventions [name_out ]
224226
227+
228+ # volume radius
225229 if "rvol" not in geqdsk ["fluxSurfaces" ]["geo" ]:
226230 R0 = geqdsk ["RMAXIS" ]
227231 eq_vol = geqdsk ["fluxSurfaces" ]["geo" ]["vol" ]
@@ -238,71 +242,73 @@ def rad_coord_transform(x, name_in, name_out, geqdsk):
238242 rvol = geqdsk ["fluxSurfaces" ]["geo" ]["rvol" ]
239243 # R at midplane
240244 Rmid = geqdsk ["fluxSurfaces" ]["midplane" ]["R" ]
241- # r at midplane
242245 R0 = geqdsk ["fluxSurfaces" ]["R0" ]
243- rmid = Rmid - R0
246+ # r at midplane
247+ rmid = geqdsk ["fluxSurfaces" ]["geo" ]["a" ]
244248
245249 # Interpolate to transform coordiantes
246250 if name_in == "rhon" :
247251 coord_in = rhon_ref
248- elif name_in == "psin" :
249- coord_in = psin_ref
250252 elif name_in == "rhop" :
251253 coord_in = rhop_ref
254+ elif name_in == "PsiN" :
255+ coord_in = rhop_ref
256+ x = n .sqrt (np .abs (x )) * np .sign (x )
252257 elif name_in == "rvol" :
253258 coord_in = rvol
254259 elif name_in == "rhov" :
255260 rvol_lcfs = np .interp (1 , rhon_ref , rvol )
256261 coord_in = rvol / rvol_lcfs
257262 elif name_in == "Rmid" :
258263 coord_in = rmid # use rmid since it starts at 0.0, making interpolation easier
259- x -= R0 # make x represent a rmid value
264+ x = x - R0 # make x represent a rmid value
260265 elif name_in == "rmid" :
261- coord_in = rmid
266+ coord_in = Rmid - R0
262267 elif name_in == "r/a" :
263268 rmid_lcfs = np .interp (1 , rhon_ref , rmid )
264269 coord_in = rmid / rmid_lcfs
265270 else :
266- raise ValueError ("Input coordinate was not recognized!" )
271+ raise ValueError (f "Input coordinate { name_in } was not recognized!" )
267272
268273 if name_out == "rhon" :
269274 coord_out = rhon_ref
270275 elif name_out == "psin" :
271276 coord_out = psin_ref
272277 elif name_out == "rhop" :
273278 coord_out = rhop_ref
279+ elif name_out == "PsiN" :
280+ coord_out = rhop_ref
274281 elif name_out == "rvol" :
275282 coord_out = rvol
276283 elif name_out == "rhov" :
277284 rvol_lcfs = np .interp (1 , rhon_ref , rvol )
278285 coord_out = rvol / rvol_lcfs
279286 elif name_out == "Rmid" :
280- coord_out = rmid # use rmid since it starts at 0.0, making interpolation easier
287+ coord_out = Rmid - R0 # use rmid since it starts at 0.0, making interpolation easier
281288 elif name_out == "rmid" :
282- coord_out = rmid
289+ coord_out = Rmid - R0
283290 elif name_out == "r/a" :
284291 rmid_lcfs = np .interp (1 , rhon_ref , rmid )
285292 coord_out = rmid / rmid_lcfs
286293 else :
287- raise ValueError ("Output coordinate was not recognized!" )
294+ raise ValueError (f "Output coordinate { name_out } was not recognized!" )
288295
289296 # trick for better extrapolation
290297 ind0 = coord_in == 0
291- out = np .interp (x , coord_in [~ ind0 ], coord_out [~ ind0 ] / coord_in [~ ind0 ]) * x
292-
293- if (x == coord_in [0 ]).any () and np .sum (ind0 ):
298+ out = np .interp (np .abs (x ), coord_in [~ ind0 ], coord_out [~ ind0 ] / coord_in [~ ind0 ]) * x
299+ if (x == coord_in [0 ]).any () and np .ndim (out ):
294300 x0 = x == coord_in [0 ]
301+
295302 out [x0 ] = coord_out [ind0 ] # give exact magnetic axis
296303
297304 if name_out == "Rmid" : # interpolation was done on rmid rather than Rmid
298305 out += R0
306+ if name_out == "PsiN" :
307+ out **= 2
299308
300309 return out
301310
302-
303-
304-
305-
311+
306312def rhoTheta2RZ (geqdsk , rho , theta , coord_in = 'rhop' , n_line = 201 ):
307313 '''Convert values of rho,theta into R,Z coordinates from a geqdsk dictionary.
308314
0 commit comments