nucleon_elastic_ff.data.scripts.average

Script for time averaging correlator data

nucleon_elastic_ff.data.scripts.average.dset_avg(files: List[str], out_file: str, dset_replace_patterns: Optional[Dict[str, str]], overwrite: bool = False, expected_dsets: Optional[int] = None)[source]

Reads h5 files and exports the average of datasets across files.

Each group in the file list will be averaged over files.

Also the average meta info is stored in the resulting output file in the meta attribute of local_current.

Note

Suppose you pass two h5 files files = ["file1.h5", "file2.h5"]. to write to the out file out_file = "out.h5". Lets assume the dset structure is as follows

file1.h5
/x1y1
/x1y2

and also

file2.h5
/x2y1
/x2y2

If you pass the dset_replace_patterns = {"x[0-9]y1": "x_avg_y1"}, this will create the file

out.h5
/x_avg_y1

where the dset x_avg_y1 is the average over file1.h5/x1y1 and file1.h5/x2y1. file1.h5/x1y2 and file2.h5/x2y2 are ignored because they don’t match the patterns.

Arguments
files: List[str]
List of h5 file address which will be read into memory and averaged over.
out_file: str
The name of the file which will contain the averages.
dset_replace_patterns: Optional[Dict[str, str]]
A map for how dsets in the input files are used to write to the output file. The routine only averages over dsets which match all keys of dset_replace_patterns.
overwrite: bool = False
Overwrite existing sliced files.
expected_dsets: Optional[int] = None
If true, raises an error if number of found dsets is less then the number of specified desets.
nucleon_elastic_ff.data.scripts.average.main()[source]

Command line interface for averaging list of h5 files

nucleon_elastic_ff.data.scripts.average.source_average(root: str, overwrite: bool = False, n_expected_sources: Optional[int] = None, expected_sources: Optional[List[str]] = None, file_name_addition: Optional[str] = None, additional_file_patterns: Optional[List[str]] = None)[source]

Recursively scans directory for files and averages matches which over specified component.

The input files must be h5 files (ending with “.h5”) and must have formfac_4D_tslice`in their file name. Files which have `formfac_4D_tslice_src_avg as name are excluded. Also, this routine ignores exporting to files which already exist.

Arguments
root: str
The directory to look for files.
overwrite: bool = False
Overwrite existing sliced files.
n_expected_sources: Optional[int] = None
Added control to pass excepted number of sources. If given and sources in one group is less than a certain number, raises ValueError.
expected_sources: Optional[List[str]] = None
Adds expected sources to file filter patterns. After files have been filtered and grouped, checks if all strings in this list are present in the file group. Note: this counts the number of files not the number of dsets within a file. This also overwrites n_expected_sources. If not exactly all sources are found in the group, raises AssertionError.
file_name_addition: Optional[str] = None
Appends this string to the file name if not None.
additional_file_patterns: Optional[List[str]] = None
Only consideres files for averaging if additional patterns are fulfilled.
nucleon_elastic_ff.data.scripts.average.spec_average(root: str, overwrite: bool = False, n_expected_sources: Optional[int] = None, expected_sources: Optional[List[str]] = None, file_name_addition: Optional[str] = None)[source]

Recursively scans directory for files and averages matches which over specified component.

Averages over source, spin and parity without shifting or slicing. Thus, the data must already be in the correct shape.

The input files must be h5 files (ending with “.h5”) and must have spec_4D_tslice in their file name. Files which have spec_4D_tslice_avg as name are excluded. Also, this routine ignores exporting to files which already exist.

Arguments
root: str
The directory to look for files.
overwrite: bool = False
Overwrite existing sliced files.
n_expected_sources: Optional[int] = None
Added control to pass excepted number of sources. If given and sources in one group is less than a certain number, raises AssertionError.
expected_sources: Optional[List[str]] = None
Adds expected sources to file filter patterns. After files have been filtered and grouped, checks if all strings in this list are present in the file group. Note: this counts the number of files not the number of dsets within a file. This also overwrites n_expected_sources. If not exactly all sources are found in the group, raises AssertionError.
file_name_addition: Optional[str] = None
Appends this string to the file name if not None.