SpecatalogArchive

class specatalog.data_management.archive_manager.SpecatalogArchive(use_remote_archive, local_path='')[source]

Bases: object

Handles file operations for the measurement archive. All file operations run relative to the archive root (self.archive).

Parameters:
  • use_remote_archive (bool)

  • local_path (str)

copy_directory_to_archive(src, dst_p)[source]

Copy directory to archive.

Parameters:
  • src (Union[str, Path]) – Source directory path

  • dst_p (Union[str, Path]) – Destination path in archive

Return type:

None

copy_to_archive(src, dst_p)[source]

Copy file to archive.

Parameters:
  • src (Union[str, Path]) – Source file path

  • dst_p (Union[str, Path]) – Destination path in archive

Return type:

None

delete_file(p)[source]

Delete file from archive.

Parameters:

p (Union[str, Path]) – Path of file to delete

Return type:

None

delete_folder(p)[source]

Delete directory from archive.

Parameters:

p (Union[str, Path]) – Path of directory to delete

Return type:

None

exists(p)[source]

Check if path exists.

Parameters:

p (Union[str, Path]) – Path to check

Returns:

True if path exists

Return type:

bool

list_files(p)[source]

List files in a directory.

Parameters:

p (Union[str, Path]) – Directory path

Returns:

List of filenames

Return type:

list[str]

make_dir(p)[source]

Create directory.

Parameters:

p (Union[str, Path]) – Directory path to create

Return type:

None

measurement_path(ms_id)[source]

Get measurement directory path ‘data/M{ms_id}’.

Parameters:

ms_id (Union[str, int]) – Measurement ID

Returns:

Path to measurement directory

Return type:

Path

Raises:

FileNotFoundError – If measurement directory doesn’t exist

open_file(p, mode='r', encoding='utf-8')[source]

Context manager for opening files.

Parameters:
  • p (Union[str, Path]) – Path of file to open

  • mode (str, optional) – File opening mode

  • encoding (str, optional) – File encoding

Yields:

file – Open file object

open_measurement_h5_file(p, mode)[source]

Open an HDF5 measurement file, optionally using a local cache.

For remote archives, the file is downloaded to a local cache before opening. Writable changes are uploaded atomically when the context exits successfully. Concurrent remote modifications are detected and prevent the upload.

Parameters:
  • p (str | Path) – Path to the measurement file relative to the archive root.

  • mode (str) – HDF5 file access mode.

Yields:

h5py.File – The opened HDF5 file.

Return type:

Iterator[File]

path_to_unc(p)[source]

Convert local path to UNC path format.

Parameters:

p (Union[str, Path]) – Local path to convert

Returns:

UNC path string

Return type:

str

temporary_path(p)[source]

Context manager for temporary local copies.

Parameters:

p (Union[str, Path]) – Path of remote file/directory

Yields:

Path – Path to local temporary copy