def background_thread(ds, year_ds, month_ds, timeseries_ds): """Plot animation, update data if play is True, otherwise stop""" try: while True: for year_index in np.arange(2000, 2015, 1): year_ds.data["text"] = [str(year_index)] for month_index in np.arange(1, 13, 1): if should_play(): month_ds.data["text"] = [months_str[month_index-1]] image = get_slice(t, year_index, month_index) date = datetime.date(year_index, month_index, 1) timeseries_ds.data["x"] = [date] timeseries_ds.data["y"] = [df[df.datetime == date].moving_average] ds.data["image"] = [image] cursession().store_objects(ds, year_ds, month_ds, timeseries_ds) time.sleep(0.5) time.sleep(0.5) except: logger.exception("An error occurred") raise
def background_thread(ds, year_ds, month_ds, timeseries_ds): """Plot animation, update data if play is True, otherwise stop""" try: while True: for year_index in np.arange(2000, 2015, 1): year_ds.data["text"] = [str(year_index)] for month_index in np.arange(1, 13, 1): if should_play(): month_ds.data["text"] = [months_str[month_index - 1]] image = get_slice(t, year_index, month_index) date = datetime.date(year_index, month_index, 1) timeseries_ds.data["x"] = [date] timeseries_ds.data["y"] = [ df[df.datetime == date].moving_average ] ds.data["image"] = [image] cursession().store_objects(ds, year_ds, month_ds, timeseries_ds) time.sleep(0.5) time.sleep(0.5) except: logger.exception("An error occurred") raise
# Output option output_server("climate") # Plots climate_map = climate_map() timeseries = timeseries() legend = legend() # Create layout map_legend = hplot(climate_map, legend) layout = vplot(map_legend, timeseries) # Show show(layout) # Select data source for climate_map renderer = climate_map.select(dict(name="image")) ds = renderer[0].data_source # Create an infite loop to update image data import time while True: for year_index in np.arange(2000, 2015, 1): for month_index in np.arange(1, 13, 1): image = get_slice(t, year_index, month_index) ds.data["image"] = [image] cursession().store_objects(ds) time.sleep(0.2)
def update(): for year_index in np.arange(2000, 2015, 1): for month_index in np.arange(1, 13, 1): image = get_slice(t, year_index, month_index) ds.data["image"] = [image]