From c9bf9e598bd7a3ec3c5b6977db893799f40a71d9 Mon Sep 17 00:00:00 2001 From: Zhang Yunjun Date: Thu, 13 Feb 2025 23:33:43 +0800 Subject: [PATCH] bugfix for snwe in numpy.int64 or float --- src/pyaps3/autoget.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/pyaps3/autoget.py b/src/pyaps3/autoget.py index 78c2a91..7b41d9f 100644 --- a/src/pyaps3/autoget.py +++ b/src/pyaps3/autoget.py @@ -10,6 +10,7 @@ import os.path import configparser +import math import urllib3 import cdsapi import pyaps3 as pa @@ -40,6 +41,17 @@ def ECMWFdload(bdate,hr,filedir,model='ERA5',datatype='fc',humidity='Q',snwe=Non #------------------------------------------- # Initialize + # Ensure snwe is in native int, not numpy.int32/64 or float etc. + # Note that even though cdsapi support float, we still use int + # for file naming simplicity at the cost of slightly larger file size. + if snwe is not None: + s, n, w, e = snwe + snwe = (math.floor(s), math.ceil(n), math.floor(w), math.ceil(e)) + snwe = tuple(int(x) for x in snwe) + if (s, n, w, e) != snwe: + print(f'WARNING: input area ({s}, {n}, {w}, {e}) is NOT exact integer,', + f'\n\tconvert to its bounding box in integer {snwe} and continue.') + # Check data assert model in ('ERA5', 'ERAINT', 'HRES'), f'Unknown model for ECMWF: {model}'