Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update ONC VENUS nodes model/obs comparison figure module #254

Merged
merged 6 commits into from
Apr 8, 2024
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
6 changes: 2 additions & 4 deletions config/nowcast.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -393,10 +393,8 @@ results archive:
# Values are directories on results server where run results are stored
# in ddmmmyy/ directories.
nowcast: /results/SalishSea/nowcast-blue.202111/
### retained until make_plots is refactored to remove nowcast-dev
### that refactoring needs to come after compare_venus_ctd fig module is updated
### to handle ONC API v3
nowcast-dev: /results/SalishSea/nowcast-dev.201905/
### nowcast-dev is not presently bing run
nowcast-dev: None
forecast: /results/SalishSea/forecast.202111/
forecast2: /results/SalishSea/forecast2.202111/
nowcast-green: /results2/SalishSea/nowcast-green.202111/
Expand Down
1 change: 1 addition & 0 deletions envs/environment-fig-dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ dependencies:

# For figures development
- jupyterlab
- notebook

# For documentation
- sphinx=7.2.6
Expand Down
135 changes: 91 additions & 44 deletions notebooks/figures/comparison/TestCompareVENUS_CTD.ipynb

Large diffs are not rendered by default.

103 changes: 56 additions & 47 deletions nowcast/figures/comparison/compare_venus_ctd.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""
"""Produce a 2-panel figure that shows time series of temperature and salinity observations and
model run results at an Ocean Networks Canada (ONC) Salish Sea (VENUS) node.

Testing notebook for this module is
https://nbviewer.org/github/SalishSeaCast/SalishSeaNowcast/blob/main/comparison/TestCompareVENUS_CTD.ipynb
"""
import os
from collections import namedtuple
Expand Down Expand Up @@ -127,40 +131,43 @@
w_depths,
)
# Development model results
dev_model_time = nc_tools.timestamp(
dev_grid_T_hr, range(grid_T_hr.variables["time_counter"].size)
)
tracer_depths = dev_mesh_mask.variables["gdept_0"][..., j, i][0]
tracer_mask = dev_mesh_mask.variables["tmask"][..., j, i][0]
w_depths = dev_mesh_mask.variables["gdepw_0"][..., j, i][0]
salinity_profiles = dev_grid_T_hr.variables["vosaline"][..., j, i]
temperature_profiles = dev_grid_T_hr.variables["votemper"][..., j, i]
dev_model_salinity_ts = _calc_results_time_series(
salinity_profiles,
dev_model_time,
node_depth,
timezone,
tracer_depths,
tracer_mask,
w_depths,
)
dev_model_temperature_ts = _calc_results_time_series(
temperature_profiles,
dev_model_time,
node_depth,
timezone,
tracer_depths,
tracer_mask,
w_depths,
)
if dev_grid_T_hr is None:
dev_model_salinity_ts, dev_model_temperature_ts = None, None

Check warning on line 135 in nowcast/figures/comparison/compare_venus_ctd.py

View check run for this annotation

Codecov / codecov/patch

nowcast/figures/comparison/compare_venus_ctd.py#L135

