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

refeactor and docs #49

Merged
merged 6 commits into from
Mar 7, 2021
Merged

refeactor and docs #49

merged 6 commits into from
Mar 7, 2021

Conversation

rafaqz
Copy link
Member

@rafaqz rafaqz commented Mar 3, 2021

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)

  • 🐛 Bug fix (non-breaking change which fixes an issue)
  • ❇️ New feature (non-breaking change which adds functionality)
  • 💥 Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • 📖 This change requires a documentation update

Checklist

  • The changes are documented
    • The docstrings of the different functions describe the arguments, purpose, and behavior
    • There are examples in the documentation website
  • The changes are tested
  • The changes do not modify the behavior of the previously existing functions
    • If they do, please explain why and how in the introduction paragraph
  • For new contributors - my name and information are added to .zenodo.json
  • The Project.toml field version has been updated
    • Change the last number for a v0.0.x series release, a bug fix, or a performance improvement
    • Change the middle number for additional features that do not break the current test suite (unless you fix a bug in the test suite)
    • Change the first number for changes that break the current test suite

@rafaqz rafaqz changed the title Rs/docs refeactor and docs Mar 3, 2021
@codecov-io
Copy link

codecov-io commented Mar 3, 2021

Codecov Report

Merging #49 (cecab92) into main (18df1db) will decrease coverage by 0.74%.
The diff coverage is 50.00%.

Impacted file tree graph

@@            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     
Flag Coverage Δ
unittests 61.71% <50.00%> (-0.75%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
src/NeutralLandscapes.jl 100.00% <ø> (ø)
src/algorithms/discretevoronoi.jl 0.00% <0.00%> (ø)
src/algorithms/distancegradient.jl 0.00% <ø> (ø)
src/algorithms/edgegradient.jl 100.00% <ø> (ø)
src/algorithms/nncluster.jl 0.00% <0.00%> (ø)
src/algorithms/nnelement.jl 94.44% <ø> (-0.30%) ⬇️
src/algorithms/nogradient.jl 100.00% <ø> (ø)
src/algorithms/perlinnoise.jl 89.65% <ø> (ø)
src/algorithms/planargradient.jl 100.00% <ø> (ø)
src/algorithms/rectangularcluster.jl 100.00% <ø> (ø)
... and 5 more

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 18df1db...cecab92. Read the comment docs.

@rafaqz rafaqz requested review from tpoisot, mkborregaard and gottacatchenall and removed request for tpoisot and mkborregaard March 3, 2021 13:10
Copy link
Member

@mkborregaard mkborregaard left a 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
Copy link
Member

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

Copy link
Contributor

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

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)

Copy link
Contributor

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.

Copy link
Member Author

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.

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

Choose a reason for hiding this comment

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

behavive => behave

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

Choose a reason for hiding this comment

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

intepolates => interpolates


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

Choose a reason for hiding this comment

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

indecies => indices

Copy link
Contributor

@tpoisot tpoisot left a comment

Choose a reason for hiding this comment

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

  1. bring the documentation from internal functions into dosctrings as opposed to into comments
  2. do we want to use @kwdef?


include(joinpath("algorithms", "diamondsquare.jl"))
export DiscreteVoronoi
export DiamondSquare, MidpointDisplacement
Copy link
Contributor

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

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?

Copy link
Member Author

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

Copy link
Contributor

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

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.

"""
# 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.
Copy link
Contributor

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.

Copy link
Member Author

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

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

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

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.

Copy link
Member Author

@rafaqz rafaqz Mar 3, 2021

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?

@mkborregaard
Copy link
Member

But why do we want docstrings on unexported functions that are never meant to be user-facing?

@tpoisot
Copy link
Contributor

tpoisot commented Mar 3, 2021

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.

@mkborregaard
Copy link
Member

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

@rafaqz
Copy link
Member Author

rafaqz commented Mar 3, 2021

If you have docstrings not in the docs, you get a warning so tests wont pass when strict=true. If you turn off strict to fix this, they will pass when a new PR misses a docstring or messes something up.

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 @kwdef? I guess we can write the constructors out. But it is a base macro.

@tpoisot
Copy link
Contributor

tpoisot commented Mar 3, 2021

Let's use @kwdef if it makes it user frieldier. I still think internal functions should be documented - a thing that many packages do is to have a specific page for them called "internals" or something. It can start with a disclaimer that people should probably not use these functions for daily use.

@mkborregaard
Copy link
Member

mkborregaard commented Mar 4, 2021

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.

@tpoisot
Copy link
Contributor

tpoisot commented Mar 6, 2021

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!

@tpoisot tpoisot removed the request for review from gottacatchenall March 6, 2021 23:37
@tpoisot tpoisot merged commit 478a2b4 into main Mar 7, 2021
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.

4 participants