Exemple #1
0
def reduceSANS(sampleSANS,
               sampleTRANS=None,
               canSANS=None,
               canTRANS=None,
               EBTRANS=None,
               maskfile=None,
               inst=inst,
               cycle=cycle,
               wavs=wavs,
               outputdir=''):
    # This is the function that runs everything using the sans instrument command interface
    # by default the reduction will just reduce the sample sans with no transmission.
    setupReduction(sampleSANS,
                   sampleTRANS=sampleTRANS,
                   canSANS=canSANS,
                   canTRANS=canTRANS,
                   EBTRANS=EBTRANS,
                   maskfile=maskfile,
                   inst=inst,
                   cycle=cycle)

    wkspnames = []
    # Perform the full reduction listed in the userfile
    wksp1d = ici.WavRangeReduction(None, None, ici.DefaultTrans)
    SaveNXcanSAS(wksp1d, os.path.join(outputdir, wksp1d + '_autoreduced.h5'))
    SaveRKH(wksp1d, os.path.join(outputdir, wksp1d + '_autoreduced.dat'))
    wkspnames.append(wksp1d)

    # the order of 2d then everything else is importand for the multiplot to work
    # perform the full 2d reduction in the user file
    ici.Set2D()
    #ici.WavRangeReduction(None, None, ici.DefaultTrans)
    wksp2d = ici.WavRangeReduction(None, None, ici.DefaultTrans)
    #SaveNexus(mtd["{}rear_2D_0.1_12.0".format(run)],join(base_dir,"{}_2D.nxs".format(run)))
    SaveNXcanSAS(wksp2d, os.path.join(outputdir, wksp2d + '_autoreduced.h5'))

    # Set up the figure for the 6 plots combined
    fig, axes = plt.subplots(2,
                             3,
                             figsize=[12.0, 8.0],
                             num='Multiplot',
                             subplot_kw={'projection': 'mantid'})
    # change the fontsize for the legends
    plt.rcParams['legend.fontsize'] = 'x-small'
    # plot the 2d data seperately
    plot2Ddata(wksp2d, outputdir=outputdir, fig=fig, axes=axes[0, 2])

    # check that the transmission workspaces exist and plot.
    transwksps = []
    if mtd.doesExist(wksp1d.replace("rear_1D", "trans_Sample")):
        transwksps.append(wksp1d.replace("rear_1D", "trans_Sample"))
    if mtd.doesExist(wksp1d.replace("rear_1D", "trans_Can")):
        transwksps.append(wksp1d.replace("rear_1D", "trans_Can"))
    if mtd.doesExist(wksp1d.replace("rear_1D", "trans_Sample_unfitted")):
        transwksps.append(wksp1d.replace("rear_1D", "trans_Sample_unfitted"))
    if mtd.doesExist(wksp1d.replace("rear_1D", "trans_Can_unfitted")):
        transwksps.append(wksp1d.replace("rear_1D", "trans_Can_unfitted"))
    if len(transwksps) > 0:
        plotTransmissions(transwksps, fig=fig, axes=axes[0, 0])
    else:
        plotTransmissions(transwksps,
                          'No Transmission Data Found',
                          fig=fig,
                          axes=axes[0, 0])

    # Now perform the overlap reduction with different wavelength ranges
    ici.Set1D()
    for i in range(len(wavs) - 1):
        wksp1d = ici.WavRangeReduction(wavs[i], wavs[i + 1], False)
        wkspnames.append(wksp1d)
    #SaveNexus(mtd["{}rear_1D_0.9_12.5".format(run)],join(base_dir,"{}_1D.nxs".format(run)))

    plot1Ddata(wkspnames,
               fig=fig,
               axes1=axes[1, 2],
               axes2=axes[1, 0],
               axes3=axes[0, 1])

    # reset everything for the sector reduction
    wkspnames = []
    setupReduction(sampleSANS,
                   sampleTRANS=sampleTRANS,
                   canSANS=canSANS,
                   canTRANS=canTRANS,
                   EBTRANS=EBTRANS,
                   maskfile=maskfile,
                   inst=inst,
                   cycle=cycle)
    # perform reduction of 4 sectors to check for anisotropy
    ici.SetPhiLimit(0.0, 180.0, use_mirror=False)
    wksp1d = ici.WavRangeReduction(None, None, ici.DefaultTrans)
    RenameWorkspace(wksp1d, wksp1d + '_top')
    wkspnames.append(wksp1d + '_top')
    ici.SetPhiLimit(180.0, 360.0, use_mirror=False)
    wksp1d = ici.WavRangeReduction(None, None, ici.DefaultTrans)
    RenameWorkspace(wksp1d, wksp1d + '_bottom')
    wkspnames.append(wksp1d + '_bottom')
    ici.SetPhiLimit(90.0, 270.0, use_mirror=False)
    wksp1d = ici.WavRangeReduction(None, None, ici.DefaultTrans)
    RenameWorkspace(wksp1d, wksp1d + '_left')
    wkspnames.append(wksp1d + '_left')
    ici.SetPhiLimit(-90.0, 90.0, use_mirror=False)
    wksp1d = ici.WavRangeReduction(None, None, ici.DefaultTrans)
    RenameWorkspace(wksp1d, wksp1d + '_right')
    wkspnames.append(wksp1d + '_right')
    plot1Dsectors(wkspnames, fig=fig, axes=axes[1, 1])

    fig.tight_layout()  #pad=0.4, w_pad=0.5, h_pad=1.0)

    if os.path.exists(outputdir):
        print(outputdir)
        print(os.path.join(outputdir, inst + '{:08d}.png'.format(sampleSANS)))
        fig.savefig(
            os.path.join(outputdir, inst + '{:08d}.png'.format(sampleSANS)))
