pencil.read.varraw ================== .. py:module:: pencil.read.varraw .. autoapi-nested-parse:: Contains classes and methods to read the varfile data. Fortran binary varfiles for all Pencil code I/O schemes supported. Selective reading of variables supported. The section with vector_groups is incomplete. Please add variable names as necessary. Reading reduced varfiles from 'data/reduced' not implemented, since that would require the same to be implemented in at least dims.py as well (and in grids.py also for completeness). swap_endian option has not been tested. Persistent variables not yet implemented. Downsampled snapshots not implemented. OGVAR files not implemented. IMPORTANT: the f array returned is Fortran-ordered: f[nx, ny, nz, nvar]. Please transpose if required. Classes ------- .. autoapisummary:: pencil.read.varraw.Varraw Functions --------- .. autoapisummary:: pencil.read.varraw.varraw Module Contents --------------- .. 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:class:: Varraw Bases: :py:obj:`object` Varraw -- holds Pencil Code VAR file data. Fill members with default values. .. py:attribute:: t :value: 0.0 .. py:attribute:: x :value: None .. py:attribute:: y :value: None .. py:attribute:: z :value: None .. py:attribute:: f :value: None .. py:attribute:: l1 :value: None .. py:attribute:: l2 :value: None .. py:attribute:: m1 :value: None .. py:attribute:: m2 :value: None .. py:attribute:: n1 :value: None .. py:attribute:: n2 :value: None .. py:method:: keys() .. py:method:: read(var_file='', datadir='data', proc=-1, ivar=-1, var_list=None, quiet=False, precision='d', trimall=False, swap_endian=False) read(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 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']]