SimpleSDMLayers.jl icon indicating copy to clipboard operation
SimpleSDMLayers.jl copied to clipboard

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

Open gabrieldansereau opened this issue 2 years ago • 0 comments

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)

gabrieldansereau avatar Aug 03 '21 22:08 gabrieldansereau