Skip to content

Utilities and Visualization

Common helpers and visualization tools.

Utilities

project_name.utils

Utility functions for data loading and environment detection.

get_data_path

get_data_path(config_path: str | Path, gcs_bucket: str | None = None) -> Path

Get the appropriate data path based on the environment.

In cloud environments (GCP/Vertex AI), data is mounted to /gcs/. In local environments, data is loaded from the configured path.

Parameters:

Name Type Description Default
config_path str | Path

The data path from config (e.g., 'data' or 'data/processed').

required
gcs_bucket str | None

Optional GCS bucket name. If provided and running in cloud, will use /gcs/ as the base path.

None

Returns:

Type Description
Path

Path object pointing to the correct data location.

Source code in src/project_name/utils.py
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
def get_data_path(config_path: str | Path, gcs_bucket: str | None = None) -> Path:
    """Get the appropriate data path based on the environment.

    In cloud environments (GCP/Vertex AI), data is mounted to /gcs/<bucket-name>.
    In local environments, data is loaded from the configured path.

    Args:
        config_path: The data path from config (e.g., 'data' or 'data/processed').
        gcs_bucket: Optional GCS bucket name. If provided and running in cloud,
                    will use /gcs/<bucket-name> as the base path.

    Returns:
        Path object pointing to the correct data location.
    """
    gcs_mount = Path("/gcs")

    if gcs_mount.exists() and gcs_bucket:
        data_path = gcs_mount / gcs_bucket / config_path
    else:
        data_path = Path(config_path)

    return data_path

Visualization

project_name.visualize