pencil.read =========== .. py:module:: pencil.read .. autoapi-nested-parse:: Read data and parameters from data directories. Submodules ---------- .. toctree:: :maxdepth: 1 /code/sourcePython/pencil/read/allslices/index /code/sourcePython/pencil/read/averages/index /code/sourcePython/pencil/read/dims/index /code/sourcePython/pencil/read/fortran_file/index /code/sourcePython/pencil/read/grids/index /code/sourcePython/pencil/read/indices/index /code/sourcePython/pencil/read/ogdims/index /code/sourcePython/pencil/read/ogvar/index /code/sourcePython/pencil/read/params/index /code/sourcePython/pencil/read/pdfs/index /code/sourcePython/pencil/read/pdims/index /code/sourcePython/pencil/read/pencil_record_types/index /code/sourcePython/pencil/read/phiaverages/index /code/sourcePython/pencil/read/powers/index /code/sourcePython/pencil/read/pstalk/index /code/sourcePython/pencil/read/pstalk2/index /code/sourcePython/pencil/read/pvarfile/index /code/sourcePython/pencil/read/timeseries/index /code/sourcePython/pencil/read/varfile/index /code/sourcePython/pencil/read/varraw/index /code/sourcePython/pencil/read/zprof/index Attributes ---------- .. autoapisummary:: pencil.read.record_types Classes ------- .. autoapisummary:: pencil.read.PDim pencil.read.pdf Functions --------- .. autoapisummary:: pencil.read.pdim pencil.read.index pencil.read.ts pencil.read.power pencil.read.ogdim pencil.read.ogvar pencil.read.dim pencil.read.param pencil.read.grid pencil.read.var pencil.read.slices pencil.read.aver pencil.read.pvar pencil.read.phiaver pencil.read.varraw pencil.read.pstalk2 pencil.read.pstalk Package Contents ---------------- .. py:function:: pdim(*args, **kwargs) Wrapper for :py:meth:`PDim.read` .. py:class:: PDim Bases: :py:obj:`object` Class holding the data from pdim.dat and its methods. Fill members with default values. .. py:attribute:: npar :value: 0 .. py:attribute:: mpvar :value: 0 .. py:attribute:: npar_stalk :value: 0 .. py:attribute:: mpaux :value: 0 .. py:method:: keys() .. py:method:: read(datadir='data') read(sim=None, datadir='data') Read the pdim.dat file. :param sim: Specifies the simulation object from which to obtain the datadir. :type sim: obj :param datadir: Directory where the data is stored. :type datadir: string :rtype: Object containing the particle dimensions. .. py:function:: index(*args, **kwargs) index(datadir='data', param=None, dim=None) Read Pencil Code index data from index.pro. :param datadir: Directory where the data is stored. :type datadir: string :param param: Parameter object. :type param: obj :param dim: Dimension object. :type dim: obj :rtype: Class containing the index information. .. py:function:: ts(*args, **kwargs) Wrapper for :py:meth:`TimeSeries.read` .. py:class:: pdf(datadir='data', filename=None, debug=False) Reads the output of the power_xy subroutine Arguments datadir: path to the data directory. Default: "data" filename: name of the file to read. Default: all files named pdf_*.dat Examples >>> p = pc.read.pdfs() >>> p.t #1D array, length nt >>> p.lnrho #PDFContainer instance >>> p.lnrho.bins: #1D array, length nb >>> p.lnrho.counts #2D array, size (nt,nb): counts in each bin at a particular timestep >>> plt.semilogy(p.lnrho.bin_centers, p.lnrho.calc_counts(t_min=10)) #plots the PDF of lnrho for t>10 Attributes t: 1D array, times Remaining attributes are PDFContainer instances, named after the variables whose PDFs are being calculated. .. py:method:: keys() .. py:function:: power(*args, **kwargs) Wrapper for :py:meth:`Power.read` .. py:function:: ogdim(*args, **kwargs) ogdim(datadir='data', proc=-1) Read the ogdim.dat file. :param datadir: Directory where the data is stored. :type datadir: string :param proc: Processor to be read. If proc is -1, then read the 'global' dimensions. If proc is >=0, then read the dim.dat in the corresponding processor directory. :type proc: int :rtype: Class containing the simulation dimensions. .. py:function:: ogvar(*args, **kwargs) ogvar(var_file='', datadir='data', proc=-1, iogvar=-1, quiet=True, trimall=False, magic=None, sim=None, precision='f') Read OGVAR files from Pencil Code. If proc < 0, then load all data and assemble, otherwise load OGVAR file from specified processor. The file format written by output() (and used, e.g. in ogvar.dat) consists of the followinig Fortran records: 1. data(mx, my, mz, nvar) 2. t(1), x(mx), y(my), z(mz), dx(1), dy(1), dz(1), deltay(1) Here nvar denotes the number of slots, i.e. 1 for one scalar field, 3 for one vector field, 8 for ogvar.dat in the case of MHD with entropy. but, deltay(1) is only there if lshear is on! need to know parameters. :param var_file: Name of the OGVAR file. :type var_file: string :param datadir: Directory where the data is stored. :type datadir: string :param proc: Processor to be read. If -1 read all and assemble to one array. :type proc: int :param iogvar: Index of the OGVAR file, if var_file is not specified. :type iogvar: int :param quiet: Flag for switching off output. :type quiet: bool :param trimall: Trim the data cube to exclude ghost zones. :type trimall: bool :param magic: Values to be computed from the data, e.g. B = curl(A). :type magic: list of string :param sim: Simulation sim object. :type sim: obj :param precision: Precision of the data. Either float 'f' or double 'd'. :type precision: string .. py:data:: record_types .. py:function:: dim(*args, **kwargs) Wrapper for :py:meth:`Dim.read` .. py:function:: param(*args, **kwargs) Wrapper for :py:meth:`Param.read` .. py:function:: grid(*args, **kwargs) Wrapper for :py:meth:`Grid.read` .. py:function:: var(*args, **kwargs) Wrapper for :py:meth:`DataCube.read` .. py:function:: slices(*args, **kwargs) Wrapper for :py:meth:`SliceSeries.read` .. py:function:: aver(*args, **kwargs) Wrapper for :py:meth:`Averages.read` .. py:function:: pvar(*args, **kwargs) pvar(pvarfile='', datadir='data', proc=-1, ipvar=-1, quiet=True, ID=False, pflist=None, sim=None, precision='f', dtype=np.float64) Read PVAR files from Pencil Code. If proc < 0, then load all data and assemble, otherwise load VAR file from specified processor. The file format written by output() (and used, e.g. in pvar.dat) consists of the followinig Fortran records: 1. [npar] 2. indices(npar) 3. pdata(npvar, npar) Here npvar denotes the number of slots, i.e. 1 for one scalar field, 3 for one vector field, 6 for pvar.dat in the case of npar particles with 3 coordinates and 3 velocity components. :param pvarfile: Name of the VAR file. If not specified, use var.dat (which is the latest snapshot of the fields) :type pvarfile: string :param datadir: Directory where the data is stored. :type datadir: string :param proc: Processor to be read. If -1 read all and assemble to one array. :type proc: int :param ipvar: Index of the VAR file, if var_file is not specified. :type ipvar: int :param quiet: Flag for switching off output. :type quiet: bool :param ID: Flag for including the particle IDs in the object. :type ID: bool :param pflist: If present list of exclusive basic pfarrays to include :type pflist: bool :param sim: Contains information about the local simulation. :type sim: pencil code simulation object :param precision: Float 'f', double 'd' or half 'half'. :type precision: string :param lpersist: Read the persistent variables if they exist :type lpersist: bool :returns: Instance of the pencil.read.var.DataCube class. All of the computed fields are imported as class members. :rtype: DataCube .. rubric:: Examples Read the latest var.dat file and print the shape of the uu array: >>> pvar = pc.read.pvar() >>> print(pvar.px.shape) Read the PVAR2 file, and include only the x coordinates and velocity e.g., for instance to reduce memory load for large arrays. >>> pvar = pc.read.pvar(pvar_file='PVAR2', pflist=['px','pvx']) >>> print(pvar.pvx.shape) .. py:function:: phiaver(*args, **kwargs) Wrapper for :py:meth:`Averages.read` .. py:function:: varraw(*args, **kwargs) varraw(var_file="", datadir="data", proc=-1, ivar=-1, var_list=None, quiet=False, precision="d", trimall=False, swap_endian=False) Read VAR files from Pencil Code. If proc < 0, then load all data and assemble, otherwise load VAR file from specified processor. The file format written by output() (and used, e.g. in var.dat) consists of the following Fortran records: 1. data(mx, my, mz, nvar) 2. t(1), x(mx), y(my), z(mz), dx(1), dy(1), dz(1), deltay(1) Here nvar denotes the number of slots, i.e. 1 for one scalar field, 3 for one vector field, 8 for var.dat in the case of MHD with entropy. but, deltay(1) is only there if lshear is on! need to know parameters. :param var_file: Name of the VAR file. If not specified, use var.dat (which is the latest snapshot of the fields) :type var_file: string :param datadir: Directory where the data is stored. :type datadir: string :param proc: Processor to be read. If -1, read all and assemble to one array. :type proc: int :param ivar: Index of the VAR file, if var_file is not specified. :type ivar: int :param var_list: List of variables to read. If not provided or empty, all available variables will be read by default. :type var_list: list of str :param quiet: Flag for switching off output. :type quiet: bool :param precision: Float 'f', double 'd' or half 'half'. :type precision: string :param trimall: Trim the data cube to exclude ghost zones. :type trimall: bool :param swap_endian: Flag for swapping the endianness. :type swap_endian: bool :returns: Class instance containing the varfile information. :rtype: Varraw .. rubric:: Examples Read the latest var.dat file and print the shape of the uu array: >>> var = pc.read.varraw() >>> print(var.uu.shape) Read the VAR2 file, only the logarithmic temperature & density, and remove the ghost zones: >>> var = pc.read.varraw(var_file='VAR2', var_list=['lnTT', 'lnrho'], trimall=True) >>> print(var.lnTT.shape) or >>> print(var.f[:,:,:,var.tags['lnTT']].shape) Read the VAR2 file, only the vector potential & z-velocity, in single precision: >>> var = pc.read.varraw(ivar=2, var_list=['aa', 'uz'], precision='f') >>> ay = var.ay[:] or >>> ay = var.aa[:,:,:,1] or >>> ay = var.f[:,:,:,var.tags['ay']] Read the VAR2 file, only the vector potential & z-velocity, in single precision: >>> var = pc.read.varraw(ivar=2, var_list=['ax', 'uz','ay','az'], precision='f') >>> ay = var.ay[:] or >>> ay = var.aa[:,:,:,1] or >>> ay = var.f[:,:,:,var.tags['ay']] .. py:function:: pstalk2(datadir='data', it0=0, it1=-1, swap_endian=False, quiet=False, noutmax=None, single=False, nstalk=None, ipar=None, read_last=False) Read Pencil Code particle stalker data (PSTALK) and return a Struct with dot-access fields: fs.t : (nout,) fs.ipar : (nstalk,) fs.: (nstalk, nout) for each field in particles_stalker_header.dat :param datadir: Base data directory (e.g. "data"). ~ expansion is supported. :type datadir: str :param it0: First time index to read (inclusive). :type it0: int :param it1: If >0, print a log line whenever it % it1 == 0. :type it1: int :param swap_endian: If True, swap endianness when reading the binary PSTALK files. :type swap_endian: bool :param quiet: If True, suppress most logging. :type quiet: bool :param noutmax: Maximum number of output times to read. None => use all available. Semantics match IDL: min(noutmax, noutmaxfile), with -1 meaning "all". :type noutmax: int or None :param single: If True, store output data in float32; otherwise float64. (Binary precision is auto-detected and then cast.) :type single: bool :param nstalk: Max number of stalked particles to keep. Defaults to pdim.npar_stalk. In non-sink mode, particles with index >= nstalk are ignored. In sink-particle mode, nstalk may be increased internally if needed. :type nstalk: int or None :param ipar: If given, read only these particle indices (memory-efficient). :type ipar: int or list of int or None :param read_last: If True, read only the last timestep (overrides it0) :type read_last: bool :returns: **fs** -- Container with fields t, ipar, and one field per stalk quantity. :rtype: Struct .. py:function:: pstalk(*args, **kwargs) Wrapper for :py:class:`ParticleStalkData`