-
Notifications
You must be signed in to change notification settings - Fork 2
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
refeactor and docs #49
Conversation
Codecov Report
@@ Coverage Diff @@
## main #49 +/- ##
==========================================
- Coverage 62.45% 61.71% -0.75%
==========================================
Files 14 14
Lines 277 269 -8
==========================================
- Hits 173 166 -7
+ Misses 104 103 -1
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
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.
Looks sensible - some few comments on naming. This only covers some of the stuff discussed at #47 right?
|
||
include(joinpath("algorithms", "diamondsquare.jl")) | ||
export DiscreteVoronoi | ||
export DiamondSquare, MidpointDisplacement |
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.
good idea to give mpd it's own file
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 it's mostly an application of DiamondSquare, but not opposed to the idea - @gottacatchenall ?
@@ -21,48 +23,40 @@ edge midpoints from the nearest two corners and the square's center, where as | |||
midpoint-displacement only intepolates from the nearest corners (see `MidpointDisplacement`). | |||
|
|||
""" | |||
struct DiamondSquare <: NeutralLandscapeMaker | |||
H::Float64 | |||
@kwdef struct DiamondSquare <: NeutralLandscapeMaker |
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 don't usually use @kwdef - does that mean you need to call it as DiamondSquare(H = 0.2)
to initialize this object? If that's the case I suggest replacing H
with a more informative variable name like autocor
or even autocorrelation
(and the same for all other algs)
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 all packages use H, so I would document what it means, and then use the same syntax for constructors as the other methods. This would make the code more consistent.
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.
@kwdef
is basically a shortcut for adding keyword constructors. The single argument methods don't really need them, but they're nice for multi-argument methods, so I standardised that all have both keywords and regular arg constructors to avoid confusion.
You can still use regular argument constructors - I just forgot to include that in this particular doc, it's in most of the other docs.
And yes the fieldnames as keywords do become more important. I'm not a huge fan of math in struct fields, it tends to make the algorithms impenetrable. H = alg.autocor
is my usual preference. But if it's common in the package it's probably ok.
src/algorithms/diamondsquare.jl
Outdated
Creates a midpoint-displacement algorithm object `MidpointDisplacement`. | ||
The degree of spatial autocorrelation is controlled by a parameter `H`, | ||
which varies from 0.0 (low autocorrelation) to 1.0 (high autocorrelation) --- | ||
note this is non-inclusive and H = 0 and H = 1 will not behavive as expected. |
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.
behavive => behave
src/algorithms/diamondsquare.jl
Outdated
A similar algorithm, diamond-square, functions almost | ||
identically, except that in diamond-square, the square step interpolates | ||
edge midpoints from the nearest two corners and the square's center, where as | ||
`MidpointDisplacement` only intepolates from the nearest corners (see `DiamondSquare`). |
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.
intepolates => interpolates
src/algorithms/diamondsquare.jl
Outdated
|
||
Computes the mean of a set of points, represented as a list of indecies to a matrix `mat`. | ||
""" | ||
# Computes the mean of a set of points, represented as a list of indecies to a matrix `mat`. |
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.
indecies => indices
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.
- bring the documentation from internal functions into dosctrings as opposed to into comments
- do we want to use
@kwdef
?
|
||
include(joinpath("algorithms", "diamondsquare.jl")) | ||
export DiscreteVoronoi | ||
export DiamondSquare, MidpointDisplacement |
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 it's mostly an application of DiamondSquare, but not opposed to the idea - @gottacatchenall ?
using NearestNeighbors: KDTree, knn, nn | ||
using DataStructures: IntDisjointSets, union!, find_root, push! | ||
using Base: @kwdef |
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.
As far as I can tell it's only used by a single type - can't we just remove it?
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.
@kwdef
is used on all types now
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.
👍 let's keep it
@@ -21,48 +23,40 @@ edge midpoints from the nearest two corners and the square's center, where as | |||
midpoint-displacement only intepolates from the nearest corners (see `MidpointDisplacement`). | |||
|
|||
""" | |||
struct DiamondSquare <: NeutralLandscapeMaker | |||
H::Float64 | |||
@kwdef struct DiamondSquare <: NeutralLandscapeMaker |
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 all packages use H, so I would document what it means, and then use the same syntax for constructors as the other methods. This would make the code more consistent.
src/algorithms/diamondsquare.jl
Outdated
""" | ||
# Check if `mat` is the right size. | ||
# If mat is not the correct size (DiamondSquare can only run on a lattice of size NxN where N = (2^n)+1 for integer n), | ||
# allocates the smallest lattice large enough to contain `mat` that can run DiamondSquare. |
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.
Why is this in comments instead of a docstring? I think the docstring versions makes more sense.
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.
Docstrings not in docs throw a warning that will be a test failure
|
||
""" | ||
# Diamond-square is an iterative procedure, where the lattice is divided |
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.
same as above
Initialize's the `DiamondSquare` algorithm by displacing the four corners of the | ||
lattice using `displace`, scaled by the algorithm's autocorrelation `H`. | ||
""" | ||
# Initialize's the `DiamondSquare` algorithm by displacing the four corners of the |
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.
same as above
|
||
This type is used to generate an edge gradient landscape, where values change | ||
as a bilinear function of the *x* and *y* coordinates. The direction is | ||
expressed as a floating point value, which will be in *[0,360]*. The inner | ||
constructor takes the mod of the value passed and 360, so that a value that is | ||
out of the correct interval will be corrected. | ||
""" | ||
struct EdgeGradient <: NeutralLandscapeMaker | ||
direction::Float64 | ||
@kwdef struct EdgeGradient <: NeutralLandscapeMaker |
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 would really rather get rid of @kwdef
- it doesn't seem the be the "community standard" for constructors.
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.
That's largely because Parameters.jl predates it so there isn't really a community standard. I even have another package that does this differently! (FieldDefaults.jl).
Out options using Base are to use @kwdef
or to write out the keyword argument constructors - are you saying you would prefer them fully written out or not to have keyword constructors?
But why do we want docstrings on unexported functions that are never meant to be user-facing? |
Maybe that's just me, but I like having the docstring when I'm writing things for the package - as in, when I hover the function name in VS Code - it's easier than having to look into the code for the comments. |
It seems a little strange to me, but I don't feel strongly about it, as long as they are kept out of the docs :-) |
If you have docstrings not in the docs, you get a warning so tests wont pass when The idea was to enforce documentation. Its made my life a lot easier on my own packages to get test failures whenever the docs break in any way, and made the docs more reliable. Otherwise Im easy either way. But underscore functions are for devs only, so comments seem right to me anyway? And why not use |
Let's use |
I'm OK with having them under "internals" if that is useful for you guys. And I don't care either way about kwdef :-) Then we just have some docstrings to write - I didn't docstring any internal functions. |
I'm fine with the package as is, so I'm going to merge and tag as soon as it passes. I'll start building the SimpleSDMLayers integration as soon as we have a version! |
What the pull request does
Refactors and cleans up a little, standardises all algorithm arguments and docs, and fixes documentation so there are no warnings - which means documenting everything exported, and moving a lot of docs to code comments.
Type of change
Please indicate the relevant option(s)
Checklist
.zenodo.json
Project.toml
fieldversion
has been updatedv0.0.x
series release, a bug fix, or a performance improvement