2. Main Function Operation and Use

Created on Aug 4, 2015

@author: amcmahon

Main.main()[source]

Main function for generating CSV files from a directory of Unispec data.

Input/Output paths, white plate identifier string and header size should be specified in “config.txt”.

Outputs one CSV file per tram run, where each row represets a stop and columns are wavelengths interpolated to 1nm.

2.1. Operation

This main function reads in the configuration options, sets up some lists to pass information between functions and iterates through each run as a group.

First, the object Spec is created from the UnispecProcessing class. The Init function for the class also opens the config file specified and loads the values into class level variables.

>path = str(os.path.realpath('.'))
>Spec = UnispecProcessing(path + r'\config.txt')

Then, file lists for runs, white plates and stops are generated. These lists are also stored within the class.

>run_count, WP_count, stop_count = Spec.GetFileLists()

For each run (as determined by the poisitions of white plates between stops in chronological order), arrays are created for the “raw” imported data and saturation counts.

>for run in range(0,run_count):
>
    >       #There must be at least one white plate and one stop for a run to produce any useful data, otherwise skip it.
>    if (WP_count[run] == 0) or (stop_count[run] == 0):
>        continue
>
>    WP_data = [[[None], [None]] for item in range(0,WP_count[run])]
>    Stop_data = [[[None], [None]] for item in range(0,stop_count[run])]
>    sat = [[None], [None]]

These arrays are populated by ReadFiles() with the white plates and stops as two seperate groups.

>    WP_data = Spec.ReadFiles(Spec.WPs[run], Spec.HeaderLines)
>    Stop_data = Spec.ReadFiles(Spec.Stops[run], Spec.HeaderLines)

Next, both data sets are checked for saturated values and a count of these are returned. These counts could be used as a condition for whether or not to keep data from a specific stop/run.

>    sat_WP = Spec.CheckSaturation(WP_data)
>    sat_stops = Spec.CheckSaturation(Stop_data)

The counts for each white plate/stop are also printed as a diagnostic.

>    print("Saturated Measurement Count\n\t\tCh_B\tCh_A")
>    for idx, curfile in enumerate(sat_WP):
>        print("WP " + str(idx) + ":\t\t" + str(curfile[1]) + "\t" + str(curfile[2]))
>    for idx, curfile in enumerate(sat_stops):
>        print("Stop " + str(idx) + ":\t\t" + str(curfile[1]) + "\t" + str(curfile[2]))
>    print("\n" + str(len(sat_WP)) + " WPs and " + str(len(sat_stops)) + " stops saturated.")

Optionally, saturated stops are removed.

>    #Spec.RemoveSaturated(WP_data, sat_WP)
>    #Spec.RemoveSaturated(Stop_data, sat_stops)

The “raw” data is then interpolated to 1 1nm.

>    intdata_WPs = Spec.Interp(WP_data)
>    intdata_Stops = Spec.Interp(Stop_data)

All of the white plate values are averaged to a single data set.

>    avg_WP = Spec.AvgWPs(intdata_WPs)

Optionally, the white plate average can be plotted against all of the individual measurments as a diagnostic.

>    #Plot all WPs with average
>    #Spec.plot_Averaging(intdata_WPs, avg_WP)

Next, the reflectance values are calculated.

>    R = Spec.Refl(intdata_Stops, avg_WP)

These can also be plotted for a particular stop as a diasgnostic.

>    #Spec.plot_R(R,20)

Finally, the CSV output is generated. The date and tiem from the first white plate of a given run are used in the filename as a reference.

>    dt = Spec.GetDateTime(WP_data[0])
>    Spec.WriteOutput(R, "c:\\UniSpec\\Test", "test_R_" + dt[consts.date] + "__" + dt[consts.time].replace(':','_') + ".csv")

2.2. Configuration File

The configuration file is seperated into an Input and an Output section to help organize parameters, especially as future options are potentially added.

[Input]
SourcePath = C:\Users\amcmahon\Documents\TEST\UnispecScripts\TestData\2015
WP_Identifier = 000
HeaderLines = 10

[Output]
OutputPath = C:\\UniSpec\\Test