Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions profsea/components/core/local_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from rich.progress import track

from profsea.utils import (
PROFSEA_VERSION,
fetch_zenodo_fingerprints,
save_components,
validate_component_map,
Expand Down Expand Up @@ -132,7 +133,7 @@ def _arr_to_xr(self, arr_dict: dict[str, da.Array]) -> dict[str, xr.DataArray]:
attrs={
"units": "m",
"long_name": f"Local {name} sea-level projections",
"source": "ProFSea-Climate v0.1",
"source": f"ProFSea v{PROFSEA_VERSION}",
},
)
else:
Expand All @@ -153,7 +154,7 @@ def _arr_to_xr(self, arr_dict: dict[str, da.Array]) -> dict[str, xr.DataArray]:
attrs={
"units": "m",
"long_name": f"Local {name} sea-level projections",
"source": "ProFSea-Climate v0.1",
"source": f"ProFSea v{PROFSEA_VERSION}",
},
)

Expand Down
5 changes: 3 additions & 2 deletions profsea/components/core/spatial_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from rich.progress import track

from profsea.utils import (
PROFSEA_VERSION,
fetch_zenodo_fingerprints,
save_components,
validate_component_map,
Expand Down Expand Up @@ -186,7 +187,7 @@ def _arr_to_xr(self, arr_dict: dict[str, da.Array]) -> dict[str, xr.DataArray]:
attrs={
"units": "m",
"long_name": f"Regional {name} sea-level projections",
"source": "ProFSea-Climate v0.1",
"source": f"ProFSea v{PROFSEA_VERSION}",
},
)

Expand All @@ -207,7 +208,7 @@ def _arr_to_xr(self, arr_dict: dict[str, da.Array]) -> dict[str, xr.DataArray]:
attrs={
"units": "m",
"long_name": f"Regional {name} sea-level projections",
"source": "ProFSea-Climate v0.1",
"source": f"ProFSea v{PROFSEA_VERSION}",
},
)

Expand Down
9 changes: 8 additions & 1 deletion profsea/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import logging
import os
import zipfile
from importlib.metadata import PackageNotFoundError
from importlib.metadata import version as package_version
from pathlib import Path

import dask
Expand All @@ -26,6 +28,11 @@
console = Console()
logger = logging.getLogger(__name__)

try:
PROFSEA_VERSION = package_version("profsea")
except PackageNotFoundError:
PROFSEA_VERSION = "unknown"


def validate_component_map(
components: dict,
Expand Down Expand Up @@ -366,7 +373,7 @@ def save_components(
ds = xr.Dataset(components)

# Add ProFSea version and scenario metadata
ds.attrs["source"] = "ProFSea v3.0"
ds.attrs["source"] = f"ProFSea v{PROFSEA_VERSION}"
ds.attrs["scenario"] = scenario_name
ds.attrs["description"] = description

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "profsea"
dynamic = ["version"]
version = "3.0.0"
description = "A rapid, modular sea-level simulator."
readme = "README.md"
authors = [
Expand Down
2 changes: 1 addition & 1 deletion tests/utils/test_utils.py

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes all look good to me -- but, should this test retrieve the package version (like in utils.py), rather than hard code v3.0.0 to avoid breaking in a future ProFSea version?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could not find an easy solution to this. So, I hard coded it. We would need to update it every time we bump the version. Maybe we can make it dynamic in future updates.
Are versions showing up properly in output files now?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah ok, makes sense. Yes, all working properly with the output files, so all looks good!

Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ def test_save_components_netcdf(tmp_path):
ds = xr.open_dataset(expected_file)
assert "comp1" in ds
assert ds.attrs["scenario"] == "ssp245"
assert ds.attrs["source"] == "ProFSea v3.0"
assert ds.attrs["source"] == "ProFSea v3.0.0"


def test_save_components_zarr(tmp_path):
Expand Down
Loading