NCAR / wrf-python

A collection of diagnostic and interpolation routines for use with output from the Weather Research and Forecasting (WRF-ARW) Model.
https://wrf-python.readthedocs.io
Apache License 2.0
410 stars 155 forks source link

wrf-python producing spurious results #207

Closed freecodegaku closed 1 year ago

freecodegaku commented 1 year ago

Running wrf-python with python=>3.11 produces different results to those from ncl e.g for example when using Python 3.11.3 on [https://www.dropbox.com/s/szxm475isnlnufh/wrfout_d01_1989-04-28_01?dl=0](https://www.dropbox.com/s/szxm475isnlnufh/wrfout_d01_1989-04-28_01?dl=0](https://www.dropbox.com/s/szxm475isnlnufh/wrfout_d01_1989-04-28_01?dl=0](https://www.dropbox.com/s/szxm475isnlnufh/wrfout_d01_1989-04-28_01?dl=0)

import wrf as wrf
from netCDF4 import Dataset as dataset
import numpy as np
f = "wrfout_d01_1989-04-28_01";

ds = dataset(f)
x = wrf.getvar(ds, "tk", timeidx = wrf.ALL_TIMES)
print(np.min(x), " ", np.max(x))

gives a min of 121.18885 and max of 495.5703. While using ncl

begin
    f = "wrfout_d01_1989-04-28_01";
    a = addfile(f, "r")
    x = wrf_user_getvar(a, "tk", -1)
    print(min(x))
    print(max(x))
end

produces a min of 185.3759 and max 316.4777.

Running the python code with python version <=3.10.10 produces the same results as ncl i.e. 185.3759 and max 316.4777.

erogluorhan commented 1 year ago

Hi @freecodegaku thanks for reporting this; it's interesting! We will look into this as soon as we can.

kafitzgerald commented 1 year ago

Just noting that I was able to replicate this issue.

I can try to look into this some this week, but we should probably pin to Python <3.11 for the time being.

fraDMbo98 commented 1 year ago

I run the example script in the reference guide (https://wrf-python.readthedocs.io/en/latest/plot.html) using the same netcdf file used there. I got this unphysical result: slp_us

I used: python 3.10.9 netcdf4 1.6.3 matplotlib 3.7.1 cartopy 0.21.1

I tried both on windows 10 and linux, obtaining the same result.

Probably it's something related to the bug observed by @freecodegaku, even if I got this with a version of python<3.11.

sinan0310 commented 1 year ago

I run the example script in the reference guide (https://wrf-python.readthedocs.io/en/latest/plot.html) using the same netcdf file used there. I got this unphysical result: slp_us

I used: python 3.10.9 netcdf4 1.6.3 matplotlib 3.7.1 cartopy 0.21.1

I tried both on windows 10 and linux, obtaining the same result.

Probably it's something related to the bug observed by @freecodegaku, even if I got this with a version of python<3.11.

Had the same issue, Installed python3.9 and for now everything seems fine

Cat7102 commented 1 year ago

I run the example script in the reference guide (https://wrf-python.readthedocs.io/en/latest/plot.html) using the same netcdf file used there. I got this unphysical result: slp_us

I used: python 3.10.9 netcdf4 1.6.3 matplotlib 3.7.1 cartopy 0.21.1

I tried both on windows 10 and linux, obtaining the same result.

Probably it's something related to the bug observed by @freecodegaku, even if I got this with a version of python<3.11.

I also met this problem with python3.9, wrf-python1.4.1, netcdf1.6.2, and I guess the main reason is the "slp" in getvar function. Then I create a environment with python3.7, the problem solved.

uegajde commented 1 year ago

the reason looks like to be numpy/numpy#23651 is your numpy version 1.24.3?

kafitzgerald commented 1 year ago

Thanks for pointing that out.

I haven't time to dig into this much, but that aligns with my current suspicions as well.

kafitzgerald commented 1 year ago

the reason looks like to be numpy/numpy#23651 is your numpy version 1.24.3?

Looks like that's the case. Pinning numpy fixes this issue and the additional/related test failures I see. Numpy just released 1.24.3 less than two months ago and dropped support for Python 3.7 so older environments and Python versions likely wouldn't be impacted.

I'll throw in a PR to pin numpy.

@freecodegaku, @Cat7102, @sinan0310 if you're still having issues with a numpy version other than 1.24.3, please let us know. Thanks for the bug report!