Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH: Adding docstrings to functions in config reader #81

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

aplymill7
Copy link
Member

No description provided.

@codecov-io
Copy link

codecov-io commented Sep 18, 2019

Codecov Report

Merging #81 into master will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master      #81   +/-   ##
=======================================
  Coverage   70.81%   70.81%           
=======================================
  Files           7        7           
  Lines         209      209           
=======================================
  Hits          148      148           
  Misses         61       61
Impacted Files Coverage Δ
pytentiostat/config_reader.py 52.63% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ecdb2de...4b452bd. Read the comment docs.

Copy link
Member

@sbillinge sbillinge left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

excellent!

config_data : dict
the configuration data

override_ts : Unique string to add after output filename in stringe. Optional.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

slightly wrong structure to this one. type is string and its optional on this line, the description of what id does on the next line down.

Also, as per the other comments, remove empty lines between parameters and return values. Also, good time to fix small typo in here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I tried override_ts: (str, optional), if that seems fine? I saw it on an example doc string. Or maybe should just be str, optional?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer the latter:
override_ts: str, optional

Let's set the style to this maybe?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good!

Parameters
----------
config_data : dict
the configuration data
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

capitalize the here, remove mt lines, but this is super!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it!

Removing mt lines, capitalizing in descriptions, fixing typos.
Copy link
Member

@sbillinge sbillinge left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

very nice, nearly there!

@@ -8,22 +8,21 @@
def parse_config_file(configlocation=None):
"""
Reads config data from the config file

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line should be put back in. First line is a one-line (<80 chars) description of the overall purpose of the function, then a blank line, then as many lines as you want to expand on the explanation, then a blank line, then Parameters underlined and so on.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, makes sense!

@@ -64,13 +100,53 @@ def get_lsv_params(config_data):


def get_ca_params(config_data):
"""
Obtains the parameters for a chronoamperometry experiment
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not so sure about these guys, but I think Returns the parameters for a chronoamperometry experiment from the config data

i.e., returns is maybe better than obtains? But I am not so clear on that.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that phrasing is more clear. I changed it on the other functions that do similar things as well so they would be consistent.

Changing obtain to returns in all config data retriever functions, readding blank in first function docstring, and removing parens on str, optional
Copy link
Member

@sbillinge sbillinge left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

few more comments....got a little deeper into the functions this time....

----------
config_data : dict
The configuration data
override_ts : (str, optional)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

parens?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yeah got it now.

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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since i posted another change request, I may as well make this small req too......config file (singular) now?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops holdover from previous version. fixed now

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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The path where the file will be written?
or
The path to the directory where the file will be written?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yeah the latter. Now changed

Returns
-------
out_name_ts : str
The output filename with unique identifier.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a little unclear, this. maybe a second sentence that discusses how the name is composed rather than just "with unique identifier"?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added what unique identifier is added to the file

-------
voltage : float
The voltage which will be held at in volts.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pls delete line

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

deleted

Returns
-------
voltage : float
The voltage which will be held at in volts.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we find a better way to say it maybe?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I changed to make more descriptive.

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):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if this function should be called get_experiment_duration?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is more descriptive. Now changed

exp_type = config_data["general_parameters"]["experiment_type"]

return exp_type


def get_exp_time(config_data):
"""
Returns how long the experiment is to be run for the chronoamperometry case.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why isn't this info returned with the chronoamperometry info? Wouldn't that be better maybe?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just wrote this for plotting module since the only data it needs for the CA experiment is the time (not the voltage). But maybe this one is separate enough that I should just read from the dictionary in plotter and get rid of this function. Check for it could already be made by get CA params.

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):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still don't quite get why we are having functions that just retrieve dictionary values..... I guess it can make sense if it is part of our user-interface, and we don't expect our users to know python very well. Is that the case?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Though I expect users won't know python well, this part won't really be front-end. I envision in the end, user will enter into visual boxes which, when starting experiment, will write a config (which can be loaded if desired to conduct the same experiment later). I just thought compartmentalizing the experimental config reading here might be good so these functions can read in and then go through a series of checks to make sure they are appropriate values (I still don't have these checks in for most of these functions) instead of bundling that with the functions of the other modules. I can just remake it and place the reading and the checks in the other modules where they are used though if that makes more sense.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. Actually, this is part of the MVC pattern and it would be the controller layer that does the validation, but it would probably be structured differently with a few validation functions that are more abstract (think about validating file paths, emails or passwords), but here we would be validating that floats are within some range or sthg and then return true or false and it would have statements like

if validate_voltage(config_data["ca"]["initial_voltage"], -5., 5.):
   ca_initial voltage = config_data["ca"]["initial_voltage"]

We can certainly do it your way, but we are writing a lot of code and a way that does it robustly with less code is probably preferred.

Maybe we can discuss this a bit more on the call and make a decision. it will also depend on the UC a bit, so spending time hardening this code (docstrings and tests) may not be the best just yet (though I am glad this is now your impulse and wanting the code to validate!). I think it has also been helpful for learning. I am very excited about how you are now thinking about the coding!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay yeah this makes sense, let's discuss this in the next meeting. Especially because we were going to discuss MVC anyways!

@aplymill7 aplymill7 added the documentation Explains how the code works or how to use it label Oct 15, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Explains how the code works or how to use it
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants