From 17896fef02aea34ac4bbe4d0ff895169a5222996 Mon Sep 17 00:00:00 2001 From: Kasra Farmer Date: Thu, 27 Feb 2025 13:34:59 -0500 Subject: [PATCH] Covering region rather than satisfying lat/lon limits This commit resolves the issue of spatial subsetting to include a region of interest, rather than simply satisfying the lat/lon limits of a region. Signed-off-by: Kasra Keshavarz --- etc/scripts/coord_mrcc5_idx.ncl | 68 +++++++++++++++++++ .../ouranos-mrcc5-cmip6/mrcc5-cmip6.sh | 6 +- 2 files changed, 70 insertions(+), 4 deletions(-) create mode 100644 etc/scripts/coord_mrcc5_idx.ncl diff --git a/etc/scripts/coord_mrcc5_idx.ncl b/etc/scripts/coord_mrcc5_idx.ncl new file mode 100644 index 0000000..e3aee5e --- /dev/null +++ b/etc/scripts/coord_mrcc5_idx.ncl @@ -0,0 +1,68 @@ +; Meteorological Data Processing Workflow +; Copyright (C) 2022, University of Saskatchewan +; Copyright (C) 2023, University of Calgary +; +; This file is part of Meteorological Data Processing Workflow +; +; This program is free software: you can redistribute it and/or modify +; it under the terms of the GNU General Public License as published by +; the Free Software Foundation, either version 3 of the License, or +; (at your option) any later version. +; +; This program is distributed in the hope that it will be useful, +; but WITHOUT ANY WARRANTY; without even the implied warranty of +; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +; GNU General Public License for more details. +; +; You should have received a copy of the GNU General Public License +; along with this program. If not, see . + +; usage: +; ncl 'coord_file="./path/to/wrf/coordinate/file.nc"' \ +; 'minlat=float' \ +; 'maxlat=float' \ +; 'minlon=float' \ +; 'maxlon=float' \ +; coord_wrf_idx.ncl; + +;---suppress errors including fatal ones + err = NhlGetErrorObjectId() + + setvalues err + "errPrint" : "False" + end setvalues + +;---coordinate variable path and and name must be entered as input arguments + a = addfile(coord_file,"r") + glat2d = a->lat + glon2d = a->lon + +;---variable names below should be defined as input arguments +; minlat +; maxlat +; minlon +; maxlon +; print("coord_file: "+coord_file) +; print("minlat: "+minlat) +; print("maxlat: "+maxlat) +; print("minlon: "+minlon) +; print("maxlon: "+maxlon) + +;---Get xy indexes, and then use these to get lat/lon values back again. + opt = True + loc = region_ind (glat2d, glon2d, minlat, maxlat, minlon, maxlon) + +;---print ERROR and exit of spatial index are out of range +# if (.not. all(loc)) then +# print("ERROR") +# exit +# end if + +;---print the following box of data: [minlonidx, maxlonidx, minlatidx, maxlatidx] + minlonidx = loc(2) + maxlonidx = loc(3) + minlatidx = loc(0) + maxlatidx = loc(1) + print(minlonidx+","+maxlonidx) + print(minlatidx+","+maxlatidx) +;---END diff --git a/var/repos/builtin/recipes/ouranos-mrcc5-cmip6/mrcc5-cmip6.sh b/var/repos/builtin/recipes/ouranos-mrcc5-cmip6/mrcc5-cmip6.sh index f37371c..aa8e8a9 100755 --- a/var/repos/builtin/recipes/ouranos-mrcc5-cmip6/mrcc5-cmip6.sh +++ b/var/repos/builtin/recipes/ouranos-mrcc5-cmip6/mrcc5-cmip6.sh @@ -137,10 +137,8 @@ shopt -s expand_aliases # paths root="$(echo $(dirname $0) | grep -Po '(.*)(?=((/.*?){5})$)')" -# daymet index scripts works on RDRSv2.1 grids as well -# and ESPO-G6-R2 has similar grid system as RDRSv2.1 -coordIdxScript="$root/etc/scripts/coord_daymet_idx.ncl" -coordClosestIdxScript="$root/etc/scripts/coord_closest_daymet_idx.ncl" +# Ouranos MRCC5-CMIP6 index script +coordIdxScript="$root/etc/scripts/coord_mrcc5_idx.ncl" # ==========================