From 52d146f5e12bbe7eab0da9be55b0c0f43399168b Mon Sep 17 00:00:00 2001 From: Austin Plymill Date: Wed, 18 Sep 2019 09:59:06 -0500 Subject: [PATCH 1/5] ENH:Adding docstrings to functions in config reader --- pytentiostat/config_reader.py | 162 ++++++++++++++++++++++++++++++++++ 1 file changed, 162 insertions(+) diff --git a/pytentiostat/config_reader.py b/pytentiostat/config_reader.py index 63c68439..30aedf33 100644 --- a/pytentiostat/config_reader.py +++ b/pytentiostat/config_reader.py @@ -42,6 +42,27 @@ def parse_config_file(configlocation=None): sys.exit("Directory containing config file, {}, not found. Exiting...".format(configlocation)) def get_output_params(config_data, override_ts=None): + """ + Obtains output filename and output filepath from config file data + + Parameters + ---------- + config_data : dict + the configuration data + + override_ts : Unique string to add after output filename in stringe. Optional. + If not specified will add a time stamp hours, minutes, and seconds the experiment + was conducted at as a unique identifier. + + Returns + ------- + out_name_ts : str + the output filename with unique identifier. + + data_out_path : str + the path to which the output file will be written to. + + """ data_out_name = config_data["general_parameters"]["data_output_filename"] data_out_path = config_data["general_parameters"]["data_output_path"] if data_out_path.lower() == "desktop": @@ -56,6 +77,26 @@ def get_output_params(config_data, override_ts=None): def get_lsv_params(config_data): + """ + Obtains the parameters for a linear sweep voltammetry experiment + + Parameters + ---------- + config_data : dict + the configuration data + + Returns + ------- + start_voltage : float + The voltage to start the sweep at in volts. + + end_voltage : float + The voltage to end the sweep at in volts. + + sweep_rate : float + The rate at which the experiment is performed in millivolts per second. + + """ start_voltage = config_data["linear_sweep_voltammetry"]["start_voltage"] end_voltage = config_data["linear_sweep_voltammetry"]["end_voltage"] sweep_rate = config_data["linear_sweep_voltammetry"]["sweep_rate"] @@ -64,6 +105,23 @@ def get_lsv_params(config_data): def get_ca_params(config_data): + """ + Obtains the parameters for a chronoamperometry experiment + + Parameters + ---------- + config_data : dict + the configuration data + + Returns + ------- + voltage : float + The voltage which will be held at in volts. + + time: float + How long the voltage will be held in seconds. + + """ voltage = config_data["chronoamperometry"]["voltage"] time = config_data["chronoamperometry"]["time"] @@ -71,6 +129,32 @@ def get_ca_params(config_data): def get_cv_params(config_data): + """ + Obtains the parameters for a cyclic voltammetry experiment + + Parameters + ---------- + config_data : dict + the configuration data + + Returns + ------- + start_voltage : float + The voltage to start the experiment at in volts. + + first_turnover : float + The voltage at which the voltage sweep will first change directions in volts. + + second_turnover: float + the second voltage at which the voltage sweep will change directions in volts. + + sweep_rate : float + The rate at which the experiment is performed in mV/s. + + cycle_number: int + How many times to perform this cycle. + + """ start_voltage = config_data["cyclic_voltammetry"]["start_voltage"] first_turnover = config_data["cyclic_voltammetry"]["first_turnover_voltage"] second_turnover = config_data["cyclic_voltammetry"]["second_turnover_voltage"] @@ -81,29 +165,107 @@ def get_cv_params(config_data): def get_exp_type(config_data): + """ + Obtains the type of experiment + + Parameters + ---------- + config_data : dict + the configuration data + + Returns + ------- + exp_type : str + The type of experiment to be run + + """ exp_type = config_data["general_parameters"]["experiment_type"] return exp_type def get_exp_time(config_data): + """ + Obtains the how long the experiment is to be run for the chronoamperometry case + + Parameters + ---------- + config_data : dict + the configuration data + + Returns + ------- + exp_time : float + How long the experiment will be run in seconds. + + """ exp_time = config_data["chronoamperometry"]["time"] return exp_time def get_rest(config_data): + """ + Obtains how long to hold before experiment starts + + Parameters + ---------- + config_data : dict + the configuration data + + Returns + ------- + rest_time : float + How long the starting voltage will be held in seconds. + + """ rest_time = config_data["general_parameters"]["rest_time"] return rest_time def get_steps(config_data): + """ + Obtains how many points will be measured during experiment + + Parameters + ---------- + config_data : dict + the configuration data + + Returns + ------- + step_number : int + How many points will be measured during the experiment + + """ step_number = config_data["general_parameters"]["step_number"] return step_number def get_adv_params(adv_config_data): + """ + Obtains parameters that shouldn't be altered by beginning users largely related to calibration. + + Parameters + ---------- + config_data : dict + the configuration data + + Returns + ------- + conversion_factor : float + Value to convert output number to real voltage measured. + setpoint_adjuster: float + Value to shift the starting scheduled voltage to match the input voltage. + shunt_resistor: float + Value to adjust for internal resistance largely set by shunt resistor to measure current passed. + time_step: float + Minimum time to execute read/write cycle. + average_number: int + Number of times the measurement at each point will be performed. + + """ conversion_factor = adv_config_data["advanced_parameters"]["conversion_factor"] set_gain = adv_config_data["advanced_parameters"]["setpoint_gain"] set_offset = adv_config_data["advanced_parameters"]["setpoint_offset"] From f3d560746f92d51a63da8cd8a88d9e516d244cc2 Mon Sep 17 00:00:00 2001 From: aplymill7 <47641688+aplymill7@users.noreply.github.com> Date: Sat, 21 Sep 2019 14:23:19 -0500 Subject: [PATCH 2/5] STYL: out_params doc strings Removing mt lines, capitalizing in descriptions, fixing typos. --- pytentiostat/config_reader.py | 68 ++++++++++++++++------------------- 1 file changed, 31 insertions(+), 37 deletions(-) diff --git a/pytentiostat/config_reader.py b/pytentiostat/config_reader.py index 30aedf33..ba2528f1 100644 --- a/pytentiostat/config_reader.py +++ b/pytentiostat/config_reader.py @@ -8,13 +8,12 @@ def parse_config_file(configlocation=None): """ Reads config data from the config file - the config file must be called config.yml. Parameters ---------- - configlocation : str - the path on the filesystem to the config file. Optional. If not + configlocation : (str, optional) + The path on the filesystem to the config file. If not specified pytentiostat looks in the current directory for the config files. @@ -22,8 +21,8 @@ def parse_config_file(configlocation=None): ------- config_data : dict the configuration data - """ + if not configlocation: configlocation = "./" try: @@ -48,21 +47,19 @@ def get_output_params(config_data, override_ts=None): Parameters ---------- config_data : dict - the configuration data - - override_ts : Unique string to add after output filename in stringe. Optional. - If not specified will add a time stamp hours, minutes, and seconds the experiment - was conducted at as a unique identifier. + The configuration data + override_ts : (str, optional) + Unique string to append to output filename string. If not specified will add a time stamp + hours, minutes, and seconds the experiment was conducted at as a unique identifier. Returns ------- out_name_ts : str - the output filename with unique identifier. - + The output filename with unique identifier. data_out_path : str - the path to which the output file will be written to. - + The path to which the output file will be written to. """ + data_out_name = config_data["general_parameters"]["data_output_filename"] data_out_path = config_data["general_parameters"]["data_output_path"] if data_out_path.lower() == "desktop": @@ -83,20 +80,18 @@ def get_lsv_params(config_data): Parameters ---------- config_data : dict - the configuration data + The configuration data Returns ------- start_voltage : float - The voltage to start the sweep at in volts. - + The voltage to start the sweep at in volts. end_voltage : float The voltage to end the sweep at in volts. - sweep_rate : float The rate at which the experiment is performed in millivolts per second. - """ + start_voltage = config_data["linear_sweep_voltammetry"]["start_voltage"] end_voltage = config_data["linear_sweep_voltammetry"]["end_voltage"] sweep_rate = config_data["linear_sweep_voltammetry"]["sweep_rate"] @@ -122,6 +117,7 @@ def get_ca_params(config_data): How long the voltage will be held in seconds. """ + voltage = config_data["chronoamperometry"]["voltage"] time = config_data["chronoamperometry"]["time"] @@ -141,20 +137,16 @@ def get_cv_params(config_data): ------- start_voltage : float The voltage to start the experiment at in volts. - first_turnover : float - The voltage at which the voltage sweep will first change directions in volts. - + The voltage at which the voltage sweep will first change directions in volts. second_turnover: float - the second voltage at which the voltage sweep will change directions in volts. - + The second voltage at which the voltage sweep will change directions in volts. sweep_rate : float - The rate at which the experiment is performed in mV/s. - + The rate at which the experiment is performed in mV/s. cycle_number: int How many times to perform this cycle. - """ + start_voltage = config_data["cyclic_voltammetry"]["start_voltage"] first_turnover = config_data["cyclic_voltammetry"]["first_turnover_voltage"] second_turnover = config_data["cyclic_voltammetry"]["second_turnover_voltage"] @@ -171,14 +163,14 @@ def get_exp_type(config_data): Parameters ---------- config_data : dict - the configuration data + The configuration data Returns ------- exp_type : str - The type of experiment to be run - + The type of experiment to be run. """ + exp_type = config_data["general_parameters"]["experiment_type"] return exp_type @@ -191,14 +183,14 @@ def get_exp_time(config_data): Parameters ---------- config_data : dict - the configuration data + The configuration data Returns ------- exp_time : float How long the experiment will be run in seconds. - """ + exp_time = config_data["chronoamperometry"]["time"] return exp_time @@ -211,7 +203,7 @@ def get_rest(config_data): Parameters ---------- config_data : dict - the configuration data + The configuration data Returns ------- @@ -219,6 +211,7 @@ def get_rest(config_data): How long the starting voltage will be held in seconds. """ + rest_time = config_data["general_parameters"]["rest_time"] return rest_time @@ -230,14 +223,14 @@ def get_steps(config_data): Parameters ---------- config_data : dict - the configuration data + The configuration data Returns ------- step_number : int How many points will be measured during the experiment - """ + step_number = config_data["general_parameters"]["step_number"] return step_number @@ -250,7 +243,7 @@ def get_adv_params(adv_config_data): Parameters ---------- config_data : dict - the configuration data + The configuration data Returns ------- @@ -264,8 +257,8 @@ def get_adv_params(adv_config_data): Minimum time to execute read/write cycle. average_number: int Number of times the measurement at each point will be performed. - """ + conversion_factor = adv_config_data["advanced_parameters"]["conversion_factor"] set_gain = adv_config_data["advanced_parameters"]["setpoint_gain"] set_offset = adv_config_data["advanced_parameters"]["setpoint_offset"] @@ -281,6 +274,7 @@ def get_adv_params(adv_config_data): time_step, average_number, ) + def check_config_inputs(arg): """ Checks that all the data that should be numerical from that config @@ -295,8 +289,8 @@ def check_config_inputs(arg): _______ is_number: Boolean Value is True if the arg is a number, False if not. - """ + try: return isinstance(float(arg), float) except: From ad7d0d6759dd837712b5eb2e06051bc559fca740 Mon Sep 17 00:00:00 2001 From: aplymill7 <47641688+aplymill7@users.noreply.github.com> Date: Sun, 22 Sep 2019 17:05:09 -0500 Subject: [PATCH 3/5] STYL: Improving the docstrings. Changing obtain to returns in all config data retriever functions, readding blank in first function docstring, and removing parens on str, optional --- pytentiostat/config_reader.py | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/pytentiostat/config_reader.py b/pytentiostat/config_reader.py index ba2528f1..1a1582fd 100644 --- a/pytentiostat/config_reader.py +++ b/pytentiostat/config_reader.py @@ -7,12 +7,13 @@ def parse_config_file(configlocation=None): """ - Reads config data from the config file - the config file must be called config.yml. + Reads config data from the config file. + + The config file must be called config.yml. Parameters ---------- - configlocation : (str, optional) + configlocation : str, optional The path on the filesystem to the config file. If not specified pytentiostat looks in the current directory for the config files. @@ -42,7 +43,7 @@ def parse_config_file(configlocation=None): def get_output_params(config_data, override_ts=None): """ - Obtains output filename and output filepath from config file data + Returns the output filename and output filepath from the config file data. Parameters ---------- @@ -75,7 +76,7 @@ def get_output_params(config_data, override_ts=None): def get_lsv_params(config_data): """ - Obtains the parameters for a linear sweep voltammetry experiment + Returns the parameters for a linear sweep voltammetry experiment from the config data. Parameters ---------- @@ -101,7 +102,7 @@ def get_lsv_params(config_data): def get_ca_params(config_data): """ - Obtains the parameters for a chronoamperometry experiment + Returns the parameters for a chronoamperometry experiment from the config data. Parameters ---------- @@ -126,7 +127,7 @@ def get_ca_params(config_data): def get_cv_params(config_data): """ - Obtains the parameters for a cyclic voltammetry experiment + Returns the parameters for a cyclic voltammetry experiment from the config data. Parameters ---------- @@ -158,7 +159,7 @@ def get_cv_params(config_data): def get_exp_type(config_data): """ - Obtains the type of experiment + Returns the type of experiment from the config data. Parameters ---------- @@ -178,7 +179,7 @@ def get_exp_type(config_data): def get_exp_time(config_data): """ - Obtains the how long the experiment is to be run for the chronoamperometry case + Returns how long the experiment is to be run for the chronoamperometry case. Parameters ---------- @@ -198,7 +199,7 @@ def get_exp_time(config_data): def get_rest(config_data): """ - Obtains how long to hold before experiment starts + Returns how long to hold before experiment starts from the config data. Parameters ---------- @@ -218,7 +219,7 @@ def get_rest(config_data): def get_steps(config_data): """ - Obtains how many points will be measured during experiment + Returns how many points will be measured during experiment from the config data. Parameters ---------- @@ -238,7 +239,7 @@ def get_steps(config_data): def get_adv_params(adv_config_data): """ - Obtains parameters that shouldn't be altered by beginning users largely related to calibration. + Returns parameters that shouldn't be altered by beginning users largely related to calibration from the config data. Parameters ---------- From e38fbc57c47358b2d79a64a9e968924c7bb64604 Mon Sep 17 00:00:00 2001 From: aplymill7 <47641688+aplymill7@users.noreply.github.com> Date: Sun, 22 Sep 2019 18:52:19 -0500 Subject: [PATCH 4/5] STYL: making docstring changes --- pytentiostat/config_reader.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/pytentiostat/config_reader.py b/pytentiostat/config_reader.py index 1a1582fd..d30f2966 100644 --- a/pytentiostat/config_reader.py +++ b/pytentiostat/config_reader.py @@ -16,12 +16,12 @@ def parse_config_file(configlocation=None): configlocation : str, optional The path on the filesystem to the config file. If not specified pytentiostat looks in the current directory for the - config files. + config file. Returns ------- config_data : dict - the configuration data + The configuration data. """ if not configlocation: @@ -49,16 +49,17 @@ def get_output_params(config_data, override_ts=None): ---------- config_data : dict The configuration data - override_ts : (str, optional) + override_ts : str, optional Unique string to append to output filename string. If not specified will add a time stamp hours, minutes, and seconds the experiment was conducted at as a unique identifier. Returns ------- out_name_ts : str - The output filename with unique identifier. + The output filename with unique identifier. The unique identifier is the time in hours, minutes, and seconds + at which the experiment was conducted. data_out_path : str - The path to which the output file will be written to. + The path to the directory to which the file will be written. """ data_out_name = config_data["general_parameters"]["data_output_filename"] @@ -112,8 +113,7 @@ def get_ca_params(config_data): Returns ------- voltage : float - The voltage which will be held at in volts. - + The voltage which will be held constant over the course of the experiment in volts. time: float How long the voltage will be held in seconds. @@ -177,7 +177,7 @@ def get_exp_type(config_data): return exp_type -def get_exp_time(config_data): +def get_exp_duration(config_data): """ Returns how long the experiment is to be run for the chronoamperometry case. From 4b452bd0df27d938ab453f060db30e8efb10de97 Mon Sep 17 00:00:00 2001 From: aplymill7 <47641688+aplymill7@users.noreply.github.com> Date: Sun, 22 Sep 2019 19:15:01 -0500 Subject: [PATCH 5/5] ENH: changing plotter from time -> duration --- pytentiostat/plotter.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pytentiostat/plotter.py b/pytentiostat/plotter.py index 04640d2f..30ed66b8 100644 --- a/pytentiostat/plotter.py +++ b/pytentiostat/plotter.py @@ -4,7 +4,7 @@ def plot_initializer(config_data): exp_type = pytentiostat.config_reader.get_exp_type(config_data) - exp_time = pytentiostat.config_reader.get_exp_time(config_data) + exp_duration = pytentiostat.config_reader.get_exp_duration(config_data) times = [] voltages = [] @@ -18,7 +18,7 @@ def plot_initializer(config_data): # This is just for testing if exp_type == "CA": - axes.set_xlim(0, 2 * exp_time) + axes.set_xlim(0, 2 * exp_duration) # Let's switch commands based on experiment run if exp_type == "LSV":