diff --git a/enacts/config-defaults.yaml b/enacts/config-defaults.yaml index 2f8877fbf..364f35c46 100644 --- a/enacts/config-defaults.yaml +++ b/enacts/config-defaults.yaml @@ -102,3 +102,4 @@ wat_bal_monit: # menu_label: Crop Evapotranspiration # description: The map shows the crop evapotranspiration... # units: mm + diff --git a/enacts/config-sng.yaml b/enacts/config-sng.yaml index 428c4917b..b98af7af1 100644 --- a/enacts/config-sng.yaml +++ b/enacts/config-sng.yaml @@ -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 diff --git a/enacts/wat_bal/agronomy.py b/enacts/wat_bal/agronomy.py index ae83881c7..85737c457 100644 --- a/enacts/wat_bal/agronomy.py +++ b/enacts/wat_bal/agronomy.py @@ -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) @@ -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 \ No newline at end of file + return ra diff --git a/enacts/wat_bal/maproom_monit.py b/enacts/wat_bal/maproom_monit.py index 3af9cecd6..e17917bcc 100644 --- a/enacts/wat_bal/maproom_monit.py +++ b/enacts/wat_bal/maproom_monit.py @@ -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, ) @@ -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"), @@ -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( @@ -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], )