Skip to content

Commit d862db5

Browse files
authored
taw read from file depends on X/Y instead of constant (#321)
* taw read from file depends on X/Y instead of constant * taw_max in config thus taw file reading always in callbacks * cosmetics * it's conventional to use the name _ (underscore) for a return value you don't intend to use
1 parent 0ed65e1 commit d862db5

File tree

4 files changed

+36
-27
lines changed

4 files changed

+36
-27
lines changed

enacts/config-defaults.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,3 +102,4 @@ wat_bal_monit:
102102
# menu_label: Crop Evapotranspiration
103103
# description: The map shows the crop evapotranspiration...
104104
# units: mm
105+

enacts/config-sng.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,4 +80,6 @@ wat_bal_monit:
8080
crop_name: Rice
8181
kc_v: [0, 0, 1.1, 1.1, 0]
8282
kc_l: [3, 27, 45, 60]
83+
taw_file: /data/remic/mydatafiles/soilgrids/Senegal/GYGA_ERZD_wat_cap_abs_anacim_enacts3.nc
84+
taw_max: 136
8385

enacts/wat_bal/agronomy.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ def soil_plant_water_step(
5959
6060
.. math:: drainage = |wb - sm|
6161
"""
62-
6362
# Water Balance
6463
wb = (sm_yesterday + peffective - et).clip(min=0)
6564
drainage = (wb - taw).clip(min=0)
@@ -500,4 +499,4 @@ def solar_radiation(doy, lat):
500499
/ np.pi
501500
).rename("ra")
502501
ra.attrs = dict(description="Extraterrestrial Radiation", units="MJ/m**2/day")
503-
return ra
502+
return ra

enacts/wat_bal/maproom_monit.py

Lines changed: 32 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -364,12 +364,13 @@ def wat_bal_plots(
364364
error_fig = pingrid.error_fig(error_msg="Grid box out of data domain")
365365
return error_fig
366366
precip.load()
367+
taw = pingrid.sel_snap(xr.open_dataarray(Path(CONFIG["taw_file"])), lat, lng)
367368
try:
368369
sm, drainage, et_crop, et_crop_red, planting_date = ag.soil_plant_water_balance(
369370
precip,
370371
et=5,
371-
taw=60,
372-
sminit=60./3.,
372+
taw=taw,
373+
sminit=taw/3.,
373374
kc_params=kc_params,
374375
planting_date=p_d,
375376
)
@@ -379,16 +380,16 @@ def wat_bal_plots(
379380
)
380381
return error_fig
381382
if map_choice == "sm":
382-
myts = sm
383+
ts = sm
383384
elif map_choice == "drainage":
384-
myts = drainage
385+
ts = drainage
385386
elif map_choice == "et_crop":
386-
myts = et_crop
387+
ts = et_crop
387388
wat_bal_graph = pgo.Figure()
388389
wat_bal_graph.add_trace(
389390
pgo.Scatter(
390-
x=myts["T"].dt.strftime("%-d %b %y"),
391-
y=myts.values,
391+
x=ts["T"].dt.strftime("%-d %b %y"),
392+
y=ts.values,
392393
hovertemplate="%{y} on %{x}",
393394
name="",
394395
line=pgo.scatter.Line(color="blue"),
@@ -458,33 +459,39 @@ def wat_bal_tile(tz, tx, ty):
458459
data=[kc_init, kc_veg, kc_mid, kc_late, kc_end], dims=["kc_periods"], coords=[kc_periods]
459460
)
460461

461-
mymap_min = 0
462-
mymap_max = 60 #taw.max()
463-
mycolormap = CMAPS["precip"]
462+
_, taw_tile = xr.align(
463+
precip,
464+
xr.open_dataarray(Path(CONFIG["taw_file"])),
465+
join="override",
466+
exclude="T",
467+
)
468+
taw_tile = taw_tile.sel(
469+
X=slice(x_min - x_min % RESOLUTION, x_max + RESOLUTION - x_max % RESOLUTION),
470+
Y=slice(y_min - y_min % RESOLUTION, y_max + RESOLUTION - y_max % RESOLUTION),
471+
).compute()
464472

465473
sm, drainage, et_crop, et_crop_red, planting_date = ag.soil_plant_water_balance(
466474
precip_tile,
467475
et=5,
468-
taw=60,
469-
sminit=60./3.,
476+
taw=taw_tile,
477+
sminit=taw_tile/3.,
470478
kc_params=kc_params,
471479
planting_date=p_d,
472480
)
473481
if map_choice == "sm":
474-
mymap = sm
482+
map = sm
475483
elif map_choice == "drainage":
476-
mymap = drainage
484+
map = drainage
477485
elif map_choice == "et_crop":
478-
mymap = et_crop
486+
map = et_crop
479487
else:
480488
raise Exception("can not enter here")
481-
mymap = mymap.isel(T=-1)
482-
mymap.attrs["colormap"] = mycolormap
483-
mymap = mymap.rename(X="lon", Y="lat")
484-
mymap.attrs["scale_min"] = mymap_min
485-
mymap.attrs["scale_max"] = mymap_max
486-
result = pingrid.tile(mymap, tx, ty, tz, clip_shape)
487-
return result
489+
map = map.isel(T=-1)
490+
map.attrs["colormap"] = CMAPS["precip"]
491+
map = map.rename(X="lon", Y="lat")
492+
map.attrs["scale_min"] = 0
493+
map.attrs["scale_max"] = CONFIG["taw_max"]
494+
return pingrid.tile(map, tx, ty, tz, clip_shape)
488495

489496

490497
@APP.callback(
@@ -497,12 +504,12 @@ def wat_bal_tile(tz, tx, ty):
497504
def set_colorbar(
498505
map_choice,
499506
):
500-
mymap_max = 60 #taw.max()
507+
map_max = CONFIG["taw_max"]
501508
return (
502509
f"{CONFIG['map_text'][map_choice]['menu_label']} [{CONFIG['map_text'][map_choice]['units']}]",
503510
CMAPS["precip"].to_dash_leaflet(),
504-
mymap_max,
505-
[i for i in range(0, mymap_max + 1) if i % int(mymap_max/12) == 0],
511+
map_max,
512+
[i for i in range(0, map_max + 1) if i % int(map_max/8) == 0],
506513
)
507514

508515

0 commit comments

Comments
 (0)