def __init__(self, rootname, snap, fdir='.', sel_units = 'cgs', verbose=True): self.fdir = fdir self.rootname = rootname self.savefile = rsav(os.path.join(fdir,rootname+'{:06d}'.format(snap)+'.sav')) self.snap = snap self.sel_units= sel_units self.verbose = verbose self.uni = Matsumotosav_units() self.time = self.savefile['v']['time'][0].copy() self.grav = self.savefile['v']['gx'][0].copy() self.gamma = self.savefile['v']['gm'][0].copy() if self.sel_units=='cgs': self.x = self.savefile['v']['x'][0].copy() # cm self.y = self.savefile['v']['y'][0].copy() self.z = self.savefile['v']['z'][0].copy() self.dx = self.savefile['v']['dx'][0].copy() self.dy = self.savefile['v']['dy'][0].copy() self.dz = self.savefile['v']['dz'][0].copy() else: self.x = self.savefile['v']['x'][0].copy()/1e8 # Mm self.y = self.savefile['v']['y'][0].copy()/1e8 self.z = self.savefile['v']['z'][0].copy()/1e8 self.dx = self.savefile['v']['dx'][0].copy()/1e8 self.dy = self.savefile['v']['dy'][0].copy()/1e8 self.dz = self.savefile['v']['dz'][0].copy()/1e8 self.nx = len(self.x) self.ny = len(self.y) self.nz = len(self.z) if self.nx > 1: self.dx1d = np.gradient(self.x) else: self.dx1d = np.zeros(self.nx) if self.ny > 1: self.dy1d = np.gradient(self.y) else: self.dy1d = np.zeros(self.ny) if self.nz > 1: self.dz1d = np.gradient(self.z) else: self.dz1d = np.zeros(self.nz) self.transunits = False self.cstagop = False # This will not allow to use cstagger from Bifrost in load self.hion = False # This will not allow to use HION from Bifrost in load self.genvar() document_vars.create_vardict(self) document_vars.set_vardocs(self)
def get_var(self,var , *args, snap=None, iix=None, iiy=None, iiz=None, layout=None, **kargs): ''' Reads the variables from a snapshot (snap). Parameters ---------- var - string Name of the variable to read. Must be Bifrost internal names. snap - integer, optional Snapshot number to read. By default reads the loaded snapshot; if a different number is requested, will load that snapshot. Axes: ----- y and z axes horizontal plane x-axis is vertical axis, top corona is first index and negative. Variable list: -------------- ro -- Density (g/cm^3) [nx, ny, nz] temperature -- Temperature (K) [nx, ny, nz] vx -- component x of the velocity (cm/s) [nx, ny, nz] vy -- component y of the velocity (cm/s) [nx, ny, nz] vz -- component z of the velocity (cm/s) [nx, ny, nz] bx -- component x of the magnetic field (G) [nx, ny, nz] by -- component y of the magnetic field (G) [nx, ny, nz] bz -- component z of the magnetic field (G) [nx, ny, nz] pressure -- Pressure (dyn/cm^2) [nx, ny, nz] ''' if snap != None: self.snap = snap self.savefile = rsav(os.path.join(self.fdir,self.rootname+'{:06d}'.format(self.snap)+'.sav')) if var in self.varn.keys(): varname=self.varn[var] else: varname=var try: if self.sel_units == 'cgs': varu=var.replace('x','') varu=varu.replace('y','') varu=varu.replace('z','') if (var in self.varn.keys()) and (varu in self.uni.uni.keys()): cgsunits = self.uni.uni[varu] else: cgsunits = 1.0 else: cgsunits = 1.0 self.data = self.savefile['v'][varname][0].T * cgsunits ''' if (np.shape(self.data)[0]>self.nx): self.data = (self.data[1:,:,:] + self.data[:-1,:,:]) / 2 if (np.shape(self.data)[1]>self.ny): self.data = (self.data[:,1:,:] + self.data[:,:-1,:]) / 2 if (np.shape(self.data)[2]>self.nz): self.data = (self.data[:,:,1:] + self.data[:,:,:-1]) / 2 ''' except: # Loading quantities if self.verbose: print('Loading composite variable',end="\r",flush=True) self.data = load_noeos_quantities(self,var, **kargs) if np.shape(self.data) == (): self.data = load_quantities(self,var,PLASMA_QUANT='', CYCL_RES='', COLFRE_QUANT='', COLFRI_QUANT='', IONP_QUANT='', EOSTAB_QUANT='', TAU_QUANT='', DEBYE_LN_QUANT='', CROSTAB_QUANT='', COULOMB_COL_QUANT='', AMB_QUANT='', HALL_QUANT='', BATTERY_QUANT='', SPITZER_QUANT='', KAPPA_QUANT='', GYROF_QUANT='', WAVE_QUANT='', FLUX_QUANT='', CURRENT_QUANT='', COLCOU_QUANT='', COLCOUMS_QUANT='', COLFREMX_QUANT='', **kargs) # Loading arithmetic quantities if np.shape(self.data) == (): if self.verbose: print('Loading arithmetic variable',end="\r",flush=True) self.data = load_arithmetic_quantities(self,var, **kargs) if document_vars.creating_vardict(self): return None elif var == '': print(help(self.get_var)) print('VARIABLES USING CGS OR GENERIC NOMENCLATURE') for ii in self.varn: print('use ', ii,' for ',self.varn[ii]) if hasattr(self,'vardict'): self.vardocs() return None return self.data
def get_var(self, var, *args, snap=None, iix=None, iiy=None, iiz=None, layout=None, **kargs): ''' Reads the variables from a snapshot (it). Parameters ---------- var - string Name of the variable to read. Must be Bifrost internal names. snap - integer, optional Snapshot number to read. By default reads the loaded snapshot; if a different number is requested, will load that snapshot. Axes: ----- z-axis is along the loop x and y axes are perperdicular to the loop Variable list: -------------- ro_cube -- Density (multipy by self.uni['rho'] to get in g/cm^3) te_cube -- Temperature (multipy by self.uni['tg'] to get in K) vx_cube -- component x of the velocity (multipy by self.uni['u'] to get in cm/s) vy_cube -- component y of the velocity (multipy by self.uni['u'] to get in cm/s) vz_cube -- component z of the velocity (multipy by self.uni['u'] to get in cm/s) bx_cube -- component x of the magnetic field (multipy by self.uni['b'] to get in G) by_cube -- component y of the magnetic field (multipy by self.uni['b'] to get in G) bz_cube -- component z of the magnetic field (multipy by self.uni['b'] to get in G) ''' if snap != None: self.snap = snap if var in self.varn.keys(): varname = self.varn[var] else: varname = var try: if self.sel_units == 'cgs': varu = var.replace('x', '') varu = varu.replace('y', '') varu = varu.replace('z', '') if (var in self.varn.keys()) and (varu in self.uni.uni.keys()): cgsunits = self.uni.uni[varu] else: cgsunits = 1.0 else: cgsunits = 1.0 if self.snap == None: varfile = self.varfile self.data = np.transpose(varfile[varname]) * cgsunits else: itname = '{:04d}'.format(self.snap) varfile = rsav(self.fdir + 'vars_' + self.rootname + '_' + itname + '.sav') self.data = np.transpose(varfile[varname]) * cgsunits # varfile = rsav(os.path.join(self.fdir,self.rootname+'_'+itname+'.sav')) except: # Loading quantities if self.verbose: print('Loading composite variable', end="\r", flush=True) self.data = load_noeos_quantities(self, var, **kargs) if np.shape(self.data) == (): self.data = load_quantities(self, var, PLASMA_QUANT='', CYCL_RES='', COLFRE_QUANT='', COLFRI_QUANT='', IONP_QUANT='', EOSTAB_QUANT='', TAU_QUANT='', DEBYE_LN_QUANT='', CROSTAB_QUANT='', COULOMB_COL_QUANT='', AMB_QUANT='', HALL_QUANT='', BATTERY_QUANT='', SPITZER_QUANT='', KAPPA_QUANT='', GYROF_QUANT='', WAVE_QUANT='', FLUX_QUANT='', CURRENT_QUANT='', COLCOU_QUANT='', COLCOUMS_QUANT='', COLFREMX_QUANT='', **kargs) # Loading arithmetic quantities if np.shape(self.data) == (): if self.verbose: print('Loading arithmetic variable', end="\r", flush=True) self.data = load_arithmetic_quantities(self, var, **kargs) if document_vars.creating_vardict(self): return None elif var == '': print(help(self.get_var)) print('VARIABLES USING CGS OR GENERIC NOMENCLATURE') for ii in self.varn: print('use ', ii, ' for ', self.varn[ii]) if hasattr(self, 'vardict'): self.vardocs() return None return self.data
def __init__(self, rootname, snap, fdir='./', sel_units='cgs', verbose=True): self.rootname = rootname self.fdir = fdir self.snap = snap self.sel_units = sel_units self.verbose = verbose self.uni = Cipmocct_units() params = rsav(os.path.join(self.fdir, 'params_' + rootname + '.sav')) if snap == None: self.x = params['x1'].copy() self.y = params['x3'].copy() self.z = params['time'].copy() self.nx = len(params['x1']) self.ny = len(params['x3']) self.nz = len(params['time']) if self.sel_units == 'cgs': self.x *= self.uni.uni['l'] self.y *= self.uni.uni['l'] self.time = params['time'] # No uniform (array) self.varfile = rsav( os.path.join(self.fdir, 'variables_' + self.rootname + '.sav')) else: self.x = params['x1'].copy() self.y = params['x3'].copy() self.z = params['x2'].copy() self.nx = len(params['x1']) self.ny = len(params['x3']) self.nz = len(params['x2']) if self.sel_units == 'cgs': self.x *= self.uni.uni['l'] self.y *= self.uni.uni['l'] self.z *= self.uni.uni['l'] self.time = params['time'] # No uniform (array) if self.nx > 1: self.dx1d = np.gradient(self.x) self.dx = self.dx1d else: self.dx1d = np.zeros(self.nx) self.dx = self.dx1d if self.ny > 1: self.dy1d = np.gradient(self.y) self.dy = self.dy1d else: self.dy1d = np.zeros(self.ny) self.dy = self.dy1d if self.nz > 1: self.dz1d = np.gradient(self.z) self.dz = self.dz1d else: self.dz1d = np.zeros(self.nz) self.dz = self.dz1d self.transunits = False self.cstagop = False # This will not allow to use cstagger from Bifrost in load self.hion = False # This will not allow to use HION from Bifrost in load self.genvar() document_vars.create_vardict(self) document_vars.set_vardocs(self)
def __init__(self, snap, fdir='.', sel_units='cgs', verbose=True): self.fdir = fdir try: self.savefile = rsav( os.path.join(self.fdir, '{:03d}'.format(snap) + '.sav')) self.root_name = '{:03d}'.format(snap) except: self.savefile = rsav( os.path.join(self.fdir, '{:04d}'.format(snap) + '.sav')) self.root_name = '{:04d}'.format(snap) self.filename = self.savefile['d']['filename'][0] self.snap = snap self.sel_units = sel_units self.verbose = verbose self.uni = Laresav_units() self.set_time() self.visc_heating = self.savefile['d']['visc_heating'][0].copy() self.visc3_heating = self.savefile['d']['visc3_heating'][0].copy() self.x = self.savefile['d']['x'][0].copy().byteswap('=').newbyteorder( '=') self.y = self.savefile['d']['y'][0].copy().byteswap('=').newbyteorder( '=') self.z = self.savefile['d']['z'][0].copy().byteswap('=').newbyteorder( '=') self.z -= np.min(self.z) if self.sel_units == 'cgs': self.x *= self.uni.uni['l'] self.y *= self.uni.uni['l'] self.z *= self.uni.uni['l'] #GRID STRUCT -> <Anonymous> Array[1] self.nx = len(self.x) self.ny = len(self.y) self.nz = len(self.z) if self.nx > 1: self.dx1d = np.gradient(self.x) else: self.dx1d = np.zeros(self.nx) if self.ny > 1: self.dy1d = np.gradient(self.y) else: self.dy1d = np.zeros(self.ny) if self.nz > 1: self.dz1d = np.gradient(self.z) else: self.dz1d = np.zeros(self.nz) self.transunits = False self.cstagop = False # This will not allow to use cstagger from Bifrost in load self.hion = False # This will not allow to use HION from Bifrost in load self.genvar() document_vars.create_vardict(self) document_vars.set_vardocs(self)