Beispiel #1
0
def process_collection(summary_content=None, report_list=[], publish=True, run_number=None):
    """
        Process a collection of reports into on final report
    """
    plot_html = ''
    script = ''

    if summary_content is not None:
        plot_html += "<div>%s</div>\n" % summary_content

    for r in report_list:
        script += r.script
        plot_html += "<div>%s</div>\n" % r.report
        plot_html += "<table style='width:100%'>\n"
        plot_html += "<tr>\n"
        for p in r.plots:
            plot_html += "<td>%s</td>\n" % p
        plot_html += "</tr>\n"
        plot_html += "</table>\n"

    # Send to the web monitor as needed
    if run_number is None and len(report_list)>0:
        run_number = report_list[0].data_info.run_number
    if publish:
        try:
            from postprocessing.publish_plot import publish_plot
            publish_plot("REF_M", run_number, files={'file': plot_html})
        except:
            logging.error("Could not publish web report: %s", sys.exc_value)

    return plot_html, script
Beispiel #2
0
def process_collection(summary_content=None,
                       report_list=[],
                       publish=True,
                       run_number=None):
    """
        Process a collection of reports into on final report
        :param str summary_content: html content at the top of the report
        :param list report_list: list of html contents to be appended at the bottom of the page
        :param bool publish: if True, the report will be sent to the live data server
        :param int run_number: run number to associate this report with
    """
    logger.notice("Processing... %s" % len(report_list))
    plot_html = '<div></div>'
    script = ''

    if summary_content is not None:
        plot_html += "<div>%s</div>\n" % summary_content

    if report_list:
        plot_html += report_list[0].report
    for report in report_list:
        script += report.script
        plot_html += "<div>%s</div>\n" % report.cross_section_info
        plot_html += "<table style='width:100%'>\n"
        plot_html += "<tr>\n"
        for plot in report.plots:
            if plot is not None:
                plot_html += "<td>%s</td>\n" % plot
        plot_html += "</tr>\n"
        plot_html += "</table>\n"
        plot_html += "<hr>\n"

    # Send to the web monitor as needed
    if run_number is None and report_list:
        run_number = report_list[0].data_info.run_number
    if publish:
        # Depending on where we run, we might get our publisher from
        # different places, or not at all.
        _publisher_found = False
        try:  # version on autoreduce
            from postprocessing.publish_plot import publish_plot
            _publisher_found = True
        except ImportError:  # version on instrument computers
            from finddata.publish_plot import publish_plot
            _publisher_found = True
        if _publisher_found:
            publish_plot("REF_M", run_number, files={'file': str(plot_html)})
        else:
            logger.error("Could not publish web report: %s" %
                         sys.exc_info()[1])

    return plot_html, script
plots = generate_plots(run_number, input)
info = ''
try:
    n_evts = input.getNumberEvents()
    seq_number = input.getRun()['sequence_number'].value[0]
    seq_total = input.getRun()['sequence_total'].value[0]
    info = "<div>Events: %s</div>\n" % n_evts
    info += "<div>Sequence: %s of %s</div>\n" % (seq_number, seq_total) 
except:
    info = "<div>Error: %s</div>\n" % sys.exc_value

plot_html = "<div>Live data</div>\n"
plot_html += info
plot_html += refl_info
plot_html += "<table style='width:100%'>\n"
plot_html += "<tr>\n"
for plot in plots:
    plot_html += "<td>%s</td>\n" % plot
plot_html += "</tr>\n"
plot_html += "</table>\n"
plot_html += "<hr>\n"

mantid.logger.information('Posting plot of run %s' % run_number)
try: # version on autoreduce
    from postprocessing.publish_plot import publish_plot
except ImportError: # version on instrument computers
    from finddata import publish_plot
request = publish_plot('REF_L', run_number, files={'file':plot_html})
mantid.logger.information("post returned %d" % request.status_code)

def publish_plots(run_number):
    from postprocessing.publish_plot import publish_plot
    plot_html_inst = '<div><img style="max-width:90%" src="/static/web_monitor/images/MANDI_{0}_IV.png" alt="Instrument view"></div>\n'.format(
        run_number)  # noqa: E501
    publish_plot("MANDI", run_number, files={'file': plot_html_inst})
plot_html += reduction_info
plot_html += "<table style='width:100%'>\n"
plot_html += "<tr>\n"
for plot in plots:
    plot_html += "<td>%s</td>\n" % plot
plot_html += "</tr>\n"
plot_html += "</table>\n"
plot_html += "<hr>\n"
plot_html += pol_info

if DEBUG:
    logfile.write("\nhtml ready\n")
    #logfile.write(plot_html)
try:
    mantid.logger.information('Posting plot of run %s' % run_number)
    try:  # version on autoreduce
        from postprocessing.publish_plot import publish_plot
    except ImportError:  # version on instrument computers
        from finddata import publish_plot
    request = publish_plot('REF_M', run_number, files={'file': plot_html})
