@@ -1888,6 +1888,8 @@ def Rfunc(self, x, z, phi):
18881888
18891889
18901890class EMC3 (MagneticField ):
1891+ """Field based on a EMC3 grid file"""
1892+
18911893 def __init__ (self , ds ):
18921894 self .ds = ds
18931895 assert hasattr (ds , "emc3" ), "Expected an xemc3 dataset. Is xemc3 imported?"
@@ -1899,7 +1901,6 @@ def Bxfunc(self, x, z, phi):
18991901 raise NotImplementedError ("Use maybe EMC3 tracer?" )
19001902
19011903 def Byfunc (self , x , z , phi ):
1902- # raise NotImplementedError("Use maybe EMC3 tracer?")
19031904 return self .Bmag (x , z , phi )
19041905
19051906 def Bzfunc (self , x , z , phi ):
@@ -1914,45 +1915,20 @@ def Bmag(self, x, z, phi):
19141915 ].values
19151916 nans = np .isnan (vals )
19161917 if np .any (nans ):
1917- if 1 :
1918- from scipy .interpolate import CubicSpline as CS
1919-
1920- for i in range (x .shape [1 ]):
1921- ni = nans [:, i ]
1922- if not np .any (ni ):
1923- continue
1924- xi = x [:, i ]
1925- zi = z [:, i ]
1926- vi = vals [:, i ]
1927- si = np .zeros_like (xi )
1928- si [1 :] = np .cumsum (
1929- np .sqrt ((xi [1 :] - xi [:- 1 ]) ** 2 + (zi [1 :] - zi [:- 1 ]) ** 2 )
1930- )
1931- interp = CS (si [~ ni ], vi [~ ni ])
1932- vals [ni , i ] = interp (si [ni ])
1933- else :
1934- from scipy .interpolate import LinearNDInterpolator as LinInter
1935-
1936- if phi .shape == ():
1937- pos = np .array ((x , z ))
1938- else :
1939- pos = np .array ((x , z , phi ))
1940- inter = LinInter (pos [:, ~ nans ].T , vals [~ nans ])
1941- print (vals [~ nans ])
1942-
1943- print (inter (pos [:, nans ].T ))
1944- vals [nans ] = inter (pos [:, nans ].T )
1945-
1946- import matplotlib .pyplot as plt
1947-
1948- plt .figure ()
1949- # plt.pcolormesh(X, Y, Z, shading='auto')
1950- plt .plot (* pos [:, ~ nans ], "ok" , label = "input point" )
1951- plt .plot (* pos [:, nans ], "or" , label = "evaled" )
1952- print (* pos [:, nans ].T )
1953- plt .legend ()
1954- # plt.colorbar()
1955- plt .axis ("equal" )
1956- plt .show ()
1918+ from scipy .interpolate import CubicSpline as CS
1919+
1920+ for i in range (x .shape [1 ]):
1921+ ni = nans [:, i ]
1922+ if not np .any (ni ):
1923+ continue
1924+ xi = x [:, i ]
1925+ zi = z [:, i ]
1926+ vi = vals [:, i ]
1927+ si = np .zeros_like (xi )
1928+ si [1 :] = np .cumsum (
1929+ np .sqrt ((xi [1 :] - xi [:- 1 ]) ** 2 + (zi [1 :] - zi [:- 1 ]) ** 2 )
1930+ )
1931+ interp = CS (si [~ ni ], vi [~ ni ])
1932+ vals [ni , i ] = interp (si [ni ])
19571933
19581934 return vals
0 commit comments