fre.pp.rename_split_script module
- fre.pp.rename_split_script.get_duration_from_two_dates(date1: cftime.datetime, date2: cftime.datetime) str
Accept two dates and output duration in ISO8601.
- Parameters:
date1 (cftime.datetime) – The first date for comparison.
date2 (cftime.datetime) – The second date for comparison.
- Returns:
The ISO8601 duration string.
- Return type:
str
- Raises:
ValueError – If the duration cannot be determined from the dates.
- fre.pp.rename_split_script.get_freq_and_format_from_two_dates(date1: cftime.datetime, date2: cftime.datetime) -> (<class 'str'>, <class 'str'>)
Accept two dates and returns frequency string in ISO8601 and associated format string.
- Parameters:
date1 (cftime.datetime) – The first date for comparison.
date2 (cftime.datetime) – The second date for comparison.
- Returns:
A tuple containing the ISO8601 frequency string and the format string.
- Return type:
tuple[str, str]
- Raises:
ValueError – If the frequency cannot be determined from the dates.
- fre.pp.rename_split_script.link_or_copy(source: str, destination: str) None
Create a hard link including creating destination directory parents. If hard linking is not available, copy instead.
- Parameters:
source (str) – Path to the source file.
destination (str) – Path to the destination file.
- Returns:
None
- Return type:
None
- fre.pp.rename_split_script.rename_file(input_file: str, diag_manifest: tuple[str, ...] | str | None = ()) Path
Accept an input netCDF file that is the result of split-netcdf, e.g.
00010101.atmos_daily.tile1.temp.ncand output a directory and filename that identifies its frequency, interval, and beginning and ending dates, e.g.P1D/P6M/atmos_daily.00010101-0001063.temp.tile1.nc- Parameters:
input_file (str) – Path to the input NetCDF file.
diag_manifest (tuple[str, ...] or str or None) – Optional tuple of paths to diagnostic manifest files.
- Returns:
The new path for the renamed file.
- Return type:
Path
- Raises:
ValueError – If the file cannot be parsed or if diag manifest is required but not provided.
FileNotFoundError – If a diag manifest does not exist.
Exception – If unexpected frequency units are found in the diag manifest, or if the label is not found.
- fre.pp.rename_split_script.rename_split(input_dir: str, output_dir: str, component: str, use_subdirs: bool, diag_manifest: tuple[str, ...] | str | None = ()) None
Accept a flat directory of NetCDF files and output a nested directory structure containing frequency and time interval. If hard-linking is available, use it; otherwise copy. For regridded cases, accept subdirectories corresponding to the regrid label in the input directory and use them in the output directory.
- Parameters:
input_dir (str) – Path to the input directory containing NetCDF files.
output_dir (str) – Path to the output directory for the nested structure.
component (str) – The component name to filter files (e.g., ‘atmos’).
use_subdirs (bool) – Whether to use subdirectories for regridded cases.
diag_manifest (tuple[str, ...] or str or None) – Optional tuple of paths to diagnostic manifest files.
- Returns:
None
- Return type:
None
- Raises:
FileNotFoundError – If no files matching the component are found in the input directory.