swiftsimio.subset_writer module
Contains functions for reading a subset of a SWIFT dataset and writing it to a new file.
- swiftsimio.subset_writer.get_swift_name(name: str) str [source]
Returns the particle type name used in SWIFT
- Parameters:
name (str) – swiftsimio particle name (e.g. gas)
- Returns:
SWIFT particle type corresponding to name (e.g. PartType0)
- Return type:
str
- swiftsimio.subset_writer.get_dataset_mask(mask: SWIFTMask, dataset_name: str, suffix: str | None = None) ndarray [source]
Return appropriate mask or mask size for given dataset
- Parameters:
mask (SWIFTMask) – the mask used to define subset that is written to new snapshot
dataset_name (str) – the name of the dataset we’re interested in. This is the name from the hdf5 file (i.e. “PartType0”, rather than “gas”)
suffix (str, optional) – specify a suffix string to append to dataset underscore name to return something other than the dataset mask. This is specifically used for returning the mask size by setting suffix=”_size”, which would return, for example mask.gas_size
- Returns:
mask for the appropriate dataset
- Return type:
np.ndarray
- swiftsimio.subset_writer.find_datasets(input_file: File, dataset_names=[], path=None, recurse=False) List[str] [source]
Recursively finds all the datasets in the snapshot and writes them to a list
- Parameters:
input_file (h5py.File) – hdf5 file handle for snapshot
dataset_names (list of str, optional) – names of datasets found in the snapshot
path (str, optional) – the path to the current location in the snapshot
recurse (bool, optional) – flag to indicate whether we’re recursing or not
- Returns:
dataset_names – names of datasets in path in input_file
- Return type:
list of str
- swiftsimio.subset_writer.find_links(input_file: File, link_names: List | None = [], link_paths: List | None = [], path: str | None = None)[source]
Recursively finds all the links in the snapshot and writes them to a list
- Parameters:
input_file (h5py.File) – hdf5 file handle for snapshot
link_names (list of str, optional) – names of links found in the snapshot
link_paths (list of str, optional) – paths where links found in the snapshot point to
path (str, optional) – the path to the current location in the snapshot
- Returns:
link_names, link_paths – lists of the names and links of paths in input_file
- Return type:
list of str, list of str
- swiftsimio.subset_writer.update_metadata_counts(infile: File, outfile: File, mask: SWIFTMask)[source]
Recalculates the cell particle counts and offsets based on the particles present in the subset
- Parameters:
infile (h5py.File) – File handle for input snapshot
outfile (h5py.File) – File handle for output subset of snapshot
mask (SWIFTMask) – the mask being used to define subset
- swiftsimio.subset_writer.write_metadata(infile: File, outfile: File, links_list: List[str], mask: SWIFTMask)[source]
Copy over all the metadata from snapshot to output file
- Parameters:
infile (h5py.File) – hdf5 file handle for input snapshot
outfile (h5py.File) – hdf5 file handle for output snapshot
links_list (list of str) – names of links found in the snapshot
mask (SWIFTMask) – the mask being used to define subset
- swiftsimio.subset_writer.write_datasubset(infile: File, outfile: File, mask: SWIFTMask, dataset_names: List[str], links_list: List[str])[source]
Writes subset of all datasets contained in snapshot according to specified mask :param infile: hdf5 file handle for input snapshot :type infile: h5py.File :param outfile: hdf5 file handle for output snapshot :type outfile: h5py.File :param mask: the mask used to define subset that is written to new snapshot :type mask: SWIFTMask :param dataset_names: names of datasets found in the snapshot :type dataset_names: list of str :param links_list: names of links found in the snapshot :type links_list: list of str
- swiftsimio.subset_writer.connect_links(outfile: File, links_list: List[str], paths_list: List[str])[source]
Connects up the links to the appropriate path
- Parameters:
outfile (h5py.File) – file containing the hdf5 subsnapshot
links_list (list of str) – list of names of soft links
paths_list (list of str) – list of paths specifying how to link each soft link
- swiftsimio.subset_writer.write_subset(output_file: str, mask: SWIFTMask)[source]
Writes subset of snapshot according to specified mask to new snapshot file
- Parameters:
input_file (str) – path to input snapshot
output_file (str) – path to output snapshot
mask (SWIFTMask) – the mask used to define subset that is written to new snapshot