morphfits.paths#

Resolve, create, and otherwise handle directory and file structure for GalWrap.

Attributes#

logger

Logging object for this module.

PATH_STANDARDS

Path to data standard detailing paths for the MorphFITS filesystem structure.

TEMPLATE_MAPPINGS

Dict mapping from template abbreviations to parameter names.

MORPHFITS_PATHS

Dict of paths used in MorphFITS, where the key, value pair is the path's

Classes#

MorphFITSPath

Path model for a single path in the MorphFITS filesystem structure.

Functions#

get_path_obj(→ pathlib.Path)

Get a resolved Path object for a potential string.

get_directories(→ list[pathlib.Path])

Get a list of subdirectories under a path.

get_files(→ list[pathlib.Path])

Get a list of files in a directory.

find_parameter_from_input(→ list[str] | list[int])

Find values for a parameter, e.g. filters, from an input directory

get_path_name(→ str)

Get internally-standardized name of path corresponding to passed name.

get_path(→ pathlib.Path | None)

Get the path to a MorphFITS file or directory.

Module Contents#

morphfits.paths.logger#

Logging object for this module.

morphfits.paths.PATH_STANDARDS#

Path to data standard detailing paths for the MorphFITS filesystem structure.

morphfits.paths.TEMPLATE_MAPPINGS#

Dict mapping from template abbreviations to parameter names.

class morphfits.paths.MorphFITSPath(/, **data: Any)#

Bases: pydantic.BaseModel

Path model for a single path in the MorphFITS filesystem structure.

Parameters:

BaseModel (class) – Base pydantic model class to enforce type validation upon creation.

file#

Flag for whether path is a file.

Type:

bool

path#

Path to object (directory or file) as a template, where other paths are wrapped by square brackets and parameters are wrapped by curly brackets, e.g. [input_root]/{F}/{I}.

Type:

str

alts#

List of recognized alternate names for this path.

Type:

list[sr]

file: bool#
path: str#
alts: list[str]#
resolve(morphfits_root: pathlib.Path | None = None, input_root: pathlib.Path | None = None, output_root: pathlib.Path | None = None, product_root: pathlib.Path | None = None, run_root: pathlib.Path | None = None, field: str | None = None, image_version: str | None = None, catalog_version: str | None = None, filter: str | None = None, object: int | None = None, datetime: datetime.datetime | None = None, run_number: int | None = None) pathlib.Path | None#

Get the full path for this path object for passed configuration parameters.

Parameters:
  • morphfits_root (Path | None, optional) – Path to root of MorphFITS filesystem, by default None.

  • input_root (Path | None, optional) – Path to root input directory, by default None.

  • output_root (Path | None, optional) – Path to root output directory, by default None.

  • product_root (Path | None, optional) – Path to root products directory, by default None.

  • run_root (Path | None, optional) – Path to root runs directory, by default None.

  • field (str | None, optional) – Field of observation, by default None.

  • image_version (str | None, optional) – Image version of science frame, by default None.

  • catalog_version (str | None, optional) – Catalog version of science frame, by default None.

  • filter (str | None, optional) – Filter used in observation, by default None.

  • object (int | None, optional) – Target galaxy or cluster ID in catalog, by default None.

  • datetime (datetime | None, optional) – Datetime at start of program run, by default None.

  • run_number (int | None, optional) – Number of run in collection with same datetime, by default None.

Returns:

Full path to directory or file corresponding to this path object.

Return type:

Path

morphfits.paths.MORPHFITS_PATHS#

Dict of paths used in MorphFITS, where the key, value pair is the path’s path_name, then a MorphFITSPath instance.

morphfits.paths.get_path_obj(path_like: str | pathlib.Path) pathlib.Path#

Get a resolved Path object for a potential string.

Parameters:

path_like (str | Path) – Path which may or may not be of string type.

Returns:

Corresponding Path object.

Return type:

Path

morphfits.paths.get_directories(path: pathlib.Path) list[pathlib.Path]#

Get a list of subdirectories under a path.

Parameters:

path (Path) – Path to be walked.

Returns:

List of subdirectories under specified path.

Return type:

list[Path]

Raises:

ValueError – Specified path not a directory.

morphfits.paths.get_files(path: pathlib.Path) list[pathlib.Path]#

Get a list of files in a directory.

Parameters:

path (Path) – Path to be walked.

Returns:

List of files in specified directory.

Return type:

list[Path]

Raises:

ValueError – Specified path not a directory.

morphfits.paths.find_parameter_from_input(parameter_name: str, input_root: pathlib.Path) list[str] | list[int]#

Find values for a parameter, e.g. filters, from an input directory structure.

Parameters:
  • parameter_name (str) – Name of parameter, one of “field”, “image_version”, or “filter”. Other parameters are not currently supported for discovery.

  • input_root (Path) – Path to root directory of input products.

Returns:

List of discovered parameter values.

Return type:

list[str] | list[int]

Raises:

ValueError – Unrecognized parameter name.

morphfits.paths.get_path_name(name: str) str#

Get internally-standardized name of path corresponding to passed name.

Parameters:

name (str) – Name of directory or file, e.g. input_images.

Returns:

Corresponding standardized path name for internal usage.

Return type:

str

Raises:
  • TypeError – Passed name not a str.

  • ValueError – Passed name unrecognized.

Notes

A path name is resolvable if its casefold is equal to 1. The standardized path name itself

e.g input_images

  1. A recognized alternative name

    e.g. images for input_images

  2. The standardized path name, separated by spaces rather than underscores

    e.g. input images for input_images

  3. The standardized path name, space-separated, with a corresponding dir or file suffix

    e.g. input images dir for input_images

  4. The standardized path name, space-separated, suffixed, un-pluralized

    e.g. input image dir for input_images

See also

data

List of recognized alternative path names for each path.

morphfits.paths.get_path(name: str, morphfits_root: pathlib.Path | None = None, input_root: pathlib.Path | None = None, output_root: pathlib.Path | None = None, product_root: pathlib.Path | None = None, run_root: pathlib.Path | None = None, field: str | None = None, image_version: str | None = None, catalog_version: str | None = None, filter: str | None = None, object: int | None = None, datetime: datetime.datetime | None = None, run_number: int | None = None) pathlib.Path | None#

Get the path to a MorphFITS file or directory.

Parameters:
  • name (str) – Name of path to get.

  • morphfits_root (Path | None, optional) – Path to root of MorphFITS filesystem, by default None.

  • input_root (Path | None, optional) – Path to root input directory, by default None.

  • output_root (Path | None, optional) – Path to root output directory, by default None.

  • product_root (Path | None, optional) – Path to root products directory, by default None.

  • run_root (Path | None, optional) – Path to root runs directory, by default None.

  • field (str | None, optional) – Field of observation, by default None.

  • image_version (str | None, optional) – Image version of science frame, by default None.

  • catalog_version (str | None, optional) – Catalog version of science frame, by default None.

  • filter (str | None, optional) – Filter used in observation, by default None.

  • object (int | None, optional) – Target galaxy or cluster ID in catalog, by default None.

  • datetime (datetime | None, optional) – Datetime at start of program run, by default None.

  • run_number (int | None, optional) – Number of run in collection with same datetime, by default None.

Returns:

Path to file or directory.

Return type:

Path

See also

data

Data standards dictionary detailing MorphFITS paths.