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

pep8 compliance in pgamit classes #114

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

Conversation

pdsmith90
Copy link

@pdsmith90 pdsmith90 commented Oct 14, 2024

Formatting edits on a few things inside pgamit folder. Mostly shortening lines and cleaning spaces.

Copy link
Collaborator

@espg espg left a 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

Comment on lines +51 to +60
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.
Copy link
Collaborator

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...

Comment on lines +64 to +65
raise ValueError(('insert_rinex exception: both record and '
'rinexobj cannot be None.'))
Copy link
Collaborator

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.

Comment on lines +216 to +217
return int(sdate[0]), int(sdate[1]), int(sdate[2]), int(sdate[3]), \
int(sdate[4])
Copy link
Collaborator

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

Copy link
Author

@pdsmith90 pdsmith90 Oct 14, 2024

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))

Comment on lines +248 to +250
hl[t > self.date.fyear] = \
np.log10(1. + (t[t > self.date.fyear] -
self.date.fyear) / r)
Copy link
Collaborator

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)

Copy link
Author

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

Comment on lines +290 to +291
a = np.sin(dlat / 2) ** 2 + np.cos(lat1) * \
np.cos(lat2) * np.sin(dlon / 2) ** 2
Copy link
Collaborator

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)

Comment on lines +2746 to +2747
source = self.soln.stack_name.upper() + \
' with ETM solution: filtered'
Copy link
Collaborator

Choose a reason for hiding this comment

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

use parens continuation

Comment on lines +2774 to +2775
source = 'No ' + self.soln.stack_name.upper() + \
' solution, no ETM: mean coordinate'
Copy link
Collaborator

Choose a reason for hiding this comment

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

use parens continuation

Comment on lines +2791 to +2792
sig = np.sqrt(np.square(sig) + np.square(np.array(
[[sigma_h], [sigma_h], [sigma_v]])))
Copy link
Collaborator

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
Copy link
Collaborator

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.

Comment on lines -3054 to +3172
# 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)
Copy link
Collaborator

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?

@pdsmith90
Copy link
Author

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')
Copy link
Collaborator

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")

@espg
Copy link
Collaborator

espg commented Oct 14, 2024

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.

Yeah, of course. I do think that implicit continuation inside of [], {}, and ()'s is basically always preferred unless doing something with assert or with statements that doesn't allow doing implicit continuation.

@espg
Copy link
Collaborator

espg commented Oct 17, 2024

@pdsmith90 you'll need to update your master branch and rebase this branch before it can be merged

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants