Extending flitsr inputs¶
flitsr provides a number of Input types out-of-the-box, which cover a
range of use cases. However, if you have a different spectral format (say, the
output of a tool for a different programming language), you may also easily
extend flitsr to support this format as well.
To extend flitsr to support a different output format, you must create an
Input class.
This class may either be created in the flitsr tool’s input package, or
you may create a flitsr pluin using entry points. For details on how to
create a flitsr plugin, see Creating flitsr plugins. If creating a
flitsr plugin, you may use the flitsr.input entry point, for example:
[project.entry-points.'flitsr.input']
test_input = "my-package.custom_input:CustomInput"
Where CustomInput is a custom input type that inherits
Input.
Note
The test_input variable name is not used by flitsr and thus can be
arbitrary.
Abstract Input class¶
See the Input class for the structure that your custom input type
must extend. It is advised that you extend from either DirInput
or FileInput as a custom input type that reads in directories or
files respectively.
Note
Your custom input type must implement all abstract methods, and may optionally
implement any of the non-abstract, and non-final methods such as
search_pattern, write_spectrum,
and get_elem_separators.
The main method to implement is the Input._read_spectrum method as given here:
- flitsr.input.Input._read_spectrum(self, input_path: str) Spectrum¶
Abstract method to facilitate reading in the spectrum. Any concrete class extending
Inputmust implement this method.The method is called on a constructed
Inputobject, which contains all options, as well an initializedSpectrumBuilderobject which may be used for constructing the spectrum. TheSpectrumBuilderobject handles any advanced usage scenarios such as duplicates, method level collapsing, and fault splitting. Callingget_spectrumwill return the constructedSpectrumobject.- Parameters:
input_path – The path to the input file to read in.
- Returns:
The spectrum that was read in.
Note
Using the SpectrumBuilder object provided in
self.sbto construct the Spectrum is strongly advised.Added in version 2.5.0.