From 6b01c39541090119bbb4d45d19613688b28842a4 Mon Sep 17 00:00:00 2001 From: Zhang Yunjun Date: Sun, 16 Feb 2025 23:25:42 +0800 Subject: [PATCH] `autoget.ECMWFdload()`: bugfix for `snwe` in `numpy.int64` or `float` (#45) + `autoget.ECMWFdload()`: bugfix for `snwe` in `numpy.int64` or `float` (#45) + `README`: collapse dev install note --- README.md | 6 ++++++ src/pyaps3/autoget.py | 13 ++++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 5eba9fd..fe36197 100644 --- a/README.md +++ b/README.md @@ -37,6 +37,10 @@ apt install python3-pyaps3 #### b. Install the development version +

+

+

Click to expand for more details

+ The development version can be installed via `pip` as: ```bash @@ -56,6 +60,8 @@ Test the installation by running: ```bash python PyAPS/tests/test_calc.py ``` +
+

### 2. Account setup for [ERA5](https://www.ecmwf.int/en/forecasts/dataset/ecmwf-reanalysis-v5) diff --git a/src/pyaps3/autoget.py b/src/pyaps3/autoget.py index 8e42c8f..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}' @@ -238,4 +250,3 @@ def NARRdload(bdate,hr,filedir): urllib3.urlretrieve(weburl,dname) return flist -