romspline/greedy.py
def readSpline(file, group=None):
  """
  Load spline interpolant data from HDF5 or text format 
  without having to create a ReducedOrderSpline object.
  
  Input
  =====
  file -- load data from this file assuming form of
          /my/directory/filename.extension
  
  Output
  ======
  spline -- object that has the attributes and methods
            of ReducedOrderSpline class
  
  Valid file extensions are 'h5', 'hdf5', and 'txt'.
  """
  
  # Get file name and extension
  types = ['.txt', '.h5', '.hdf5']
  file = Path(file).resolve()
  file_extension = file.suffix
  assert file_extension in types, "File type must be have extension txt, h5, or hdf5."
  
  # HDF5 format
  if file_extension in ['.h5', '.hdf5']:
    try:
      fp = h5py.File(file, 'r')
      isopen = True
    except Exception as err:
      raise Exception("Could not open file for reading, error: {}".format(err))
    if isopen:
      gp = fp[group] if group else fp
      deg = gp['deg'][()]
      tol = gp['tol'][()]
      X = gp['X'][:]
      Y = gp['Y'][:]
      if hasattr(gp, 'errors') or 'errors' in gp.keys():
        errors = gp['errors'][:]
      else:
        errors = []
      fp.close()
      _made = True
  
  # Text format
  if file_extension == '.txt':

    # Try to open as many things as possible in the same context manager
    with (file / 'deg.txt').open('r') as deg_f, \
         (file / 'tol.txt').open('r') as tol_f, \
         (file / 'X.txt').open('r') as X_f, \
         (file / 'Y.txt').open('r') as Y_f:
      deg = int(deg_f.read())

      tol = float(tol_f.read())

      X = np.loadtxt(X_f)
      Y = np.loadtxt(Y_f)

    try:
      with (file / 'err.txt').open('r') as err_f:
        errors = np.loadtxt(err_f)
    except:
      errors = []
      
    _made = True
  
  if _made:
    spline = ReducedOrderSpline()
    spline._spline = UnivariateSpline(X, Y, k=deg, s=0)
    spline.X = X
    spline.Y = Y
    spline._deg = deg
    spline.errors = errors
    spline.tol = tol
    spline.size = len(X)
    spline.compression = None  # Original data set not available so setting to None
    spline._made = _made
    return spline
  else:
    raise Exception("Reduced-order spline interpolant could not be constructed from file.")

  Load spline interpolant data from HDF5 or text format 
  without having to create a ReducedOrderSpline object.
  
  Input
  =====
  file -- load data from this file assuming form of
          /my/directory/filename.extension
  
  Output
  ======
  spline -- object that has the attributes and methods
            of ReducedOrderSpline class
  
  Valid file extensions are 'h5', 'hdf5', and 'txt'.
  
Load spline interpolant data from HDF5 or text format
without having to create a ReducedOrderSpline object.

Input

- load data from this file assuming form of
my/directory/filename.extension

Output

- object that has the attributes and methods
of ReducedOrderSpline class


Load spline interpolant data from HDF5 or text format without having to create a ReducedOrderSpline object . Input - load data from this file assuming form of my / directory / filename . extension Output - object that has the attributes and methods of ReducedOrderSpline class
def readSpline(file, group=None):
  types = ['.txt', '.h5', '.hdf5']
  file = Path(file).resolve()
  file_extension = file.suffix
  assert file_extension in types, "File type must be have extension txt, h5, or hdf5."
  if file_extension in ['.h5', '.hdf5']:
    try:
      fp = h5py.File(file, 'r')
      isopen = True
    except Exception as err:
      raise Exception("Could not open file for reading, error: {}".format(err))
    if isopen:
      gp = fp[group] if group else fp
      deg = gp['deg'][()]
      tol = gp['tol'][()]
      X = gp['X'][:]
      Y = gp['Y'][:]
      if hasattr(gp, 'errors') or 'errors' in gp.keys():
        errors = gp['errors'][:]
      else:
        errors = []
      fp.close()
      _made = True
  if file_extension == '.txt':
    with (file / 'deg.txt').open('r') as deg_f, \
         (file / 'tol.txt').open('r') as tol_f, \
         (file / 'X.txt').open('r') as X_f, \
         (file / 'Y.txt').open('r') as Y_f:
      deg = int(deg_f.read())
      tol = float(tol_f.read())
      X = np.loadtxt(X_f)
      Y = np.loadtxt(Y_f)
    try:
      with (file / 'err.txt').open('r') as err_f:
        errors = np.loadtxt(err_f)
    except:
      errors = []
    _made = True
  if _made:
    spline = ReducedOrderSpline()
    spline._spline = UnivariateSpline(X, Y, k=deg, s=0)
    spline.X = X
    spline.Y = Y
    spline._deg = deg
    spline.errors = errors
    spline.tol = tol
    spline.size = len(X)
    spline.compression = None  
    spline._made = _made
    return spline
  else:
    raise Exception("Reduced-order spline interpolant could not be constructed from file.")
def readSpline ( file , group = None ) : types = [ '.txt' , '.h5' , '.hdf5' ] file = Path ( file ) . resolve ( ) file_extension = file . suffix assert file_extension in types , "File type must be have extension txt, h5, or hdf5." if file_extension in [ '.h5' , '.hdf5' ] : try : fp = h5py . File ( file , 'r' ) isopen = True except Exception as err : raise Exception ( "Could not open file for reading, error: {}" . format ( err ) ) if isopen : gp = fp [ group ] if group else fp deg = gp [ 'deg' ] [ ( ) ] tol = gp [ 'tol' ] [ ( ) ] X = gp [ 'X' ] [ : ] Y = gp [ 'Y' ] [ : ] if hasattr ( gp , 'errors' ) or 'errors' in gp . keys ( ) : errors = gp [ 'errors' ] [ : ] else : errors = [ ] fp . close ( ) _made = True if file_extension == '.txt' : with ( file / 'deg.txt' ) . open ( 'r' ) as deg_f , ( file / 'tol.txt' ) . open ( 'r' ) as tol_f , ( file / 'X.txt' ) . open ( 'r' ) as X_f , ( file / 'Y.txt' ) . open ( 'r' ) as Y_f : deg = int ( deg_f . read ( ) ) tol = float ( tol_f . read ( ) ) X = np . loadtxt ( X_f ) Y = np . loadtxt ( Y_f ) try : with ( file / 'err.txt' ) . open ( 'r' ) as err_f : errors = np . loadtxt ( err_f ) except : errors = [ ] _made = True if _made : spline = ReducedOrderSpline ( ) spline . _spline = UnivariateSpline ( X , Y , k = deg , s = 0 ) spline . X = X spline . Y = Y spline . _deg = deg spline . errors = errors spline . tol = tol spline . size = len ( X ) spline . compression = None spline . _made = _made return spline else : raise Exception ( "Reduced-order spline interpolant could not be constructed from file." )
Load spline interpolant data from HDF5 or text format
without having to create a ReducedOrderSpline object.
Load spline interpolant data from HDF5 or text format without having to create a ReducedOrderSpline object .
"""
  Load spline interpolant data from HDF5 or text format 
  without having to create a ReducedOrderSpline object.
  
  Input
  =====
  file -- load data from this file assuming form of
          /my/directory/filename.extension
  
  Output
  ======
  spline -- object that has the attributes and methods
            of ReducedOrderSpline class
  
  Valid file extensions are 'h5', 'hdf5', and 'txt'.
  """ # Get file name and extension # HDF5 format # Text format # Try to open as many things as possible in the same context manager # Original data set not available so setting to None
file
group