romspline/greedy.py
def write(self, file, slim=False):
    """
    Write spline interpolant data in HDF5 or text format
    
    Input
    =====
    file -- write data to this file 
    slim -- export minimal data to this file (i.e., exclude writing errors array)
            (default False)
    
    Comments
    ========
    Data written to file includes:
      
      deg    -- degree of spline polynomial interpolants
      tol    -- greedy algorithm threshold tolerance
      X      -- reduced data samples
      Y      -- reduced data values
      errors -- L-infinity norm of differences between 
                reduced order spline and full data set
    
    Input file can be an HDF5 file or group descriptor. Also,
    file can be a string and is expected to be in the form of
      
      /my/directory/filename.extension
    
    Currently, HDF5 and text formats are supported. If text 
    format, a directory is created with text files containing 
    the reduced order spline data.
    """
    
    # If file is an HDF5 file or group descriptor...
    if file.__class__ in [h5py._hl.files.File, h5py._hl.group.Group]:
      self._write(file, slim=slim)
    
    # If file is a file name...
    elif isinstance(file, (str, Path)):
      file = Path(file)
      # Get file name and extension
      types = ['.txt', '.h5', '.hdf5']
      file_extension = file.suffix
      assert file_extension in types, "File type must have extension txt, h5, or hdf5."
      
      # HDF5 format
      if file_extension in ['.h5', '.hdf5']:
        try:
          fp = h5py.File(file, 'w')
          isopen = True
        except Exception as err:
          raise Exception("Could not open file for writing, error: {}".format(err))
        if isopen:
          self._write(fp, slim=slim)
          fp.close()

      # Text format
      if file_extension == '.txt':
        # Make directory with given filename
        if not file.exists():
          file.mkdir(parents=True)

        # Try to open as many things as possible in the same context manager
        with (file / 'deg.txt').open('w') as deg_f, \
             (file / 'tol.txt').open('w') as tol_f, \
             (file / 'X.txt').open('w') as X_f, \
             (file / 'Y.txt').open('w') as Y_f:
          # Write polynomial degree of reduced-order spline
          deg_f.write(unicode(self._deg))
          # Write greedy algorithm tolerance
          tol_f.write(unicode(self.tol))
          # Write nearly optimal subset of x data (i.e., "knots")
          for xx in self.X:
            X_f.write(unicode(xx)+'\n')
          # Write nearly optimal subset of y data
          for yy in self.Y:
            Y_f.write(unicode(yy)+'\n')

        # Write L-infinity spline errors from greedy algorithm
        if not slim:
          with (file / 'errors.txt').open('w') as err_f:
            for ee in self.errors:
              err_f.write(unicode(ee)+'\n')

    Write spline interpolant data in HDF5 or text format
    
    Input
    =====
    file -- write data to this file 
    slim -- export minimal data to this file (i.e., exclude writing errors array)
            (default False)
    
    Comments
    ========
    Data written to file includes:
      
      deg    -- degree of spline polynomial interpolants
      tol    -- greedy algorithm threshold tolerance
      X      -- reduced data samples
      Y      -- reduced data values
      errors -- L-infinity norm of differences between 
                reduced order spline and full data set
    
    Input file can be an HDF5 file or group descriptor. Also,
    file can be a string and is expected to be in the form of
      
      /my/directory/filename.extension
    
    Currently, HDF5 and text formats are supported. If text 
    format, a directory is created with text files containing 
    the reduced order spline data.
    
Write spline interpolant data in HDF5 or text format
Input

- write data to this file
slim -- export minimal data to this file
(default False)

Comments

Data written to file includes.



Input file can be an HDF5 file or group descriptor. Also,
file can be a string and is expected to be in the form of



