PoisotLab / SimpleSDMLayers.jl

Simple layers for species distribution modeling and bioclimatic data
https://docs.ecojulia.org/SimpleSDMLayers.jl/stable/
MIT License
19 stars 2 forks source link

`mask` overload for `DataFrames` errors with coordinates outside the layer's range #111

Open gabrieldansereau opened 3 years ago

gabrieldansereau commented 3 years ago

The mask overload for DataFrames returns an unintuitive error if the DataFrame contains observations outside the template layer's range. For example, I encountered this when trying to create a presence-absence layer for a small region, but using a DataFrame with observations across a continent.

julia> mask_layer = mask(layer, df, Bool)
ERROR: LoadError: ArgumentError: invalid index: nothing of type Nothing

I'll fix the mask implementation to allow this, but for now a workaround is to make sure to filter out the coordinates around the layer's bounding coordinates.

filtered_df = filter!(:longitude => >(layer.left), df)
filter!(:longitude => <(layer.right), filtered_df)
filter!(:latitude => >(layer.bottom), filtered_df)
filter!(:latitude => <(layer.top), filtered_df)
mask_layer = mask(layer, filtered_df, Bool)