Example #1
0
def generatePDF():

    gu, gd, gs = get_gSM()
    si_modifier = get_SI_modifier()

    global selected_datasets
    #Will re-use the previously selected values for the dataset_type
    #Optional: provide datasel file names in the POST parameters
    if request.method == 'POST':
        print('Use this are to parse to posted datasets')

    datasets = selected_datasets
    dfs = map(get_data, datasets)

    #Filter, TODO: Apply filter to selected_datasets prior to conversion (attempt)
    #get_data will return a 'None' object if the selected dataset could not be converted, (bad experiement string..)
    dfs = [x for x in dfs if determine(x)]

    metadata = map(get_metadata, datasets)

    p1 = getSimplifiedPlot()
    p2 = getDDPlot()
    legendPlot = getLegendPlot()

    legendItems = []
    x = 1
    y = 2 * x
    for df, color in zip(dfs, colors):
        label = df['label'].any()
        df['color'] = color
        p1.line(df['m_med'], df['m_DM'], line_width=2, color=color)
        p2.line(df['m_DM'], df['sigma'], line_width=2, color=color)
        line = legendPlot.line(x, y, line_width=2, color=color)
        legendItems.append((label, [line]))

    #Initialize all_data in the case that all datasets selected where invalid
    all_data = pd.DataFrame()
    if (len(dfs) > 0):
        all_data = pd.concat(dfs)

    legend = Legend(items=legendItems, location=(0, 0))
    legendPlot.add_layout(legend, 'above')

    script1, div1 = components(p1, CDN)
    script2, div2 = components(p2, CDN)
    script3, div3 = components(legendPlot, CDN)
    html = render_template('pdf.html',
                           plot_script1=script1,
                           plot_div1=div1,
                           plot_script2=script2,
                           plot_div2=div2,
                           plot_script3=script3,
                           plot_div3=div3,
                           bokeh_version=bokeh.__version__,
                           metadata=metadata,
                           selected_datasets=selected_datasets,
                           si_modifier=si_modifier,
                           gSM_gSM=gu)
    return html
Example #2
0
def dmplotter():
    known_datasets = get_datasets()
    gu, gd, gs = get_gSM()
    si_modifier = get_SI_modifier()

    #Generate Array of options
    options = list(getSavedPlots().keys())

    dataset_selection = DatasetForm(gSM_input=gu)
    dataset_selection.datasets.choices = zip(get_datasets(), get_datasets())
    dataset_selection.savedPlots.choices = zip(options, options)
    dataset_upload = UploadForm()

    global selected_datasets
    print(selected_datasets)

    if request.method == 'POST':
        # check if the post request has the file part
        # print(request.values, request.data, request.form)
        print(dataset_selection.datasets.data)
        if dataset_selection.validate():
            selected_datasets = dataset_selection.datasets.data
            gSM = dataset_selection.gSM_input.data
            set_gSM(gSM, gSM, gSM)
            gu, gd, gs = get_gSM()
            si_modifier = dataset_selection.radio_inputSI.data
            set_SI_modifier(si_modifier)

    datasets = selected_datasets
    dfs = map(get_data, datasets)

    #Filter, TODO: Apply filter to selected_datasets prior to conversion (attempt)
    #get_data will return a 'None' object if the selected dataset could not be converted, (bad experiement string..)
    dfs = [x for x in dfs if determine(x)]

    metadata = map(get_metadata, datasets)
    allmetadata = map(get_metadata, known_datasets)

    p1 = getSimplifiedPlot()
    p2 = getDDPlot()
    legendPlot = getLegendPlot()

    legendItems = []
    x = 1
    y = 2 * x
    for df, color in zip(dfs, colors):
        label = df['label'].any()
        df['color'] = color
        p1.line(df['m_med'], df['m_DM'], line_width=2, color=color)
        p2.line(df['m_DM'], df['sigma'], line_width=2, color=color)
        line = legendPlot.line(x, y, line_width=2, color=color)
        legendItems.append((label, [line]))

    #Initialize all_data in the case that all datasets selected where invalid
    all_data = pd.DataFrame()
    if (len(dfs) > 0):
        all_data = pd.concat(dfs)

    legend = Legend(items=legendItems, location=(0, 0))
    legendPlot.add_layout(legend, 'above')

    script1, div1 = components(p1, CDN)
    script2, div2 = components(p2, CDN)
    script3, div3 = components(legendPlot, CDN)
    return render_template('dmplotter.html',
                           _debug=app.debug,
                           _signedIn=current_user.is_authenticated,
                           plot_script1=script1,
                           plot_div1=div1,
                           plot_script2=script2,
                           plot_div2=div2,
                           plot_script3=script3,
                           plot_div3=div3,
                           bokeh_version=bokeh.__version__,
                           data_table=all_data.to_html(),
                           datasets=known_datasets,
                           metadata=metadata,
                           dataset_selection=dataset_selection,
                           selected_datasets=selected_datasets,
                           allmetadata=allmetadata,
                           savedPlots=getSavedPlots(),
                           dataset_upload=dataset_upload,
                           si_modifier=si_modifier,
                           gSM_gSM=gu,
                           gSM_gU=gu,
                           gSM_gD=gd,
                           gSM_gS=gs)