Problem with Running WRF_Hydro_Regridding_Spatial_Weights.py – Empty spatialweights.nc Output

64 views
Skip to first unread message

Aref Farhangmehr

unread,
Aug 3, 2025, 11:30:21 AMAug 3
to wrf-hydro_users
Dear WRF-Hydro Team,

We am trying to use the bucket_loss option for calibration in WRF-Hydro (version 5.3), but we understand that this requires UDMP=1, which means we need a valid spatialweights.nc file.

To generate this file, we used the WRF_Hydro_Regridding_Spatial_Weights.py script. The script runs without errors and creates the file spatialweights_out.nc, but the output has empty variables. It seems the geo_em.nc file and the shapefile do not have overlap (I am not sure!).

It is worth to mention that when I load both the shapefile and the geo_em.nc file into ArcMap, they clearly overlap.

All required code and files are attached.

Do you know what could be causing this? 

Thank you in advance.

Best regards,
Aref

loss.rar

zed li

unread,
Sep 2, 2025, 8:51:19 AMSep 2
to wrf-hydro_users, Aref Farhangmehr

Hello,Aref

I hope this message finds you well. Sorry to bother you with this, but I'm having some trouble running the WRF_Hydro_Regridding_Spatial_Weights.py script and was hoping you might be able to offer some guidance.

I've been encountering an error that says: "TypeError: in method 'Geometry_Transform', argument 2 of type 'OSRCoordinateTransformationShadow *'". Interestingly, I get the same error even when using your script and input files directly.

I did some searching online and it seems this might be related to the GDAL package version. Would you be able to share which version of GDAL you were using when you successfully ran the script? I believe this information could really help me resolve the issue.

I also wanted to ask about how you prepared the input shp file. I generated the basn_msk raster using ArcGIS with the wrf_hydro_arcgis_preprocessor tool, and then exported it to a shp file. I was wondering if this approach is appropriate, or if there might be a better way to create the required shp file.

Thank you so much for your time and help. I truly appreciate any advice you might be able to offer.

Best regards,

Zed Li

Fatemeh Shirkhanloo

unread,
Sep 2, 2025, 6:39:01 PMSep 2
to wrf-hyd...@ucar.edu, ddlw...@gmail.com, Aref Farhangmehr
Hi Zed, 

Regarding to modules for running WRF_Hydro_Regridding_Spatial_Weights.py script successfully please install these : 

conda –version

conda create -n gdal_env python=3.10 gdal netCDF4 numpy -c conda-forge

conda activate gdal_env

python -c "from osgeo import gdal, ogr, osr; print('GDAL loaded successfully')"

conda install -c conda-forge libgdal-netcdf


then if you are submitting a job, add this section to your job script on HPC: 

# Load conda environment

source ~/.bashrc

conda activate gdal_env

cd /home/fatemehs/WRB/wrf_hydro_arcgis_preprocessor-master

python3 WRF_Hydro_Regridding_Spatial_Weights.py


Best regards,
Fatemeh



--
You received this message because you are subscribed to the Google Groups "wrf-hydro_users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to wrf-hydro_use...@ucar.edu.
To view this discussion visit https://groups.google.com/a/ucar.edu/d/msgid/wrf-hydro_users/c2b35c3b-565c-4f3e-a32b-47b31181f1edn%40ucar.edu.

Aref Farhangmehr

unread,
Sep 3, 2025, 7:57:58 AMSep 3
to zed li, wrf-hydro_users
Hi Zed

I am using the GDAL version of 3.8.5 and the python version of 3.10.18 .

All installed libraries in the conda environment are listed at the end of the email.

Regarding shapefile, I remember it needs a minor modification. I had the shapefile of the basin and just added "GRIDCODE" field in the shapefile Attribute Table using arcGIS/QGIS with a value of 1. 

Hope it helps.
  
Regards;
Aref


