Пример #1
0
    def saveAsMatlab(self,
                     fileP,
                     reconvert=True,
                     metadata=None,
                     append=True,
                     format='5',
                     longNames=True,
                     compress=True,
                     oned='row'):
        """
        Write a binary MATLAB file from the contents of this reader

        .. deprecated:: 0.7.0
            Use :meth:`~serpentTools.DepletionReader.toMatlab`

        Parameters
        ----------
        fileP: str or file-like object
            Name of the file to write
        reconvert: bool
            If this evaluates to true, convert values back into their
            original form as they appear in the output file, e.g.
            ``MAT_TOTAL_ING_TOX``. Otherwise, maintain the ``mixedCase``
            style, ``total_ingTox``.
        metadata: bool or str or list of strings
            If this evaluates to true, then write all metadata to the
            file as well.
        append: bool
            If true and a file exists under ``output``, append to that file.
            Otherwise the file will be overwritten
        format: {'5', '4'}
            Format of file to write. ``'5'`` for MATLAB 5 to 7.2, ``'4'`` for
            MATLAB 4
        longNames: bool
            If true, allow variable names to reach 63 characters,
            which works with MATLAB 7.6+. Otherwise, maximum length is
            31 characters
        compress: bool
            If true, compress matrices on write
        oned: {'row', 'col'}:
            Write one-dimensional arrays as row vectors if
            ``oned=='row'`` (default), or column vectors

        Raises
        ------
        ImportError:
            If :term:`scipy` is not installed

        See Also
        --------
        :func:`scipy.io.savemat`
        """
        if metadata is not None:
            warn("metadata argument is deprecated. All metadata written",
                 FutureWarning)
            # need this path to perserve selecting not to write
            # metadata
        converter = MatlabConverter(self, fileP)
        return converter.convert(reconvert, append, format, longNames,
                                 compress, oned)
Пример #2
0
def matlabHook(obj,
               fileP,
               reconvert=True,
               append=True,
               format='5',
               longNames=True,
               compress=True,
               oned='row'):
    """
    Write a binary MATLAB file from the contents of this object

    Parameters
    ----------
    fileP : str or file-like object
        Name of the file to write. ``.mat`` extension is not needed
        if ``append==True``
    reconvert : bool
        If this evaluates to true, convert values back into their
        original form as they appear in the output file.
    append : bool
        If true and a file exists under ``output``, append to that file.
        Otherwise the file will be overwritten
    format : {'5', '4'}
        Format of file to write. ``'5'`` for MATLAB 5 to 7.2, ``'4'`` for
        MATLAB 4
    longNames : bool
        If true, allow variable names to reach 63 characters,
        which works with MATLAB 7.6+. Otherwise, maximum length is
        31 characters
    compress : bool
        If true, compress matrices on write
    oned : {'row', 'col'}
        Write one-dimensional arrays as row vectors if
        ``oned=='row'`` (default), or column vectors

    Raises
    ------
    ImportError
        If :term:`scipy` is not installed

    See Also
    --------
    * :func:`scipy.io.savemat`
    """
    converter = MatlabConverter(obj, fileP)
    return converter.convert(reconvert, append, format, longNames, compress,
                             oned)
Пример #3
0
def _toMatlab(args):
    """
    Write contents of a file to matlab.

    Return codes:
        0: all good
        1: need scipy
        3: conversion for file type not supported yet
    """
    inFile = args.file
    outFile = args.output
    if not outFile:
        base = splitext(inFile)[0]
        outFile = base + '.mat'

    # inferReader returns the class, but we need an instance
    reader = inferReader(inFile)(inFile)
    try:
        converter = MatlabConverter(reader, outFile)
    except ImportError:
        error("scipy >= 1.0 required to convert to matlab")
        return 1
    except NotImplementedError:
        error("Conversion not supported for {} reader at this time. ".format(
            reader.__class__.__name__))
        error("Please alert the developers of your need.")
        return 3
    reader.read()
    converter.convert(True,
                      append=args.append,
                      format=args.format,
                      longNames=args.longNames,
                      compress=not args.large,
                      oned=args.oned)
    if not args.q:
        if args.v:
            info("Wrote contents of {} to {}".format(inFile, outFile))
        else:
            print(outFile)

    return 0
Пример #4
0
    def toMatlab(self,
                 fileP,
                 reconvert=True,
                 append=True,
                 format='5',
                 longNames=True,
                 compress=True,
                 oned='row'):
        """
        Write a binary MATLAB file from the contents of this reader

        The group constant data will be presented as a multi-dimensional
        array, rather than a stacked 2D matrix. The axis are ordered
        ``burnup, universeIndex, group, value/uncertainty``

        The ordering of the universes can be found in the ``'UNIVERSES'``
        vector if ``reconvert==True``, otherwise ``'universes'``. Each
        universe ID is present in this vector, ordered to their
        position along the second axis in the matrix.

        Parameters
        ----------
        fileP: str or file-like object
            Name of the file to write
        reconvert: bool
            If this evaluates to true, convert values back into their
            original form as they appear in the output file.
        append: bool
            If true and a file exists under ``output``, append to that file.
            Otherwise the file will be overwritten
        format: {'5', '4'}
            Format of file to write. ``'5'`` for MATLAB 5 to 7.2, ``'4'`` for
            MATLAB 4
        longNames: bool
            If true, allow variable names to reach 63 characters,
            which works with MATLAB 7.6+. Otherwise, maximum length is
            31 characters
        compress: bool
            If true, compress matrices on write
        oned: {'row', 'col'}:
            Write one-dimensional arrays as row vectors if
            ``oned=='row'`` (default), or column vectors

        Examples
        --------

        >>> import serpentTools
        >>> from scipy.io import loadmat
        >>> r = serpentTools.readDataFile('pwr_res.m')
        # convert to original variable names
        >>> r.toMatlab('pwr_res.mat', True)
        >>> loaded = loadmat('pwr_res.mat')
        >>> loaded['ABS_KEFF']
        array([[0.991938, 0.00145 ],
               [0.181729, 0.0024  ]])
        >>> kinf = loaded['INF_KINF']
        >>> kinf.shape
        (2, 1, 1, 2)
        >>> kinf[:, 0, 0, 0]
        array([0.993385, 0.181451])
        >>> tot = loaded['INF_TOT']
        >>> tot.shape
        (2, 1, 2, 2)
        >>> tot[:, 0, :, 0]
        array([[0.496553, 1.21388 ],
               [0.481875, 1.30993 ]])
        # use the universes key to identify ordering of universes
        >>> loaded['UNIVERSES']
        array([0])

        Raises
        ------
        ImportError
            If :term:`scipy` is not installed

        See Also
        --------
        * :func:`scipy.io.savemat`
        """
        converter = MatlabConverter(self, fileP)
        return converter.convert(reconvert, append, format, longNames,
                                 compress, oned)