def main():
    print('Running!')
    # Read in arguments from the command line
    args = parser.parse_args()
    # File to be plotted
    input_path = args.file_path
    path, file = os.path.split(input_path)
    # Folder to which the graph should be saved
    if args.output_directory == ' ':
        output_directory = path
    else:
        output_directory = args.output_directory

    # Assign variable with inputs from the command line
    name = args.name
    plot_type = args.plot_type
    plot_th = input_boolean(args.plot_temp_and_hum)
    plot_fit = input_boolean(args.plot_fits)
    average = args.choose_average
    remove = args.remove_anomalous

    # Extract the data
    data = Data()
    data.name = name
    data.type = plot_type
    data.extract_data(input_path, average)

    if remove is not None:
        for i in range(len(remove)):
            data.remove_anomalies(i)

    # Plot the graph
    plot = Plot()
    plot.plot_graph(output_directory, plot_th, plot_fit, data)
Exemple #2
0
 def plot_graph(self, output_folder, th, fits, data=Data()):
     # Create the axes
     self.add_axes(th=th)
     # Plot the data
     if data.type == 'it':
         self.plot_it(th, fits, data)
     elif data.type == 'cv':
         self.plot_cv(th, fits, data)
     elif data.type == 'iv':
         self.plot_iv(th, fits, data)
     # Save the graph
     self.save_graph(output_folder, data)
def main():
    print('amw_2')
    args = parser.parse_args()

    input_directory = args.file_directory

    if args.output_directory == ' ':
        output_directory = args.file_directory
    else:
        output_directory = args.output_directory

    plot_iv = input_boolean(args.plot_iv)
    plot_cv = input_boolean(args.plot_cv)
    plot_it = input_boolean(args.plot_it)
    plot_ivth = input_boolean(args.plot_ivth)
    plot_cvth = input_boolean(args.plot_cvth)
    plot_itth = input_boolean(args.plot_itth)
    plot_ivf = input_boolean(args.plot_ivf)
    plot_cvf = input_boolean(args.plot_cvf)
    plot_itf = input_boolean(args.plot_itf)
    #plot_ivg = input_boolean(args.plot_ivg)
    #plot_cvg = input_boolean(args.plot_cvg)
    #plot_itg = input_boolean(args.plot_itg)
    average_type = args.choose_mean

    print(input_directory)
    print(output_directory)
    print(plot_cv)
    print(plot_iv)
    print(plot_it)
    print(plot_itth)
    print(plot_ivth)
    print(plot_cvth)
    print(plot_itf)
    print(plot_ivf)
    print(plot_cvf)
    print(average_type)

    files = []
    #print(os.listdir(input_directory))
    folder = os.listdir(input_directory)
    """
    for Input in args.file_directory:
        print("\tInput, ", Input)
        OSInputs = sorted(glob.glob(Input+'/*.txt'))
        print(OSInputs)
        for OSInput in OSInputs:
            if os.path.isfile(OSInput) and OSInput.endswith('.txt') and 'short' not in OSInput:
                files.append(OSInput)
                print("\t\t" + OSInput)
    """
    for filename in folder:
        if os.path.isfile(os.path.join(input_directory,
                                       filename)) and filename.endswith(
                                           '.txt') and 'short' not in filename:
            files.append(os.path.join(input_directory, filename))
        else:
            continue

    file_data = {}
    #print(files)

    for i in range(len(files)):
        data = Data()
        data.extract_data(files[i], average_type)
        file_data[files[i]] = data
    """
    for f in file_data.values():
        print(f.v_mean)
        continue
    """

    iv_data = {}
    cv_data = {}
    it_data = {}
    for f1, f2 in file_data.items():
        if f2.type == 'iv':
            iv_data[f1] = f2
        elif f2.type == 'cv':
            cv_data[f1] = f2
        elif f2.type == 'it':
            it_data[f1] = f2

    if plot_iv:
        #print('plotting iv')
        for f1, f2 in iv_data.items():
            graph = Plot()
            graph.plot_graph(output_directory, plot_ivth, plot_ivf, f2)
    if plot_cv:
        for f1, f2 in cv_data.items():
            graph = Plot()
            graph.plot_graph(output_directory, plot_cvth, plot_cvf, f2)
    if plot_it:
        #print('plotting it')
        for f1, f2 in it_data.items():
            graph = Plot()
            graph.plot_graph(output_directory, plot_itth, plot_itf, f2)
