Writing data¶
Contain functions to create and write datasets in Mojito L1 HDF5 files.
You can use the functions in this module to create and write datasets and
attributes in a Mojito L1 HDF5 file. In particular, you can combine multiple
single-brick files into a single file containing all the data from the input
files, using the combine_bricks() function.
Note
You must open the HDF5 file in write (‘w’) or append (‘a’) mode to use these
functions, see mojito.reader.MojitoL1File.
Combining bricks¶
Use the combine_bricks() function to combine multiple single-brick files
into a single file containing all the data from the input files.
The function can check that the input files are consistent with each other before combining, and will raise an error if any of the files are not consistent.
from mojito.writer import combine_bricks
combine_bricks(
paths=["brick1.h5", "brick2.h5", "brick3.h5"],
output_path="combined.h5",
mode="w",
check_consistent=True,
compression="lzf",
)
- mojito.writer.combine_bricks(paths, output_path, *, mode='w-', check_consistent=True, compression='lzf')[source]¶
Combine multiple Mojito brick files into a single file.
A new file is created at
output_pathand filled with the combined data from the input files.Consistency between the input files is verified using
mojito.MojitoL1File.check_consistent()and raises an error if any of the files are not consistent with each other.- Parameters:
paths (
list) – A list of paths to the input files to be combined.output_path (
str) – The path to the output file to be created.mode (
Literal['r','r+','a','w','w-'], default:'w-') – The mode to open the output file in. Must be a mode that allows writing.check_consistent (
bool, default:True) – Whether to check that all input files are consistent with each other before combining. If True, then an error is raised if any of the files are not consistent with each other. If False, then the consistency check is skipped.compression (
str|None, default:'lzf') – The compression to use for the output file. Must be a valid h5py compression method or None for no compression. If not specified, then the default compression defined inmojito.writer.DEFAULT_COMPRESSION`is used.
- Raises:
ValueError – If the list of paths is empty.
Exception – If any of the input files are not consistent with each other and
check_consistentis True.
- Return type:
None
Writing attributes¶
Use the following function to write the main attributes to a Mojito L1 file.
- mojito.writer.write_attrs(mojito_file, *, pipeline_name, laser_frequency, lolipops_version)[source]¶
Write attributes to the Mojito L1 file.
- Parameters:
mojito_file (
MojitoL1File) – Single-brick MojitoL1File instance where to write the attributes.pipeline_name (
str) – Name of the pipeline that generated the file.laser_frequency (
float) – Laser frequency in Hz.lolipops_version (
str) – Version of the Lolipops software used.
- Raises:
ValueError – If the provided MojitoL1File is a combined file (multi-brick).
- Return type:
None
Creating groups and datasets¶
You can create the main groups and datasets in a Mojito L1 file using the following functions:
- mojito.writer.create_tdis(mojito_file, time_sampling, *, data=None, compression='lzf', **kwargs)[source]¶
Create TDI group and datasets in the given HDF5 file.
- Parameters:
mojito_file (
MojitoL1File) – Single-brick MojitoL1File instance where to create the TDI group.time_sampling (
UniformTimeSampling) – Uniform time sampling for the TDI datasets.data (
TDI|None, default:None) – TDI data to initialize the datasets with. Missing datasets will not be copied and will be created empty. If None, datasets are created empty.compression (
str|None, default:'lzf') – Compression algorithm to use for the datasets.**kwargs – Additional keyword arguments for dataset creation.
- Raises:
ValueError – If the provided MojitoL1File is a combined file (multi-brick).
- Return type:
None
- mojito.writer.create_ltts(mojito_file, time_sampling, *, data=None, compression='lzf', **kwargs)[source]¶
Create LTT group and datasets in the given HDF5 file.
- Parameters:
mojito_file (
MojitoL1File) – Single-brick MojitoL1File instance where to create the LTT group.time_sampling (
UniformTimeSampling) – Uniform time sampling for the LTT datasets.data (
LTT|None, default:None) – LTT data to initialize the datasets with. Missing datasets will not be copied and will be created empty. If None, datasets are created empty.compression (
str|None, default:'lzf') – Compression algorithm to use for the datasets.**kwargs – Additional keyword arguments for dataset creation.
- Raises:
ValueError – If the provided MojitoL1File is a combined file (multi-brick).
- Return type:
None
- mojito.writer.create_orbits(mojito_file, time_sampling, *, data=None, compression='lzf', **kwargs)[source]¶
Create Orbits group and datasets in the given HDF5 file.
- Parameters:
mojito_file (
MojitoL1File) – Single-brick MojitoL1File instance where to create the Orbits group.time_sampling (
UniformTimeSampling) – Uniform time sampling for the Orbits datasets.data (
Any|None, default:None) – Orbits data to initialize the datasets with. Missing datasets will not be copied and will be created empty. If None, datasets are created empty.compression (
str|None, default:'lzf') – Compression algorithm to use for the datasets.**kwargs – Additional keyword arguments for dataset creation.
- Raises:
ValueError – If the provided MojitoL1File is a combined file (multi-brick).
- Return type:
None
- mojito.writer.create_noise_estimates(mojito_file, time_sampling, freq_sampling, *, data=None, compression='lzf', **kwargs)[source]¶
Create Noise Estimates group and datasets in the given HDF5 file.
- Parameters:
mojito_file (
MojitoL1File) – Single-brick MojitoL1File instance where to create the Noise Estimates group.time_sampling (
UniformTimeSampling) – Uniform time sampling for the noise estimates datasets.freq_sampling (
LogUniformFrequencySampling) – Log-uniform frequency sampling for the noise estimates datasets.data (
Any|None, default:None) – Noise estimates data to initialize the datasets with. Missing datasets will not be copied and will be created empty. If None, datasets are created empty.compression (
str|None, default:'lzf') – Compression algorithm to use for the datasets.**kwargs – Additional keyword arguments for dataset creation.
- Raises:
ValueError – If the provided MojitoL1File is a combined file (multi-brick).
- Return type:
None
The datasets will be created empty and with default compression (LZF), unless you provide data to initialize them with, or specify a different compression algorithm.
Note that missing datasets in the provided data will not be copied, and will be created empty instead.
Writing sampling attributes¶
- mojito.writer.write_uniform_time_sampling(group, sampling)[source]¶
Write the sampling attributes to an HDF5 group.
- Parameters:
group (
Group) – HDF5 group where to write the sampling attributes.sampling (
UniformTimeSampling) – Uniform time sampling instance containing the attributes to write.
- Return type:
None
- mojito.writer.write_log_uniform_frequency_sampling(group, sampling)[source]¶
Write the log-uniform frequency sampling attributes to an HDF5 group.
- Parameters:
group (
Group) – HDF5 group where to write the frequency sampling attributes.sampling (
LogUniformFrequencySampling) – Log-uniform frequency sampling instance containing the attributes to write.
- Return type:
None