Esempio n. 1
0
def update_output(clicks, x_axis, y_axis,
                  start_date, end_date, nbins_x, nbins_y):
    """ Return an updated heatmap based on the changes in the configuration.

    Keyword arguments:
    clicks -- Number of clicks on the apply button
    x-axis -- The column used for the x-axis
    y-axis -- The column used for the y-axis
    start_date -- String from the date picker representing the start date
    end_date -- String from the date picker representing the end date
    nbins_x -- Number of bins used for the x-axis
    nbins_y -- Number of bins used for the y-axis
    """
    if clicks is None:
        raise PreventUpdate

    start_date = get_datetime_from_str(start_date)
    end_date = get_datetime_from_str(end_date) + timedelta(days=1)

    session_id = session.get_session_id()
    eq_data = earthquake_data.get_earthquake_data(session_id)
    filtered_data = eq_data.filter_by_dates(start_date, end_date)

    x_axis = filtered_data.data[x_axis]
    y_axis = filtered_data.data[y_axis]

    z, xbins, ybins = filtered_data.get_weight_matrix(
        x_axis.name, y_axis.name, nbins_x, nbins_y
    )

    return heatmap.get_component(z, xbins, ybins)
Esempio n. 2
0
def update_time_slider(apply_clicks, start_date, end_date, timestep_value,
                       timestep_seconds, interval_seconds, current_time):
    """Update the time slider based on the configuration.

    This is a callback function invoked by changes to the configuration.

    Keyword arguments:
    apply_clicks -- The number of clicks on the apply button.
    start_date -- String from the date picker representing the start date
    end_date -- String from the date picker representing the end date
    timestep_value -- The time step in some time unit. Earthquakes that
        happened within the time window of this size are shown.
    timestep_seconds -- The number of seconds the selected time unit is
        equal to
    interval_seconds -- The update frequency of the time slider in seconds
    current_time -- String containing the current slider time
    """
    if apply_clicks is None:
        raise PreventUpdate

    timestep = timestep_seconds * timestep_value
    start_date = get_datetime_from_str(start_date)
    end_date = get_datetime_from_str(end_date) + timedelta(days=1)

    if current_time is not None:
        current_time = datetime.strptime(current_time, r'%Y-%m-%dT%H:%M:%S')

    return time_slider.get_component(start_date, end_date, timestep,
                                     interval_seconds, current_time)
Esempio n. 3
0
def update_map(slider_value, apply_clicks, start_date, end_date,
               timestep_value, timestep_seconds, size_column, color_column,
               template_id, show_uncertainties, show_faults, show_opacity,
               opacity_value, opacity_unit):
    """Update the map based on the slider position and the configuration.

    This is a callback function invoked by changes to either the time slider
    or the configuration.

    Keyword arguments:
    slider_value -- The value of the current slider position.
        Between 0 and steps-1.
    apply_clicks -- The number of clicks on the apply button.
    start_date -- String from the date picker representing the start date
    end_date -- String from the date picker representing the end date
    timestep_value -- The time step in some time unit. Earthquakes that
        happened within the time window of this size are shown.
    timestep_seconds -- The number of seconds the selected time unit is
        equal to
    size_column -- The column for computing the size of each data point
    color_column -- The column for computing the color of each data point
    template_id -- ID of the template which determines the earthquakes
        shown on the map
    show_uncertainties -- An array with length one if the toggle for
        showing location uncertainties is on, and zero if not
    show_faults -- A list indicating if faults shall be visible, length 1
        indicates yes
    show_opacity -- An array with length one if the rock healing should
        be visible, and zero otherwise
    opacity_value -- Number of opacity units selected
    opacity_unit -- Number of seconds equal to selected opacity unit
    """
    start_date = get_datetime_from_str(start_date)
    end_date = get_datetime_from_str(end_date) + timedelta(days=1)

    session_id = session.get_session_id()
    eq_data = earthquake_data.get_earthquake_data_by_dates(
        session_id, start_date, end_date)

    timestep = timestep_seconds * timestep_value
    filtered_data = filter_data(eq_data, start_date, timestep, slider_value,
                                len(show_opacity) == 1)
    end_date = start_date\
        + timedelta(seconds=slider_value*timestep + timestep)

    if template_id is not None:
        filtered_data = filtered_data.filter_by_template_id(template_id)

    sizes = get_sizes(filtered_data.data,
                      eq_data.get_column_params(size_column))
    opacities = get_opacities(filtered_data.dates, start_date, end_date,
                              opacity_value * opacity_unit,
                              len(show_opacity) == 1)
    color_params = eq_data.get_column_params(color_column)

    return quake_map.get_component(filtered_data, sizes, opacities,
                                   color_params,
                                   len(show_uncertainties) == 1,
                                   len(show_faults) == 1)
Esempio n. 4
0
def update_time_slider_value(slider_value, start_date, timestep_value,
                             timestep_seconds, constant_start_time):
    """Update the time slider value to represent the selected date and
    time, as well as a hidden div that keeps track of the current slider time.

    This is a callback function invoked by a change to the time slider.

    Keyword arguments:
    slider_value -- Current value of the time slider
    start_date -- A datetime object corresponding to the lowest value
        on the slider
    timestep_value -- The number of time units one timestep contains
    timestep_seconds -- The unit of the timestep in seconds
    constant_start_time -- An array with length one if the start time should
        not change according to value selected on the time slider
    """
    timestep = timestep_seconds * timestep_value
    start_date = get_datetime_from_str(start_date)
    slider_time = start_date + timedelta(seconds=slider_value * timestep)

    if len(constant_start_time) == 1:
        timestep = ((slider_time + timedelta(seconds=timestep)) -
                    start_date).total_seconds()
        slider_time = start_date

    return time_slider.get_time_string(slider_time, timestep), slider_time
Esempio n. 5
0
def update_template_options(start_date, end_date):
    """Update the list of template IDs to choose from to include all template
    IDs occurring at least once in the selected time period.

    Keyword arguments:
    start_date -- String from the date picker representing the start date
    end_date -- String from the date picker representing the end date
    """
    session_id = session.get_session_id()
    eq_data = earthquake_data.get_earthquake_data(session_id)

    start_date = get_datetime_from_str(start_date)
    end_date = get_datetime_from_str(end_date) + timedelta(days=1)

    templates = eq_data.filter_by_dates(start_date, end_date).get_templateids()
    if templates is None:
        templates = []

    return [{'label': template, 'value': template} for template in templates]
Esempio n. 6
0
def update_output(clicks, column, nbins, start_date, end_date):
    """ Return an updated histogram based on the changes in the configuration.

    Keyword arguments:
    clicks -- Number of clicks on the apply button
    column -- Name of the column to use for the histogram
    nbins -- Maximum number of bins used
    start_date -- String from the date picker representing the start date
    end_date -- String from the date picker representing the end date
    """
    if clicks is None:
        raise PreventUpdate

    start_date = get_datetime_from_str(start_date)
    end_date = get_datetime_from_str(end_date) + timedelta(days=1)

    session_id = session.get_session_id()
    eq_data = earthquake_data.get_earthquake_data(session_id)
    filtered_data = eq_data.filter_by_dates(start_date, end_date)

    column = filtered_data.data[column]
    return histogram.get_component(column, nbins)