except:
    exc_type, exc_value, exc_traceback = sys.exc_info()
    if DEBUG:
        logfile.write('\n' + exc_value + '\n')
        for line in traceback.format_exception(exc_type, exc_value,
                                               exc_traceback):
            logfile.write(line)
if DEBUG:
    logfile.write("DONE\n")
    logfile.close()
Beispiel #6
0
    ConvertUnits(InputWorkspace=wksp_name,
                 OutputWorkspace=wksp_name,
                 Target="dSpacing")

    # save a picture of the normalized ritveld data
    banklabels = [
        'bank 1 - 15 deg', 'bank 2 - 31 deg', 'bank 3 - 67 deg',
        'bank 4 - 122 deg', 'bank 5 - 154 deg', 'bank 6 - 7 deg'
    ]
    spectratoshow = [2, 3, 4, 5]

    saveplot1d_args = dict(InputWorkspace=wksp_name,
                           SpectraList=spectratoshow,
                           SpectraNames=banklabels)

    post_image = True
    if post_image:
        div = SavePlot1D(OutputType='plotly', **saveplot1d_args)
        from postprocessing.publish_plot import publish_plot
        request = publish_plot('NOM', samRun, files={'file': div})
        print("post returned %d" % request.status_code)
        print("resulting document:")
        print(request.text)
    else:
        filename = os.path.join(outputDir, wksp_name + '.html')
        SavePlot1D(OutputFilename=filename,
                   OutputType='plotly-full',
                   **saveplot1d_args)
        print('saved', filename)
datadict = datafile.to_dict()

table = '<div></div><p></p><table class="info display">'
row = '<tr><td>{}</td><td>{}</td></tr>'
table += row.format('Scan', '<b>{} - {}</b>'.format(datadict.get('metadata').get('scan', ''), datadict.get('metadata').get('scan_title', '')))
table += row.format('Experiment', '{} - {}'.format(datadict.get('metadata').get('experiment_number', ''), datadict.get('metadata').get('experiment', '')))
table += row.format('IPTS', datadict.get('metadata').get('proposal', ''))
table += row.format('Run start', datadict.get('metadata').get('date', '') + ' ' + datadict.get('metadata').get('time', ''))
table += row.format('Total counts', datadict.get('metadata').get('Sum of Counts', ''))
table += row.format('Command', datadict.get('metadata').get('command', ''))
table += '</table><p></p>'

try:
    runNumber = datafile.to_dict()['indexed']['run_number']
    request = publish_plot('HB2A', runNumber, files={'file': table+div})
except KeyError:
    print("This file doesn't have a run number")

################################################################################
# Create suammary csv

projection = ["location", "metadata.completed", "metadata.command", "metadata.scan_title", "indexed.scan_number", "metadata.samplename"]

datafiles = oncat.Datafile.list(
    facility="HFIR",
    instrument="HB2A",
    experiment=ipts,
    projection=projection
)
                        ClearRHSWorkspace=True)
        simpleapi.DeleteWorkspace(Workspace=vanback)
        simpleapi.CompressEvents(InputWorkspace=van, OutputWorkspace=van)


    simpleapi.ConvertUnits(InputWorkspace=van, OutputWorkspace=van,
                            Target='dSpacing', EMode='Elastic')
    simpleapi.StripVanadiumPeaks(InputWorkspace=van, OutputWorkspace=van,
                                  BackgroundType='Quadratic', PeakPositionTolerance=.05)
    smooth(van)


if van is not None:
    simpleapi.Divide(LHSWorkspace=output, RHSWorkspace=van, OutputWorkspace=output)

##### generate plot and post
div = simpleapi.SavePlot1D(InputWorkspace=output, OutputType='plotly')
runNumber = simpleapi.mtd[output].getRunNumber()
if runNumber > 0:  # it is 0 between runs
    mantid.logger.information('Posting plot of PG3_%s' % runNumber)
    try: # version on autoreduce
        from postprocessing.publish_plot import publish_plot
    except ImportError: # version on instrument computers
        from finddata import publish_plot
    request = publish_plot('PG3', runNumber, files={'file':div})
    mantid.logger.information("post returned %d" % request.status_code)
    mantid.logger.information("resulting document:")
    mantid.logger.information(str(request.text))
else:
    mantid.logger.information('Not posting becuase run number is not greater than zero: %s' % runNumber)
Beispiel #9
0
oncat = pyoncat.ONCat(
    'https://oncat.ornl.gov',
    client_id=CLIENT_ID,
    client_secret=CLIENT_SECRET,
    token_getter=token_store.get_token,
    token_setter=token_store.set_token,
    flow=pyoncat.RESOURCE_OWNER_CREDENTIALS_FLOW
)

