@@ -364,12 +364,13 @@ def wat_bal_plots(
364
364
error_fig = pingrid .error_fig (error_msg = "Grid box out of data domain" )
365
365
return error_fig
366
366
precip .load ()
367
+ taw = pingrid .sel_snap (xr .open_dataarray (Path (CONFIG ["taw_file" ])), lat , lng )
367
368
try :
368
369
sm , drainage , et_crop , et_crop_red , planting_date = ag .soil_plant_water_balance (
369
370
precip ,
370
371
et = 5 ,
371
- taw = 60 ,
372
- sminit = 60. / 3. ,
372
+ taw = taw ,
373
+ sminit = taw / 3. ,
373
374
kc_params = kc_params ,
374
375
planting_date = p_d ,
375
376
)
@@ -379,16 +380,16 @@ def wat_bal_plots(
379
380
)
380
381
return error_fig
381
382
if map_choice == "sm" :
382
- myts = sm
383
+ ts = sm
383
384
elif map_choice == "drainage" :
384
- myts = drainage
385
+ ts = drainage
385
386
elif map_choice == "et_crop" :
386
- myts = et_crop
387
+ ts = et_crop
387
388
wat_bal_graph = pgo .Figure ()
388
389
wat_bal_graph .add_trace (
389
390
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 ,
392
393
hovertemplate = "%{y} on %{x}" ,
393
394
name = "" ,
394
395
line = pgo .scatter .Line (color = "blue" ),
@@ -458,33 +459,39 @@ def wat_bal_tile(tz, tx, ty):
458
459
data = [kc_init , kc_veg , kc_mid , kc_late , kc_end ], dims = ["kc_periods" ], coords = [kc_periods ]
459
460
)
460
461
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 ()
464
472
465
473
sm , drainage , et_crop , et_crop_red , planting_date = ag .soil_plant_water_balance (
466
474
precip_tile ,
467
475
et = 5 ,
468
- taw = 60 ,
469
- sminit = 60. / 3. ,
476
+ taw = taw_tile ,
477
+ sminit = taw_tile / 3. ,
470
478
kc_params = kc_params ,
471
479
planting_date = p_d ,
472
480
)
473
481
if map_choice == "sm" :
474
- mymap = sm
482
+ map = sm
475
483
elif map_choice == "drainage" :
476
- mymap = drainage
484
+ map = drainage
477
485
elif map_choice == "et_crop" :
478
- mymap = et_crop
486
+ map = et_crop
479
487
else :
480
488
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 )
488
495
489
496
490
497
@APP .callback (
@@ -497,12 +504,12 @@ def wat_bal_tile(tz, tx, ty):
497
504
def set_colorbar (
498
505
map_choice ,
499
506
):
500
- mymap_max = 60 #taw.max()
507
+ map_max = CONFIG [ "taw_max" ]
501
508
return (
502
509
f"{ CONFIG ['map_text' ][map_choice ]['menu_label' ]} [{ CONFIG ['map_text' ][map_choice ]['units' ]} ]" ,
503
510
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 ],
506
513
)
507
514
508
515
0 commit comments