# Name                    Version                   Build  Channel
aws-c-auth                0.8.0               h6c5491b_10    conda-forge
aws-c-cal                 0.8.0                hb414858_2    conda-forge
aws-c-common              0.10.3               h2466b09_0    conda-forge
aws-c-compression         0.3.0                hb414858_2    conda-forge
aws-c-event-stream        0.5.0                hab6af6e_7    conda-forge
aws-c-http                0.9.1                hab0f966_2    conda-forge
aws-c-io                  0.15.2               hef77f12_2    conda-forge
aws-c-mqtt                0.11.0               hbfeb708_8    conda-forge
aws-c-s3                  0.7.4                h6108ab3_0    conda-forge
aws-c-sdkutils            0.2.1                hb414858_1    conda-forge
aws-checksums             0.2.2                hb414858_1    conda-forge
aws-crt-cpp               0.29.6               h505e3f6_2    conda-forge
aws-sdk-cpp               1.11.449             h0ed5b37_4    conda-forge
azure-core-cpp            1.14.0               haf5610f_0    conda-forge
azure-identity-cpp        1.10.0               hd6deed7_0    conda-forge
azure-storage-blobs-cpp   12.13.0              h3241184_1    conda-forge
azure-storage-common-cpp  12.8.0               hd6deed7_1    conda-forge
blosc                     1.21.6               h85f69ea_0    conda-forge
bzip2                     1.0.8                h2466b09_7    conda-forge
c-ares                    1.34.5               h2466b09_0    conda-forge
ca-certificates           2025.7.14            h4c7d964_0    conda-forge
cairo                     1.18.4               h5782bbf_0    conda-forge
certifi                   2025.7.14          pyhd8ed1ab_0    conda-forge
cfitsio                   4.4.1                hae32d5d_2    conda-forge
cftime                    1.6.4           py310hb0944cc_1    conda-forge
fmt                       11.0.2               hf4da5c8_1    conda-forge
font-ttf-dejavu-sans-mono 2.37                 hab24e00_0    conda-forge
font-ttf-inconsolata      3.000                h77eed37_0    conda-forge
font-ttf-source-code-pro  2.038                h77eed37_0    conda-forge
font-ttf-ubuntu           0.83                 h77eed37_3    conda-forge
fontconfig                2.15.0               h765892d_1    conda-forge
fonts-conda-ecosystem     1                             0    conda-forge
fonts-conda-forge         1                             0    conda-forge
freetype                  2.13.3               h57928b3_1    conda-forge
freexl                    2.0.0                hf297d47_2    conda-forge
gdal                      3.8.5           py310hc001a87_16    conda-forge
geos                      3.12.2               h5a68840_1    conda-forge
geotiff                   1.7.3                h232476a_2    conda-forge
hdf4                      4.2.15               h5557f11_7    conda-forge
hdf5                      1.14.3          nompi_hb2c4d47_109    conda-forge
icu                       75.1                 he0c23c2_0    conda-forge
intel-openmp              2024.2.1          h57928b3_1083    conda-forge
kealib                    1.5.3                h6c43f9b_2    conda-forge
krb5                      1.21.3               hdf4eb48_0    conda-forge
lcms2                     2.17                 hbcf6048_0    conda-forge
lerc                      4.0.0                h6470a55_1    conda-forge
libabseil                 20240722.0      cxx17_h4eb7d71_4    conda-forge
libaec                    1.1.4                h20038f6_0    conda-forge
libarchive                3.7.7                h88ece9c_0    conda-forge
libblas                   3.9.0           32_h641d27c_mkl    conda-forge
libcblas                  3.9.0           32_h5e41251_mkl    conda-forge
libcrc32c                 1.1.2                h0e60522_0    conda-forge
libcurl                   8.14.1               h88aaa65_0    conda-forge
libdeflate                1.21                 h2466b09_0    conda-forge
libexpat                  2.7.1                hac47afa_0    conda-forge
libffi                    3.4.6                h537db12_1    conda-forge
libflang                  20.1.8               hac47afa_0    conda-forge
libfreetype               2.13.3               h57928b3_1    conda-forge
libfreetype6              2.13.3               h0b5ce68_1    conda-forge
libgdal                   3.8.5               h7e7fdb3_16    conda-forge
libglib                   2.84.1               h7025463_0    conda-forge
libgoogle-cloud           2.31.0               h07d40e7_0    conda-forge
libgoogle-cloud-storage   2.31.0               he5eb982_0    conda-forge
libgrpc                   1.67.1               h7aa3b8a_0    conda-forge
libhwloc                  2.11.2          default_h88281d1_1002    conda-forge
libiconv                  1.18                 h135ad9c_1    conda-forge
libintl                   0.22.5               h5728263_3    conda-forge
libjpeg-turbo             3.1.0                h2466b09_0    conda-forge
libkml                    1.3.0             h538826c_1021    conda-forge
liblapack                 3.9.0           32_h1aa476e_mkl    conda-forge
liblzma                   5.8.1                h2466b09_2    conda-forge
liblzma-devel             5.8.1                h2466b09_2    conda-forge
libnetcdf                 4.9.2           nompi_h008f77d_116    conda-forge
libpng                    1.6.50               h7351971_1    conda-forge
libpq                     16.9                 hddc24e7_0    conda-forge
libprotobuf               5.28.2               hcaed137_0    conda-forge
libre2-11                 2024.07.02           h4eb7d71_2    conda-forge
librttopo                 1.1.0               h6c42fcb_16    conda-forge
libspatialite             5.1.0                hab0cb6d_9    conda-forge
libsqlite                 3.50.4               hf5d6505_0    conda-forge
libssh2                   1.11.1               h9aa295b_0    conda-forge
libtiff                   4.7.0                hb151862_0    conda-forge
libwebp-base              1.6.0                h4d5522a_0    conda-forge
libwinpthread             12.0.0.r4.gg4f2fc60ca      h57928b3_9    conda-forge
libxml2                   2.13.8               h442d1da_0    conda-forge
libzip                    1.11.2               h3135430_0    conda-forge
libzlib                   1.3.1                h2466b09_2    conda-forge
lz4-c                     1.9.4                hcfcfb64_0    conda-forge
lzo                       2.10              h6a83c73_1002    conda-forge
minizip                   4.0.10               h9fa1bad_0    conda-forge
mkl                       2024.2.2            h66d3029_15    conda-forge
netcdf4                   1.7.2                    pypi_0    pypi
numpy                     2.2.6           py310h4987827_0    conda-forge
openjpeg                  2.5.3                h4d64b90_0    conda-forge
openssl                   3.5.1                h725018a_0    conda-forge
pcre2                     10.44                h99c9b8b_2    conda-forge
pip                       25.2               pyh8b19718_0    conda-forge
pixman                    0.46.4               hc614b68_0    conda-forge
poppler                   24.04.0              h747fd5a_0    conda-forge
poppler-data              0.4.12               hd8ed1ab_0    conda-forge
postgresql                16.9                 hff4f714_0    conda-forge
proj                      9.4.1                hd9569ee_1    conda-forge
python                    3.10.18         h8c5b53a_0_cpython    conda-forge
python_abi                3.10                    8_cp310    conda-forge
re2                       2024.07.02           haf4117d_2    conda-forge
setuptools                80.9.0             pyhff2d567_0    conda-forge
snappy                    1.2.2                h7fa0ca8_0    conda-forge
spdlog                    1.14.1               h9f2357e_1    conda-forge
sqlite                    3.50.4               hdb435a2_0    conda-forge
tbb                       2021.13.0            h62715c5_1    conda-forge
tiledb                    2.25.0              h16585dd_27    conda-forge
tk                        8.6.13               h2c6b04d_2    conda-forge
tzdata                    2025b                h78e105d_0    conda-forge
ucrt                      10.0.22621.0         h57928b3_1    conda-forge
uriparser                 0.9.8                h5a68840_0    conda-forge
vc                        14.3                h41ae7f8_31    conda-forge
vc14_runtime              14.44.35208         h818238b_31    conda-forge
vcomp14                   14.44.35208         h818238b_31    conda-forge
vs2015_runtime            14.44.35208         h38c0c73_31    conda-forge
wheel                     0.45.1             pyhd8ed1ab_1    conda-forge
xerces-c                  3.2.5                he0c23c2_2    conda-forge
xz                        5.8.1                h208afaa_2    conda-forge
xz-tools                  5.8.1                h2466b09_2    conda-forge
zlib                      1.3.1                h2466b09_2    conda-forge
zstd
Message has been deleted

