orsopy.fileio package
The role of the fileio module is to enable the creation of and parsing from ORSO reduced data files.
All public classes and functions in the fileio module are available directly from
fileio without needing to specify a particular submodule.
The ORSO file format specification is available here.
- class orsopy.fileio.Column(name, unit=None, physical_quantity=None, flag_is=None, comment=None)[source]
Bases:
HeaderInformation about a data column.
-
name:
str
-
unit:
Optional[str] = None
-
physical_quantity:
Optional[str] = None
-
flag_is:
Optional[List[str]] = None
- yaml_representer(dumper)
-
comment:
Optional[str] = None
-
name:
- class orsopy.fileio.ComplexValue(real, imag=None, unit=None, error=None, comment=None)[source]
Bases:
HeaderA value or list of values with an optional unit.
-
real:
float
-
imag:
Optional[float] = None
-
unit:
Optional[str] = None
-
error:
Optional[ErrorValue] = None
- yaml_representer(dumper)
-
comment:
Optional[str] = None
-
real:
- class orsopy.fileio.DataSource(owner, experiment, sample, measurement, comment=None)[source]
Bases:
HeaderThe data_source object definition.
- Parameters:
owner (
Person) – This refers to the actual owner of the data set, i.e. the main proposer or the person doing the measurement on a lab reflectometer.experiment (
Experiment) – Details of the experimental.sample (
Sample) – Sample information.measurement (
Measurement) – Measurement specifics.
-
experiment:
Experiment
-
measurement:
Measurement
-
comment:
Optional[str] = None
- class orsopy.fileio.ErrorColumn(error_of, error_type=None, value_is=None, distribution=None, comment=None)[source]
Bases:
HeaderInformation about a data column.
-
error_of:
str
-
error_type:
Optional[Literal['uncertainty','resolution']] = None
-
value_is:
Optional[Literal['sigma','FWHM']] = None
-
distribution:
Optional[Literal['gaussian','triangular','uniform','lorentzian']] = None
- yaml_representer(dumper)
- property name
A convenience property to allow programs to get a valid name attribute for any column.
- property to_sigma
The multiplicative factor needed to convert a FWHM to sigma.
The conversion factors can be found in common statistics and experimental physics text books or derived manually solving the variance definition integral. (e.g. Dekking, Michel (2005). A modern introduction to probability and statistics : understanding why and how. Springer, London, UK:) Values and some references available on Wikipedia, too.
-
comment:
Optional[str] = None
-
error_of:
- class orsopy.fileio.Experiment(title, instrument, start_date, probe, facility=None, proposalID=None, doi=None, comment=None)[source]
Bases:
HeaderA definition of the experiment performed.
- Parameters:
title (
str) – Proposal or project title.instrument (
str) – Reflectometer identifier.start_date (
datetime) – Start date for the experiment.probe (
Literal['neutron','x-ray']) – Radiation probe, either'neutron'or'x-ray'.facility (
Optional[str]) – Facility where the experiment was performed.proposalID (
Optional[str]) – Identifier for experiment at a facility.doi (
Optional[str]) – Digital object identifier for the experiment, possibly provided by the facility.
-
title:
str
-
instrument:
str
-
start_date:
datetime
-
probe:
Literal['neutron','x-ray']
-
facility:
Optional[str] = None
-
proposalID:
Optional[str] = None
-
doi:
Optional[str] = None
-
comment:
Optional[str] = None
- class orsopy.fileio.File(file, timestamp=None, hash=None, comment=None)[source]
Bases:
HeaderA file with file path and a last modified timestamp.
-
file:
str
-
timestamp:
Optional[datetime] = None
-
hash:
Optional[ContentHash] = None
-
comment:
Optional[str] = None
-
file:
- class orsopy.fileio.Header[source]
Bases:
objectThe super class for all the items in the orso module.
- classmethod from_dict(data_dict)[source]
Create class from dictionary as is returned from yaml file reader.
If user-supplied attributes are provided, they are not passed to the constructor but applied after instance generation.
- property user_data
- classmethod empty()[source]
Create an empty instance of this item containing all non-option attributes as
None.- Return type:
- Returns:
Empty class.
- static asdict(header)[source]
Static method for
to_dict().- Parameters:
header (
Header) – Object to convert to dictionary.- Return type:
dict- Returns:
Dictionary result.
- class orsopy.fileio.InstrumentSettings(incident_angle, wavelength, polarization=Polarization.unpolarized, configuration=None, comment=None)[source]
Bases:
HeaderSettings associated with the instrumentation.
- Parameters:
incident_angle (
Union[Value,ValueRange]) – Angle (range) of incidence.wavelength (
Union[Value,ValueRange]) – Neutron/x-ray wavelength (range).polarization (
Union[Polarization,ValueVector]) – Radiation polarization as one of'unpolarized','p','m','pp','pm','mp','mm', or aorsopy.fileio.base.ValueVector.configuration (
Optional[str]) – Description of the instreument configuration (full polarized/liquid surface/etc).
-
incident_angle:
Union[Value,ValueRange]
-
wavelength:
Union[Value,ValueRange]
-
polarization:
Union[Polarization,ValueVector] = 'unpolarized'
-
configuration:
Optional[str] = None
-
comment:
Optional[str] = None
- class orsopy.fileio.Measurement(instrument_settings, data_files, additional_files=None, scheme=None, comment=None)[source]
Bases:
HeaderThe measurement elements for the header.
- Parameters:
instrument_settings (
InstrumentSettings) – Instrumentation details.data_files (
List[Union[File,str]]) – Raw data files produced in the measurement.additional_files (
Optional[List[Union[File,str]]]) – Raw reference files used in the reduction.scheme (
Optional[Literal['angle- and energy-dispersive','angle-dispersive','energy-dispersive']]) – Measurement scheme (one of'angle-dispersive','energy-dispersive'/'angle- and energy-dispersive').
-
instrument_settings:
InstrumentSettings
-
scheme:
Optional[Literal['angle- and energy-dispersive','angle-dispersive','energy-dispersive']] = None
-
comment:
Optional[str] = None
- class orsopy.fileio.Orso(data_source, reduction, columns, data_set=None, **user_data)[source]
Bases:
HeaderThe Orso object collects the necessary metadata.
- Parameters:
data_source (
DataSource) – Information about the origin and ownership of the raw data.reduction (
Reduction) – Details of the data reduction that has been performed. The content of this section should contain enough information to rerun the reduction.columns (
List[Union[Column,ErrorColumn]]) – Information about the columns of data that will be contained in the file.data_set (
Union[int,str,None]) – An identifier for the data set, i.e. if there is more than one data set in the object.
-
data_source:
DataSource
-
columns:
List[Union[Column,ErrorColumn]]
-
data_set:
Union[int,str,None] = None
- classmethod empty()[source]
Create an empty instance of the ORSO header with all non-optional attributes as
None.- Return type:
- Returns:
Empty Orso class, within minimum required columns
- column_header()[source]
An information string that explains what each of the columns in a dataset corresponds to.
- Return type:
str- Returns:
Explanatory string.
- from_difference(other_dict)[source]
Constructs another
Orsoinstance from self, and a dict containing updated header information.
- to_difference(other)[source]
A dictionary containing the difference in header information between two
Orsoobjects.- Parameters:
other (
Orso) – Other header to diff with.- Return type:
dict- Returns:
Dictionary of the header information difference.
-
comment:
Optional[str] = None
- class orsopy.fileio.OrsoDataset(info, data)[source]
Bases:
object- Parameters:
info (
Orso) – The header information for the reflectivity measurementdata (
Union[ndarray,Sequence[ndarray],Sequence[Sequence]]) – The numerical data associated with the reflectivity measurement. The data has shape(npnts, ncols).
- Raises:
ValueError – When
ncols != len(self.info.columns).
-
data:
Union[ndarray,Sequence[ndarray],Sequence[Sequence]]
- diff_header(other)[source]
Return a header string that only contains changes to other
OrsoDatasetensure that data_set is the first entry.- Parameters:
other (
OrsoDataset) – OtherOrsoDatasetto compare against.- Return type:
str- Returns:
Header string with only changes.
- save(fname)[source]
Save the
OrsoDataset.- Parameters:
fname (
Union[TextIO,str]) – The file name to save to.
- class orsopy.fileio.Person(name, affiliation, contact=None, comment=None)[source]
Bases:
HeaderInformation about a person, including name, affiliation(s), and contact information.
-
name:
str
-
affiliation:
str
-
contact:
Optional[str] = None
-
comment:
Optional[str] = None
-
name:
- class orsopy.fileio.Polarization(value)[source]
Bases:
str,EnumPolarization of the beam used for the reflectivity.
Neutrons: The first symbol indicates the magnetisation direction of the incident beam, the second symbol indicates the direction of the scattered beam. If either polarization or analysis are not employed the symbol is replaced by “o”.
X-rays: Uses the conventional names pi, sigma, left and right. In experiments with polarization analysis the incident and outgoing polarizations are separated with an underscore “_”.
- unpolarized = 'unpolarized'
- po = 'po'
- mo = 'mo'
- op = 'op'
- om = 'om'
- mm = 'mm'
- mp = 'mp'
- pm = 'pm'
- pp = 'pp'
- pi = 'pi'
- sigma = 'sigma'
- left = 'left'
- right = 'right'
- pi_pi = 'pi_pi'
- sigma_sigma = 'sigma_sigma'
- pi_sigma = 'pi_sigma'
- sigma_pi = 'sigma_pi'
- class orsopy.fileio.Reduction(software, timestamp=None, creator=None, corrections=None, computer=None, call=None, script=None, binary=None, comment=None)[source]
Bases:
HeaderA description of the reduction that has been performed.
- Parameters:
software (
Software) – Software used for reduction.timestamp (
Optional[datetime]) – Datetime of reduced file creation.creator (
Optional[Person]) – The person or routine who created the reduced file.corrections (
Optional[List[str]]) – A list of the corrections that have been performed.computer (
Optional[str]) – Name of the reduction machine.call (
Optional[str]) – Command line call or similar.script (
Optional[str]) – Path to reduction script or notebook.binary (
Optional[str]) – Path to full reduction information file.
-
timestamp:
Optional[datetime] = None
-
corrections:
Optional[List[str]] = None
-
computer:
Optional[str] = None
-
call:
Optional[str] = None
-
script:
Optional[str] = None
-
binary:
Optional[str] = None
-
comment:
Optional[str] = None
- class orsopy.fileio.Sample(name, category=None, composition=None, description=None, size=None, environment=None, sample_parameters=None, model=None, comment=None)[source]
Bases:
HeaderA description of the sample measured.
- Parameters:
name (
str) – An identified for the individual sample or the subject and state being measured.category (
Optional[str]) – Simple sample description, front (beam side) / back, each side should be one of'solid/liquid','liquid/solid','gas/liquid','liquid/liquid','solid/gas','gas/solid'.composition (
Optional[str]) – Notes on the nominal composition of the sample e.g.Si | SiO2 (20 angstrom) | Fe (200 angstrom) | air (beam side).description (
Optional[str]) – Further details of the sample, e.g. size.size (
Optional[ValueVector]) – Sample size in x, y, z direction, where z is parallel to the surface normal and x is along the beam direction (important for footprint correction).environment (
Optional[List[str]]) – Name of the sample environment device(s).sample_parameters (
Optional[Dict[str,Union[Value,ValueRange,ValueVector,ComplexValue,AlternatingField]]]) – Dictionary of sample parameters. See Sample.PARAMETER_DEFAULT_KEYS for some common names defined in the specification.model (
Optional[SampleModel]) – A model using the simple model description (https://www.reflectometry.org/projects/simple_model)
-
name:
str
-
category:
Optional[str] = None
-
composition:
Optional[str] = None
-
description:
Optional[str] = None
-
size:
Optional[ValueVector] = None
-
environment:
Optional[List[str]] = None
-
sample_parameters:
Optional[Dict[str,Union[Value,ValueRange,ValueVector,ComplexValue,AlternatingField]]] = None
-
model:
Optional[SampleModel] = None
- PARAMETER_DEFAULT_KEYS = ['temperature', 'magnetic_field', 'electric_potential', 'electric_current', 'electric_ac_field']
-
comment:
Optional[str] = None
- class orsopy.fileio.Software(name, version=None, platform=None, comment=None)[source]
Bases:
HeaderSoftware description.
- Parameters:
name (
str) – Software name.version (
Optional[str]) – Version identified for the software.platform (
Optional[str]) – Operating system.
-
name:
str
-
version:
Optional[str] = None
-
platform:
Optional[str] = None
- yaml_representer(dumper)
-
comment:
Optional[str] = None
- class orsopy.fileio.Value(magnitude, unit=None, error=None, offset=None, comment=None)[source]
Bases:
HeaderA value or list of values with an optional unit.
-
magnitude:
float
-
unit:
Optional[str] = None
-
error:
Optional[ErrorValue] = None
-
offset:
Optional[float] = None
- yaml_representer(dumper)
-
comment:
Optional[str] = None
-
magnitude:
- class orsopy.fileio.ValueRange(min, max, unit=None, individual_magnitudes=None, offset=None, comment=None)[source]
Bases:
HeaderA range or list of ranges with mins, maxs, and an optional unit.
-
min:
float
-
max:
float
-
unit:
Optional[str] = None
-
individual_magnitudes:
Optional[List[float]] = None
-
offset:
Optional[float] = None
- yaml_representer(dumper)
-
comment:
Optional[str] = None
-
min:
- class orsopy.fileio.ValueVector(x, y, z, unit=None, error=None, comment=None)[source]
Bases:
HeaderA vector or list of vectors with an optional unit. For vectors relating to the sample, such as polarisation, the follow definitions are used.
- Parameters:
x (
float) – is defined as parallel to the radiation beam, positive going with the beam direction.y (
float) – is defined from the other two based on the right hand rule.z (
float) – is defined as normal to the sample surface, positive direction in scattering direction.unit (
Optional[str]) – SI unit string.
-
x:
float
-
y:
float
-
z:
float
-
unit:
Optional[str] = None
-
error:
Optional[ErrorValue] = None
- yaml_representer(dumper)
-
comment:
Optional[str] = None
- orsopy.fileio.load_nexus(fname)[source]
- Return type:
List[OrsoDataset]
- orsopy.fileio.load_orso(fname)[source]
- Parameters:
fname (
Union[TextIO,str]) – The Orso file to load.- Return type:
List[OrsoDataset]- Returns:
OrsoDatasetobjects for each dataset contained within the ORT file.
- orsopy.fileio.save_orso(datasets, fname, comment=None, data_separator='')[source]
Saves an ORSO file. Each of the datasets must have a unique
OrsoDataset.info.data_setattribute. If that attribute is not set, it is given an integer value corresponding to it’s position in the list.- Parameters:
datasets (
List[OrsoDataset]) – List of OrsoDataset to save into the Orso file.fname (
Union[TextIO,str]) – The file name to save to.comment (
Optional[str]) – Comment to write at the top of Orso file.data_separator (
str) – Optional string of newline characters to separate multiple datasets.
- Raises:
ValueError – If the
OrsoDataset.info.data_setvalues are not unique.- Return type:
None
Submodules
orsopy.fileio.base module
Implementation of the base classes for the ORSO header.
- class orsopy.fileio.base.Header[source]
Bases:
objectThe super class for all the items in the orso module.
- classmethod from_dict(data_dict)[source]
Create class from dictionary as is returned from yaml file reader.
If user-supplied attributes are provided, they are not passed to the constructor but applied after instance generation.
- property user_data
- classmethod empty()[source]
Create an empty instance of this item containing all non-option attributes as
None.- Return type:
- Returns:
Empty class.
- static asdict(header)[source]
Static method for
to_dict().- Parameters:
header (
Header) – Object to convert to dictionary.- Return type:
dict- Returns:
Dictionary result.
- class orsopy.fileio.base.OrsoDumper(stream, default_style=None, default_flow_style=False, canonical=None, indent=None, width=None, allow_unicode=None, line_break=None, encoding=None, explicit_start=None, explicit_end=None, version=None, tags=None, sort_keys=True)[source]
Bases:
SafeDumper
- class orsopy.fileio.base.ErrorValue(error_value, error_type=None, value_is=None, distribution=None, comment=None)[source]
Bases:
HeaderInformation about errors on a value.
-
error_value:
float
-
error_type:
Optional[Literal['uncertainty','resolution']] = None
-
value_is:
Optional[Literal['sigma','FWHM']] = None
-
distribution:
Optional[Literal['gaussian','triangular','uniform','lorentzian']] = None
- yaml_representer(dumper)
- property sigma
Return value converted to standard deviation.
The conversion factors can be found in common statistics and experimental physics text books or derived manually solving the variance definition integral. (e.g. Dekking, Michel (2005). A modern introduction to probability and statistics : understanding why and how. Springer, London, UK:) Values and some references available on Wikipedia, too.
-
comment:
Optional[str] = None
-
error_value:
- class orsopy.fileio.base.Value(magnitude, unit=None, error=None, offset=None, comment=None)[source]
Bases:
HeaderA value or list of values with an optional unit.
-
magnitude:
float
-
unit:
Optional[str] = None
-
error:
Optional[ErrorValue] = None
-
offset:
Optional[float] = None
- yaml_representer(dumper)
-
comment:
Optional[str] = None
-
magnitude:
- class orsopy.fileio.base.ComplexValue(real, imag=None, unit=None, error=None, comment=None)[source]
Bases:
HeaderA value or list of values with an optional unit.
-
real:
float
-
imag:
Optional[float] = None
-
unit:
Optional[str] = None
-
error:
Optional[ErrorValue] = None
- yaml_representer(dumper)
-
comment:
Optional[str] = None
-
real:
- class orsopy.fileio.base.ValueRange(min, max, unit=None, individual_magnitudes=None, offset=None, comment=None)[source]
Bases:
HeaderA range or list of ranges with mins, maxs, and an optional unit.
-
min:
float
-
max:
float
-
unit:
Optional[str] = None
-
individual_magnitudes:
Optional[List[float]] = None
-
offset:
Optional[float] = None
- yaml_representer(dumper)
-
comment:
Optional[str] = None
-
min:
- class orsopy.fileio.base.ValueVector(x, y, z, unit=None, error=None, comment=None)[source]
Bases:
HeaderA vector or list of vectors with an optional unit. For vectors relating to the sample, such as polarisation, the follow definitions are used.
- Parameters:
x (
float) – is defined as parallel to the radiation beam, positive going with the beam direction.y (
float) – is defined from the other two based on the right hand rule.z (
float) – is defined as normal to the sample surface, positive direction in scattering direction.unit (
Optional[str]) – SI unit string.
-
x:
float
-
y:
float
-
z:
float
-
unit:
Optional[str] = None
-
error:
Optional[ErrorValue] = None
- yaml_representer(dumper)
-
comment:
Optional[str] = None
- class orsopy.fileio.base.AlternatingField(amplitude, frequency, phase=None, comment=None)[source]
Bases:
HeaderA physical field with regular variations as AC magnetic field.
-
comment:
Optional[str] = None
-
comment:
- class orsopy.fileio.base.Person(name, affiliation, contact=None, comment=None)[source]
Bases:
HeaderInformation about a person, including name, affiliation(s), and contact information.
-
name:
str
-
affiliation:
str
-
contact:
Optional[str] = None
-
comment:
Optional[str] = None
-
name:
- class orsopy.fileio.base.Column(name, unit=None, physical_quantity=None, flag_is=None, comment=None)[source]
Bases:
HeaderInformation about a data column.
-
name:
str
-
unit:
Optional[str] = None
-
physical_quantity:
Optional[str] = None
-
flag_is:
Optional[List[str]] = None
- yaml_representer(dumper)
-
comment:
Optional[str] = None
-
name:
- class orsopy.fileio.base.ErrorColumn(error_of, error_type=None, value_is=None, distribution=None, comment=None)[source]
Bases:
HeaderInformation about a data column.
-
error_of:
str
-
error_type:
Optional[Literal['uncertainty','resolution']] = None
-
value_is:
Optional[Literal['sigma','FWHM']] = None
-
distribution:
Optional[Literal['gaussian','triangular','uniform','lorentzian']] = None
- yaml_representer(dumper)
- property name
A convenience property to allow programs to get a valid name attribute for any column.
- property to_sigma
The multiplicative factor needed to convert a FWHM to sigma.
The conversion factors can be found in common statistics and experimental physics text books or derived manually solving the variance definition integral. (e.g. Dekking, Michel (2005). A modern introduction to probability and statistics : understanding why and how. Springer, London, UK:) Values and some references available on Wikipedia, too.
-
comment:
Optional[str] = None
-
error_of:
- class orsopy.fileio.base.ContentHash(digest, algorithm, comment=None)[source]
Bases:
HeaderA hash of some content, using standard algorithms
-
digest:
str
-
algorithm:
Literal['sha1','sha256','sha384','sha512','sha3_256','sha3_512']
-
comment:
Optional[str] = None
-
digest:
orsopy.fileio.data_source module
Implementation of the data_source for the ORSO header.
- class orsopy.fileio.data_source.Experiment(title, instrument, start_date, probe, facility=None, proposalID=None, doi=None, comment=None)[source]
Bases:
HeaderA definition of the experiment performed.
- Parameters:
title (
str) – Proposal or project title.instrument (
str) – Reflectometer identifier.start_date (
datetime) – Start date for the experiment.probe (
Literal['neutron','x-ray']) – Radiation probe, either'neutron'or'x-ray'.facility (
Optional[str]) – Facility where the experiment was performed.proposalID (
Optional[str]) – Identifier for experiment at a facility.doi (
Optional[str]) – Digital object identifier for the experiment, possibly provided by the facility.
-
title:
str
-
instrument:
str
-
start_date:
datetime
-
probe:
Literal['neutron','x-ray']
-
facility:
Optional[str] = None
-
proposalID:
Optional[str] = None
-
doi:
Optional[str] = None
-
comment:
Optional[str] = None
- class orsopy.fileio.data_source.Sample(name, category=None, composition=None, description=None, size=None, environment=None, sample_parameters=None, model=None, comment=None)[source]
Bases:
HeaderA description of the sample measured.
- Parameters:
name (
str) – An identified for the individual sample or the subject and state being measured.category (
Optional[str]) – Simple sample description, front (beam side) / back, each side should be one of'solid/liquid','liquid/solid','gas/liquid','liquid/liquid','solid/gas','gas/solid'.composition (
Optional[str]) – Notes on the nominal composition of the sample e.g.Si | SiO2 (20 angstrom) | Fe (200 angstrom) | air (beam side).description (
Optional[str]) – Further details of the sample, e.g. size.size (
Optional[ValueVector]) – Sample size in x, y, z direction, where z is parallel to the surface normal and x is along the beam direction (important for footprint correction).environment (
Optional[List[str]]) – Name of the sample environment device(s).sample_parameters (
Optional[Dict[str,Union[Value,ValueRange,ValueVector,ComplexValue,AlternatingField]]]) – Dictionary of sample parameters. See Sample.PARAMETER_DEFAULT_KEYS for some common names defined in the specification.model (
Optional[SampleModel]) – A model using the simple model description (https://www.reflectometry.org/projects/simple_model)
-
name:
str
-
category:
Optional[str] = None
-
composition:
Optional[str] = None
-
description:
Optional[str] = None
-
size:
Optional[ValueVector] = None
-
environment:
Optional[List[str]] = None
-
sample_parameters:
Optional[Dict[str,Union[Value,ValueRange,ValueVector,ComplexValue,AlternatingField]]] = None
-
model:
Optional[SampleModel] = None
- PARAMETER_DEFAULT_KEYS = ['temperature', 'magnetic_field', 'electric_potential', 'electric_current', 'electric_ac_field']
-
comment:
Optional[str] = None
- class orsopy.fileio.data_source.Polarization(value)[source]
Bases:
str,EnumPolarization of the beam used for the reflectivity.
Neutrons: The first symbol indicates the magnetisation direction of the incident beam, the second symbol indicates the direction of the scattered beam. If either polarization or analysis are not employed the symbol is replaced by “o”.
X-rays: Uses the conventional names pi, sigma, left and right. In experiments with polarization analysis the incident and outgoing polarizations are separated with an underscore “_”.
- unpolarized = 'unpolarized'
- po = 'po'
- mo = 'mo'
- op = 'op'
- om = 'om'
- mm = 'mm'
- mp = 'mp'
- pm = 'pm'
- pp = 'pp'
- pi = 'pi'
- sigma = 'sigma'
- left = 'left'
- right = 'right'
- pi_pi = 'pi_pi'
- sigma_sigma = 'sigma_sigma'
- pi_sigma = 'pi_sigma'
- sigma_pi = 'sigma_pi'
- class orsopy.fileio.data_source.InstrumentSettings(incident_angle, wavelength, polarization=Polarization.unpolarized, configuration=None, comment=None)[source]
Bases:
HeaderSettings associated with the instrumentation.
- Parameters:
incident_angle (
Union[Value,ValueRange]) – Angle (range) of incidence.wavelength (
Union[Value,ValueRange]) – Neutron/x-ray wavelength (range).polarization (
Union[Polarization,ValueVector]) – Radiation polarization as one of'unpolarized','p','m','pp','pm','mp','mm', or aorsopy.fileio.base.ValueVector.configuration (
Optional[str]) – Description of the instreument configuration (full polarized/liquid surface/etc).
-
incident_angle:
Union[Value,ValueRange]
-
wavelength:
Union[Value,ValueRange]
-
polarization:
Union[Polarization,ValueVector] = 'unpolarized'
-
configuration:
Optional[str] = None
-
comment:
Optional[str] = None
- class orsopy.fileio.data_source.Measurement(instrument_settings, data_files, additional_files=None, scheme=None, comment=None)[source]
Bases:
HeaderThe measurement elements for the header.
- Parameters:
instrument_settings (
InstrumentSettings) – Instrumentation details.data_files (
List[Union[File,str]]) – Raw data files produced in the measurement.additional_files (
Optional[List[Union[File,str]]]) – Raw reference files used in the reduction.scheme (
Optional[Literal['angle- and energy-dispersive','angle-dispersive','energy-dispersive']]) – Measurement scheme (one of'angle-dispersive','energy-dispersive'/'angle- and energy-dispersive').
-
instrument_settings:
InstrumentSettings
-
scheme:
Optional[Literal['angle- and energy-dispersive','angle-dispersive','energy-dispersive']] = None
-
comment:
Optional[str] = None
- class orsopy.fileio.data_source.DataSource(owner, experiment, sample, measurement, comment=None)[source]
Bases:
HeaderThe data_source object definition.
- Parameters:
owner (
Person) – This refers to the actual owner of the data set, i.e. the main proposer or the person doing the measurement on a lab reflectometer.experiment (
Experiment) – Details of the experimental.sample (
Sample) – Sample information.measurement (
Measurement) – Measurement specifics.
-
experiment:
Experiment
-
measurement:
Measurement
-
comment:
Optional[str] = None
orsopy.fileio.model_language module
Implementation of the simplified model language for the ORSO header.
It includes parsing of models from header or different input information and resolving the model to a simple list of slabs.
- class orsopy.fileio.model_language.SubStack(repetitions=1, stack=None, sequence=None, sub_stack_class='SubStack', environment=None, comment=None)[source]
Bases:
Header,SubStackType-
repetitions:
int= 1
-
stack:
Optional[str] = None
-
sub_stack_class:
Optional[Literal['SubStack']] = 'SubStack'
- original_name = None
- resolve_to_blocks()[source]
- Return type:
List[Union[Layer,SubStackType]]
-
comment:
Optional[str] = None
-
repetitions:
- class orsopy.fileio.model_language.ItemChanger(like, but, comment=None)[source]
Bases:
HeaderAllows to define a simple change in SubStackType item by just updating a selected set of parameters.
-
like:
str
-
but:
dict
- original_name = None
-
comment:
Optional[str] = None
-
like:
- class orsopy.fileio.model_language.SampleModel(stack, origin=None, sub_stacks=None, layers=None, materials=None, composits=None, globals=None, reference=None, comment=None)[source]
Bases:
Header-
stack:
str
-
origin:
Optional[str] = None
-
sub_stacks:
Optional[Dict[str,Union[ItemChanger,SubStack,FunctionTwoElements]]] = None
-
globals:
Optional[ModelParameters] = None
-
reference:
Optional[str] = None
- property resolvable_items
- resolve_to_blocks()[source]
- Return type:
List[Union[Layer,SubStackType]]
-
comment:
Optional[str] = None
-
stack:
orsopy.fileio.orso module
Implementation of the top level class for the ORSO header.
- class orsopy.fileio.orso.Orso(data_source, reduction, columns, data_set=None, **user_data)[source]
Bases:
HeaderThe Orso object collects the necessary metadata.
- Parameters:
data_source (
DataSource) – Information about the origin and ownership of the raw data.reduction (
Reduction) – Details of the data reduction that has been performed. The content of this section should contain enough information to rerun the reduction.columns (
List[Union[Column,ErrorColumn]]) – Information about the columns of data that will be contained in the file.data_set (
Union[int,str,None]) – An identifier for the data set, i.e. if there is more than one data set in the object.
-
data_source:
DataSource
-
columns:
List[Union[Column,ErrorColumn]]
-
data_set:
Union[int,str,None] = None
- classmethod empty()[source]
Create an empty instance of the ORSO header with all non-optional attributes as
None.- Return type:
- Returns:
Empty Orso class, within minimum required columns
- column_header()[source]
An information string that explains what each of the columns in a dataset corresponds to.
- Return type:
str- Returns:
Explanatory string.
- from_difference(other_dict)[source]
Constructs another
Orsoinstance from self, and a dict containing updated header information.
- to_difference(other)[source]
A dictionary containing the difference in header information between two
Orsoobjects.- Parameters:
other (
Orso) – Other header to diff with.- Return type:
dict- Returns:
Dictionary of the header information difference.
-
comment:
Optional[str] = None
- class orsopy.fileio.orso.OrsoDataset(info, data)[source]
Bases:
object- Parameters:
info (
Orso) – The header information for the reflectivity measurementdata (
Union[ndarray,Sequence[ndarray],Sequence[Sequence]]) – The numerical data associated with the reflectivity measurement. The data has shape(npnts, ncols).
- Raises:
ValueError – When
ncols != len(self.info.columns).
-
data:
Union[ndarray,Sequence[ndarray],Sequence[Sequence]]
- diff_header(other)[source]
Return a header string that only contains changes to other
OrsoDatasetensure that data_set is the first entry.- Parameters:
other (
OrsoDataset) – OtherOrsoDatasetto compare against.- Return type:
str- Returns:
Header string with only changes.
- save(fname)[source]
Save the
OrsoDataset.- Parameters:
fname (
Union[TextIO,str]) – The file name to save to.
- orsopy.fileio.orso.save_orso(datasets, fname, comment=None, data_separator='')[source]
Saves an ORSO file. Each of the datasets must have a unique
OrsoDataset.info.data_setattribute. If that attribute is not set, it is given an integer value corresponding to it’s position in the list.- Parameters:
datasets (
List[OrsoDataset]) – List of OrsoDataset to save into the Orso file.fname (
Union[TextIO,str]) – The file name to save to.comment (
Optional[str]) – Comment to write at the top of Orso file.data_separator (
str) – Optional string of newline characters to separate multiple datasets.
- Raises:
ValueError – If the
OrsoDataset.info.data_setvalues are not unique.- Return type:
None
- orsopy.fileio.orso.load_orso(fname)[source]
- Parameters:
fname (
Union[TextIO,str]) – The Orso file to load.- Return type:
List[OrsoDataset]- Returns:
OrsoDatasetobjects for each dataset contained within the ORT file.
- orsopy.fileio.orso.load_nexus(fname)[source]
- Return type:
List[OrsoDataset]
orsopy.fileio.reduction module
The reduction elements for the ORSO header
- class orsopy.fileio.reduction.Software(name, version=None, platform=None, comment=None)[source]
Bases:
HeaderSoftware description.
- Parameters:
name (
str) – Software name.version (
Optional[str]) – Version identified for the software.platform (
Optional[str]) – Operating system.
-
name:
str
-
version:
Optional[str] = None
-
platform:
Optional[str] = None
- yaml_representer(dumper)
-
comment:
Optional[str] = None
- class orsopy.fileio.reduction.Reduction(software, timestamp=None, creator=None, corrections=None, computer=None, call=None, script=None, binary=None, comment=None)[source]
Bases:
HeaderA description of the reduction that has been performed.
- Parameters:
software (
Software) – Software used for reduction.timestamp (
Optional[datetime]) – Datetime of reduced file creation.creator (
Optional[Person]) – The person or routine who created the reduced file.corrections (
Optional[List[str]]) – A list of the corrections that have been performed.computer (
Optional[str]) – Name of the reduction machine.call (
Optional[str]) – Command line call or similar.script (
Optional[str]) – Path to reduction script or notebook.binary (
Optional[str]) – Path to full reduction information file.
-
timestamp:
Optional[datetime] = None
-
corrections:
Optional[List[str]] = None
-
computer:
Optional[str] = None
-
call:
Optional[str] = None
-
script:
Optional[str] = None
-
binary:
Optional[str] = None
-
comment:
Optional[str] = None
orsopy.fileio.typing_backport module
Module for compatibility with Python <3.8. Requires the typing_extensions module to be installed.