Пример #1
0
def test(testsdir, verbose = False):
    idir = os.path.join(testsdir, "input")
    statuses = []
    testcount = 0

    testcount = testcount + 1    
    fs = sorted(os.listdir(idir))
    fps = [os.path.join(idir, f) for f in fs]
    ins = [SdalReader().read_spectrum(f) for f in fps]
    reqdet = [False]*len(ins)
    reqdet[0] = True
    reqdet[12:15] = [True, True, True]
    refdet = ReferenceDetector(context = "gveg")
    det = [refdet.is_reference(s) for s in ins]
    statuses.append(reqdet == det)
    if not all(statuses):
        print("Failed TEST {}".format(testcount))
    
    #status message
    if all(statuses):
        print("{}: PASSED".format(__file__))
    else:
        print("{}: FAILED".format(__file__))
Пример #2
0
def test(testsdir, verbose=False):
    idir = os.path.join(testsdir, "input")
    statuses = []
    testcount = 0

    testcount = testcount + 1
    fs = sorted(os.listdir(idir))
    fps = [os.path.join(idir, f) for f in fs]
    ins = [SdalReader().read_spectrum(f) for f in fps]
    reqdet = [False] * len(ins)
    reqdet[0] = True
    reqdet[12:15] = [True, True, True]
    refdet = ReferenceDetector(context="gveg")
    det = [refdet.is_reference(s) for s in ins]
    statuses.append(reqdet == det)
    if not all(statuses):
        print("Failed TEST {}".format(testcount))

    #status message
    if all(statuses):
        print("{}: PASSED".format(__file__))
    else:
        print("{}: FAILED".format(__file__))
Пример #3
0
def process(params):
#    params.print_params()
    #get the project params and verify
    project = params.get_params("project")
    if project:
        verify_project(project)
    else:
        print("--project is required")
        sys.exit(0)
    #get the resampling params
    resampling = params.get_params("resampling")
    #get the jumpcorrection params and verify
    jumpcorrection = params.get_params("jumpcorrection")
    if jumpcorrection:
        verify_jumpcorrection(jumpcorrection)
    
    #get the groupings and verify them
    groupings = {grp:params.get_params(grp) for grp in params.get_groups()}
    verify_groupings(params.default_group, params.get_groups(), groupings)

    tags = ["raw", params.default_group]
    specs = defaultdict(list)
    #specs["raw"] created
    #get the filenames
    allfiles = os.listdir(project["indir"])
    extfiles = []
    for f in allfiles:
        ext = get_directory_filename_extension(f)[2]
        if ext == project["fileext"]:
            extfiles.append(os.path.join(project["indir"], f))
    #read the raw spectrums
    uniquifier = WaveUniquifier()
    rawspecs = [SdalReader().read_spectrum(f) for f in extfiles]
    uniqspecs = [uniquifier.uniquify(s) for s in rawspecs]
    specs["raw"] = uniqspecs
    
    #specs["preproc"] created
    #do the pre-processing
    prepspecs = specs["raw"]
    if resampling:
        resampler = WaveResampler(rstype = resampling["type"],
                                  wavestart = resampling["range"][0],
                                  wavestop = resampling["range"][1],
                                  spacing = resampling["spacing"])
        rsspecs = [resampler.resample(s) for s in prepspecs]
        prepspecs = rsspecs
    if jumpcorrection:
        corrector = JumpCorrector(jumpcorrection["wavelengths"],
                                  jumpcorrection["stablezone"])
        jcspecs = [corrector.correct(s) for s in prepspecs]
        prepspecs = jcspecs
    #detect the references
    refdet = ReferenceDetector(context = "gveg")
    nonrefs = []
    refs = []
    for s in prepspecs:
        if refdet.is_reference(s):
            refs.append(s)
        else:
            nonrefs.append(s)
    specs[params.default_group] = nonrefs
    
    #specs[group_tag] created
    #do the grouping 
    for t in groupings:
        tags.append(t)
        itag = groupings[t]["intag"]
        patt = groupings[t]["pattern"]
        regex = SpectrumRegex()
        tgrps = regex.make_groups(specs[itag], patt)
        for tg in tgrps:
            sg = SpectrumGroup(spectrums = tgrps[tg])
            ms = sg.mean_spectrum()
            ms.idstr = tg
            specs[t].append(ms)

#    subsets = {grp:params.get_params(grp) for grp in params.get_subsets()}
#    print(subsets)
#    for t in subsets:
#        itag = subsets[t]["intag"]
#        otag = subsets[t]["outtag"]
#        wavestart = subsets[t]["range"][0]
#        wavestop = subsets[t]["range"][1]
#        for s in specs[itag]:
#            subspec = s.wavelength_subset(wavestart, wavestop)
#            subspec.idstr = subspec.idstr + otag
#            print("idstr = {}".format(subspec.idstr))
#            specs[otag].append(subspec)
                           
    #create outputs
    prjdir = os.path.join(project["outdir"], project["name"])
    os.mkdir(prjdir)
    for t in specs:
        tdir = os.path.join(prjdir, t)
        os.mkdir(tdir)
        tgrpfn = "___{}___.csv".format(t)                       
        for s in specs[t]:
            s.write_csv(odir = tdir)
        sg = SpectrumGroup(spectrums = specs[t])
        sg.write_csv(tdir, tgrpfn)