Exemple #2
0
def analyse(data_table,
            masks,
            output_file,
            show_fits=False,
            show_quality=False):
    """

    Analyse a set of combined Sans and Semsans measurements.
    The result will be a set of workspaces with the Semsans data
    and a csv file that can be loaded into the batch sans interface
    to load the sans data.

    Parameters
    ----------
    data_table
      The name of WorkspaceTable with the runs that need to be analysed.  This
      table should be generated by the get_log function.
    masks
      A list of strings containing the filenames of the masks for the
      individual tubes used in the semsans polarisation calculation
    output_file
      Where to save the CSV file that will generate the SANS runs
    show_fits
      Whether to show the individual tube fits used to calculate the spin echo
      length.  Defaults to False
    show_quality
      Whether to show the quality of the linear fit of the precession
      frequencies used to calculate the spin echo length.  Defaults to False

    """
    if "Full_Blank" not in mtd.getObjectNames():
        int3samples(table_to_run(mtd["metadata_Full_Blank_runs"]),
                    "Full_Blank", masks)
    const = sel_const(
        [mtd["Full_Blank_{}".format(tube)] for tube, _ in enumerate(masks)],
        show_fits=show_fits,
        show_quality=show_quality)

    k = data_table[9:-5]
    runs = table_to_run(mtd[data_table])
    for run in runs:
        get_shimed(run.number, dirname(output_file))
        get_shimed(run.trans, dirname(output_file))
        get_shimed(run.csans, dirname(output_file))
        get_shimed(run.ctrans, dirname(output_file))
        get_shimed(run.direct, dirname(output_file))
        semsans_ws = "{}_hours_{:0.02f}".format(
            k, (run.start - runs[0].start).seconds / 3600.0)
        int3samples([run], semsans_ws, masks)
        # DeleteWorkspace("{}_sans_nxs".format(run.number))
        norm(semsans_ws, "Full_Blank", masks)
        sel(semsans_ws + "_norm", const)
        DeleteWorkspaces([semsans_ws, semsans_ws + "_Norm"])
    with open(output_file, "w") as outfile:
        framework = "sample_sans,{}-add," \
                    "sample_trans,{}-add," \
                    "sample_direct_beam,{}-add,"\
                    "can_sans,{}-add,"\
                    "can_trans,{}-add,"\
                    "can_direct_beam,{}-add,"\
                    "output_as,{}_hours_{:0.2f}\n"
        for idx, run in enumerate(runs):
            outfile.write(
                framework.format(run.number, run.trans, run.direct, run.csans,
                                 run.ctrans, run.direct, k,
                                 (run.start - runs[0].start).seconds / 3600.0))

    import sans.command_interface.ISISCommandInterface as ici
    ici.Clean()
    ici.LARMOR()
    ici.MaskFile(
        r"\\isis\inst$\NDXLARMOR\User\Users\Masks\USER_Edler_171B_a2_8mm_SEMSANS_r20287.txt"
    )
    ici.BatchReduce(output_file, format=".nxs", verbose=True)