Added line #L135 was not covered by tests
else:
dev_model_time = nc_tools.timestamp(

Check warning on line 137 in nowcast/figures/comparison/compare_venus_ctd.py

View check run for this annotation

Codecov / codecov/patch

nowcast/figures/comparison/compare_venus_ctd.py#L137

Added line #L137 was not covered by tests
dev_grid_T_hr, range(grid_T_hr.variables["time_counter"].size)
)
tracer_depths = dev_mesh_mask.variables["gdept_0"][..., j, i][0]
tracer_mask = dev_mesh_mask.variables["tmask"][..., j, i][0]
w_depths = dev_mesh_mask.variables["gdepw_0"][..., j, i][0]
salinity_profiles = dev_grid_T_hr.variables["vosaline"][..., j, i]
temperature_profiles = dev_grid_T_hr.variables["votemper"][..., j, i]
dev_model_salinity_ts = _calc_results_time_series(

Check warning on line 145 in nowcast/figures/comparison/compare_venus_ctd.py

View check run for this annotation

Codecov / codecov/patch

nowcast/figures/comparison/compare_venus_ctd.py#L140-L145

Added lines #L140 - L145 were not covered by tests
salinity_profiles,
dev_model_time,
node_depth,
timezone,
tracer_depths,
tracer_mask,
w_depths,
)
dev_model_temperature_ts = _calc_results_time_series(

Check warning on line 154 in nowcast/figures/comparison/compare_venus_ctd.py

View check run for this annotation

Codecov / codecov/patch

nowcast/figures/comparison/compare_venus_ctd.py#L154

Added line #L154 was not covered by tests
temperature_profiles,
dev_model_time,
node_depth,
timezone,
tracer_depths,
tracer_mask,
w_depths,
)
# Observations
onc_data = data_tools.get_onc_data(
"scalardata",
"getByStation",
"getByLocation",
os.environ["ONC_USER_TOKEN"],
station=station_code,
deviceCategory="CTD",
sensors="salinity,temperature",
locationCode=station_code,
deviceCategoryCode="CTD",
sensorCategoryCodes="salinity,temperature",
dateFrom=data_tools.onc_datetime(model_time[0], "utc"),
dateTo=data_tools.onc_datetime(model_time[-1], "utc"),
)
Expand Down Expand Up @@ -241,14 +248,15 @@
color=theme.COLOURS["time series"]["VENUS node model salinity"],
alpha=0.7,
)
ax.plot(
[t.datetime for t in plot_data.dev_model_salinity_ts.time],
plot_data.dev_model_salinity_ts.var,
linewidth=2,
label="Dev Model",
color=theme.COLOURS["time series"]["VENUS node dev model salinity"],
alpha=0.5,
)
if plot_data.dev_model_salinity_ts is not None:
ax.plot(

Check warning on line 252 in nowcast/figures/comparison/compare_venus_ctd.py

View check run for this annotation

Codecov / codecov/patch

nowcast/figures/comparison/compare_venus_ctd.py#L252

Added line #L252 was not covered by tests
[t.datetime for t in plot_data.dev_model_salinity_ts.time],
plot_data.dev_model_salinity_ts.var,
linewidth=2,
label="Dev Model",
color=theme.COLOURS["time series"]["VENUS node dev model salinity"],
alpha=0.5,
)
_salinity_axis_labels(ax, place, plot_data, theme)


Expand Down Expand Up @@ -297,14 +305,15 @@
color=theme.COLOURS["time series"]["VENUS node model temperature"],
alpha=0.7,
)
ax.plot(
[t.datetime for t in plot_data.dev_model_temperature_ts.time],
plot_data.dev_model_temperature_ts.var,
linewidth=2,
label="Dev Model",
color=theme.COLOURS["time series"]["VENUS node dev model temperature"],
alpha=0.5,
)
if plot_data.dev_model_salinity_ts is not None:
ax.plot(

Check warning on line 309 in nowcast/figures/comparison/compare_venus_ctd.py

View check run for this annotation

Codecov / codecov/patch

nowcast/figures/comparison/compare_venus_ctd.py#L309

Added line #L309 was not covered by tests
[t.datetime for t in plot_data.dev_model_temperature_ts.time],
plot_data.dev_model_temperature_ts.var,
linewidth=2,
label="Dev Model",
color=theme.COLOURS["time series"]["VENUS node dev model temperature"],
alpha=0.5,
)
tzname = plot_data.model_temperature_ts.time[0].datetime.tzname()
_temperature_axis_labels(ax, plot_data, timezone, tzname, theme)

Expand Down
23 changes: 9 additions & 14 deletions nowcast/workers/make_plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,11 @@

