dklinges9 / mcera5

mcera5
12 stars 9 forks source link

spatial extent check extract_clima #33

Closed ilyamaclean closed 1 month ago

ilyamaclean commented 1 month ago

In function extract_clima you have various extent checks. E.g for longitude

Check if requested coordinates are in spatial grid

if (long_min < min(nc_dat$dim$longitude$vals) | long_min > max(nc_dat$dim$longitude$vals) | long_max < min(nc_dat$dim$longitude$vals) | long_max > max(nc_dat$dim$longitude$vals) ) { long_out <- TRUE } else { long_out <- FALSE }

However min(nc_dat$dim$longitude$vals gives you the centre of the grid cell not the edge, so if long_min, long_max etc are a bounding box of the area of interest (as would typically be assumed by a user), the function uncessarily throws and error. Also since long_min is always < long_max, the double check is unecssary. Would suggest replacing with e.g.

if (long_min < (min(nc_dat$dim$longitude$vals)-0.125) | long_max > (max(nc_dat$dim$longitude$vals)+0.125) ) { long_out <- TRUE } else { long_out <- FALSE }

If you'd like me to fix it I can do I pull request, but maybe merge the last one first??

dklinges9 commented 1 month ago

Thanks Ilya, good catch about the unnecessary error. Merged your pull request after some testing. As for the double check, I added that in case the user had long_min > long_max, but this should just be a separate check (which I already had)