if token_store.get_token() is None:
    username = getpass.getuser()
    password = getpass.getpass()
    oncat.login(username, password)

filename = sys.argv[1]
ipts = filename.split('/')[3]

datafile = oncat.Datafile.retrieve(
    filename,
    facility="HFIR",
    instrument="HB2A",
    experiment=ipts,
    projection=["indexed.run_number"],
)

try:
    runNumber = datafile.to_dict()['indexed']['run_number']
    request = publish_plot('HB2A', runNumber, files={'file': div}, config='/SNS/users/rwp/post_processing.conf')
except KeyError:
    print("This file doesn't have a run number")
Beispiel #10
0
    # do some plots
    fig = plt.gcf()
    numfig = len(config.plots)
    fig.set_size_inches(5.0, 5.0 * (numfig + 1))
    for i in range(numfig):
        plt.subplot(numfig + 1, 1, i + 2)
        if config.useCC == "True" and CCsucceded:
            makePlot(mdcc, config.plots[i], config.can_do_norm)
        else:
            makePlot(mdraw, config.plots[i], config.can_do_norm)
    plt.subplot(numfig + 1, 1, 1)
    raw = Rebin(raw, str(kmin) + ',' + str(kmax - kmin) + ',' + str(kmax))
    makeInstrumentView(raw)

    figfile = BytesIO()
    plt.savefig(figfile, bbox_inches='tight')
    plt.close()

    figfile.seek(0)
    figdata_png = base64.b64encode(figfile.getvalue())
    try:
        figdata_png = figdata_png.decode()
    except:
        pass
    div = '<div><img alt="{}" src="data:image/png;base64,{}" /></div>'.format(
        output_file, figdata_png)
    with open("div.txt", "w") as f:
        f.write(div)
    request = publish_plot('CORELLI', runNumber, files={'file': div})
    print(request)
Beispiel #11
0
    CharacterizationRunsFile=char_file,
    LowResRef=0,
    RemovePromptPulseWidth=50,
    Binning=-0.0008,
    BinInDspace=True,
    BackgroundSmoothParams="5,2",
    FilterBadPulses=10,
    ScaleData=100,
    SaveAs="gsas topas and fullprof",
    OutputDirectory=outputDir,
    FinalDataUnits="dSpacing",
)

GeneratePythonScript(InputWorkspace="PG3_" + runNumber, Filename=os.path.join(outputDir, "PG3_" + runNumber + ".py"))
ConvertUnits(InputWorkspace="PG3_" + runNumber, OutputWorkspace="PG3_" + runNumber, Target="dSpacing", EMode="Elastic")

# interactive plots
post_image = True
if post_image:
    div = SavePlot1D(InputWorkspace="PG3_" + runNumber, OutputType="plotly")
    from postprocessing.publish_plot import publish_plot

    request = publish_plot("PG3", runNumber, files={"file": div})
    print "post returned %d" % request.status_code
    print "resulting document:"
    print request.text
else:
    filename = os.path.join(outputDir, "PG3_%s.html" % runNumber)
    SavePlot1D(InputWorkspace="PG3_" + runNumber, OutputType="plotly-full", OutputFilename=filename)
    print "saved", filename
Beispiel #12
0
if powder:

    from mantid.simpleapi import LoadWAND, WANDPowderReduction, SavePlot1D, SaveFocusedXYE, Scale

    data = LoadWAND(filename, Grouping='4x4')
    runNumber = data.getRunNumber()
    cal = get_vanadium(runNumber)
    WANDPowderReduction(InputWorkspace=data,
                        CalibrationWorkspace=cal,
                        Target='Theta',
                        NumberBins=1200,
                        OutputWorkspace='reduced')
    Scale(InputWorkspace='reduced',OutputWorkspace='reduced',Factor=100)
    SaveFocusedXYE('reduced', Filename=os.path.join(outdir, output_file+'.xye'), SplitFiles=False, IncludeHeader=False)
    div = SavePlot1D('reduced', OutputType='plotly')
    request = publish_plot('HB2C', runNumber, files={'file': div})

else:  # Single Crystal

    with h5py.File(filename, 'r') as f:
        offset = decode(f['/entry/DASlogs/HB2C:Mot:s2.RBV/average_value'].value[0])
        title = decode(f['/entry/title'].value[0])
        mon = decode(f['/entry/monitor1/total_counts'].value[0])
        duration = decode(f['/entry/duration'].value[0])
        run_number = decode(f['/entry/run_number'].value[0])
        bc = np.zeros((512*480*8))
        for b in range(8):
            bc += np.bincount(f['/entry/bank'+str(b+1)+'_events/event_id'].value,
                              minlength=512*480*8)
        bc = bc.reshape((480*8, 512))
        bc = (bc[::4, ::4] + bc[1::4, ::4] + bc[2::4, ::4] + bc[3::4, ::4]