Skip to content

Adding the Compare to... time series options #333

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 7 commits into from
May 23, 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
16 changes: 10 additions & 6 deletions controls.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def Text(id, default):
dbc Input component with text inputs.
"""
return [ dbc.Input(id=id, type="text",
size="sm", className="m-1 d-inline-block w-auto",debounce=True, value=default) ]
size="sm", className="m-1 d-inline-block w-auto", debounce=True, value=default) ]


def Number(id, default, min=None, max=None, html_size=None):
Expand Down Expand Up @@ -158,7 +158,7 @@ def Sentence(*elems):

return dbc.Form(groups)

def Block(title, *body, is_on=True, width="100%"): #width of the block in its container
def Block(title, *body, is_on=True, width="100%", border_color="grey"): #width of the block in its container
"""Separates out components in individual Cards

Auto-generates a formatted block with a card header and body.
Expand All @@ -185,10 +185,14 @@ def Block(title, *body, is_on=True, width="100%"): #width of the block in its co
the_display = "inline-block"
else:
the_display = "none"
return dbc.Card([
dbc.CardHeader(title),
dbc.CardBody(body),
], className="mb-4 ml-4 mr-4", style={"display": the_display, "width": width})
return dbc.Card(
[
dbc.CardHeader(title),
dbc.CardBody(body),
],
className="mb-4 ml-4 mr-4",
style={"display": the_display, "width": width, "border-color": border_color, "line-height": 1},
)