Currently, HDF5 and text formats are supported. If text
format, a directory is created with text files containing
the reduced order spline data.
Write spline interpolant data in HDF5 or text format Input - write data to this file slim -- export minimal data to this file ( default False ) Comments Data written to file includes . Input file can be an HDF5 file or group descriptor . Also file can be a string and is expected to be in the form of Currently HDF5 and text formats are supported . If text format a directory is created with text files containing the reduced order spline data .
def write(self, file, slim=False):
    if file.__class__ in [h5py._hl.files.File, h5py._hl.group.Group]:
      self._write(file, slim=slim)
    elif isinstance(file, (str, Path)):
      file = Path(file)
      types = ['.txt', '.h5', '.hdf5']
      file_extension = file.suffix
      assert file_extension in types, "File type must have extension txt, h5, or hdf5."
      if file_extension in ['.h5', '.hdf5']:
        try:
          fp = h5py.File(file, 'w')
          isopen = True
        except Exception as err:
          raise Exception("Could not open file for writing, error: {}".format(err))
        if isopen:
          self._write(fp, slim=slim)
          fp.close()
      if file_extension == '.txt':
        if not file.exists():
          file.mkdir(parents=True)
        with (file / 'deg.txt').open('w') as deg_f, \
             (file / 'tol.txt').open('w') as tol_f, \
             (file / 'X.txt').open('w') as X_f, \
             (file / 'Y.txt').open('w') as Y_f:
          deg_f.write(unicode(self._deg))
          tol_f.write(unicode(self.tol))
          for xx in self.X:
            X_f.write(unicode(xx)+'\n')
          for yy in self.Y:
            Y_f.write(unicode(yy)+'\n')
        if not slim:
          with (file / 'errors.txt').open('w') as err_f:
            for ee in self.errors:
              err_f.write(unicode(ee)+'\n')
def write ( self , file , slim = False ) : if file . __class__ in [ h5py . _hl . files . File , h5py . _hl . group . Group ] : self . _write ( file , slim = slim ) elif isinstance ( file , ( str , Path ) ) : file = Path ( file ) types = [ '.txt' , '.h5' , '.hdf5' ] file_extension = file . suffix assert file_extension in types , "File type must have extension txt, h5, or hdf5." if file_extension in [ '.h5' , '.hdf5' ] : try : fp = h5py . File ( file , 'w' ) isopen = True except Exception as err : raise Exception ( "Could not open file for writing, error: {}" . format ( err ) ) if isopen : self . _write ( fp , slim = slim ) fp . close ( ) if file_extension == '.txt' : if not file . exists ( ) : file . mkdir ( parents = True ) with ( file / 'deg.txt' ) . open ( 'w' ) as deg_f , ( file / 'tol.txt' ) . open ( 'w' ) as tol_f , ( file / 'X.txt' ) . open ( 'w' ) as X_f , ( file / 'Y.txt' ) . open ( 'w' ) as Y_f : deg_f . write ( unicode ( self . _deg ) ) tol_f . write ( unicode ( self . tol ) ) for xx in self . X : X_f . write ( unicode ( xx ) + '\n' ) for yy in self . Y : Y_f . write ( unicode ( yy ) + '\n' ) if not slim : with ( file / 'errors.txt' ) . open ( 'w' ) as err_f : for ee in self . errors : err_f . write ( unicode ( ee ) + '\n' )
Write spline interpolant data in HDF5 or text format
Input
Write spline interpolant data in HDF5 or text format Input
"""
    Write spline interpolant data in HDF5 or text format
    
    Input
    =====
    file -- write data to this file 
    slim -- export minimal data to this file (i.e., exclude writing errors array)
            (default False)
    
    Comments
    ========
    Data written to file includes:
      
      deg    -- degree of spline polynomial interpolants
      tol    -- greedy algorithm threshold tolerance
      X      -- reduced data samples
      Y      -- reduced data values
      errors -- L-infinity norm of differences between 
                reduced order spline and full data set
    
    Input file can be an HDF5 file or group descriptor. Also,
    file can be a string and is expected to be in the form of
      
      /my/directory/filename.extension
    
    Currently, HDF5 and text formats are supported. If text 
    format, a directory is created with text files containing 
    the reduced order spline data.
    """ # If file is an HDF5 file or group descriptor... # If file is a file name... # Get file name and extension # HDF5 format # Text format # Make directory with given filename # Try to open as many things as possible in the same context manager # Write polynomial degree of reduced-order spline # Write greedy algorithm tolerance # Write nearly optimal subset of x data (i.e., "knots") # Write nearly optimal subset of y data # Write L-infinity spline errors from greedy algorithm
self
file
slim