isofit.core.fileio

class SpectrumFile(fname, write=False, n_rows=None, n_cols=None, n_bands=None, interleave=None, dtype=<class 'numpy.float32'>, wavelengths=None, fwhm=None, band_names=None, bad_bands='[]', zrange='{0.0, 1.0}', flag=-9999.0, ztitles='{Wavelength (nm), Magnitude}', map_info='{}')[source]

Bases: object

A buffered file object that contains configuration information about formatting, etc.

open_map_with_retries()[source]

Try to open a memory map, handling Beowulf I/O issues.

get_frame(row)[source]

The frame is a 2D array, essentially a list of spectra. The self.frames list acts as a hash table to avoid storing the entire cube in memory. So we read them or create them on an as-needed basis. When the buffer flushes via a call to flush_buffers, they will be deleted.

write_spectrum(row, col, x)[source]

We write a spectrum. If a binary format file, we simply change the data cached in self.frames and defer file I/O until flush_buffers is called.

read_spectrum(row, col)[source]

Get a spectrum from the frame list or ASCII file. Note that if we are an ASCII file, we have already read the single spectrum and return it as-is (ignoring the row/column indices).

flush_buffers()[source]

Write to file, and refresh the memory map object.

class InputData[source]

Bases: object

clear()[source]
class IO(config, forward)[source]

Bases: object

get_components_at_index(row, col)[source]

Load data from input files at the specified (row, col) index.

Parameters:
  • row (int) – row to retrieve data from

  • col (int) – column to retrieve data from

Returns:

object containing all current data reads

Return type:

InputData

flush_buffers()[source]

Write all buffered output data to disk, and erase read buffers.

write_datasets(row, col, output, states, flush_immediately=False)[source]

Write all valid datasets to disk (possibly buffered).

Parameters:
  • row (int) – row to write to

  • col (int) – column to write to

  • output (dict) – dictionary with keys corresponding to config.input file references

  • states (List) – results states from inversion. In the MCMC case, these are interpreted as samples from the

  • posterior

  • converged (otherwise they are a gradient descent trajectory (with the last spectrum being the) –

  • solution).

  • flush_immediately – IO argument telling us to immediately write to disk, ignoring config settings

build_output(states, input_data, fm, iv)[source]

Build the output to be written to disk as a dictionary

Parameters:
  • states (List) – results states from inversion. In the MCMC case, these are interpreted as samples from the

  • posterior

  • converged (otherwise they are a gradient descent trajectory (with the last spectrum being the) –

  • solution).

  • input_data (InputData) – an InputData object

  • fm (ForwardModel) – the forward model used to solve the inversion

  • iv (Inversion) – the inversion object

write_spectrum(row, col, states, fm, iv, flush_immediately=False, input_data=None)[source]

Convenience function to build and write output in one step

Parameters:
  • row (int) – data row to write

  • col (int) – data column to write

  • states (List) – results states from inversion. In the MCMC case, these are interpreted as samples from the

  • posterior

  • converged (otherwise they are a gradient descent trajectory (with the last spectrum being the) –

  • solution).

  • meas – measurement radiance

  • geom – geometry object of the observation

  • fm (ForwardModel) – the forward model used to solve the inversion

  • iv (Inversion) – the inversion object

  • flush_immediately – IO argument telling us to immediately write to disk, ignoring config settings

  • input_data (Optional[InputData]) – optionally overwride self.current_input_data

write_bil_chunk(dat, outfile, line, shape, dtype='float32')[source]

Write a chunk of data to a binary, BIL formatted data cube. :type dat: array :param dat: data to write :type outfile: str :param outfile: output file to write to :type line: int :param line: line of the output file to write to :type shape: tuple :param shape: shape of the output file :type dtype: str :param dtype: output data type

Return type:

None

Returns:

None