diff --git a/conf/models.json b/conf/models.json
index 3f8ca50eda2cdd99e8f11b620ddfda7542e11c54..f6f2046ba1057b3232927b7865e5a83220f65a12 100644
--- a/conf/models.json
+++ b/conf/models.json
@@ -5,6 +5,7 @@
"path": "/data/products/median",
"color": "#303030",
"start": 0,
+ "start_before": 12,
"weight": 0
},
"monarch": {
diff --git a/data_handler.py b/data_handler.py
index f740719b749f85669def9a7357786b97ecc931ba..01a070fead90483408693e16b58c0633d0e5cf7c 100644
--- a/data_handler.py
+++ b/data_handler.py
@@ -157,10 +157,10 @@ class Observations1dHandler(object):
# sites = pd.read_table(os.path.join('./conf/',
# OBS[obs]['sites']), delimiter=r"\s+", engine='python')
- idxs, self.station_names = np.array([[idx, st_name[~st_name.mask].tostring().decode('utf-8')]
+ idxs, self.station_names = np.array([[idx, st_name[~st_name.mask].tobytes().decode('utf-8')]
for idx, st_name in
enumerate(input_files[0].variables['station_name'][:])
- if st_name[~st_name.mask].tostring().decode('utf-8').upper() in map(str.upper, sites['SITE'])]
+ if st_name[~st_name.mask].tobytes().decode('utf-8').upper() in map(str.upper, sites['SITE'])]
).T
if DEBUG: print('IDXS', idxs)
@@ -200,7 +200,7 @@ class Observations1dHandler(object):
),
hideout=dict(
circleOptions=dict(
- fillOpacity=0.7,
+ fillOpacity=OPACITY,
stroke=False,
fillColor='#f0b450',
radius=8),
@@ -376,7 +376,8 @@ class TimeSeriesHandler(object):
if DEBUG: print("----------", model)
method = 'netcdf'
- if not DELAY and MODELS[model]['start'] == 12:
+ if (MODELS[model]['start'] == 12 and not DELAY and DELAY_DATE and (datetime.strptime(self.currdate, "%Y%m%d") >= datetime.strptime(DELAY_DATE, "%Y%m%d"))) or \
+ (MODELS[model]['start'] == 12 and not DELAY and not DELAY_DATE):
mod_date = (datetime.strptime(self.currdate, "%Y%m%d") -
timedelta(days=1)).strftime("%Y%m%d")
else:
@@ -418,7 +419,8 @@ class TimeSeriesHandler(object):
if forecast:
method = 'netcdf'
- if not DELAY and MODELS[mod]['start'] == 12:
+ if (MODELS[mod]['start'] == 12 and not DELAY and DELAY_DATE and (datetime.strptime(self.currdate, "%Y%m%d") >= datetime.strptime(DELAY_DATE, "%Y%m%d"))) or \
+ (MODELS[mod]['start'] == 12 and not DELAY and not DELAY_DATE):
mod_date = (datetime.strptime(self.currdate, "%Y%m%d") -
timedelta(days=1)).strftime("%Y%m%d")
else:
@@ -710,7 +712,7 @@ class FigureHandler(object):
varname)))
if DEBUG: print("MODEL", self.model, "GEOJSON_URL", geojson_url)
- style = dict(weight=0, opacity=0, color='white', dashArray='', fillOpacity=0.7)
+ style = dict(weight=0, opacity=0, color='white', dashArray='', fillOpacity=OPACITY)
# Create colorbar.
ctg = ["{:d}".format(int(cls)) if cls.as_integer_ratio()[1] == 1 else "{:.1f}".format(cls) for i, cls in enumerate(bounds[1:-1])]
@@ -866,7 +868,7 @@ class FigureHandler(object):
name=name,
hovertemplate="lon: %{lon:.2f}
lat: %{lat:.2f}
" +
"value: %{text:.2f}",
- opacity=0.7,
+ opacity=OPACITY,
showlegend=False,
marker=dict(
# autocolorscale=True,
@@ -1305,7 +1307,8 @@ class VisFigureHandler(object):
className="vis-legend"
)
- if DEBUG: print('VIS ___', xlon, ylat, '\n*********', visibility, '\n*********', humidity)
+ if DEBUG:
+ print('VIS ___', xlon, ylat, '\n*********', visibility, '\n*********', humidity)
df = pd.DataFrame({
'lon': np.array(xlon).round(2),
'lat': np.array(ylat).round(2),
@@ -1341,7 +1344,7 @@ class VisFigureHandler(object):
colorProp='value',
colorscale=self.colors,
circleOptions=dict(
- fillOpacity=0.7,
+ fillOpacity=OPACITY,
stroke=False,
#fillColor='#f0b450',
radius=8),
@@ -1387,7 +1390,7 @@ class ProbFigureHandler(object):
""" Class to manage the figure creation """
def __init__(self, var=None, prob=None, selected_date=None):
- """ """
+ """ Initialization with variable, prob and date """
if var is None:
var = DEFAULT_VAR
@@ -1485,7 +1488,7 @@ class ProbFigureHandler(object):
if DEBUG: print("GEOJSON_URL", geojson_url)
- style = dict(weight=0, opacity=0, color='white', dashArray='', fillOpacity=0.7)
+ style = dict(weight=0, opacity=0, color='white', dashArray='', fillOpacity=OPACITY)
# Create colorbar.
ctg = ["{:.1f}".format(cls) if '.' in str(cls) else "{:d}".format(cls)
@@ -1682,7 +1685,7 @@ class WasFigureHandler(object):
names, colors, definitions = self.get_regions_data(day=day)
colors = np.array(colors)
if DEBUG: print("::::::::::", names, colors, definitions)
- style = dict(weight=1, opacity=1, color='white', dashArray='3', fillOpacity=0.7)
+ style = dict(weight=1, opacity=1, color='white', dashArray='3', fillOpacity=OPACITY)
# Create colorbar.
colormap = WAS[self.was]['colors']
@@ -1721,7 +1724,7 @@ class WasFigureHandler(object):
url=self.get_geojson_url(day=day),
# data=geojson_data,
# zoomToBounds=True,
- hoverStyle=arrow_function(dict(weight=2, color='white', dashArray='', fillOpacity=0.7)),
+ hoverStyle=arrow_function(dict(weight=2, color='white', dashArray='', fillOpacity=OPACITY)),
options=dict(style=style_handle),
hideout=dict(colorscale=list(colormap.keys()),
bounds=[i for i in range(len(colormap.keys()))],
diff --git a/preproc/median_calc.py b/preproc/median_calc.py
index 18d77788a20183329b3ff1dd9a26d1204cde6dd0..48de4f2b99230fa0ced1707f1710d0c5c3463258 100644
--- a/preproc/median_calc.py
+++ b/preproc/median_calc.py
@@ -18,7 +18,6 @@ import subprocess
import time
from datetime import datetime
from datetime import timedelta
-from operator import itemgetter
np.set_printoptions(precision=2)
@@ -29,56 +28,44 @@ NETCDF_TEMPLATE = "{}/archive/{}{}.nc"
DEBUG = True
DELAY = DATES['delay']['delayed']
+DELAY_DATE = DATES['delay']['start_date']
lonlat = "-27,65,0,65"
main_output_path = "/data/products/median/"
interpolated_path = os.path.join(main_output_path, "interpolated")
-# archive_path = os.path.join(main_output_path, "tmp")
archive_path = os.path.join(main_output_path, "archive")
-# selected_date = "20220515"
def generate_median_file(selected_date):
""" Generates the median of stored data models """
- model_conf = {
- True: {
- 0: {
- 'tsteps': "5/25",
- 'model_date': selected_date,
- 'start_hour': "12"
- },
- 12: {
- 'tsteps': "1/21",
- 'model_date': selected_date,
- 'start_hour': "12"
- },
- },
- False: {
- 0: {
- 'tsteps': "1/25",
- 'model_date': selected_date,
- 'start_hour': "00"
- },
- 12: {
- 'tsteps': "5/29",
- 'model_date': (datetime.strptime(selected_date, "%Y%m%d") -
- timedelta(days=1)).strftime("%Y%m%d"),
- 'start_hour': "00"
- },
- }
- }
+ from utils import get_currdate_tstep
filepaths = []
cdo_date = datetime.strptime(selected_date, "%Y%m%d").strftime("%Y-%m-%d")
+ current_time_before = (DELAY_DATE and datetime.strptime(selected_date,
+ "%Y%m%d") < datetime.strptime(DELAY_DATE, "%Y%m%d"))
+ start_hour = ((not current_time_before and DELAY) or (current_time_before
+ and not DELAY)) and '12' or '00'
+
if DEBUG:
print("CDO DATE", cdo_date)
for model in MODELS:
+ if DEBUG:
+ print("MODEL", model)
model_start = MODELS[model]['start']
- cur_dict = model_conf[DELAY][model_start]
- tsteps, model_date, start_hour = itemgetter(*cur_dict.keys())(cur_dict)
+ model_start_before = ('start_before' in MODELS[model]) and MODELS[model]['start_before'] or False
+ print(f"""
+ *******************************
+ START: {model_start}, BEFORE: {model_start_before}, CURR_BEFORE: {current_time_before}
+ """)
+ model_date, _, tsteps = get_currdate_tstep(model_start, model_start_before, current_time_before, DELAY, selected_date)
+ print(f"""
+ *******************************
+ {model_date}, {start_hour}, {tsteps}
+ """)
filepath_interp = NETCDF_TEMPLATE.format(
MODELS[model]['path'],
@@ -98,8 +85,7 @@ def generate_median_file(selected_date):
continue
if DEBUG:
- print('MODEL', model, filepath, model_date, filepath_interp, selected_date)
-
+ print('MODEL', model, filepath, filepath_interp, model_date, selected_date)
remap_script = "cdo -L -r -settaxis," +\
cdo_date + "," + start_hour + ":00:00,3hours" +\
@@ -123,6 +109,7 @@ def generate_median_file(selected_date):
filepaths.append(interp_filepath)
+ # median_start_hour = "{:02d}".format(current_time_before and MODELS['median']['start_before'] or MODELS['median']['start'])
sconc_ds = xr.open_mfdataset(
"{}/{}*SCONC_DUST.nc".format(interpolated_path, selected_date),
concat_dim='model', combine='nested')
@@ -149,6 +136,8 @@ def generate_median_file(selected_date):
if __name__ == "__main__":
import sys
+ from os import path
+ sys.path.append(os.path.dirname(os.path.abspath('.')))
if len(sys.argv) > 1:
generate_median_file(sys.argv[1])
else:
diff --git a/preproc/nc2geojson_was.py b/preproc/nc2geojson_was.py
index 294a189646e8b316869a47914ba3279862856d48..4c71c536b7fb312362fb844b92f766801d86d465 100755
--- a/preproc/nc2geojson_was.py
+++ b/preproc/nc2geojson_was.py
@@ -30,13 +30,14 @@ NETCDF_TEMPLATE = "{}/archive/{}{}.nc"
DEBUG = True
DELAY = DATES['delay']['delayed']
+DELAY_DATE = DATES['delay']['start_date']
if DELAY:
DAYS = range(1, 3)
else:
DAYS = range(0, 3)
-class WasTables(object):
+class WasTables:
""" Class to manage the figure creation """
def __init__(self, was=None, model='median', variable='SCONC_DUST', selected_date=None):
diff --git a/preproc/probability_maps.py b/preproc/probability_maps.py
index b703cf6e834c4a15e06c715ea160c9836942a34e..b284095a7e02b00c4a7ce471dbac091851934ada 100644
--- a/preproc/probability_maps.py
+++ b/preproc/probability_maps.py
@@ -15,7 +15,6 @@ DEBUG = True
PARAMS = ('SCONC_DUST', 'OD550_DUST')
-# INPUT_DIR = "/data/daily_dashboard/prob/tmp/interpolated/"
INPUT_DIR = "/data/products/median/interpolated/"
DIR_PATH = os.path.abspath(os.path.dirname(__file__))
@@ -24,15 +23,14 @@ DATES = json.load(open(os.path.join(DIR_PATH, '../conf/dates.json')))
VARS = json.load(open(os.path.join(DIR_PATH, '../conf/vars.json')))
DELAY = DATES['delay']['delayed']
DELAY_DATE = DATES['delay']['start_date']
-
TSTEPS = 8
if DELAY:
- FIRST_STEPS_LEN = 2
+ FIRST_STEP = 0
else:
- FIRST_STEPS_LEN = 3
+ FIRST_STEP = 1
+FIRST_STEPS_LEN = 3
-FIRST_STEP = 0
LON0 = 5
LON1 = -10
@@ -75,6 +73,8 @@ class ProbabilityMaps:
lat = []
first_steps = []
for model in MODELS:
+ if model == 'median':
+ continue
tpl = MODELS[model]['template']
ifile = os.path.join(self.input_dir, f'{self.curdate}{tpl}.nc')
if DEBUG:
@@ -95,7 +95,7 @@ class ProbabilityMaps:
continue
else:
param_values = nc_file.variables[self.parameter_name][:,:,LON0:LON1]
- first_steps = np.arange(FIRST_STEP, param_values[FIRST_STEP:,:,:].shape[0], TSTEPS)[:-1]
+ first_steps = np.arange(FIRST_STEP, param_values[FIRST_STEP:,:,:].shape[0], TSTEPS) # [:-1]
if len(first_steps) < FIRST_STEPS_LEN:
continue
if DEBUG:
@@ -210,6 +210,7 @@ if __name__ == "__main__":
threshold_list = VARS[param_name]['threshold_list']
conv_factor = VARS[param_name]['mul']**-1
for thresh in threshold_list:
+ print(param_name, thresh)
out_dir = f"/data/daily_dashboard/prob/{param_name.lower()}/{thresh}/netcdf/"
ProbabilityMaps(cdate, INPUT_DIR,
out_dir, param_name,
diff --git a/tabs/evaluation_callbacks.py b/tabs/evaluation_callbacks.py
index d70c6e40ae89b8cb0f1edb06a81fbe934a606332..7a5b1162309a10049476c4784d98da5c5527c6c0 100644
--- a/tabs/evaluation_callbacks.py
+++ b/tabs/evaluation_callbacks.py
@@ -698,7 +698,7 @@ def update_eval_aeronet(n_clicks, sdate, edate, obs):
if sdate is None or edate is None or obs != 'aeronet':
raise PreventUpdate
- from tools import get_figure
+ from tools import get_models_figure
from tools import get_obs1d
if DEBUG: print('SERVER: calling figure from EVAL picker callback')
if DEBUG: print('SERVER: SDATE', str(sdate))
@@ -726,7 +726,7 @@ def update_eval_aeronet(n_clicks, sdate, edate, obs):
edate = END_DATE
stations, points_layer = get_obs1d(sdate, edate, obs, DEFAULT_VAR)
- fig = get_figure(model=None, var=DEFAULT_VAR, layer=points_layer)
+ fig = get_models_figure(model=None, var=DEFAULT_VAR, layer=points_layer)
return stations.to_dict(), fig
@@ -754,7 +754,7 @@ def update_eval_modis(n_clicks, date, mod, obs, mod_div):
if date is None or mod is None or obs != 'modis':
raise PreventUpdate
- from tools import get_figure
+ from tools import get_models_figure
if DEBUG: print('SERVER: calling figure from EVAL picker callback')
if DEBUG: print(mod_div)
mod_center = mod_div['props']['center']
@@ -778,9 +778,9 @@ def update_eval_modis(n_clicks, date, mod, obs, mod_div):
tstep = 4
else:
tstep = 0
- fig_mod = get_figure(model=mod, var=DEFAULT_VAR, selected_date=date, tstep=tstep,
+ fig_mod = get_models_figure(model=mod, var=DEFAULT_VAR, selected_date=date, tstep=tstep,
hour=12, center=mod_center, zoom=mod_zoom)
- fig_obs = get_figure(model=obs, var=DEFAULT_VAR, selected_date=date, tstep=0,
+ fig_obs = get_models_figure(model=obs, var=DEFAULT_VAR, selected_date=date, tstep=0,
center=mod_center, zoom=mod_zoom, tag='modis')
if DEBUG: print("MODIS", fig_obs)
@@ -797,7 +797,7 @@ def update_eval_modis(n_clicks, date, mod, obs, mod_div):
@cache.memoize(timeout=cache_timeout)
def update_eval(obs):
""" Update evaluation figure according to all parameters """
- from tools import get_figure
+ from tools import get_models_figure
# from tools import get_obs1d
if DEBUG: print('SERVER: calling figure from EVAL picker callback')
# if DEBUG: print('SERVER: interval ' + str(n))
@@ -820,7 +820,7 @@ def update_eval(obs):
eval_graph = html.Div([
html.Div(
- get_figure(),
+ get_models_figure(),
id='graph-eval-aeronet'
),
html.Div(
@@ -846,8 +846,8 @@ def update_eval(obs):
# with_portal=True,
)]
- fig_mod = get_figure()
- fig_obs = get_figure(tag='modis')
+ fig_mod = get_models_figure()
+ fig_obs = get_models_figure(tag='modis')
graph_obs = html.Div([
html.Div(
diff --git a/tabs/forecast.py b/tabs/forecast.py
index c599a76cc6cea76db4ab8df59fab6aabc1ee46f0..30da9490543437b16f2d022d1d770434e0fc1610 100644
--- a/tabs/forecast.py
+++ b/tabs/forecast.py
@@ -20,72 +20,66 @@ def get_forecast_days(curdate=END_DATE):
""" Return forecast days according to configuration file """
delay = DELAY
st_date = DELAY_DATE
- if delay and st_date:
- if dt.strptime(curdate, "%Y%m%d") >= dt.strptime(st_date, "%Y%m%d"):
- days = 2
- else:
- days = 3
- elif delay:
- days = 2
- elif not delay and st_date:
- if dt.strptime(curdate, "%Y%m%d") >= dt.strptime(st_date, "%Y%m%d"):
- days = 3
- else:
- days = 2
+ if (delay and st_date \
+ and (dt.strptime(curdate, "%Y%m%d") >= dt.strptime(st_date, "%Y%m%d"))) or \
+ (not delay and st_date \
+ and (dt.strptime(curdate, "%Y%m%d") < dt.strptime(st_date, "%Y%m%d"))) or \
+ (delay and not st_date):
+ st_day = 1
else:
- days = 3
+ st_day = 0
- return [
- (dt.strptime(curdate, "%Y%m%d") +
+ return dict([
+ (
+ idx, (dt.strptime(curdate, "%Y%m%d") + \
timedelta(days=idx)).strftime("%a %d").upper()
- for idx in range(days)
- ]
+ ) for idx in range(st_day, 3)
+ ])
-def gen_ts_marks(ts_type, tstep, ts_min, curdate=END_DATE):
+def gen_ts_marks(ts_type, curdate=END_DATE):
""" Generate time slider marks """
- if DEBUG: print("TS MARKS", ts_type, tstep, ts_min)
-
+ if DEBUG: print("TS MARKS", ts_type, curdate)
if ts_type in ('prob', 'was'):
- return get_forecast_days(curdate)[tstep-ts_min]
-
- if DEBUG: print("RET", f'{tstep:d}')
- return f'{tstep:d}'
+ forecast_dict = get_forecast_days(curdate)
+ forecast_values = sorted(forecast_dict.keys())
+ fcst_min = forecast_values[0]
+ fcst_max = forecast_values[-1]
+ play = False
+ freq = 1
+ else:
+ fcst_min = 0
+ fcst_max = 72
+ forecast_values = range(fcst_min, fcst_max+FREQ, FREQ)
+ forecast_dict = dict([
+ (fcst_val, f'{fcst_val}') for fcst_val in forecast_values
+ ])
+
+ play = True
+ freq = FREQ
+
+ return {
+ 'min': fcst_min,
+ 'max': fcst_max,
+ 'step': freq,
+ 'marks': forecast_dict,
+ 'play': play
+ }
def gen_time_slider(ts_type='prob', end_date=END_DATE):
""" Generate time slider """
- ts_dict = {
- 'model':
- {
- 'min': 0,
- 'max': 72,
- 'step': FREQ,
- 'play': True
- },
- 'prob':
- {
- 'min': 0,
- 'max': len(get_forecast_days(end_date))-1,
- 'step': 1,
- 'play': False
- },
- 'was':
- {
- 'min': 0,
- 'max': len(get_forecast_days(end_date))-1,
- 'step': 1,
- 'play': False
- },
- }
- ts_min = ts_dict[ts_type]['min']
- ts_max = ts_dict[ts_type]['max']
- ts_step = ts_dict[ts_type]['step']
- ts_play = ts_dict[ts_type]['play']
+ ts_dict = gen_ts_marks(ts_type, end_date)
+
+ ts_min = ts_dict['min']
+ ts_max = ts_dict['max']
+ ts_step = ts_dict['step']
+ ts_play = ts_dict['play']
+ ts_marks = ts_dict['marks']
marks = {
- tstep: {'label': gen_ts_marks(ts_type, tstep, ts_min, end_date)}
- for tstep in range(ts_min, ts_max+ts_step, ts_step)
+ tstep: {'label': ts_marks[tstep]}
+ for tstep in ts_marks
}
if DEBUG: print("FCST MARKS", marks[list(marks.keys())[-1]])
diff --git a/tabs/forecast_callbacks.py b/tabs/forecast_callbacks.py
index 0c5dd701823751c1c3cc054e553060cee55f59dc..78e5c1268516eea5e1899898811240161e4472f6 100644
--- a/tabs/forecast_callbacks.py
+++ b/tabs/forecast_callbacks.py
@@ -219,7 +219,7 @@ def download_anim_link(models, variable, date, tstep):
if variable is None or date is None or tstep is None:
raise PreventUpdate
- # from tools import get_figure
+ # from tools import get_models_figure
from tools import download_image_link
if DEBUG: print('GIF', models, variable, date)
@@ -259,7 +259,6 @@ def update_was_timeslider(date):
State({'tag': 'was-map', 'index': ALL}, 'center')],
prevent_initial_call=False
)
-@cache.memoize(timeout=cache_timeout)
def update_was_figure(n_clicks, date, day, was, var, previous, view, zoom, center):
""" Update Warning Advisory Systems maps """
if DEBUG: print('WAS', n_clicks, date, day, was, previous, view, zoom, center)
@@ -269,7 +268,7 @@ def update_was_figure(n_clicks, date, day, was, var, previous, view, zoom, cente
if button_id != 'was-apply' and date is None and day is None:
raise PreventUpdate
from tools import get_was_figure
- from tools import get_figure
+ from tools import get_models_figure
if not zoom or previous != was:
zoom = WAS[was]['zoom']
else:
@@ -299,7 +298,7 @@ def update_was_figure(n_clicks, date, day, was, var, previous, view, zoom, cente
if was:
view = list(STYLES.keys())[view.index(True)]
geojson, legend, info = get_was_figure(was, day, selected_date=date)
- fig = get_figure(model=None, var=var, layer=[geojson, legend, info], view=view, zoom=zoom, center=center, tag='was')
+ fig = get_models_figure(model=None, var=var, layer=[geojson, legend, info], view=view, zoom=zoom, center=center, tag='was')
return fig, previous
raise PreventUpdate
@@ -334,7 +333,7 @@ def update_prob_timeslider(date):
def update_prob_figure(n_clicks, date, day, prob, var, view, zoom, center):
""" Update Probability maps """
from tools import get_prob_figure
- from tools import get_figure
+ from tools import get_models_figure
# if not prob in case user navigates to section via URL
if not prob:
@@ -369,7 +368,7 @@ def update_prob_figure(n_clicks, date, day, prob, var, view, zoom, center):
prob = prob.replace('prob_', '')
view = list(STYLES.keys())[view.index(True)]
geojson, colorbar, info = get_prob_figure(var, prob, day, selected_date=date)
- fig = get_figure(model=None, var=var, layer=[geojson, colorbar, info], view=view, zoom=zoom, center=center, tag='prob')
+ fig = get_models_figure(model=None, var=var, layer=[geojson, colorbar, info], view=view, zoom=zoom, center=center, tag='prob')
if DEBUG: print("FIG", fig)
return fig
raise PreventUpdate
@@ -823,7 +822,7 @@ def update_models_figure(n_clicks, tstep, date, model, variable, static, view, z
elif tstep is None and date is None:
raise PreventUpdate
- from tools import get_figure
+ from tools import get_models_figure
if DEBUG: print('SERVER: calling figure from picker callback')
st_time = time.time()
@@ -881,7 +880,7 @@ def update_models_figure(n_clicks, tstep, date, model, variable, static, view, z
for mod, mod_zoom, mod_center in zip(model, zoom, center):
if DEBUG: print("MOD", mod, "ZOOM", mod_zoom, "CENTER", mod_center, 'VIEW', view)
- figure = get_figure(mod, variable, date, tstep,
+ figure = get_models_figure(mod, variable, date, tstep,
static=static, aspect=(nrows, ncols), view=view,
center=mod_center, zoom=mod_zoom)
diff --git a/tabs/observations_callbacks.py b/tabs/observations_callbacks.py
index 30b050076a3a903bb0c17646527209faf694bba0..a540e32de68810f6cf323502d0991ea78c88e014 100644
--- a/tabs/observations_callbacks.py
+++ b/tabs/observations_callbacks.py
@@ -255,7 +255,7 @@ def update_obs_slider(n):
@cache.memoize(timeout=cache_timeout)
def update_vis_figure(date, tstep, zoom, center):
from tools import get_vis_figure
- from tools import get_figure
+ from tools import get_models_figure
if DEBUG: print("*************", date, tstep, zoom, center)
if date is not None:
date = date.split(' ')[0]
@@ -281,5 +281,5 @@ def update_vis_figure(date, tstep, zoom, center):
if DEBUG: print('SERVER: VIS callback date {}, tstep {}'.format(date, tstep))
df, points_layer = get_vis_figure(tstep=tstep, selected_date=date)
if DEBUG: print("POINTS LAYER", points_layer)
- fig = get_figure(model=None, var=None, layer=points_layer, zoom=zoom, center=center, tag='obs-vis')
+ fig = get_models_figure(model=None, var=None, layer=points_layer, zoom=zoom, center=center, tag='obs-vis')
return fig
diff --git a/tests/test_forecast.py b/tests/test_forecast.py
index 0984038e15d8050ccc70bccafc4dae1b4b362272..ae24b6e46e04207c52c1f340e02ea8ea360ccbc9 100644
--- a/tests/test_forecast.py
+++ b/tests/test_forecast.py
@@ -17,33 +17,29 @@ def test_model_time_bar():
assert str(code.gen_time_bar('model', '20120120', '20220808').children[1]) == "Span(children=[Button(id='btn-play', className='fa fa-play text-center', n_clicks=0, title='Play')], className='timesliderline anim-buttons')"
def test_prob_time_bar():
- assert "Div(children=[Span(children=[DatePickerSingle(date='20220809', min_date_allowed=datetime.datetime(2012, 1, 20, 0, 0), max_date_allowed=datetime.datetime(2022, 8, 9, 0, 0), placeholder='DD MON YYYY', initial_visible_month=datetime.datetime(2022, 8, 9, 0, 0), display_format='DD MMM YYYY', id='prob-date-picker'), Button(id='clear_button')], className='timesliderline'), Span(children=Slider(min=0, max=1, step=1, marks={0: {'label': 'TUE 09'}, 1: {'label': 'WED 10', 'style': {'left': '', 'right': '-40px'}}}, value=0, id='prob-slider-graph'), id='prob-slider-container', className='timesliderline')], className='timeslider')" in str(code.gen_time_bar('prob', '20120120', '20220809'))
+ assert "Div(children=[Span(children=[DatePickerSingle(date='20220809', min_date_allowed=datetime.datetime(2012, 1, 20, 0, 0), max_date_allowed=datetime.datetime(2022, 8, 9, 0, 0), placeholder='DD MON YYYY', initial_visible_month=datetime.datetime(2022, 8, 9, 0, 0), display_format='DD MMM YYYY', id='prob-date-picker'), Button(id='clear_button')], className='timesliderline'), Span(children=Slider(min=1, max=2, step=1, marks={1: {'label': 'WED 10'}, 2: {'label': 'THU 11', 'style': {'left': '', 'right': '-40px'}}}, value=1, id='prob-slider-graph'), id='prob-slider-container', className='timesliderline')], className='timeslider')" in str(code.gen_time_bar('prob', '20120120', '20220809'))
def test_was_time_bar():
- assert "Div(children=[Span(children=[DatePickerSingle(date='20220808', min_date_allowed=datetime.datetime(2012, 1, 20, 0, 0), max_date_allowed=datetime.datetime(2022, 8, 8, 0, 0), placeholder='DD MON YYYY', initial_visible_month=datetime.datetime(2022, 8, 8, 0, 0), display_format='DD MMM YYYY', id='was-date-picker'), Button(id='clear_button')], className='timesliderline'), Span(children=Slider(min=0, max=1, step=1, marks={0: {'label': 'MON 08'}, 1: {'label': 'TUE 09', 'style': {'left': '', 'right': '-40px'}}}, value=0, id='was-slider-graph'), id='was-slider-container', className='timesliderline')], className='timeslider')" in str(code.gen_time_bar('was', '20120120', '20220808'))
+ assert "Div(children=[Span(children=[DatePickerSingle(date='20220808', min_date_allowed=datetime.datetime(2012, 1, 20, 0, 0), max_date_allowed=datetime.datetime(2022, 8, 8, 0, 0), placeholder='DD MON YYYY', initial_visible_month=datetime.datetime(2022, 8, 8, 0, 0), display_format='DD MMM YYYY', id='was-date-picker'), Button(id='clear_button')], className='timesliderline'), Span(children=Slider(min=1, max=2, step=1, marks={1: {'label': 'TUE 09'}, 2: {'label': 'WED 10', 'style': {'left': '', 'right': '-40px'}}}, value=1, id='was-slider-graph'), id='was-slider-container', className='timesliderline')], className='timeslider')" in str(code.gen_time_bar('was', '20120120', '20220808'))
def test_models_children():
assert "[Div(id={'tag': 'tab-name', 'index': 'models'}), Alert(children='To explore the forecast, please select a variable and click on APPLY.', id='alert-forecast', color='primary', duration=6000, fade=True, is_open=True, style={'overflow': 'auto', 'marginBottom': 0}), Div(children=[Container(children=[], id='graph-collection', fluid=True), Div(children=[Span(children=P('Dust data ©2023 WMO Barcelona Dust Regional Center.'), id='forecast-disclaimer')], className='disclaimer')], id='div-collection'), Div([Store(id='model-clicked-coords'), Store(id='current-popups-stored')]), Div(Interval(id='slider-interval', disabled=True, interval=1000, n_intervals=0))" in str(code.models_children('20120120', '20220808'))
def test_prob_children():
- assert "Div(id={'tag': 'tab-name', 'index': 'prob'})" in str(code.prob_children('20120120', '20220808')[0])
- assert len(code.prob_children('20120120', '20220808'))== 4
- assert 'layout-dropdown' in str(code.prob_children('20120120', '20220808')[-1].children[0].id)
+ assert "[Div(id={'tag': 'tab-name', 'index': 'prob'}), Div(id='prob-graph', className='graph-with-slider'), Div(children=[Span(children=P('Dust data ©2023 WMO Barcelona Dust Regional Center.'), id='forecast-disclaimer')], className='disclaimer'), NavbarSimple(children=[Div(children=[Div(children=[Span(children=[DatePickerSingle(date='20220808', min_date_allowed=datetime.datetime(2012, 1, 20, 0, 0), max_date_allowed=datetime.datetime(2022, 8, 8, 0, 0), placeholder='DD MON YYYY', initial_visible_month=datetime.datetime(2022, 8, 8, 0, 0), display_format='DD MMM YYYY', id='prob-date-picker'), Button(id='clear_button')], className='timesliderline'), Span(children=Slider(min=1, max=2, step=1, marks={1: {'label': 'TUE 09'}, 2: {'label': 'WED 10', 'style': {'left': '', 'right': '-40px'}}}, value=1, id='prob-slider-graph'), id='prob-slider-container', className='timesliderline')], className='timeslider'), Div(children=[Span(DropdownMenu(children=[DropdownMenuItem(children='Light', id={'tag': 'view-style', 'index': 'carto-positron'}, active=True), DropdownMenuItem(children='Open street map', id={'tag': 'view-style', 'index': 'open-street-map'}, active=False), DropdownMenuItem(children='Terrain', id={'tag': 'view-style', 'index': 'stamen-terrain'}, active=False), DropdownMenuItem(children='ESRI', id={'tag': 'view-style', 'index': 'esri-world'}, active=False)], id='map-view-dropdown', direction='up', in_navbar=True, label='VIEW'))], id='map-view-dropdown-div')], id='layout-dropdown', className='layout-dropdown')], className='fixed-bottom navbar-timebar', dark=True, expand='lg', fixed='bottom', fluid=True)]" in str(code.prob_children('20120120', '20220808'))
def test_was_children():
- assert "Div(id={'tag': 'tab-name', 'index': 'was'})" in str(code.was_children('20120120', '20220808')[0])
- assert len(code.was_children('20120120', '20220808')) == 4
- assert 'layout-dropdown' in str(code.was_children('20120120', '20220808')[-1].children[0].id)
+ assert """[Div(id={'tag': 'tab-name', 'index': 'was'}), Spinner(Div(children=[Div(id="{'index':'None', 'tag': 'empty-map'}")], id='was-graph', className='graph-with-slider')), Div(children=[Span(children=P('Dust data ©2023 WMO Barcelona Dust Regional Center.'), id='forecast-disclaimer')], className='disclaimer'), NavbarSimple(children=[Div(children=[Div(children=[Span(children=[DatePickerSingle(date='20220808', min_date_allowed=datetime.datetime(2012, 1, 20, 0, 0), max_date_allowed=datetime.datetime(2022, 8, 8, 0, 0), placeholder='DD MON YYYY', initial_visible_month=datetime.datetime(2022, 8, 8, 0, 0), display_format='DD MMM YYYY', id='was-date-picker'), Button(id='clear_button')], className='timesliderline'), Span(children=Slider(min=1, max=2, step=1, marks={1: {'label': 'TUE 09'}, 2: {'label': 'WED 10', 'style': {'left': '', 'right': '-40px'}}}, value=1, id='was-slider-graph'), id='was-slider-container', className='timesliderline')], className='timeslider'), Div(children=[Span(DropdownMenu(children=[DropdownMenuItem(children='Light', id={'tag': 'view-style', 'index': 'carto-positron'}, active=True), DropdownMenuItem(children='Open street map', id={'tag': 'view-style', 'index': 'open-street-map'}, active=False), DropdownMenuItem(children='Terrain', id={'tag': 'view-style', 'index': 'stamen-terrain'}, active=False), DropdownMenuItem(children='ESRI', id={'tag': 'view-style', 'index': 'esri-world'}, active=False)], id='map-view-dropdown', direction='up', in_navbar=True, label='VIEW'))], id='map-view-dropdown-div')], id='layout-dropdown', className='layout-dropdown')], className='fixed-bottom navbar-timebar', dark=True, expand='lg', fixed='bottom', fluid=True)]""" in str(code.was_children('20120120', '20220808'))
def test_tab_forecast():
#TEST MODELS
assert "Div(children=[Span(DropdownMenu(children=[DropdownMenuItem(children='Light', id={'tag': 'view-style', 'index': 'carto-positron'}, active=True), DropdownMenuItem(children='Open street map', id={'tag': 'view-style', 'index': 'open-street-map'}, active=False), DropdownMenuItem(children='Terrain', id={'tag': 'view-style', 'index': 'stamen-terrain'}, active=False), DropdownMenuItem(children='ESRI', id={'tag': 'view-style', 'index': 'esri-world'}, active=False)], id='map-view-dropdown', direction='up', in_navbar=True, label='VIEW'))], id='map-view-dropdown-div'), Div(children=[Spinner(children=[Modal(children=[], id='ts-modal', centered=True, is_open=False, size='xl')], id='loading-ts-modal', fullscreen=True, fullscreen_style={'opacity': '0.5', 'zIndex': '200000'}, show_initially=False)], id='open-timeseries')], id='layout-dropdown', className='layout-dropdown')], className='fixed-bottom navbar-timebar', dark=True, expand='lg', fixed='bottom', fluid=True)], id='forecast-tab', className='horizontal-menu', label='Forecast', value='forecast-tab')" in str(code.tab_forecast('models', '20120120', '20220808'))
#TEST WAS
- assert "id='was-graph', className='graph-with-slider')), Div(children=[Span(children=P('Dust data ©2023 WMO Barcelona Dust Regional Center.'), id='forecast-disclaimer')], className='disclaimer'), NavbarSimple(children=[Div(children=[Div(children=[Span(children=[DatePickerSingle(date='20220808', min_date_allowed=datetime.datetime(2012, 1, 20, 0, 0), max_date_allowed=datetime.datetime(2022, 8, 8, 0, 0), placeholder='DD MON YYYY', initial_visible_month=datetime.datetime(2022, 8, 8, 0, 0), display_format='DD MMM YYYY', id='was-date-picker'), Button(id='clear_button')], className='timesliderline'), Span(children=Slider(min=0, max=1, step=1, marks={0: {'label': 'MON 08'}, 1: {'label': 'TUE 09', 'style': {'left': '', 'right': '-40px'}}}, value=0, id='was-slider-graph'), id='was-slider-container', className='timesliderline')], className='timeslider'), Div(children=[Span(DropdownMenu(children=[DropdownMenuItem(children='Light', id={'tag': 'view-style', 'index': 'carto-positron'}, active=True), DropdownMenuItem(children='Open street map', id={'tag': 'view-style', 'index': 'open-street-map'}, active=False), DropdownMenuItem(children='Terrain', id={'tag': 'view-style', 'index': 'stamen-terrain'}, active=False), DropdownMenuItem(children='ESRI', id={'tag': 'view-style', 'index': 'esri-world'}, active=False)], id='map-view-dropdown', direction='up', in_navbar=True, label='VIEW'))], id='map-view-dropdown-div')], id='layout-dropdown', className='layout-dropdown')], className='fixed-bottom navbar-timebar', dark=True, expand='lg', fixed='bottom', fluid=True)], id='forecast-tab', className='horizontal-menu', label='Forecast', value='forecast-tab')" in str(code.tab_forecast('was', '20120120', '20220808'))
+ assert """Tab(children=[Div(id={'tag': 'tab-name', 'index': 'was'}), Spinner(Div(children=[Div(id="{'index':'None', 'tag': 'empty-map'}")], id='was-graph', className='graph-with-slider')), Div(children=[Span(children=P('Dust data ©2023 WMO Barcelona Dust Regional Center.'), id='forecast-disclaimer')], className='disclaimer'), NavbarSimple(children=[Div(children=[Div(children=[Span(children=[DatePickerSingle(date='20220808', min_date_allowed=datetime.datetime(2012, 1, 20, 0, 0), max_date_allowed=datetime.datetime(2022, 8, 8, 0, 0), placeholder='DD MON YYYY', initial_visible_month=datetime.datetime(2022, 8, 8, 0, 0), display_format='DD MMM YYYY', id='was-date-picker'), Button(id='clear_button')], className='timesliderline'), Span(children=Slider(min=1, max=2, step=1, marks={1: {'label': 'TUE 09'}, 2: {'label': 'WED 10', 'style': {'left': '', 'right': '-40px'}}}, value=1, id='was-slider-graph'), id='was-slider-container', className='timesliderline')], className='timeslider'), Div(children=[Span(DropdownMenu(children=[DropdownMenuItem(children='Light', id={'tag': 'view-style', 'index': 'carto-positron'}, active=True), DropdownMenuItem(children='Open street map', id={'tag': 'view-style', 'index': 'open-street-map'}, active=False), DropdownMenuItem(children='Terrain', id={'tag': 'view-style', 'index': 'stamen-terrain'}, active=False), DropdownMenuItem(children='ESRI', id={'tag': 'view-style', 'index': 'esri-world'}, active=False)], id='map-view-dropdown', direction='up', in_navbar=True, label='VIEW'))], id='map-view-dropdown-div')], id='layout-dropdown', className='layout-dropdown')], className='fixed-bottom navbar-timebar', dark=True, expand='lg', fixed='bottom', fluid=True)], id='forecast-tab', className='horizontal-menu', label='Forecast', value='forecast-tab')""" in str(code.tab_forecast('was', '20120120', '20220808'))
#TEST PROB
- assert "DropdownMenuItem(children='Terrain', id={'tag': 'view-style', 'index': 'stamen-terrain'}, active=False), DropdownMenuItem(children='ESRI', id={'tag': 'view-style', 'index': 'esri-world'}, active=False)], id='map-view-dropdown', direction='up', in_navbar=True, label='VIEW'))], id='map-view-dropdown-div')], id='layout-dropdown', className='layout-dropdown')], className='fixed-bottom navbar-timebar', dark=True, expand='lg', fixed='bottom', fluid=True)], id='forecast-tab', className='horizontal-menu', label='Forecast', value='forecast-tab')" in str(code.tab_forecast('prob', '20120120', '20220808'))
+ assert "Tab(children=[Div(id={'tag': 'tab-name', 'index': 'prob'}), Div(id='prob-graph', className='graph-with-slider'), Div(children=[Span(children=P('Dust data ©2023 WMO Barcelona Dust Regional Center.'), id='forecast-disclaimer')], className='disclaimer'), NavbarSimple(children=[Div(children=[Div(children=[Span(children=[DatePickerSingle(date='20220808', min_date_allowed=datetime.datetime(2012, 1, 20, 0, 0), max_date_allowed=datetime.datetime(2022, 8, 8, 0, 0), placeholder='DD MON YYYY', initial_visible_month=datetime.datetime(2022, 8, 8, 0, 0), display_format='DD MMM YYYY', id='prob-date-picker'), Button(id='clear_button')], className='timesliderline'), Span(children=Slider(min=1, max=2, step=1, marks={1: {'label': 'TUE 09'}, 2: {'label': 'WED 10', 'style': {'left': '', 'right': '-40px'}}}, value=1, id='prob-slider-graph'), id='prob-slider-container', className='timesliderline')], className='timeslider'), Div(children=[Span(DropdownMenu(children=[DropdownMenuItem(children='Light', id={'tag': 'view-style', 'index': 'carto-positron'}, active=True), DropdownMenuItem(children='Open street map', id={'tag': 'view-style', 'index': 'open-street-map'}, active=False), DropdownMenuItem(children='Terrain', id={'tag': 'view-style', 'index': 'stamen-terrain'}, active=False), DropdownMenuItem(children='ESRI', id={'tag': 'view-style', 'index': 'esri-world'}, active=False)], id='map-view-dropdown', direction='up', in_navbar=True, label='VIEW'))], id='map-view-dropdown-div')], id='layout-dropdown', className='layout-dropdown')], className='fixed-bottom navbar-timebar', dark=True, expand='lg', fixed='bottom', fluid=True)], id='forecast-tab', className='horizontal-menu', label='Forecast', value='forecast-tab')" in str(code.tab_forecast('prob', '20120120', '20220808'))
def test_expand_dropdown():
assert "{'models': True, 'prob': False, 'was': False}" in str(code.expand_dropdown('models'))
diff --git a/tests/test_forecast_callbacks.py b/tests/test_forecast_callbacks.py
index 34fb246232963dd67bf21e7d458c12dccf27d8c0..bd60063332ac7fac713730de3d94179be68fcaf3 100644
--- a/tests/test_forecast_callbacks.py
+++ b/tests/test_forecast_callbacks.py
@@ -227,7 +227,7 @@ def test_update_slider():
def test_update_was_figure():
def run_callback():
context_value.set(AttributeDict(**{"triggered_inputs": [{"prop_id": "was-apply.n_clicks"},{"prop_id": "was-date-picker.date"},{"prop_id": "was-slider-graph.value"},{"prop_id": "was-dropdown.value"},{"prop_id": "variable-dropdown-forecast.value"},{"prop_id": "was-previous.data"},{"prop_id": "view-style.active"},{"prop_id": "was-map.zoom"},{"prop_id": "was-map.center"}]}))
- return code.update_was_figure.uncached(1, '20230404', 1, 'burkinafaso', None, [True, False, False, False], [True], [], [])
+ return code.update_was_figure(1, '20230404', 1, 'burkinafaso', None, [True, False, False, False], [True], [], [])
ctx = copy_context()
output = ctx.run(run_callback)
@@ -236,7 +236,7 @@ def test_update_was_figure():
def test_update_was_figure_zooms():
def run_callback():
context_value.set(AttributeDict(**{"triggered_inputs": [{"prop_id": "was-apply.n_clicks"},{"prop_id": "was-date-picker.date"},{"prop_id": "was-slider-graph.value"},{"prop_id": "was-dropdown.value"},{"prop_id": "variable-dropdown-forecast.value"},{"prop_id": "was-previous.data"},{"prop_id": "view-style.active"},{"prop_id": "was-map.zoom"},{"prop_id": "was-map.center"}]}))
- return code.update_was_figure.uncached(2, '20230404', 1, 'cabo_verde', 'burkinafaso', [True, False, False, False],[True], [8], [[11.982397942974229, -2.6312255859375004]])
+ return code.update_was_figure(2, '20230404', 1, 'cabo_verde', 'burkinafaso', [True, False, False, False],[True], [8], [[11.982397942974229, -2.6312255859375004]])
ctx = copy_context()
output = ctx.run(run_callback)
diff --git a/tests/test_tools.py b/tests/test_tools.py
index bacf932db358504bc304551e084c08d5e674d31c..1bf71504ec516ee2ee4139dfff0f87015f675159 100644
--- a/tests/test_tools.py
+++ b/tests/test_tools.py
@@ -45,20 +45,14 @@ def test_get_vis_figure():
assert result in run1
assert result2 in run2
-def test_get_figure():
- result = "/dashboard/assets/geojsons/median/geojson/20220808/00_20220808_OD550_DUST.geojson"
- run1 = str(code.get_figure(model='median', var='OD550_DUST', selected_date='20220808', tstep=0,
- hour=3, static=True, aspect=(1, 1), center=None,
- view='carto-positron', zoom=None, layer=None, tag='empty').children[2].url)
+def test_get_models_figure():
+ result = "/dashboard/assets/geojsons/median/geojson/20230408/00_20230408_OD550_DUST.geojson"
+ run1 = str(code.get_models_figure(model='median', var='OD550_DUST',
+ selected_date='20230408', tstep=0).children[2].url)
assert result in run1
result2 = "{'tag': 'model-tile-layer', 'index': 'monarch'}"
- run2 = str(code.get_figure(model='monarch', var='SCONC_DUST', selected_date='20220809', tstep=1,
+ run2 = str(code.get_models_figure(model='monarch', var='SCONC_DUST', selected_date='20220809', tstep=1,
hour=3, static=True, aspect=(1, 1), center=None,
view='carto-positron', zoom=None, layer=None, tag='empty').children[0].id)
assert result2 in run2
-
-
-
-
-
diff --git a/tools.py b/tools.py
index 56ab34156c969d05b303730e2286517e35c81602..2df73cbdadb2afe116ba3dd0779295fd5f58d2ce 100644
--- a/tools.py
+++ b/tools.py
@@ -2,6 +2,10 @@
# -*- coding: utf-8 -*-
""" Tools module with functions related to plots """
+from datetime import datetime as dt
+from datetime import timedelta
+import os
+
from data_handler import FigureHandler
from data_handler import WasFigureHandler
from data_handler import ProbFigureHandler
@@ -13,31 +17,32 @@ from data_handler import Observations1dHandler
from data_handler import DEBUG
from data_handler import MODELS
from data_handler import END_DATE, DELAY, DELAY_DATE
-
-from datetime import datetime as dt
-from datetime import timedelta
-import os
-
+from utils import get_currdate_tstep
def download_image_link(models, variable, curdate, tstep=0, anim=False):
""" Generates links to animated gifs """
- if DEBUG: print('CURRDIR', os.getcwd())
+ if DEBUG:
+ print('CURRDIR', os.getcwd())
filepath = "assets/comparison/{model}/{variable}/{year}/{month}/{curdate}_{model}_{tstep}.{ext}"
if len(models) == 1:
model = models[0]
- if DEBUG: print('DOWNLOAD MODELS', model)
+ if DEBUG:
+ print('DOWNLOAD MODELS', model)
else:
- if DEBUG: print('DOWNLOAD ALL MODELS')
+ if DEBUG:
+ print('DOWNLOAD ALL MODELS')
model = "all"
if anim:
tstep = "loop"
ext = "gif"
- if DEBUG: print('DOWNLOAD LOOP')
+ if DEBUG:
+ print('DOWNLOAD LOOP')
else:
tstep = "%02d" % tstep
ext = "png"
- if DEBUG: print('DOWNLOAD PNG', tstep)
+ if DEBUG:
+ print('DOWNLOAD PNG', tstep)
filename = filepath.format(
model=model,
@@ -48,31 +53,38 @@ def download_image_link(models, variable, curdate, tstep=0, anim=False):
tstep=tstep,
ext=ext
)
- if DEBUG: print('DOWNLOAD FILENAME', filename)
+ if DEBUG:
+ print('DOWNLOAD FILENAME', filename)
return filename
def get_eval_timeseries(obs, start_date, end_date, var, idx, name, model):
""" Retrieve timeseries """
- if DEBUG: print('SERVER: OBS TS init for obs {} ... '.format(str(obs)))
+ if DEBUG:
+ print('SERVER: OBS TS init for obs {} ... '.format(str(obs)))
th = ObsTimeSeriesHandler(obs, start_date, end_date, var)
- if DEBUG: print('SERVER: OBS TS generation ... ')
+ if DEBUG:
+ print('SERVER: OBS TS generation ... ')
return th.retrieve_timeseries(idx, name, model)
def get_timeseries(model, date, var, lat, lon, forecast=False):
""" Retrieve timeseries """
- if DEBUG: print('SERVER: TS init for models {} ... '.format(str(model)))
+ if DEBUG:
+ print('SERVER: TS init for models {} ... '.format(str(model)))
th = TimeSeriesHandler(model, date, var)
- if DEBUG: print('SERVER: TS generation ... ')
+ if DEBUG:
+ print('SERVER: TS generation ... ')
return th.retrieve_timeseries(lat, lon, method='feather', forecast=forecast)
def get_single_point(model, date, tstep, var, lat, lon):
""" Retrieve sigle point """
- if DEBUG: print('SERVER: SINGLE POINT init for models {} ... '.format(str(model)))
+ if DEBUG:
+ print('SERVER: SINGLE POINT init for models {} ... '.format(str(model)))
th = TimeSeriesHandler(model, date, var)
- if DEBUG: print('SERVER: SINGLE POINT generation ... ')
+ if DEBUG:
+ print('SERVER: SINGLE POINT generation ... ')
return th.retrieve_single_point(tstep, lat, lon)
@@ -90,92 +102,107 @@ def get_scores_figure(network, model, statistic, selection=END_DATE):
def get_prob_figure(var, prob=None, day=0, selected_date=END_DATE):
""" Retrieve figure """
- if DEBUG: print(prob, day, selected_date)
+ if DEBUG:
+ print(prob, day, selected_date)
try:
selected_date = dt.strptime(
selected_date, "%Y-%m-%d").strftime("%Y%m%d")
except:
pass
- if DEBUG: print(prob, day, selected_date)
+ if DEBUG:
+ print(prob, day, selected_date)
if prob:
- if DEBUG: print('SERVER: PROB Figure init ... ')
+ if DEBUG:
+ print('SERVER: PROB Figure init ... ')
fh = ProbFigureHandler(var=var, prob=prob, selected_date=selected_date)
- if DEBUG: print('SERVER: PROB Figure generation ... ')
+ if DEBUG:
+ print('SERVER: PROB Figure generation ... ')
return fh.retrieve_var_tstep(day=day)
- if DEBUG: print('SERVER: NO PROB Figure')
+ if DEBUG:
+ print('SERVER: NO PROB Figure')
return ProbFigureHandler().retrieve_var_tstep()
def get_was_figure(was=None, day=0, selected_date=END_DATE):
""" Retrieve figure """
- if DEBUG: print(was, day, selected_date)
+ if DEBUG:
+ print(was, day, selected_date)
try:
selected_date = dt.strptime(
selected_date, "%Y-%m-%d").strftime("%Y%m%d")
except:
pass
- if DEBUG: print(was, day, selected_date)
+ if DEBUG:
+ print(was, day, selected_date)
if was:
- if DEBUG: print('SERVER: WAS Figure init ... ')
+ if DEBUG:
+ print('SERVER: WAS Figure init ... ')
fh = WasFigureHandler(was=was, selected_date=selected_date)
- if DEBUG: print('SERVER: WAS Figure generation ... ')
+ if DEBUG:
+ print('SERVER: WAS Figure generation ... ')
return fh.retrieve_var_tstep(day=day)
- if DEBUG: print('SERVER: NO WAS Figure')
+ if DEBUG:
+ print('SERVER: NO WAS Figure')
return WasFigureHandler().retrieve_var_tstep()
def get_vis_figure(tstep=0, selected_date=END_DATE):
""" Retrieve figure """
- if DEBUG: print(tstep, selected_date)
+ if DEBUG:
+ print(tstep, selected_date)
try:
selected_date = dt.strptime(
selected_date, "%Y-%m-%d").strftime("%Y%m%d")
except:
pass
- if DEBUG: print(tstep, selected_date)
+ if DEBUG:
+ print(tstep, selected_date)
if tstep is not None:
- if DEBUG: print('SERVER: VIS Figure init ... ')
+ if DEBUG:
+ print('SERVER: VIS Figure init ... ')
fh = VisFigureHandler(selected_date=selected_date)
- if DEBUG: print('SERVER: VIS Figure generation ... ')
+ if DEBUG:
+ print('SERVER: VIS Figure generation ... ')
return fh.retrieve_var_tstep(tstep=tstep)
- if DEBUG: print('SERVER: NO VIS Figure')
+ if DEBUG:
+ print('SERVER: NO VIS Figure')
return VisFigureHandler().retrieve_var_tstep()
-def get_figure(model=None, var=None, selected_date=END_DATE, tstep=0,
+def get_models_figure(model=None, var=None, selected_date=END_DATE, tstep=0,
hour=None, static=True, aspect=(1, 1), center=None,
view='carto-positron', zoom=None, layer=None, tag='empty'):
""" Retrieve figure """
- if DEBUG: print("***", model, var, selected_date, tstep, hour, "***")
+ if DEBUG:
+ print("***", model, var, selected_date, tstep, hour, "***")
try:
selected_date = dt.strptime(
selected_date, "%Y-%m-%d %H:%M:%S").strftime("%Y%m%d")
except:
pass
- if model:
- if DEBUG: print('SERVER: Figure init ... ')
- if model in MODELS and MODELS[model]['start'] == 12:
- if DELAY:
- # OLD: for models that starts at 12h considering end_date = current_date - 1
- if tstep < 4:
- selected_date = (dt.strptime(selected_date,
- "%Y%m%d") -
- timedelta(days=1)).strftime("%Y%m%d")
- tstep = int(tstep) + 4
- else:
- tstep = int(tstep) - 4
- else:
- # NEW: for models that starts at 12h considering end_date = current_date
- selected_date = (dt.strptime(selected_date,
- "%Y%m%d") -
- timedelta(days=1)).strftime("%Y%m%d")
- tstep = int(tstep) + 4
-
- if DEBUG: print('SERVER: Figure generation ... ')
+ if model in MODELS:
+ model_start = MODELS[model]['start']
+ model_start_before = ('start_before' in MODELS[model]) and MODELS[model]['start_before'] or False
+ current_time_before = (DELAY_DATE and dt.strptime(selected_date, "%Y%m%d") < dt.strptime(DELAY_DATE, "%Y%m%d"))
+ if DEBUG:
+ print(f"""
+************************ SERVER: Figure init *********************
+* DELAY: {DELAY}, DELAY_DATE: {DELAY_DATE}, SELECTED DATE: {selected_date}, CURR_BEFORE: {current_time_before} *
+* MODEL: {model}, MODEL_START: {model_start}, MODEL_START_DELAYED: {model_start_before} *
+******************************************************************
+ """)
+ # If current date is later than the delay date and the model_start is 12
+ # or current date is before than the delay date and the model_start
+ selected_date, tstep, _ = get_currdate_tstep(model_start, model_start_before, current_time_before, DELAY, selected_date, tstep)
+
+ if DEBUG:
+ print('***** SERVER: Figure generation: CURR_DATE', selected_date, 'TSTEP', tstep, '*****')
+ # return True
fh = FigureHandler(model, selected_date)
return fh.retrieve_var_tstep(var, tstep, hour, static, aspect, center,
view, zoom, layer, tag)
- if DEBUG: print('SERVER: No Figure')
+ if DEBUG:
+ print('SERVER: No Figure')
return FigureHandler().retrieve_var_tstep(layer=layer, center=center, selected_tiles=view, zoom=zoom, tag=tag)
diff --git a/utils.py b/utils.py
index 13ddd3175b6bd17721ad013ed7ede699694d7bea..81aa7038a447cccd0ea6e96bdd158f07725a8572 100644
--- a/utils.py
+++ b/utils.py
@@ -206,4 +206,40 @@ def get_vis_edate(end_date, hour=None):
if curr is not None:
return curr.strftime(fmt_date), curr.hour
- return cdate, edate.hour
+ return cdate, edate.hour
+
+
+def get_currdate_tstep(model_start, model_start_before, current_time_before, delay, selected_date, tstep=4):
+ """ Returns date and timestep """
+
+ # MODELS starting at 00 with 3 days of forecast
+ print("Starting at 0 and NOT DELAYED: 3 days forecast!")
+ cdo_tsteps = "1/25"
+ delayed = (current_time_before and not delay) or (not current_time_before and delay)
+
+ # MODELS not starting at 00
+ if (model_start == 12 and not model_start_before) or \
+ (current_time_before and model_start_before == 12):
+ if delayed:
+ print("Starting at 12 and DELAYED: 2 days forecast!")
+ # DELAYED (2 days): models that starts at 12h considering end_date = current_date - 1
+ if tstep < 4:
+ selected_date = (datetime.strptime(selected_date, "%Y%m%d") -
+ timedelta(days=1)).strftime("%Y%m%d")
+ tstep = int(tstep) + 4
+ else:
+ tstep = int(tstep) - 4
+ cdo_tsteps = "1/21"
+ else:
+ print("Starting at 12 and NOT DELAYED: 3 days forecast!")
+ # NOT DELAYED (3 days): models that starts at 12h considering end_date = current_date
+ selected_date = (datetime.strptime(selected_date, "%Y%m%d") -
+ timedelta(days=1)).strftime("%Y%m%d")
+ tstep = int(tstep) + 4
+ cdo_tsteps = "5/29"
+ # MODELS starting at 00 with 2 days of forecast
+ elif delayed:
+ print("Starting at 0 and DELAYED: 2 days forecast!")
+ cdo_tsteps = "5/25"
+
+ return selected_date, tstep, cdo_tsteps