Exemple #4
0
    def plot_it(self, th, fits, it=Data()):
        # Converts time from seconds to hours
        it.time_to_hours()
        """
        # A very rough method of trying to ignore anomalous points in the It data
        mean_current= sum(it.i_mean)/len(it.i_mean)
        mean_error = stats.tstd(it.i_mean)
        main_data_i = []
        main_data_t = []
        main_data_ierror =[]
        bad_data_i = []
        bad_data_t = []
        bad_data_ierror = []
        for i in range(len(it.i_mean)):
            if mean_current+(3 * mean_error) > it.i_mean[i] > mean_current - (3* mean_error):
                main_data_t.append(it.time[i])
                main_data_i.append(it.i_mean[i])
                main_data_ierror.append(it.i_error[i])
            else:
                bad_data_t.append(it.time[i])
                bad_data_i.append(it.i_mean[i])
                bad_data_ierror.append(it.i_error[i])
                
        current_line = self.fig.host.errorbar(x=main_data_t, y=main_data_i, yerr=main_data_ierror, fmt='r.',
                                              label='Current')
        current_line2 = self.fig.host.errorbar(x=bad_data_t, y=bad_data_i, yerr=bad_data_ierror, fmt='r.', alpha=0.5,
                                               label='Current')
        """

        # Plot the current data
        current_line = self.fig.host.errorbar(x=it.time,
                                              y=it.i_mean,
                                              yerr=it.i_error,
                                              fmt='r.',
                                              label='Current')
        # Set y axis range
        self.fig.host.set_ylim([min(it.i_mean) * 1.1, 0])
        # Label axis
        self.fig.host.set_xlabel("Time (hours)")
        self.fig.host.set_ylabel("Current ($\mu$A)")
        # List of all the lines
        lines = [current_line]
        # Line ticks
        tkw = dict(size=4, width=1.5)
        self.fig.host.tick_params(axis='x', **tkw)
        # If plotting temperature and humidity lines:
        if th:
            # Overall average temperature and humidity
            temp_averages = it.average_temp()
            hum_averages = it.average_hum()
            # Plot temperature and humidity lines
            temp_line, = self.fig.temp.plot(
                it.time,
                it.get_temperature(),
                color='b',
                alpha=0.4,
                label='Temperature, $T_{Av}$ = %s$^\circ$C' % temp_averages[0])
            hum_line, = self.fig.hum.plot(it.time,
                                          it.get_humidity(),
                                          color='g',
                                          alpha=0.4,
                                          label='Humidity, $H_{Av}$ = %s%%' %
                                          hum_averages[0])
            # Colour axis
            self.fig.temp.yaxis.label.set_color(temp_line.get_color())
            self.fig.hum.yaxis.label.set_color(hum_line.get_color())
            # Uncomment if you want to set the temperature and humidity axis range
            #self.fig.hum.set_ylim([30, 50])
            #self.fig.temp.set_ylim([18, 22])
            # Labels and tick sizes
            self.fig.temp.set_ylabel('Temperature ($^\circ$C)')
            self.fig.hum.set_ylabel('Humidity (%)')
            self.fig.temp.tick_params(axis='y',
                                      colors=temp_line.get_color(),
                                      **tkw)
            self.fig.hum.tick_params(axis='y',
                                     colors=hum_line.get_color(),
                                     **tkw)
            # Add to list of plotted lines
            lines.append(temp_line)
            lines.append(hum_line)
        # If testing the stability of the current
        if fits:
            fitting_data = Fitting.it_fits(it)
            maximum_line = self.fig.host.axhline(
                y=fitting_data[0],
                color='r',
                label='$I_{max}$ = %s$\mu$A' %
                Fitting.round_sig(fitting_data[0], 2))
            allowed_line = self.fig.host.axhline(
                y=fitting_data[2],
                color='k',
                label='Allowed $I_{min}$ = %s$\mu$A, Result: %s' %
                (Fitting.round_sig(fitting_data[2], 2), fitting_data[3]))
            minimum_line = self.fig.host.axhline(
                y=fitting_data[1],
                color='r',
                alpha=0.6,
                label='$I_{min}$ = %s$\mu$A' %
                Fitting.round_sig(fitting_data[1], 2))
            # Add to list of plotted lines
            lines.append(minimum_line)
            lines.append(maximum_line)
            lines.append(allowed_line)

        # Create legend and title
        self.fig.host.legend(lines, [l.get_label() for l in lines])
        self.fig.suptitle(it.name)
