Skip to content

taw read from file depends on X/Y instead of constant #321

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

Merged
merged 4 commits into from
May 2, 2023
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
1 change: 1 addition & 0 deletions enacts/config-defaults.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,4 @@ wat_bal_monit:
# menu_label: Crop Evapotranspiration
# description: The map shows the crop evapotranspiration...
# units: mm

2 changes: 2 additions & 0 deletions enacts/config-sng.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,6 @@ wat_bal_monit:
crop_name: Rice
kc_v: [0, 0, 1.1, 1.1, 0]
kc_l: [3, 27, 45, 60]
taw_file: /data/remic/mydatafiles/soilgrids/Senegal/GYGA_ERZD_wat_cap_abs_anacim_enacts3.nc
taw_max: 136

3 changes: 1 addition & 2 deletions enacts/wat_bal/agronomy.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ def soil_plant_water_step(

.. math:: drainage = |wb - sm|
"""

# Water Balance
wb = (sm_yesterday + peffective - et).clip(min=0)
drainage = (wb - taw).clip(min=0)
Expand Down Expand Up @@ -500,4 +499,4 @@ def solar_radiation(doy, lat):
/ np.pi
).rename("ra")
ra.attrs = dict(description="Extraterrestrial Radiation", units="MJ/m**2/day")
return ra
return ra
57 changes: 32 additions & 25 deletions enacts/wat_bal/maproom_monit.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,12 +364,13 @@ def wat_bal_plots(
error_fig = pingrid.error_fig(error_msg="Grid box out of data domain")
return error_fig
precip.load()
taw = pingrid.sel_snap(xr.open_dataarray(Path(CONFIG["taw_file"])), lat, lng)
try:
sm, drainage, et_crop, et_crop_red, planting_date = ag.soil_plant_water_balance(
precip,
et=5,
taw=60,
sminit=60./3.,
taw=taw,
sminit=taw/3.,
kc_params=kc_params,
planting_date=p_d,
)
Expand All @@ -379,16 +380,16 @@ def wat_bal_plots(
)
return error_fig
if map_choice == "sm":
myts = sm
ts = sm
elif map_choice == "drainage":
myts = drainage
ts = drainage
elif map_choice == "et_crop":
myts = et_crop
ts = et_crop
wat_bal_graph = pgo.Figure()
wat_bal_graph.add_trace(
pgo.Scatter(
x=myts["T"].dt.strftime("%-d %b %y"),
y=myts.values,
x=ts["T"].dt.strftime("%-d %b %y"),
y=ts.values,
hovertemplate="%{y} on %{x}",
name="",
line=pgo.scatter.Line(color="blue"),
Expand Down Expand Up @@ -458,33 +459,39 @@ def wat_bal_tile(tz, tx, ty):
data=[kc_init, kc_veg, kc_mid, kc_late, kc_end], dims=["kc_periods"], coords=[kc_periods]
)

mymap_min = 0
mymap_max = 60 #taw.max()
mycolormap = CMAPS["precip"]
_, taw_tile = xr.align(
precip,
xr.open_dataarray(Path(CONFIG["taw_file"])),
join="override",
exclude="T",
)
taw_tile = taw_tile.sel(
X=slice(x_min - x_min % RESOLUTION, x_max + RESOLUTION - x_max % RESOLUTION),
Y=slice(y_min - y_min % RESOLUTION, y_max + RESOLUTION - y_max % RESOLUTION),
).compute()

sm, drainage, et_crop, et_crop_red, planting_date = ag.soil_plant_water_balance(
precip_tile,
et=5,
taw=60,
sminit=60./3.,
taw=taw_tile,
sminit=taw_tile/3.,
kc_params=kc_params,
planting_date=p_d,
)
if map_choice == "sm":
mymap = sm
map = sm
elif map_choice == "drainage":
mymap = drainage
map = drainage
elif map_choice == "et_crop":
mymap = et_crop
map = et_crop
else:
raise Exception("can not enter here")
mymap = mymap.isel(T=-1)
mymap.attrs["colormap"] = mycolormap
mymap = mymap.rename(X="lon", Y="lat")
mymap.attrs["scale_min"] = mymap_min
mymap.attrs["scale_max"] = mymap_max
result = pingrid.tile(mymap, tx, ty, tz, clip_shape)
return result
map = map.isel(T=-1)
map.attrs["colormap"] = CMAPS["precip"]
map = map.rename(X="lon", Y="lat")
map.attrs["scale_min"] = 0
map.attrs["scale_max"] = CONFIG["taw_max"]
return pingrid.tile(map, tx, ty, tz, clip_shape)


@APP.callback(
Expand All @@ -497,12 +504,12 @@ def wat_bal_tile(tz, tx, ty):
def set_colorbar(
map_choice,
):
mymap_max = 60 #taw.max()
map_max = CONFIG["taw_max"]
return (
f"{CONFIG['map_text'][map_choice]['menu_label']} [{CONFIG['map_text'][map_choice]['units']}]",
CMAPS["precip"].to_dash_leaflet(),
mymap_max,
[i for i in range(0, mymap_max + 1) if i % int(mymap_max/12) == 0],
map_max,
[i for i in range(0, map_max + 1) if i % int(map_max/8) == 0],
)


Expand Down