Skip to content

Commit aecd25a

Browse files
committed
Add attributes to the DCD outputs
DCD-141
1 parent 1069fa3 commit aecd25a

1 file changed

Lines changed: 54 additions & 4 deletions

File tree

deltacd/dcd.py

Lines changed: 54 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import numpy as np
1818
import pandas as pd
1919
import xarray as xr
20+
from deltacd import __version__
2021
from deltacd.detaw import convert_to_absolute_path
2122

2223
# Set up a logger
@@ -256,14 +257,21 @@ def set_dcd_node_global_attributes(
256257
ds_dcd_nodes: xarray.Dataset
257258
dataset containing DCD node data
258259
"""
259-
title = "DeltaCD outputs"
260+
title = (
261+
"Outputs at model nodes from Delta Channel Depletion (DCD) module of DeltaCD"
262+
)
260263
leach_factor = model_params.get("leach_scale")
261264
water_surface_evaporation = model_params.get("is_adding_waterbody_evaporation")
265+
created_at = pd.Timestamp.now().strftime("%Y-%m-%d %H:%M:%S")
266+
history = (
267+
f"{created_at} - generated by DeltaCD version {__version__}, DCD module"
268+
)
262269
dcd_inputs = json.dumps(model_params)
263270
ds_dcd_nodes = ds_dcd_nodes.assign_attrs(
264271
title=title,
265272
leach_factor=leach_factor,
266273
water_surface_evaporation=str(water_surface_evaporation),
274+
history=history,
267275
dcd_inputs=dcd_inputs,
268276
)
269277
return ds_dcd_nodes
@@ -349,21 +357,21 @@ def island_to_nodes(ds_dcd, input_data):
349357
# Diversion
350358
da_div_nodes = ds_dcd.diversion.dot(ds_dist_rates.divrate)
351359
da_div_nodes = da_div_nodes.assign_attrs(
352-
unit="cfs", description="diversion flow at nodes"
360+
units="cfs", description="diversion flow at model nodes"
353361
)
354362

355363
# Seepage
356364
da_spg_nodes = ds_dcd.seepage.dot(ds_dist_rates.divrate)
357365
da_spg_nodes = da_spg_nodes.assign_attrs(
358-
unit="cfs", description="seepage flow at nodes"
366+
units="cfs", description="seepage flow at model nodes"
359367
)
360368

361369
# Drainage
362370
da_drn_nodes = ds_dcd.drainage.dot(ds_dist_rates.drnrate) + ds_dcd.runoff.dot(
363371
ds_dist_rates.drnrate
364372
)
365373
da_drn_nodes = da_drn_nodes.assign_attrs(
366-
unit="cfs", description="drainage flow at nodes"
374+
units="cfs", description="drainage flow at model nodes"
367375
)
368376

369377
# Create a xarray.Dataset.
@@ -373,6 +381,7 @@ def island_to_nodes(ds_dcd, input_data):
373381
ds_dcd_nodes = da_div_nodes.to_dataset(name="diversion")
374382
ds_dcd_nodes["seepage"] = da_spg_nodes
375383
ds_dcd_nodes["drainage"] = da_drn_nodes
384+
ds_dcd_nodes.coords["node"].attrs["description"] = "model node name"
376385

377386
return ds_dcd_nodes
378387

@@ -673,27 +682,59 @@ def calculate_depletion(model_params: dict, input_data: dict) -> xr.Dataset:
673682
# FIXME Add attributes
674683
da_gwf *= taf2cfs
675684
ds_dcd = da_gwf.to_dataset(name="groundwater")
685+
ds_dcd["groundwater"].attrs = {
686+
"units": "cfs",
687+
"description": "groundwater at subarea",
688+
}
676689

677690
ds_dcd["groundwater_to_applied_water"] = da_gw1 * taf2cfs
691+
ds_dcd["groundwater_to_applied_water"].attrs = {
692+
"units": "cfs",
693+
"description": "groundwater flow to applied water",
694+
}
678695

679696
ds_dcd["applied_water"] = da_aw / da_eta * taf2cfs
697+
ds_dcd["applied_water"].attrs = {
698+
"units": "cfs",
699+
"description": "applied water at subarea",
700+
}
680701

681702
da_runoff_after_percolation *= taf2cfs
682703
ds_dcd["runoff"] = da_runoff_after_percolation
704+
ds_dcd["runoff"].attrs = {
705+
"units": "cfs",
706+
"description": "runoff at subarea",
707+
}
683708

684709
# Calculate deep percolation
685710
factor_deep_percolation = model_params.get("deep_percolation_rate")
686711
ds_deep_percolation = da_runoff * factor_deep_percolation
687712
ds_dcd["deep_percolation"] = ds_deep_percolation
713+
ds_dcd["deep_percolation"].attrs = {
714+
"units": "cfs",
715+
"description": "deep percolation at subarea",
716+
}
688717

689718
da_diversion *= taf2cfs
690719
ds_dcd["diversion"] = da_diversion
720+
ds_dcd["diversion"].attrs = {
721+
"units": "cfs",
722+
"description": "diversion flow at subarea",
723+
}
691724

692725
da_drainage *= taf2cfs
693726
ds_dcd["drainage"] = da_drainage
727+
ds_dcd["drainage"].attrs = {
728+
"units": "cfs",
729+
"description": "drainage flow at subarea",
730+
}
694731

695732
da_seepage *= taf2cfs
696733
ds_dcd["seepage"] = da_seepage
734+
ds_dcd["seepage"].attrs = {
735+
"units": "cfs",
736+
"description": "seepage flow at subarea",
737+
}
697738

698739
# Now we subtract the values from 'extension'
699740
ds_dcd_subtracted = ds_dcd.copy(deep=True)
@@ -705,6 +746,15 @@ def calculate_depletion(model_params: dict, input_data: dict) -> xr.Dataset:
705746
area_id=area_id
706747
)
707748

749+
created_at = pd.Timestamp.now().strftime("%Y-%m-%d %H:%M:%S")
750+
751+
title = "Outputs at subareas from Delta Channel Depletion (DCD) module of DeltaCD"
752+
ds_dcd_subtracted.attrs["title"] = title
753+
history = (
754+
f"{created_at} - generated by DeltaCD version {__version__}, DCD module"
755+
)
756+
ds_dcd_subtracted.attrs["history"] = history
757+
708758
return ds_dcd_subtracted
709759

710760

0 commit comments

Comments
 (0)