Exemple #5
0
 def plot_cv(self, th, fits, cv=Data()):
     #print('amw_3')
     # Plot capacitance data
     capacitance_line = self.fig.host.errorbar(
         x=cv.v_mean,
         y=cv.inverse_c_squared,
         yerr=cv.inverse_c_squared_error,
         fmt='r.',
         label='Capacitance')
     # Label axis
     self.fig.host.set_xlabel("Voltage (V)")
     self.fig.host.set_ylabel("$1/C^2$ ($1/pF^2$)")
     # List of plotted lines
     lines = [capacitance_line]
     # Tick size and y axis limit
     tkw = dict(size=4, width=1.5)
     self.fig.host.tick_params(axis='x', **tkw)
     self.fig.host.set_ylim([0, max(cv.inverse_c_squared) * 1.1])
     # If plotting temperature and humidity:
     if th:
         # Overall average temperature and humidity
         temp_averages = cv.average_temp()
         hum_averages = cv.average_hum()
         # Plot temperature and humidity
         temp_line, = self.fig.temp.plot(
             cv.v_mean,
             cv.temperature,
             color='b',
             alpha=0.4,
             label='Temperature, $T_{Av}$ = %s$^\circ$C' % temp_averages[0])
         hum_line, = self.fig.hum.plot(cv.v_mean,
                                       cv.humidity,
                                       color='g',
                                       alpha=0.4,
                                       label='Humidity, $H_{Av}$ = %s%%' %
                                       hum_averages[0])
         # Colour axis
         self.fig.temp.yaxis.label.set_color(temp_line.get_color())
         self.fig.hum.yaxis.label.set_color(hum_line.get_color())
         # Uncomment to constrain axis range
         #self.fig.hum.set_ylim([30, 50])
         #self.fig.temp.set_ylim([18, 22])
         # Label axis and tick parameters
         self.fig.temp.set_ylabel('Temperature ($^\circ$C)')
         self.fig.hum.set_ylabel('Humidity (%)')
         self.fig.temp.tick_params(axis='y',
                                   colors=temp_line.get_color(),
                                   **tkw)
         self.fig.hum.tick_params(axis='y',
                                  colors=hum_line.get_color(),
                                  **tkw)
         # Add to list of lines
         lines.append(temp_line)
         lines.append(hum_line)
     # if finding the depletion voltage
     if fits:
         # Get data
         fit_data = Fitting.cv_fits(cv)
         # Plot two linear lines
         self.fig.host.plot(cv.v_mean, fit_data[0], 'r')
         self.fig.host.plot(cv.v_mean, fit_data[1], 'r')
         # Plot line at full depletion
         full_depletion = self.fig.host.axvline(
             x=fit_data[2],
             linestyle='--',
             color='r',
             label='$V_{Full \: Depletion}$ = %s $\pm$ %sV' %
             (fit_data[2], fit_data[3]))
         # Add to list of lines
         lines.append(full_depletion)
     # Create legend and title
     self.fig.host.legend(lines, [l.get_label() for l in lines])
     self.fig.suptitle(cv.name)
Exemple #6
0
 def plot_iv(self, th, fits, iv=Data()):
     # Plot the current data
     current_line = self.fig.host.errorbar(x=iv.v_mean,
                                           y=iv.i_mean,
                                           yerr=iv.i_error,
                                           fmt='r.',
                                           label='Current')
     # Label axis
     self.fig.host.set_xlabel("Voltage (V)")
     self.fig.host.set_ylabel("Current ($\mu$A)")
     # List of plotted lines
     lines = [current_line]
     # Tick size
     tkw = dict(size=4, width=1.5)
     self.fig.host.tick_params(axis='x', **tkw)
     # If plotting temperature and humidity lines:
     if th:
         # Overall average temperature and humidity
         temp_averages = iv.average_temp()
         hum_averages = iv.average_hum()
         # Plot temperature and humidity
         temp_line, = self.fig.temp.plot(
             iv.v_mean,
             iv.temperature,
             color='b',
             alpha=0.4,
             label='Temperature, $T_{Av}$ = %s$^\circ$C' % temp_averages[0])
         hum_line, = self.fig.hum.plot(iv.v_mean,
                                       iv.humidity,
                                       color='g',
                                       alpha=0.4,
                                       label='Humidity, $H_{Av}$ = %s%%' %
                                       hum_averages[0])
         # Colour axis
         self.fig.temp.yaxis.label.set_color(temp_line.get_color())
         self.fig.hum.yaxis.label.set_color(hum_line.get_color())
         # Uncomment to constrain axis range
         #self.fig.hum.set_ylim([30, 50])
         #self.fig.temp.set_ylim([18, 22])
         # Label axis
         self.fig.temp.set_ylabel("Temperature ($^\circ$C)")
         self.fig.hum.set_ylabel("Humidity (%)")
         self.fig.temp.tick_params(axis='y',
                                   colors=temp_line.get_color(),
                                   **tkw)
         self.fig.hum.tick_params(axis='y',
                                  colors=hum_line.get_color(),
                                  **tkw)
         # Add to list of lines
         lines.append(temp_line)
         lines.append(hum_line)
     # If finding the breakdown voltage:
     if fits:
         bd_voltage = Fitting.breakdown_voltage(iv)[0]
         bd_statement = Fitting.breakdown_voltage(iv)[1]
         #print(bd_statement)
         # Plot a vertical line at breakdown voltage
         if bd_voltage is not None:
             bd_line = self.fig.host.axvline(
                 x=bd_voltage,
                 color='r',
                 linestyle='--',
                 label='$V_{Breakdown}$ = %sV' %
                 Fitting.round_sig(bd_voltage, 3))
             lines.append(bd_line)
         else:
             no_bd_line, = self.fig.host.plot([], [],
                                              ' ',
                                              label=bd_statement)
             lines.append(no_bd_line)
     # Create legend and title
     self.fig.host.legend(lines, [l.get_label() for l in lines])
     self.fig.suptitle(iv.name)
