dran.utils package#
Submodules#
dran.utils.config module#
- class dran.utils.config.ObservationPathParts(root_data_dir: pathlib.Path, category: str, source: str, frequency: int, filename: str, full_path: pathlib.Path, wavelength_cm: float | None = None, beam: str | None = None, band_folder: str | None = None)[source]#
Bases:
object- Parameters:
- class dran.utils.config.ObservationPathPartsFolder(root_data_dir: pathlib.Path, category: str, source: str, frequency: int, foldername: str, full_path: pathlib.Path, wavelength_cm: float | None = None, beam: str | None = None, band_folder: str | None = None)[source]#
Bases:
object- Parameters:
- class dran.utils.config.ProjectPaths(workdir: pathlib.Path, db_path: pathlib.Path, log_path: pathlib.Path, invalid_files_path: pathlib.Path, symlinks_path: pathlib.Path, diagnostics_dir: pathlib.Path, plots_dir: pathlib.Path)[source]#
Bases:
object- Parameters:
dran.utils.frequency_utils module#
- dran.utils.frequency_utils.get_band_from_frequency(frequency, log)[source]#
Determine the satellite frequency band for a given frequency (in MHz).
- Parameters:
- Returns:
- The corresponding band identifier
(e.g., ‘L’, ‘S’, ‘C’, ‘CM’, ‘X’, ‘Ku’, ‘K’, ‘Ka’).
- Return type:
- Raises:
ValueError – If the input frequency is invalid or outside known bands.
dran.utils.fs module#
- dran.utils.fs.resolve_existing_path(path, log, paths=None)[source]#
Resolve a filesystem path strictly.
- Returns:
Resolved absolute path.
- Raises:
FileNotFoundError – If the path does not exist.
OSError – If the path cannot be resolved.
- Parameters:
path (Path)
log (Logger)
paths (ProjectPaths | None)
- Return type:
- dran.utils.fs.parse_source_directory_path(path)[source]#
Extract frequency and source name from a directory path.
- Expected structure:
…/<SOURCE>/<FREQ>/ …/<SOURCE>/*_<FREQ>/
- dran.utils.fs.parse_source_frequency_band_from_path_if_folder(path, log)[source]#
Parse (source_name, frequency_mhz, band) from a FITS file path.
- Assumes a directory layout like:
…/<SOURCE_NAME>/<FREQUENCY_MHZ>/<file>.fits
- dran.utils.fs.parse_plot_path(path)[source]#
Extract source name, frequency, and filename from a plot path.
- Expected structure:
base / <src_name> / <freq> / <filename>
- dran.utils.fs.resolve_existing_path_without_logger(path)[source]#
Resolve a filesystem path strictly.
- dran.utils.fs.parse_observation_path(path_str)[source]#
Parse observation file paths for DRAN.
Supported layouts: data/calibration/3C123/12178/file.fits data/calibration/3C123_12178/file.fits data/calibration/3C123_13NB/file.fits data/calibration/3C123_13NB_dichroic_on/file.fits data/calibration/3C123_35/file.fits data/calibration/3C123_3.5NB/file.fits data/calibration/Jup/file.fits
- Parameters:
path_str (str)
- Return type:
- dran.utils.fs.parse_observation_path_if_folder(path_str)[source]#
Parse observation file paths for DRAN.
Supported layouts: data/calibration/3C123/12178/ data/calibration/3C123_12178/ data/calibration/3C123_13NB/ data/calibration/3C123_13NB_dichroic_on/ data/calibration/3C123_35/ data/calibration/3C123_3.5NB/ data/calibration/3C123/ data/calibration/Jup/
- Parameters:
path_str (str)
- Return type:
- dran.utils.fs.ensure_directory_exists(base_folder, log=None)[source]#
Ensure the given path exists and is a directory.
- dran.utils.fs.ensure_output_directories(paths, log, *, overwrite_if_contains='diagnostic')[source]#
Ensure required output directories exist.
Default behavior: - If the directory path contains the token “diagnostic”, it is recreated. - All other directories are created if missing.
- dran.utils.fs.recreate_dir(folder_path, log)[source]#
Recreate a directory.
If the directory already exists, it is removed with all contents, then recreated (including parents).
- dran.utils.fs.create_dir(folder_path, log)[source]#
Ensure a directory exists.
Creates parent directories as needed. If it already exists, it is left unchanged.
- dran.utils.fs.clear_diagnostics_dir(path, log)[source]#
Remove all files and subdirectories from a diagnostics directory. Safely deletes directory contents if the path exists. Logs a warning for any item that cannot be removed.
- dran.utils.fs.compute_file_hash(path, *, chunk_size=1048576)[source]#
Compute a SHA-256 hash for a file by streaming its contents.
- dran.utils.fs.load_invalid_paths(paths, log)[source]#
Load previously recorded invalid paths from disk.
Returns an empty set if the log file does not exist.
- Parameters:
paths (ProjectPaths)
log (Logger)
- Return type:
- dran.utils.fs.load_symlink_paths(paths, log)[source]#
Load previously recorded symlink paths from disk.
- Parameters:
paths (ProjectPaths)
log (Logger)
- Return type:
- dran.utils.fs.append_invalid_path(path, paths, log)[source]#
Append a path to the invalid path registry on disk.
Creates parent directories for the registry file if needed.
- Parameters:
path (Path)
paths (ProjectPaths)
log (Logger)
- Return type:
None
- dran.utils.fs.append_symlink_path(path, paths, log)[source]#
Append a symlink path to the symlink registry on disk.
- Parameters:
path (Path)
paths (ProjectPaths)
log (Logger)
- Return type:
None
- dran.utils.fs.record_invalid_path_once(path, paths, log, reason)[source]#
Record an invalid path only once.
If the path is already present, nothing is appended.
- Parameters:
path (Path)
paths (ProjectPaths)
log (Logger)
reason (str)
- Return type:
None
- dran.utils.fs.record_symlink_path_once(path, paths, log)[source]#
Record a symlink path only once in the symlink registry.
- Parameters:
path (Path)
paths (ProjectPaths)
log (Logger)
- Return type:
None