Exemple #3
0
def setupReduction(sampleSANS,
                   sampleTRANS=None,
                   canSANS=None,
                   canTRANS=None,
                   EBTRANS=None,
                   maskfile=None,
                   inst=inst,
                   cycle=cycle):
    # Helper to setup the reduction so that it can be reset for the sector plots easily.
    # set the search path folders needed.
    setDataSearchPath()
    # initial 1d reduction
    ici.Clean()
    ici.UseCompatibilityMode()
    if inst == "LARMOR":
        ici.LARMOR()
    else:
        ici.LARMOR()

    ici.Set1D()

    if platform == "linux" or platform == "linux2":
        prefix = "/archive"
    else:
        prefix = "//isis/inst$"

    if len(maskfile) > 0:
        #ici.MaskFile("/mnt/ceph/auxiliary/sans/Larmor/Masks/"+maskfile)
        ici.MaskFile(prefix + "/NDX" + inst + "/User/Users/Masks/" + maskfile)
    else:
        print('No Mask File Defined')
        return
    # assign the sample SANS run
    ici.AssignSample(prefix + "/NDX" + inst + "/Instrument/data/cycle_" +
                     cycle + "/" + inst + "{:08d}.nxs".format(sampleSANS))

    titleoption = 0
    # if a can has been specified assign it
    if canSANS is not None:
        ici.AssignCan(prefix + "/NDX" + inst + "/Instrument/data/cycle_" +
                      cycle + "/" + inst + "{:08d}.nxs".format(canSANS))
        titleoption += 1

    # if a sample TRANS has been specified check that the empty beam has too and assign
    if sampleTRANS is not None and EBTRANS is not None:
        TRsam = prefix + "/NDX" + inst + "/Instrument/data/cycle_" + cycle + "/" + inst + "{:08d}.nxs".format(
            sampleTRANS)
        TREB = prefix + "/NDX" + inst + "/Instrument/data/cycle_" + cycle + "/" + inst + "{:08d}.nxs".format(
            EBTRANS)
        print(TRsam)
        print(TREB)
        ici.TransmissionSample(TRsam, TREB)
        titleoption += 1

    # if a can TRANS has been specified check that the empty beam has too and assign
    if canTRANS is not None and EBTRANS is not None:
        TRcan = prefix + "/NDX" + inst + "/Instrument/data/cycle_" + cycle + "/" + inst + "{:08d}.nxs".format(
            canTRANS)
        TREB = prefix + "/NDX" + inst + "/Instrument/data/cycle_" + cycle + "/" + inst + "{:08d}.nxs".format(
            EBTRANS)
        print(TRcan)
        print(TREB)
        ici.TransmissionCan(TRcan, TREB)
        titleoption += 1

    if titleoption == 0:
        titlewarning = ''
    elif titleoption == 1:
        titlewarning = ''
    elif titleoption == 2:
        titlewarning = ''
    elif titleoption == 3:
        titlewarning = ''

    return titlewarning