Exemple #1
0
    def get_slider_name(column, low_high):
        if isinstance(low_high, dict):
            low = low_high["min"]
            high = low_high["max"]
        elif isinstance(low_high, (tuple, list)):
            low = low_high[0]
            high = low_high[1]

        if column in dashboard.utils.log_transform_columns:
            low = dashboard.utils.log_transform_slider(low)
            high = dashboard.utils.log_transform_slider(high)

        low = utils.human_format(low)
        high = utils.human_format(high)

        return f"{column}: [{low}, {high}]"
Exemple #2
0
def _insert_mark_values(mark_values):
    # https://github.com/plotly/dash-core-components/issues/159
    # work-around bug reported in https://github.com/plotly/dash-core-components/issues/159
    # if mark keys happen to fall on integers, cast them to int

    mark_labels = {}
    for mark_val in mark_values:
        # close enough to an int for my use case
        if abs(mark_val - round(mark_val)) < 1e-3:
            mark_val = int(mark_val)
        mark_labels[mark_val] = human_format(mark_val)
    return mark_labels
Exemple #3
0
def fit_results_to_string(fit_result):
    s = ""

    D_max = fit_result["D_max"]
    D_max_lower_hpdi = D_max - fit_result["D_max_lower_hpdi"]
    D_max_upper_hpdi = fit_result["D_max_upper_hpdi"] - D_max

    s += r"$D_\mathrm{max} = " + f"{D_max:.3f}" + r"_{-"
    s += f"{D_max_lower_hpdi:.3f}" + r"}^{+"
    s += f"{D_max_upper_hpdi:.3f}" + r"}$" + "\n"

    s += r"$n_\sigma = " + f"{fit_result['n_sigma']:.3f}" + r"$" + "\n"

    s += "\n"
    concentration = utils.human_format(fit_result["concentration_mean"])
    s += r"$\mathrm{concentration} = " + f"{concentration}" + r"$" + "\n"
    s += r"$q = " + f"{fit_result['q_mean']:.3f}" + r"$" + "\n"

    s += "\n"
    N_alignments = utils.human_format(fit_result["N_alignments"])
    s += r"$N_\mathrm{alignments} = " + f"{N_alignments}" + r"$" + "\n"

    return s
Exemple #4
0
def plot_fit_results_single_N_aligment(all_fit_results,
                                       cfg,
                                       N_alignments_min=0,
                                       n_sigma_lim=(-3, 20),
                                       D_max_lim=(0, 1)):

    # cmaps = {name: cmap for name, cmap in zip(all_fit_results.keys(), cmaps_list)}
    kw_marker_colors = get_cmaps_and_colors(all_fit_results)

    zmin, zmax = get_z_min_max(all_fit_results)
    vmin, vmax, func = 10, 600, np.sqrt

    zs = np.array([], dtype=int)
    kw_cols = {}

    fig, ax = plt.subplots(figsize=(10, 10))

    for name, df_res in all_fit_results.items():
        # break
        x = df_res["n_sigma"].values
        y = df_res["D_max"].values
        z = df_res["N_alignments"].values

        if N_alignments_min > 0:
            mask = z > N_alignments_min

            # if not values to plot, continue without plotting
            if mask.sum() == 0:
                continue

            x = x[mask]
            y = y[mask]
            z = z[mask]
        zs = np.append(zs, z)

        s = transform(z,
                      vmin=vmin,
                      vmax=vmax,
                      func=func,
                      xmin=func(zmin),
                      xmax=func(zmax))
        c = np.log10(z)

        kw_cols[name] = dict(
            vmin=c.min() / 10,
            vmax=c.max() * 1.25,
            ec=None,
            **kw_marker_colors[name],
        )
        ax.scatter(x, y, s=s, c=c, **kw_cols[name], alpha=0.5)

    # if not plotting anything at all, quit
    if len(zs) == 0:
        return None

    xlabel = r"$n_\sigma$"
    ylabel = r"$D_\mathrm{max}$"
    ax.set(xlim=n_sigma_lim, ylim=D_max_lim, xlabel=xlabel, ylabel=ylabel)

    set_custom_legends(zs, ax, vmin, vmax, func, kw_cols)

    title = f"Fit results "
    if N_alignments_min > 0:
        N_aligments = utils.human_format(N_alignments_min)
        title += f"with cut on " + r"$N_\mathrm{alignments}>$  " + f"{N_aligments}"
    else:
        title += "with no cut on " + r"$N_\mathrm{alignments}$"

    ax.text(
        -0.1,
        1.15,
        title,
        transform=ax.transAxes,
        horizontalalignment="left",
        verticalalignment="top",
        fontsize=50,
    )

    return fig
Exemple #5
0
def get_range_slider_keywords(fit_results, column="N_alignments", N_steps=100):

    df = fit_results.df_fit_results

    if column in dashboard.utils.log_transform_columns:

        x = df[column]

        range_log = np.log10(x[x > 0])
        range_min = np.floor(range_log.min())
        range_max = np.ceil(range_log.max())
        marks_steps = np.arange(range_min, range_max + 1)

        # if x contains 0-values
        if (x <= 0).sum() != 0:
            range_min = -1
            marks_steps = np.insert(marks_steps, 0, -1)

        if len(marks_steps) > 6:
            marks_steps = ([marks_steps[0]] + [x
                                               for x in marks_steps[1:-1:2]] +
                           [marks_steps[-1]])

        f = lambda x: human_format(dashboard.utils.log_transform_slider(x))
        marks = {int(i): f"{f(i)}" for i in marks_steps}

        marks[marks_steps[0]] = {
            "label": "No Min.",
            "style": {
                "color": "#a3ada9"
            }
        }
        marks[marks_steps[-1]] = {
            "label": "No Max.",
            "style": {
                "color": "#a3ada9"
            }
        }

    elif column == "D_max" or column == "q_mean":
        range_min = 0.0
        range_max = 1.0
        marks = {
            0.25: "0.25",
            0.5: "0.5",
            0.75: "0.75",
        }
        marks[0] = {"label": "No Min.", "style": {"color": "#a3ada9"}}
        marks[1] = {"label": "No Max.", "style": {"color": "#a3ada9"}}

    else:

        array = df[column]
        array = array[np.isfinite(array) & array.notnull()]

        range_min = np.min(array)
        range_max = np.max(array)

        if range_max - range_min > 1:
            range_min = np.floor(range_min)
            range_max = np.ceil(range_max)
            mark_values = np.linspace(range_min, range_max, 5, dtype=int)
            marks = _insert_mark_values(mark_values[1:-1])

        else:
            decimals = abs(int(np.floor(np.log10(range_max - range_min))))
            range_min = np.around(range_min, decimals=decimals)
            range_max = np.around(range_max, decimals=decimals)

            mark_values = np.linspace(range_min, range_max, 5)
            marks = {float(val): str(val) for val in mark_values[1:-1]}

        marks[int(mark_values[0])] = {
            "label": "No Min.",
            "style": {
                "color": "#a3ada9"
            }
        }
        marks[int(mark_values[-1])] = {
            "label": "No Max.",
            "style": {
                "color": "#a3ada9"
            },
        }

    step = (range_max - range_min) / N_steps

    return dict(
        min=range_min,
        max=range_max,
        step=step,
        marks=marks,
        value=[range_min, range_max],
        allowCross=False,
        updatemode="mouseup",
        included=True,
        # tooltip=dict(
        #     always_visible=False,
        #     placement="bottom",
        # ),
    )