def main():
    print('Running!')
    # Read in arguments from the command line
    args = parser.parse_args()
    # Folder containing the data
    input_directory = args.file_directory
    # Folder to which the graphs should be saved
    if args.output_directory == ' ':
        output_directory = args.file_directory
    else:
        output_directory = args.output_directory

    # Assign variable with inputs from the command line
    plot_iv = input_boolean(args.plot_iv)
    plot_cv = input_boolean(args.plot_cv)
    plot_it = input_boolean(args.plot_it)
    plot_ivth = input_boolean(args.plot_ivth)
    plot_cvth = input_boolean(args.plot_cvth)
    plot_itth = input_boolean(args.plot_itth)
    plot_ivf = input_boolean(args.plot_ivf)
    plot_cvf = input_boolean(args.plot_cvf)
    plot_itf = input_boolean(args.plot_itf)
    #plot_ivg = input_boolean(args.plot_ivg)
    #plot_cvg = input_boolean(args.plot_cvg)
    #plot_itg = input_boolean(args.plot_itg)
    average_type = args.choose_average

    # Print inputs
    print('Input Directory: ' + input_directory)
    print('Output Directory: ' + output_directory)
    print(f'Plot CV Graphs: {plot_cv}')
    print(f'Plot IV Graphs: {plot_iv}')
    print(f'Plot It Graphs: {plot_it}')
    print(f'Plot CV Graphs with temperature and humidity: {plot_cvth}')
    print(f'Plot IV Graphs with temperature and humidity: {plot_ivth}')
    print(f'Plot It Graphs with temperature and humidity: {plot_itth}')
    print(f'Plot IV Graphs with fits: {plot_ivf}')
    print(f'Plot It Graphs with fits: {plot_itf}')
    print('Calculate averages using ' + average_type)

    # List of data files
    files = []
    #print(os.listdir(input_directory))
    folder = os.listdir(input_directory)
    # Struggled to get the code below to work
    """
    for Input in args.file_directory:
        print("\tInput, ", Input)
        OSInputs = sorted(glob.glob(Input+'/*.txt'))
        print(OSInputs)
        for OSInput in OSInputs:
            if os.path.isfile(OSInput) and OSInput.endswith('.txt') and 'short' not in OSInput:
                files.append(OSInput)
                print("\t\t" + OSInput)
    """
    # Fill files list
    for filename in folder:
        if os.path.isfile(os.path.join(input_directory, filename)) and filename.endswith('.txt') and 'short' not in filename:
            files.append(os.path.join(input_directory, filename))
        else:
            continue

    file_data = {}
    #print(files)

    # Create a dictionary with all the data files and the corresponding data object
    for i in range(len(files)):
        data = Data()
        data.extract_data(files[i], average_type)
        file_data[files[i]] = data

    """
    for f in file_data.values():
        print(f.v_mean)
        continue
    """

    # Separate the data into IV, CV and It
    iv_data = {}
    cv_data = {}
    it_data = {}
    for f1, f2 in file_data.items():
        if f2.type == 'iv':
            iv_data[f1] = f2
        elif f2.type == 'cv':
            cv_data[f1] = f2
        elif f2.type == 'it':
            it_data[f1] = f2

    # Plot all IV files
    if plot_iv:
        print('Plotting IV Graphs')
        for f1, f2 in iv_data.items():
            graph = Plot()
            graph.plot_graph(output_directory, plot_ivth, plot_ivf, f2)
    # Plot all CV files
    if plot_cv:
        print('Plotting CV Graphs')
        for f1, f2 in cv_data.items():
            graph = Plot()
            graph.plot_graph(output_directory, plot_cvth, plot_cvf, f2)
    # Plot all It files
    if plot_it:
        print('Plotting It Graphs')
        for f1, f2 in it_data.items():
            graph = Plot()
            graph.plot_graph(output_directory, plot_itth, plot_itf, f2)