Skip to content

Commit 9fc4de7

Browse files
authored
Merge pull request #62 from elbeejay/one-version-loc
Refactor: single source of truth for version information
2 parents 0f8d7ff + 2f3a431 commit 9fc4de7

5 files changed

Lines changed: 25 additions & 9 deletions

File tree

dorado/__init__.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
__version__ = "2.7.0"
1+
from importlib.metadata import version, PackageNotFoundError
2+
3+
try:
4+
__version__ = version("pydorado")
5+
except PackageNotFoundError:
6+
__version__ = "unknown"
7+
28

39
from . import lagrangian_walker
410
from . import parallel_routing

dorado/routines.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1304,7 +1304,11 @@ def show_nourishment_area(visit_freq, grid=None, walk_data=None,
13041304
alphas = Normalize(0, amax, clip=True)(visit_freq) # Normalize alphas
13051305
alphas = np.clip(alphas, min_alpha, 1)
13061306
colors = Normalize(np.nanmin(visit_freq), 1)(visit_freq) # Normalize color
1307-
cmap = plt.cm.get_cmap(cmap)
1307+
if isinstance(cmap, str):
1308+
try:
1309+
cmap = matplotlib.colormaps[cmap]
1310+
except AttributeError:
1311+
cmap = plt.cm.get_cmap(cmap)
13081312
colors = cmap(colors)
13091313
colors[..., -1] = alphas
13101314

@@ -1390,7 +1394,11 @@ def show_nourishment_time(mean_times, grid=None, walk_data=None,
13901394
alphas = np.clip(alphas, min_alpha, 1)
13911395
colors = Normalize(np.nanmin(mean_times),
13921396
np.nanmax(mean_times))(mean_times) # Normalize colors
1393-
cmap = plt.cm.get_cmap(cmap)
1397+
if isinstance(cmap, str):
1398+
try:
1399+
cmap = matplotlib.colormaps[cmap]
1400+
except AttributeError:
1401+
cmap = plt.cm.get_cmap(cmap)
13941402
colors = cmap(colors)
13951403
colors[..., -1] = alphas
13961404

examples/spatial_exposure_time_example_Delft3DFM.ipynb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
"import json\n",
4242
"from pathlib import Path\n",
4343
"import dorado\n",
44+
"import matplotlib\n",
4445
"from matplotlib import pyplot as plt\n",
4546
"import dorado.spatial as spat\n",
4647
"import dorado.particle_track as pt"
@@ -423,7 +424,7 @@
423424
"outputs": [],
424425
"source": [
425426
"title = 'System-wide exposure time (days)'\n",
426-
"cmap = plt.get_cmap('plasma_r')\n",
427+
"cmap = matplotlib.colormaps['plasma_r'] if hasattr(matplotlib, 'colormaps') else plt.get_cmap('plasma_r')\n",
427428
"max_exposure = 30 # max time in model\n",
428429
"cbar_levels = 7"
429430
]
@@ -563,7 +564,7 @@
563564
"outputs": [],
564565
"source": [
565566
"title_local = 'Localized exposure time (days)'\n",
566-
"cmap_local = plt.get_cmap('viridis_r')\n",
567+
"cmap_local = matplotlib.colormaps['viridis_r'] if hasattr(matplotlib, 'colormaps') else plt.get_cmap('viridis_r')\n",
567568
"max_exposure_local = 7\n",
568569
"cbar_levels_local = 6"
569570
]
@@ -655,4 +656,4 @@
655656
},
656657
"nbformat": 4,
657658
"nbformat_minor": 5
658-
}
659+
}

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "pydorado"
7-
version = "2.7.0"
7+
version = "2.7.1"
88
description = "dorado - Lagrangian particle routing routine via weighted random walks"
99
readme = { file = "README.md", content-type = "text/markdown" }
1010
license = { file = "LICENSE" }

tests/test_spatial.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
55
@author: cturn
66
"""
7+
import matplotlib
78
from matplotlib import pyplot as plt
89
import numpy as np
910
import pytest
@@ -100,7 +101,7 @@ def test_plot_spatial(test_grid, walk_data):
100101
elevation=elevation,
101102
max_exposure=7,
102103
cbar_levels=7,
103-
cmap=plt.get_cmap("plasma_r"),
104+
cmap=matplotlib.colormaps["plasma_r"] if hasattr(matplotlib, "colormaps") else plt.get_cmap("plasma_r"),
104105
title="Test System-Wide (s)")
105106
plt.close("all")
106107

@@ -112,6 +113,6 @@ def test_plot_spatial(test_grid, walk_data):
112113
elevation=elevation,
113114
max_exposure=7,
114115
cbar_levels=7,
115-
cmap=plt.get_cmap("viridis_r"),
116+
cmap=matplotlib.colormaps["viridis_r"] if hasattr(matplotlib, "colormaps") else plt.get_cmap("viridis_r"),
116117
title="Test Localized (s)")
117118
plt.close("all")

0 commit comments

Comments
 (0)