def equ2sfc( job =None , \ InpDir =None , CnsFile =None, \ keys =None , GridMode=None, \ x1Range =None , x2Range =None, \ OutDir =None , \ silent =False, config =None ): # --- [1] 引数チェック --- # if (config is None): config = lcf.LoadConfig() if (job is None): job = config["equ_job"] if (GridMode is None): GridMode = config["equ_GridMode"] if (keys is None): keys = [config["equ_key"], "psi"] if (InpDir is None): InpDir = "../job/{0}/{1}/".format(job, GridMode) if (CnsFile is None): CnsFile = "../job/{0}/{1}/parameter.dat".format(job, GridMode) if (OutDir is None): OutDir = "../job/{0}/{1}/pdf/".format(job, GridMode) # --- [2] データ呼び出し --- # Dkeys = keys if (not ("psi" in keys)): Dkeys = keys + ["psi"] Data = feq.FetchEQU( job =job , InpDir =InpDir , CnsFile=CnsFile, \ keys =Dkeys , GridMode=GridMode, \ x1Range=x1Range, x2Range =x2Range , \ silent =silent , config =config ) # --- [3] プロット --- # xAxis = +Data["xAxis"] yAxis = +Data["yAxis"] flux = +Data["psi"] for key in keys: sfcMap = Data[key] FigName = "{0}sfc-{1}_.png".format(OutDir, key) print("[equ2sfc] {0} is under processing...".format(FigName), end="") fig = sfc.sfc3D( xAxis =yAxis , yAxis =xAxis , sfc=sfcMap, Cntr=flux, \ FigName=FigName, config=config ) print("\t [Done]")
def divBcheck( job =None , InpDir =None , CnsFile =None, \ GridMode=None , x1Range =None , x2Range =None, \ OutDir =None , \ silent =False, config =None ): # --- [1] 引数チェック --- # if ( config is None ): config = lcf.LoadConfig() if ( job is None ): job = config["equ_job"] if ( GridMode is None ): GridMode = config["equ_GridMode"] if ( InpDir is None ): InpDir = "../job/{0}/{1}/" .format( job, GridMode ) if ( CnsFile is None ): CnsFile = "../job/{0}/{1}/parameter.dat".format( job, GridMode ) if ( OutDir is None ): OutDir = "../job/{0}/{1}/pdf/" .format( job, GridMode ) # --- [2] データ呼び出し --- # Dkeys = ["Bx","By","Bz"] Data = feq.FetchEQU( job =job , InpDir =InpDir , CnsFile=CnsFile, \ keys =Dkeys , GridMode=GridMode, \ x1Range=x1Range, x2Range =x2Range , \ silent =silent , config =config ) # --- [3] プロット --- # xAxis = Data["xAxis"] yAxis = Data["yAxis"] divB = div.div2d( x1g=Data["xAxis"], x2g=Data["yAxis"], \ u1 =Data["Bz"] , u2 =Data["Bx"] , \ coordinate="RTZ" , difftype="Backward_dx1") print( Data["Bx"].shape, Data["Bz"].shape, divB.shape ) print( divB )
def show__bfield(datFile=None, pngFile=None, config=None): # ------------------------------------------------- # # --- [1] Arguments --- # # ------------------------------------------------- # if (datFile is None): datFile = "dat/shimField.dat" if (pngFile is None): pngFile = "png/shimField.png" if (config is None): config = lcf.LoadConfig() # ------------------------------------------------- # # --- [2] Fetch Data --- # # ------------------------------------------------- # with open(datFile, "r") as f: Data = np.loadtxt(f) # ------------------------------------------------- # # --- [3] config Settings --- # # ------------------------------------------------- # cfs.configSettings(configType="cMap2D_def", config=config) config["xTitle"] = "$X$" + " [m]" config["yTitle"] = "$Y$" + " [m]" config["cmp_AutoLevel"] = True config["cmp_MaxMin"] = [0.0, +1.0] config["cmp_xAutoRange"] = True config["cmp_yAutoRange"] = True config["cmp_xRange"] = [-5.0, +5.0] config["cmp_yRange"] = [-5.0, +5.0] config["xMajor_Nticks"] = 5 config["yMajor_Nticks"] = 5 config["MinimalOut"] = False # ------------------------------------------------- # # --- [4] plot Figure --- # # ------------------------------------------------- # fig = cmt.cMapTri(xAxis=xAxis, yAxis=yAxis, cMap=cMap, FigName=pngFile, config=config) fig = cm2.cMap2D(xAxis=xAxis, yAxis=yAxis, cMap=cMap, FigName=pngFile, config=config)
def equ2cmp( job =None , InpDir =None , CnsFile=None, keys=None , GridMode=None, \ x1Range=None , x2Range=None , OutDir =None, Flag__electronScale =True, \ silent =False, config =None ): # -------------------------- # # --- [1] 引数チェック --- # # -------------------------- # if (config is None): config = lcf.LoadConfig() if (job is None): job = config["equ_job"] if (GridMode is None): GridMode = config["equ_GridMode"] if (keys is None): keys = [config["equ_key"], "psi"] if (InpDir is None): InpDir = "../job/{0}/{1}/".format(job, GridMode) if (CnsFile is None): CnsFile = "../job/{0}/{1}/parameter.dat".format(job, GridMode) if (OutDir is None): OutDir = "../job/{0}/{1}/pdf/".format(job, GridMode) # -------------------------- # # --- [2] データ呼び出し --- # # -------------------------- # const = lcn.LoadConst(InpFile=CnsFile) Dkeys = keys if (not ("psi" in keys)): Dkeys = keys + ["psi"] Data = feq.FetchEQU( job =job , InpDir =InpDir , CnsFile=CnsFile, \ keys =Dkeys , GridMode=GridMode, \ x1Range=x1Range, x2Range =x2Range , \ silent =silent , config =config ) # -------------------------- # # --- [3] プロット --- # # -------------------------- # xAxis = Data["xAxis"] yAxis = Data["yAxis"] flux = Data["psi"] if (Flag__electronScale): xAxis = xAxis * const["wpewce"] yAxis = yAxis * const["wpewce"] cfs.configSettings(config=config, configType="cMap2D_def") for key in keys: FigName = "{0}{1}_.png".format(OutDir, key) clm.cMap2D( xAxis =yAxis , yAxis =xAxis , cMap=Data[key], Cntr=flux, \ FigName=FigName, config=config )
def LinearFilter1D(Data=None, alpha=None, nFilter=None, config=None): # ---------------------------------------- # # --- [1] 引数チェック --- # # ---------------------------------------- # if (Data is None): sys.exit("[fLIB__LinearFilter1D] Data= ??") if (config is None): config = lcf.LoadConfig() if (alpha is None): alpha = config["plt_LinearFilt"] if (nFilter is None): nFilter = 1 LI = Data.shape[0] ret = np.zeros((LI)) # ---------------------------------------- # # --- [2] ライブラリをロード --- # # ---------------------------------------- # # -- [2-1] ライブラリを定義 -- # path = os.path.expanduser('~') + "/.python/lib/nkFilterRoutines/" pyLIB = Flib.load_library('pylib.so', path) # -- [2-2] 入出力管理 -- # pyLIB.linearfilter1d_.argtypes = [ Flib.ndpointer(dtype=np.float64), Flib.ndpointer(dtype=np.float64), Flib.ndpointer(dtype=np.float64), ctypes.POINTER(ctypes.c_int64), ctypes.POINTER(ctypes.c_int64) ] pyLIB.linearfilter1d_.restype = ctypes.c_void_p # -- [2-3] Fortranサイズへ -- # Data_ = np.array(Data, dtype=np.float64) ret_ = np.array(ret, dtype=np.float64) alpha_ = np.array(alpha, dtype=np.float64) nFilter_ = ctypes.byref(ctypes.c_int64(nFilter)) LI_ = ctypes.byref(ctypes.c_int64(LI)) # ---------------------------------------- # # --- [3] 関数呼出 / 返却 --- # # ---------------------------------------- # pyLIB.linearfilter1d_(Data_, ret_, alpha_, nFilter_, LI_) return (ret_)
def FetchEQU( job =None , \ InpDir =None , CnsFile =None, \ keys =None , GridMode=None, \ x1Range =None , x2Range =None, \ silent =False, config =None \ ): # --- [1] 引数チェック --- # if ( config is None ): config = lcf.LoadConfig() if ( job is None ): job = config["equ_job"] if ( GridMode is None ): GridMode = config["equ_GridMode"] if ( keys is None ): keys = [ config["equ_key"], "psi" ] if ( InpDir is None ): InpDir = "../job/{0}/{1}/" .format( job, GridMode ) if ( CnsFile is None ): CnsFile = "../job/{0}/{1}/parameter.dat".format( job, GridMode ) # --- [2] データ呼び出し --- # const = lcn.LoadConst( InpFile=CnsFile ) xAxis = np.linspace( const["x1Min"], const["x1Max"], const["LI"] ) yAxis = np.linspace( const["x2Min"], const["x2Max"], const["LJ"] ) # -- [2-1] Bfd -- # InpFile = InpDir + "Bfd.bin" Bfd = lfb.LoadFortranBinary( InpFile =InpFile, \ rec =1, \ LI =3, \ LJ =const["LI"], \ LK =const["LJ"], \ order =config["LoadBinaryOrder"] \ ) # -- [2-2] Jcr -- # InpFile = InpDir + "Jcr.bin" Jcr = lfb.LoadFortranBinary( InpFile =InpFile, \ rec =1, \ LI =3, \ LJ =const["LI"], \ LK =const["LJ"], \ order =config["LoadBinaryOrder"] \ ) # -- [2-3] frp -- # InpFile = InpDir + "frp.bin" frp = lfb.LoadFortranBinary( InpFile =InpFile, \ rec =1, \ LI =3, \ LJ =const["LI"], \ LK =const["LJ"], \ order =config["LoadBinaryOrder"] \ ) # -- [2-4] uvc -- # InpFile = InpDir + "uvc.bin" uvc = lfb.LoadFortranBinary( InpFile =InpFile, \ rec =1, \ LI =3, \ LJ =const["LI"], \ LK =const["LJ"], \ order =config["LoadBinaryOrder"] \ ) Data = pil.pilearr( ( Bfd.transpose(2,0,1), Jcr.transpose(2,0,1), frp.transpose(2,0,1), uvc.transpose(2,0,1) ) \ , NoNewAxis=True ) # --- [3] Flux 磁束関数の返却 --- # flux = cfl.calcFlux( rg=yAxis, Bz=Data[2,:,:], indexing='ji' ) if ( config["reverseFlux"] ): flux = - flux if ( config["NormalizeFlux"] ): LIc, LJc = int( flux.shape[1]/2), int( flux.shape[0]/2 ) if ( flux[LJc,LIc] > 0.0 ): flux = flux / np.max( flux ) if ( flux[LJc,LIc] < 0.0 ): flux = flux / np.min( flux ) # --- [4] 切り出し : xRange, yRange で 検索して 返却 -- # if ( x1Range is not None ): idx = ( np.where( ( xAxis > x1Range[0] ) & ( xAxis < x1Range[1] ) ) )[0] Data = Data[:,:,idx] xAxis = xAxis[ idx] if ( config["Data_retPsi"] ): flux = flux[:,idx] if ( x2Range is not None ): idx = ( np.where( ( yAxis > x2Range[0] ) & ( yAxis < x2Range[1] ) ) )[0] Data = Data[:,idx,:] yAxis = yAxis[ idx] if ( config["Data_retPsi"] ): flux = flux[idx,:] # --- [5] 返却準備 --- # # -- [5-1] 対応表 -- # tbl = { "Bx" :0, "By" :1, "Bz" :2, "Jx":3, "Jy":4 , "Jz":5, "rho":7, "prs":8, "ux":9, "uy":10, "uz":11 } # -- [5-2] 荷造り -- # pack = '{ "xAxis":xAxis, "yAxis":yAxis, "flux":flux' for key in keys: if ( key in tbl.keys() ): pack += ', "' + str(key) + '":Data[{0},:,:]'.format( tbl[key] ) elif( key == "psi" ): pack += ', "psi":flux' else: sys.exit( " [ERROR] Unknown key -@FetchEQU- [ERROR] " ) pack = pack + "}" # --- [6] 返却 --- # if ( not(silent) ): print() print( "[FetchEQU] :: Return" ) print( "\t {0}".format(pack) ) ret = eval( pack ) return( ret )
def equ2cmp( job =None , InpDir =None , CnsFile =None, keys =None , GridMode=None, \ x1Range =None , x2Range =None , OutDir =None, Flag__electronScale=True, \ silent =False, config =None ): # --- [1] 引数チェック --- # if (config is None): config = lcf.LoadConfig() if (job is None): job = config["equ_job"] if (GridMode is None): GridMode = config["equ_GridMode"] if (keys is None): keys = [config["equ_key"], "psi"] if (InpDir is None): InpDir = "../../job/{0}/{1}/".format(job, GridMode) if (CnsFile is None): CnsFile = "{0}parameter.dat".format(InpDir) if (OutDir is None): OutDir = "{0}pdf/".format(InpDir) # --- [2] データ呼び出し --- # const = lcn.LoadConst(InpFile=CnsFile) Dkeys = keys if (not ("psi" in keys)): Dkeys = keys + ["psi"] Data = feq.FetchEQU( job =job , InpDir =InpDir , CnsFile=CnsFile, \ keys =Dkeys , GridMode=GridMode, \ x1Range=x1Range, x2Range =x2Range , \ silent =silent , config =config ) # --- [3] プロット --- # xAxis = +Data["xAxis"] yAxis = +Data["yAxis"] flux = +Data["psi"] if (Flag__electronScale): xAxis = xAxis * const["wpewce"] yAxis = yAxis * const["wpewce"] cfs.configSettings(config=config, configType="cMap2D_thesis") config["axes_x_NoLabel"] = True config["axes_y_NoLabel"] = True # -- Jy -- # key = "Jy" config["cnt_Color"] = "grey" config["cmp_ColorTable"] = "jet" config["cmp_AutoLevel"] = False config["cmp_MaxMin"] = [0, 0.2] FigName = "{0}{1}_.png".format(OutDir, key) print("[equ2cmp] {0:30} is under processing...".format(FigName), end="") clm.cMap2D( xAxis =yAxis , yAxis =xAxis , cMap=Data[key], Cntr=flux, \ FigName=FigName, config=config ) print("\t [Done]") # -- By -- # key = "By" config["cnt_Color"] = "grey" config["cmp_ColorTable"] = "bwr" config["cmp_AutoLevel"] = False config["cmp_MaxMin"] = [-5, 5] FigName = "{0}{1}_.png".format(OutDir, key) print("[equ2cmp] {0:30} is under processing...".format(FigName), end="") clm.cMap2D( xAxis =yAxis , yAxis =xAxis , cMap=Data[key], Cntr=flux, \ FigName=FigName, config=config ) print("\t [Done]") # -- psi -- # key = "psi" config["cnt_Color"] = "DeepSkyBlue" config["cmp_ColorTable"] = "hot" config["cmp_AutoLevel"] = False config["cmp_MaxMin"] = [-1.4, 1.0] FigName = "{0}{1}_.png".format(OutDir, key) print("[equ2cmp] {0:30} is under processing...".format(FigName), end="") clm.cMap2D( xAxis =yAxis , yAxis =xAxis , cMap=Data[key], Cntr=flux, \ FigName=FigName, config=config ) print("\t [Done]")
def LinearFilter2D( Data =None, alpha =None, coordinate=None , config=None, nFilter=1, \ x1Axis=None, x2Axis=None, dx1=None, dx2=None, x1Min =None, x2Min =None ): # ---------------------------------------- # # --- [1] 引数チェック --- # # ---------------------------------------- # if ( config is None ): config = lcf.LoadConfig() if ( Data is None ): sys.exit( "[fLIB__LinearFilter2D] v1 ???" ) if ( alpha is None ): alpha = config["cmp_LinearFilt"] if ( coordinate is None ): coordinate = config["Coordinate"] LI, LJ = Data.shape[1], Data.shape[0] ret = np.zeros( ( LJ,LI ) ) # ---------------------------------------- # # --- [2] ライブラリをロード --- # # ---------------------------------------- # # -- [2-1] ライブラリを定義 -- # path = os.path.expanduser('~') + "/.python/lib/nkFilterRoutines/" pyLIB = Flib.load_library( 'pylib.so', path ) # ---------------------------------------- # # --- [3] xyz 座標系 --- # # ---------------------------------------- # if ( coordinate=="xyz" ): # -- [3-1] 入出力管理 -- # pyLIB.linearfilter2d_.argtypes = [ Flib.ndpointer( dtype=np.float64 ), Flib.ndpointer( dtype=np.float64 ), Flib.ndpointer( dtype=np.float64 ), ctypes.POINTER( ctypes.c_int64 ), ctypes.POINTER( ctypes.c_int64 ) ] pyLIB.linearfilter2d_.restype = ctypes.c_void_p # -- [3-2] Fortranサイズへ -- # Data_ = np.array( Data , dtype=np.float64 ) ret_ = np.array( ret , dtype=np.float64 ) alpha_ = np.array( alpha , dtype=np.float64 ) LI_ = ctypes.byref( ctypes.c_int64( LI ) ) LJ_ = ctypes.byref( ctypes.c_int64( LJ ) ) # ---------------------------------------- # # --- [4] 関数呼出 / 返却 --- # # ---------------------------------------- # pyLIB.linearfilter2d_( Data_, ret_, alpha_, LI_, LJ_ ) elif ( coordinate=="rtz" ): # -- [4-1] 座標軸準備 -- # if ( x1Axis is None ): x1Axis = dx1*np.arange( LI ) + x1Min if ( x2Axis is None ): x2Axis = dx2*np.arange( LJ ) + x2Min # -- [4-2] 入出力管理 -- # pyLIB.cyllinearfilter2d_.argtypes = [ Flib.ndpointer( dtype=np.float64 ), Flib.ndpointer( dtype=np.float64 ), Flib.ndpointer( dtype=np.float64 ), Flib.ndpointer( dtype=np.float64 ), Flib.ndpointer( dtype=np.float64 ), ctypes.POINTER( ctypes.c_int64 ), ctypes.POINTER( ctypes.c_int64 ) ] pyLIB.cyllinearfilter2d_.restype = ctypes.c_void_p # -- [4-3] Fortranサイズへ -- # Data_ = np.array( Data , dtype=np.float64 ) ret_ = np.array( ret , dtype=np.float64 ) x1a_ = np.array( x1Axis, dtype=np.float64 ) x2a_ = np.array( x2Axis, dtype=np.float64 ) alpha_ = np.array( alpha , dtype=np.float64 ) LI_ = ctypes.byref( ctypes.c_int64( LI ) ) LJ_ = ctypes.byref( ctypes.c_int64( LJ ) ) # ---------------------------------------- # # --- [5] 関数呼出 / 返却 --- # # ---------------------------------------- # pyLIB.cyllinearfilter2d_( Data_, ret_, x1a_, x2a_, alpha_, LI_, LJ_ ) else: print( " coordinate = {0} ?? ".format( coordinate ) ) return( ret_ )