Skip to content
This repository has been archived by the owner on Dec 11, 2022. It is now read-only.

Extend mask function for DataFrames #74

Closed
gabrieldansereau opened this issue Feb 28, 2021 · 6 comments · Fixed by #79
Closed

Extend mask function for DataFrames #74

gabrieldansereau opened this issue Feb 28, 2021 · 6 comments · Fixed by #79

Comments

@gabrieldansereau
Copy link
Member

Love the new mask function @tpoisot ! It will be incredibly useful.

I think it would be nice if it worked on DataFrames too, not just on GBIFrecords elements. That would be in line with the previous DataFrames integration I've added, where I mostly mimicked the features from the GBIF integration so that both can be used in a similar way.

I created this function for my project a while ago and I think it works well enough. I'll update it to be similar to mask and add it in a PR, if you agree.

@gabrieldansereau
Copy link
Member Author

gabrieldansereau commented Feb 28, 2021

Also, would you mind if I added an optional removezeros argument to mask which converts zeros to nothing? The default would be false to keep the behaviour as it is. I think it makes sense since GBIF doesn't return true absences. It's essentially just replace!(layer.grid, 0 => nothing). I'd be doing that all the time if it wasn't included 😉

I also like how it allows to plot the layer with occupied sites with a background that is not on the colour scale, as on my richness figures. It enhances the difference between sites with few occurrences and no occurrences at all. Something like this:

plot(backgroundlayer, c = :lightgrey)
plot!(occurrencelayer, c = :viridis)

@tpoisot
Copy link
Member

tpoisot commented Feb 28, 2021

It all makes sense to me, go ahead!

@tpoisot
Copy link
Member

tpoisot commented Feb 28, 2021

BUT make sure it works with all types. Most of the bugs I've fixed recently where because we assumed the data would be floating point, and it's not always true. Maybe a mask function for dataframes, and then the documentation mentions replace!?

@gabrieldansereau
Copy link
Member Author

gabrieldansereau commented Feb 28, 2021

Good point, I'll see about it.

I think replace!(layer.grid, 0 => nothing) works whether the zero is a Float, an Int, or a Bool. That seems like all the cases where it would potentially make sense to call that argument. Do you see any other ones?

@tpoisot
Copy link
Member

tpoisot commented Feb 28, 2021

I think I would like it better to have replace! outside - that's one fewer argument in the function, and it makes people think about whether they really want to remove the 0.

@tpoisot
Copy link
Member

tpoisot commented Feb 28, 2021

As soon as #75 is merged (in a minute...), I'll tag a new release with a replace and replace! method, you can use this to build your thing directly with the layers (instead of the DF).

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

Successfully merging a pull request may close this issue.

2 participants