def Options(options,labels=None):
""" Creates options for definition of different Dash components.
Expand Down
8 changes: 7 additions & 1 deletion enacts/wat_bal/agronomy.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,13 @@ def soil_plant_water_balance(
planting_date = (peffective[time_dim][-1].drop_vars(time_dim)
- (planted_since - np.timedelta64(1, "D"))
)
return sm, drainage, et_crop, et_crop_red, planting_date
return (
sm.rename("sm"),
drainage.rename("drainage"),
et_crop.rename("et_crop"),
et_crop_red.rename("et_crop_red"),
planting_date.rename("planting_date"),
)


def api_runoff(
Expand Down
137 changes: 123 additions & 14 deletions enacts/wat_bal/layout_monit.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ def app_layout():

# Initialization
rr_mrg = calc.read_zarr_data(RR_MRG_ZARR)
center_of_the_map = [((rr_mrg["Y"][int(rr_mrg["Y"].size/2)].values)), ((rr_mrg["X"][int(rr_mrg["X"].size/2)].values))]
center_of_the_map = [
((rr_mrg["Y"][int(rr_mrg["Y"].size/2)].values)),
((rr_mrg["X"][int(rr_mrg["X"].size/2)].values)),
]
lat_res = np.around((rr_mrg["Y"][1]-rr_mrg["Y"][0]).values, decimals=10)
lat_min = np.around((rr_mrg["Y"][0]-lat_res/2).values, decimals=10)
lat_max = np.around((rr_mrg["Y"][-1]+lat_res/2).values, decimals=10)
Expand All @@ -48,6 +51,10 @@ def app_layout():
lon_max = np.around((rr_mrg["X"][-1]+lon_res/2).values, decimals=10)
lat_label = str(lat_min)+" to "+str(lat_max)+" by "+str(lat_res)+"˚"
lon_label = str(lon_min)+" to "+str(lon_max)+" by "+str(lon_res)+"˚"
first_year = rr_mrg["T"][0].dt.year.values
one_to_last_year = rr_mrg["T"][-367].dt.year.values
last_year = rr_mrg["T"][-1].dt.year.values
year_label = str(first_year)+" to "+str(last_year)

return dbc.Container(
[
Expand All @@ -56,7 +63,18 @@ def app_layout():
dbc.Row(
[
dbc.Col(
controls_layout(lat_min, lat_max, lon_min, lon_max, lat_label, lon_label),
controls_layout(
lat_min,
lat_max,
lon_min,
lon_max,
lat_label,
lon_label,
first_year,
one_to_last_year,
last_year,
year_label,
),
sm=12,
md=4,
style={
Expand Down Expand Up @@ -166,7 +184,18 @@ def navbar_layout():
)


def controls_layout(lat_min, lat_max, lon_min, lon_max, lat_label, lon_label):
def controls_layout(
lat_min,
lat_max,
lon_min,
lon_max,
lat_label,
lon_label,
other_year_min,
other_year_default,
other_year_max,
year_label
):
return dbc.Container(
[
html.Div(
Expand All @@ -183,26 +212,35 @@ def controls_layout(lat_min, lat_max, lon_min, lon_max, lat_label, lon_label):
),
dcc.Loading(html.P(id="map_description"), type="dot"),
html.P(
f"""
dcc.Markdown("""
The soil-plant-water balance algorithm estimates soil moisture
and other characteristics of the soil and plants since planting date
of the current season and up to now.
It is driven by rainfall and the crop cultivars Kc
that can be changed in the Control Panel below.
"""
that can be changed in the _Controls Panel_ below.
""")
),
html.P(
f"""
Map another day of the simulation using the Date control on the top bar,
dcc.Markdown("""
Map another day of the simulation using the _Date_ control in the top bar,
or by clicking a day of interest on the time series graph..
You can pick a day between planting and today (or last day of available data).
"""
""")
),
html.P(
f"""
dcc.Markdown("""
Pick another point to monitor evolution since planting
with the controls below or by clicking on the map.
"""
with the _Pick a point_ controls or by clicking on the map.
""")
),
html.P(
dcc.Markdown("""
The current evolution (blue) is put in context by comparing it
to another situation (dashed red) that can be altered
by picking another planting date and/or
another crop (Kc parameters) and/or
another year through the _Compare to..._ panel.
""")
),
html.H5("Water Balance Outputs"),
]+[
Expand All @@ -218,6 +256,14 @@ def controls_layout(lat_min, lat_max, lon_min, lon_max, lat_label, lon_label):
{GLOBAL_CONFIG["institution"]}’s archive with satellite rainfall estimates.
"""
),
html.P(
f"""
Total Available Water (TAW) regridded on rainfall data from SoilGrids's
absolute total available water capacity (mm),
aggregated over the Effective Root Zone Depth for Maize
data product.
"""
),
],
style={"position":"relative","height":"30%", "overflow":"scroll"},
),
Expand All @@ -234,6 +280,7 @@ def controls_layout(lat_min, lat_max, lon_min, lon_max, lat_label, lon_label):
min=lat_min,
max=lat_max,
type="number",
style={"height": "auto", "padding-bottom": "0px"},
),
dbc.Label("Latitude", style={"font-size": "80%"}),
dbc.Tooltip(
Expand All @@ -250,6 +297,7 @@ def controls_layout(lat_min, lat_max, lon_min, lon_max, lat_label, lon_label):
min=lon_min,
max=lon_max,
type="number",
style={"height": "auto", "padding-bottom": "0px"},
),
dbc.Label("Longitude", style={"font-size": "80%"}),
dbc.Tooltip(
Expand All @@ -259,7 +307,7 @@ def controls_layout(lat_min, lat_max, lon_min, lon_max, lat_label, lon_label):
)
]),
),
dbc.Button(id="submit_lat_lng", children='Submit'),
dbc.Button(id="submit_lat_lng", children='Submit', color="secondary"),
],
),
),
Expand All @@ -271,6 +319,7 @@ def controls_layout(lat_min, lat_max, lon_min, lon_max, lat_label, lon_label):
{"label": val["menu_label"], "value": key}
for key, val in CONFIG["map_text"].items()
],
style={"padding-top": "0px", "padding-bottom": "0px"},
),
),
Block(
Expand Down Expand Up @@ -309,7 +358,67 @@ def controls_layout(lat_min, lat_max, lon_min, lon_max, lat_label, lon_label):
Sentence(
Number("kc_end", CONFIG["kc_v"][4], min=0, max=2, html_size=4),
),
dbc.Button(id="submit_kc", children='Submit'),
dbc.Button(
id="submit_kc",
children='Submit',
color="light",
style={"color": "green", "border-color": "green"},
),
border_color="green",
),
Block(
"Compare to...",
Sentence(
"Planting Date",
DateNoYear("planting2_", 1, CONFIG["planting_month"]),
"",
Number(
"planting2_year",
other_year_default,
min=other_year_min,
max=other_year_max,
html_size=5
),
),
Sentence(
"for",
Text("crop2_name", CONFIG["crop_name"]),
"crop cultivars: initiated at",
),
Sentence(
Number("kc2_init", CONFIG["kc_v"][0], min=0, max=2, html_size=4),
"through",
Number("kc2_init_length", CONFIG["kc_l"][0], min=0, max=99, html_size=2),
"days of initialization to",
),
Sentence(
Number("kc2_veg", CONFIG["kc_v"][1], min=0, max=2, html_size=4),
"through",
Number("kc2_veg_length", CONFIG["kc_l"][1], min=0, max=99, html_size=2),
"days of growth to",
),
Sentence(
Number("kc2_mid", CONFIG["kc_v"][2], min=0, max=2, html_size=4),
"through",
Number("kc2_mid_length", CONFIG["kc_l"][2], min=0, max=99, html_size=2),
"days of mid-season to",
),
Sentence(
Number("kc2_late", CONFIG["kc_v"][3], min=0, max=2, html_size=4),
"through",
Number("kc2_late_length", CONFIG["kc_l"][3], min=0, max=99, html_size=2),
"days of late-season to",
),
Sentence(
Number("kc2_end", CONFIG["kc_v"][4], min=0, max=2, html_size=4),
),
dbc.Button(
id="submit_kc2",
children='Submit',
color="light",
style={"color": "blue", "border-color": "green"},
),
border_color="blue",
),
],
style={"position":"relative","height":"60%", "overflow":"scroll"},
Expand Down
Loading