fig_functions = {}
if model == "nemo":
dev_results_home = Path(config["results archive"]["nowcast-dev"])
dev_results_home = (

Check warning on line 179 in nowcast/workers/make_plots.py

View check run for this annotation

Codecov / codecov/patch

nowcast/workers/make_plots.py#L179

Added line #L179 was not covered by tests
None
if config["results archive"]["nowcast-dev"] == "None"
else Path(config["results archive"]["nowcast-dev"])
)
weather_path = Path(config["weather"]["ops dir"])
if run_type in ["forecast", "forecast2"]:
weather_path = weather_path / "fcst"
Expand Down Expand Up @@ -682,9 +686,11 @@
f"preparing render list for {run_date.format('YYYY-MM-DD')} NEMO nowcast-blue comparison figures"
)
hrdps_dataset_url = config["figures"]["dataset URLs"]["HRDPS fields"]
dev_results_dir = os.path.join(dev_results_home, dmy)
if dev_results_home is None:
dev_grid_T_hr = None

Check warning on line 690 in nowcast/workers/make_plots.py

View check run for this annotation

Codecov / codecov/patch

nowcast/workers/make_plots.py#L690

Added line #L690 was not covered by tests
else:
dev_grid_T_hr = _results_dataset("1h", "grid_T", dev_results_home / dmy)

Check warning on line 692 in nowcast/workers/make_plots.py

View check run for this annotation

Codecov / codecov/patch

nowcast/workers/make_plots.py#L692

Added line #L692 was not covered by tests
grid_T_hr = _results_dataset("1h", "grid_T", results_dir)
dev_grid_T_hr = _results_dataset("1h", "grid_T", dev_results_dir)
grid_central = _results_dataset_gridded("central", results_dir)
grid_obs_central = sio.loadmat("/ocean/dlatorne/MEOPAR/ONC_ADCP/ADCPcentral.mat")
grid_east = _results_dataset_gridded("east", results_dir)
Expand Down Expand Up @@ -719,17 +725,6 @@
dev_mesh_mask,
),
},
"Compare_VENUS_Delta_DDL": {
"function": compare_venus_ctd.make_figure,
"args": (
"Delta DDL node",
grid_T_hr,
dev_grid_T_hr,
timezone,
mesh_mask,
dev_mesh_mask,
),
},
"Central_ADCP": {
"function": research_VENUS.plotADCP,
"args": (
Expand Down
2 changes: 1 addition & 1 deletion tests/workers/test_download_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ def test_run_type_results_dir(
def test_results_archive(self, prod_config):
archives = {
"nowcast": "/results/SalishSea/nowcast-blue.202111/",
"nowcast-dev": "/results/SalishSea/nowcast-dev.201905/",
"nowcast-dev": "None",
"forecast": "/results/SalishSea/forecast.202111/",
"forecast2": "/results/SalishSea/forecast2.202111/",
"nowcast-green": "/results2/SalishSea/nowcast-green.202111/",
Expand Down
2 changes: 1 addition & 1 deletion tests/workers/test_make_plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def test_timezone(self, prod_config):
def test_dev_results_archive(self, prod_config):
dev_results_archive = prod_config["results archive"]["nowcast-dev"]

assert dev_results_archive == "/results/SalishSea/nowcast-dev.201905/"
assert dev_results_archive == "None"

def test_weather_path(self, prod_config):
weather_path = prod_config["weather"]["ops dir"]
Expand Down
2 changes: 1 addition & 1 deletion tests/workers/test_split_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def test_message_registry_keys(self, prod_config):
def test_results_archive(self, prod_config):
archives = {
"nowcast": "/results/SalishSea/nowcast-blue.202111/",
"nowcast-dev": "/results/SalishSea/nowcast-dev.201905/",
"nowcast-dev": "None",
"forecast": "/results/SalishSea/forecast.202111/",
"forecast2": "/results/SalishSea/forecast2.202111/",
"nowcast-green": "/results2/SalishSea/nowcast-green.202111/",
Expand Down