-
Notifications
You must be signed in to change notification settings - Fork 23
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
pep8 compliance in pgamit classes #114
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pdsmith90 thanks for starting on these fixes! I left a few minor suggestions and comments, but this looks quite close to being ready to merge
If only record is provided, only insert into db. | ||
If only rinexobj is provided, then RinexRecord of rinexobj | ||
is used for the insert. | ||
If both are given, then RinexRecord overrides the passed record. | ||
|
||
:param record: a RinexRecord dictionary to make the insert to the db | ||
:param rinexobj: the pyRinex object containing the file being processed | ||
:param rnxaction: accion to perform to rinexobj. | ||
:return: True if insertion was successful. False if no insertion was done. | ||
:return: True if insertion was successful. | ||
False if no insertion was done. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pdsmith90 @demiangomez we may want to adopt the numpydoc conventions for parameter and return definitions moving forward...
raise ValueError(('insert_rinex exception: both record and ' | ||
'rinexobj cannot be None.')) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@demiangomez do we have a general preference between defaulting to implicit line joins vs triple quotes when dealing with long strings? For longer multiline statements I tend to think that triple quotes are easier to automate formatting of within the editor, but either convention is fine, or we can use both depending on situation without a default.
return int(sdate[0]), int(sdate[1]), int(sdate[2]), int(sdate[3]), \ | ||
int(sdate[4]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this seems a bit awkward-- does the sdate
object support slicing? Alternatively, parens line continuation will also work here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could we use
return tuple(int(sdate[i]) for i in range(5))
hl[t > self.date.fyear] = \ | ||
np.log10(1. + (t[t > self.date.fyear] - | ||
self.date.fyear) / r) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is getting hard to read for me-- what about something like below, which is the same number of lines but splits on the parenthesis subtraction continuation:
varname = np.log10(1. + (t[t > self.date.fyear] -
self.date.fyear) / r)
hl[t > self.date.fyear] = varname
(deferring to @demiangomez on what an appropriate name for varname
would be here)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was trying to avoid using extra variables here, but I agree it is easier to read
a = np.sin(dlat / 2) ** 2 + np.cos(lat1) * \ | ||
np.cos(lat2) * np.sin(dlon / 2) ** 2 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
preferred way of wrapping long lines is by using Python’s implied line continuation inside parentheses, brackets and braces, with operands and operators proximate-- i.e.:
a = (np.sin(dlat / 2) ** 2
+ np.cos(lat1) * np.cos(lat2) * np.sin(dlon / 2) ** 2)
source = self.soln.stack_name.upper() + \ | ||
' with ETM solution: filtered' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use parens continuation
source = 'No ' + self.soln.stack_name.upper() + \ | ||
' solution, no ETM: mean coordinate' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use parens continuation
sig = np.sqrt(np.square(sig) + np.square(np.array( | ||
[[sigma_h], [sigma_h], [sigma_v]]))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pdsmith90 a bit more readable if each term being added is kept grouped together with the operand:
sig = np.sqrt(np.square(sig) +
np.square(np.array([[sigma_h], [sigma_h], [sigma_v]])))
# will be much larger than [1]'s `eps(mineig)`, since `mineig` is usually on | ||
# the order of 1e-16, and `eps(1e-16)` is on the order of 1e-34, whereas | ||
# `spacing` will, for Gaussian random matrixes of small dimension, be on | ||
# othe order of 1e-16. In practice, both ways converge, as the unit test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@demiangomez not a comment on @pdsmith90 pep8 fixes, but a comment on the numerics-- numpy cholesky decomposition will accept any valid positive semi-definite input, and is much faster than the svd
that is being used here. If you want / need to still output decomposition values for matrices which aren't positive semi-definite, I believe that you can use multivariate_normal
, which will default to cholesky
if possible (for speed), but then fall back to svd
if cholesky
raises a RuntimeWarning: covariance is not positive-semidefinite.
warning during runtime.
Might speed up your runtime, but also not sure how much this code is dominating runtime for you at present.
# self.polyhedrons = cnn.query_float('SELECT "X", "Y", "Z", "Year", "DOY" FROM gamit_soln ' | ||
# 'WHERE "Project" = \'%s\' AND "NetworkCode" = \'%s\' AND ' | ||
# '"StationCode" = \'%s\' ' | ||
# 'ORDER BY "Year", "DOY", "NetworkCode", "StationCode"' | ||
# % (project, NetworkCode, StationCode)) | ||
|
||
# self.gamit_soln = GamitSoln(cnn, self.polyhedrons, NetworkCode, StationCode, project) | ||
# self.polyhedrons = cnn.query_float( | ||
# 'SELECT "X", "Y", "Z", "Year", "DOY" FROM gamit_soln ' | ||
# 'WHERE "Project" = \'%s\' AND "NetworkCode" = \'%s\' AND ' | ||
# '"StationCode" = \'%s\' ' | ||
# 'ORDER BY "Year", "DOY", "NetworkCode", "StationCode"' | ||
# % (project, NetworkCode, StationCode)) | ||
|
||
# self.gamit_soln = GamitSoln( | ||
# cnn, self.polyhedrons, NetworkCode, StationCode, project) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@demiangomez can this be deleted and left in the git history?
Thanks for looking over the changes. If we want to use parenthesis continuation for strings, I will be sure to use that in the future. |
@@ -183,28 +184,32 @@ def __init__(self, m_type, **kwargs): | |||
elif isinstance(arg, float): | |||
self.relaxation = np.array(arg) | |||
else: | |||
raise pyETMException_Model('\'relaxation\' must be list, numpy.ndarray, or float') | |||
raise pyETMException_Model( | |||
'\'relaxation\' must be list, numpy.ndarray, or float') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
...I think from here to line 224, we probably don't need the python string escape characters (\
) that are used. If we want quoted quotes, we can just switch from double to single without breaking the string:
"'relaxation' must be list, numpy.ndarray, or float")
Yeah, of course. I do think that implicit continuation inside of |
@pdsmith90 you'll need to update your master branch and rebase this branch before it can be merged |
Formatting edits on a few things inside pgamit folder. Mostly shortening lines and cleaning spaces.