pacificclimate / climpyrical

A Python tool for constraining and manipulating CanRCM4 climate models.
GNU General Public License v3.0
1 stars 0 forks source link

Feature/soften_mask_tests #21

Closed nannau closed 4 years ago

nannau commented 4 years ago

This PR aims to soften some of the strict masking tests imposed, and opts for checking things like the dimensionality of an array instead of its exact shape and range of values. This is so that masking functions can take an arbitrarily shaped xarray.DataSet and apply a mask to the raster data given a polygon.

The previous PR, #20, where I've updated the interpolation method also tries to soften this, but after incorporating #20, I've realized it doesn't account for some use-cases without complicating the parameters used. For example, what if we want to mask a newly gridded dataset using climpyrical's masking functions? The previously strict checks are not flexible enough to account for this.

This PR also improves the testing functions to check precisely which error should be raised when parametrized - a design that already exists in other climpyrical functions.

TL;DR:

nannau commented 4 years ago

@rod-glover I had considered that at some point. I do think it has use, and could help with usage, particularly with clarifying the type of error. I assume its main purpose would be to extend the Python native error types...

i.e. check_ndims(arr, 1) could raise a NDimensionError or some such custom name, instead of ValueError.

I do not have a good grasp on the design features of custom exceptions, so I will raise with you in person.

Thanks for reviewing!

nannau commented 4 years ago

After more private discussion, we've opted to avoid introducing classes (more in the spirit of pacificclimate), since each exception raised has a descriptive message for the error, and the only benefit of having custom exceptions would be for their custom names.