cvpl_tools/tools/fs.py
View source at fs.py.
APIs
- cvpl_tools.tools.fs.cdir_init(cache_url: str | RDirFileSystem) CDirQueryResult
Returned CDirQueryResult is the same as calling cdir_query()
Function behavior: 1. If directory does not exist, make a new empty directory 2. If directory exists but timestamp is not found (not committed), then remove it and make a new directory 3. If commit timestamp is found, do nothing
- Parameters:
cache_url – Pointing to the directory location
- cvpl_tools.tools.fs.cdir_commit(cache_url: str | RDirFileSystem)
Create a commit timestamp
- cvpl_tools.tools.fs.cdir_query(cache_url: str | RDirFileSystem) CDirQueryResult
Query the commit status of a directory
1. If the url points to a directory that does not exists or does not have ‘.cache_url_timestamp’ file created under, then the returned query object will have query.commit = None 2. Otherwise the directory is a committed directory, and the returned query object will contain the time stamp of commit in its commit attribute query.commit
- Parameters:
cache_url – The location to be queried
- Returns:
A CDirQueryResult containing the commit status of the given cache url will be returned
- async cvpl_tools.tools.fs.save(file: str | RDirFileSystem, im, storage_options: dict = None)
Save an image object into given path
Supported im object types: - np.ndarray - dask.Array - cvpl_tools.im.ndblock.NDBlock
- Parameters:
file – The full/relative path to the directory to be saved to
im – Object to be saved
storage_options – Specifies options in saving method and saved file format -preferred_chunksize (tuple[int, …]): chunk sizes to save as; will rechunk if different from current size; only applies to dask arrays. -multiscale (int): The number of downsample layers for save ome-zarr; only applies if the image is a dask image -compressor: The compressor to use to compress array or chunks
- cvpl_tools.tools.fs.load(file: str | RDirFileSystem, storage_options: dict = None)
Load an image from the given directory.
The image is one saved by cvpl_tools.tools.fs.save()
- Parameters:
file – Full path to the directory to be read from
storage_options – Specifies options in saving method and saved file format - compressor (numcodecs.abc.Codec, optional): Compressor used to compress the chunks
- Returns:
Recreated image; this method attempts to keep meta and content of the loaded image stays the same as when they are saved
- cvpl_tools.tools.fs.display(file: str | RDirFileSystem, context_args: dict)
Display an image in the viewer; supports numpy or dask ome zarr image
The image is one saved by cvpl_tools.tools.fs.save()
- Parameters:
file – Full path to the directory to be read from
context_args – contains viewer and arguments passed to the viewer’s add image functions - viewer (napari.Viewer, optional): Only display if a viewer is provided - is_label (bool, optional): defaults to False; if True, use viewer’s add_labels() instead of add_image() to display the array - layer_args (dict, optional)