zed li

unread,
Sep 3, 2025, 10:57:33 PMSep 3
to wrf-hydro_users, Aref Farhangmehr, wrf-hydro_users, zed li

Hi Aref,

Thank you so much for your helpful response!
The GDAL and Python version information you provided was exactly what I needed. I have now successfully set up the environment, and the script ran without any issues—generating both the Model_grid.tif and spatialweights_out.nc files.

I really appreciate your guidance on the shapefile modification as well. 

Thanks again for your kind support!

Best regards,
Zed Li

zed li

unread,
Sep 5, 2025, 6:00:38 PMSep 5
to wrf-hydro_users, Fatemeh Shirkhanloo

Hi Fatemeh,

Thank you so much for your detailed and helpful response!
I really appreciate you taking the time to share the exact environment setup and job submission instructions.

I followed the steps you provided and have successfully configured the software environment.  Your guidance was incredibly valuable and made the process smooth and straightforward.

Thanks again for your kind assistance!

Best regards,
Zed Li

Fatemeh Shirkhanloo

unread,
Sep 5, 2025, 6:00:43 PMSep 5
to zed li, wrf-hydro_users
Hi Zed,

Happy to hear that worked.
Good luck. 

cheers,
Fatemeh
Reply all
Reply to author
Forward
0 new messages