-
Notifications
You must be signed in to change notification settings - Fork 28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PyAPS三次下载数据失败 #46
Comments
Potential solutionTo solve the bug, we need to address the issues related to API credentials, request syntax, and error handling. The primary plan involves ensuring that the API credentials are correctly set, updating the API request syntax to match the latest ECMWF CDS API requirements, and improving error handling to provide more informative messages and retries. Additionally, we need to fix the What is causing this bug?The bug is primarily caused by a combination of issues:
CodeHere are the implementation details and code snippets to address the issues:
# Example of improved error handling and retry logic
def ECMWFdload():
try:
# Existing logic for constructing API request
# ...
# Improved retry logic with exponential backoff
for attempt in range(max_retries):
try:
# Make API request
# ...
break # Exit loop if successful
except Exception as e:
if attempt < max_retries - 1:
time.sleep(2 ** attempt) # Exponential backoff
else:
raise e # Raise exception if all retries fail
except Exception as e:
print(f"Error downloading data: {e}")
# Additional logging or error handling How to replicate the bug
By following these steps, you should be able to replicate the bug and verify the effectiveness of the proposed solution. Click here to create a Pull Request with the proposed solution Files used for this task: Changes on src/pyaps3/ecmwfapi.pyAnalysis of
|
The following table describes the procedure:
******************** step - correct_troposphere ******************** Atmospheric correction using Weather Re-analysis dataset (PyAPS, Jolivet et al., 2011) Weather Re-analysis dataset: ERA5 tropo_pyaps3.py -f /root/work113/Stacks/mintpy/timeseries.h5 --model ERA5 -g /root/work113/Stacks/mintpy/inputs/geometryRadar.h5 -w /root/weather_data/ERA5 weather model: ERA5 - dry (hydrostatic) and wet delay weather directory: /root/weather_data/ERA5 output tropospheric delay time-series file: /root/work113/Stacks/mintpy/inputs/ERA5.h5 output corrected displacement time-series file: /root/work113/Stacks/mintpy/timeseries_ERA5.h5 read dates/time info from file: /root/work113/Stacks/mintpy/timeseries.h5 time of cloest available product: 10:00 UTC -------------------------------------------------------------------------------- Download global atmospheric model files... update mode: ON output file: /root/work113/Stacks/mintpy/inputs/ERA5.h5 1) output file either do NOT exist or is NOT newer than all GRIB files. run or skip: run -------------------------------------------------- downloading weather model data using PyAPS ... number of grib files to download: 24 -------------------------------------------------- filedir:/root/weather_data/ERA5/ERA5 INFO: You are using the latest ECMWF platform for downloading datasets: https://cds.climate.copernicus.eu/api url is None key is None url is None or key is None key;276bec02-357f-4d1d-85b1-33658fa1ec9b url:https://cds.climate.copernicus.eu/api url is None key is None url is None or key is None key;276bec02-357f-4d1d-85b1-33658fa1ec9b url:https://cds.climate.copernicus.eu/api 2025-02-24 13:51:43,991 INFO [2024-09-26T00:00:00] Watch our [Forum](https://forum.ecmwf.int/) for Announcements, news and other discussed topics. 2025-02-24 13:51:43,992 WARNING [2024-06-16T00:00:00] CDS API syntax is changed and some keys or parameter names may have also changed. To avoid requests failing, please use the "Show API request code" tool on the dataset Download Form to check you are using the correct syntax for your API request. Downloading 1 of 24: /root/weather_data/ERA5/ERA5/ERA5_N30_N40_E110_E120_20220104_10.grb {'product_type': ['reanalysis'], 'variable': ['geopotential', 'temperature', 'specific_humidity'], 'year': ['2022'], 'month': ['01'], 'day': ['04'], 'time': ['10:00'], 'pressure_level': ['1', '2', '3', '5', '7', '10', '20', '30', '50', '70', '100', '125', '150', '175', '200', '225', '250', '300', '350', '400', '450', '500', '550', '600', '650', '700', '750', '775', '800', '825', '850', '875', '900', '925', '950', '975', '1000'], 'data_format': 'grib', 'area': [40, 110, 30, 120]} WARNING: the 1 attempt to download failed, retry it. filedir:/root/weather_data/ERA5/ERA5 INFO: You are using the latest ECMWF platform for downloading datasets: https://cds.climate.copernicus.eu/api url is None key is None url is None or key is None key;276bec02-357f-4d1d-85b1-33658fa1ec9b url:https://cds.climate.copernicus.eu/api url is None key is None url is None or key is None key;276bec02-357f-4d1d-85b1-33658fa1ec9b url:https://cds.climate.copernicus.eu/api 2025-02-24 13:51:44,779 INFO [2024-09-26T00:00:00] Watch our [Forum](https://forum.ecmwf.int/) for Announcements, news and other discussed topics. 2025-02-24 13:51:44,783 WARNING [2024-06-16T00:00:00] CDS API syntax is changed and some keys or parameter names may have also changed. To avoid requests failing, please use the "Show API request code" tool on the dataset Download Form to check you are using the correct syntax for your API request. Downloading 1 of 24: /root/weather_data/ERA5/ERA5/ERA5_N30_N40_E110_E120_20220104_10.grb {'product_type': ['reanalysis'], 'variable': ['geopotential', 'temperature', 'specific_humidity'], 'year': ['2022'], 'month': ['01'], 'day': ['04'], 'time': ['10:00'], 'pressure_level': ['1', '2', '3', '5', '7', '10', '20', '30', '50', '70', '100', '125', '150', '175', '200', '225', '250', '300', '350', '400', '450', '500', '550', '600', '650', '700', '750', '775', '800', '825', '850', '875', '900', '925', '950', '975', '1000'], 'data_format': 'grib', 'area': [40, 110, 30, 120]} WARNING: the 2 attempt to download failed, retry it. filedir:/root/weather_data/ERA5/ERA5 INFO: You are using the latest ECMWF platform for downloading datasets: https://cds.climate.copernicus.eu/api url is None key is None url is None or key is None key;276bec02-357f-4d1d-85b1-33658fa1ec9b url:https://cds.climate.copernicus.eu/api url is None key is None url is None or key is None key;276bec02-357f-4d1d-85b1-33658fa1ec9b url:https://cds.climate.copernicus.eu/api 2025-02-24 13:51:45,563 INFO [2024-09-26T00:00:00] Watch our [Forum](https://forum.ecmwf.int/) for Announcements, news and other discussed topics. 2025-02-24 13:51:45,566 WARNING [2024-06-16T00:00:00] CDS API syntax is changed and some keys or parameter names may have also changed. To avoid requests failing, please use the "Show API request code" tool on the dataset Download Form to check you are using the correct syntax for your API request. Downloading 1 of 24: /root/weather_data/ERA5/ERA5/ERA5_N30_N40_E110_E120_20220104_10.grb {'product_type': ['reanalysis'], 'variable': ['geopotential', 'temperature', 'specific_humidity'], 'year': ['2022'], 'month': ['01'], 'day': ['04'], 'time': ['10:00'], 'pressure_level': ['1', '2', '3', '5', '7', '10', '20', '30', '50', '70', '100', '125', '150', '175', '200', '225', '250', '300', '350', '400', '450', '500', '550', '600', '650', '700', '750', '775', '800', '825', '850', '875', '900', '925', '950', '975', '1000'], 'data_format': 'grib', 'area': [40, 110, 30, 120]} ************************************************** WARNING: downloading failed for 3 times, stop trying and continue. ************************************************** -------------------------------------------------------------------------------- Calculate tropospheric delay and write to HDF5 file... update mode: ON output file: /root/work113/Stacks/mintpy/inputs/ERA5.h5 1) output file either do NOT exist or is NOT newer than all GRIB files. run or skip: run open geometry file: geometryRadar.h5 reading incidenceAngle data from file: /root/work113/Stacks/mintpy/inputs/geometryRadar.h5 ... reading height data from file: /root/work113/Stacks/mintpy/inputs/geometryRadar.h5 ... reading latitude data from file: /root/work113/Stacks/mintpy/inputs/geometryRadar.h5 ... reading longitude data from file: /root/work113/Stacks/mintpy/inputs/geometryRadar.h5 ... -------------------------------------------------- create HDF5 file: /root/work113/Stacks/mintpy/inputs/ERA5.h5 with w mode create dataset : date of |S1 in size of (0,) with compression = None create dataset : timeseries of <class 'numpy.float32'> in size of (0, 914, 1322) with compression = None close HDF5 file: /root/work113/Stacks/mintpy/inputs/ERA5.h5 -------------------------------------------------- calculating absolute delay for each date using PyAPS (Jolivet et al., 2011; 2014) ... number of grib files used: 0 Traceback (most recent call last): File "/root/tools/miniconda3/envs/insar/bin/smallbaselineApp.py", line 10, in <module> sys.exit(main()) File "/root/tools/miniconda3/envs/insar/lib/python3.10/site-packages/mintpy/cli/smallbaselineApp.py", line 209, in main run_smallbaselineApp(inps) File "/root/tools/miniconda3/envs/insar/lib/python3.10/site-packages/mintpy/smallbaselineApp.py", line 1155, in run_smallbaselineApp app.run(steps=inps.runSteps) File "/root/tools/miniconda3/envs/insar/lib/python3.10/site-packages/mintpy/smallbaselineApp.py", line 935, in run self.run_tropospheric_delay_correction(sname) File "/root/tools/miniconda3/envs/insar/lib/python3.10/site-packages/mintpy/smallbaselineApp.py", line 682, in run_tropospheric_delay_correction mintpy.cli.tropo_pyaps3.main(iargs) File "/root/tools/miniconda3/envs/insar/lib/python3.10/site-packages/mintpy/cli/tropo_pyaps3.py", line 166, in main run_tropo_pyaps3(inps) File "/root/tools/miniconda3/envs/insar/lib/python3.10/site-packages/mintpy/tropo_pyaps3.py", line 742, in run_tropo_pyaps3 calc_delay_timeseries(inps) File "/root/tools/miniconda3/envs/insar/lib/python3.10/site-packages/mintpy/tropo_pyaps3.py", line 672, in calc_delay_timeseries prog_bar = ptime.progressBar(maxValue=num_date, print_msg=~inps.verbose) File "/root/tools/miniconda3/envs/insar/lib/python3.10/site-packages/mintpy/objects/progress.py", line 84, in __init__ self.reset() File "/root/tools/miniconda3/envs/insar/lib/python3.10/site-packages/mintpy/objects/progress.py", line 90, in reset self.update_amount(0) # Build progress bar string File "/root/tools/miniconda3/envs/insar/lib/python3.10/site-packages/mintpy/objects/progress.py", line 109, in update_amount percentDone = (diffFromMin / float(self.span)) * 100.0 ZeroDivisionError: float division by zero
I had no problem downloading manually
import cdsapi
创建CDS API客户端
c = cdsapi.Client()
定义下载参数
years = ['2023']
months = ['12']
days = ['01']
times = ['10:00']
area = [40, 110, 30, 120] # 区域 [北, 西, 南, 东]
pressure_levels = ['1', '2', '3', '5', '7', '10', '20', '30', '50', '70', '100', '125', '150', '175', '200', '225', '250', '300', '350', '400', '450', '500', '550', '600', '650', '700', '750', '775', '800', '825', '850', '875', '900', '925', '950', '975', '1000']
variables = ['geopotential', 'temperature', 'specific_humidity']
product_type = 'reanalysis'
data_format = 'grib'
循环下载每个日期的数据
for year in years:
for month in months:
for day in days:
for time in times:
# 构建文件名
filename = f'ERA5_N30_N40_E110_E120_{year}{month}{day}_{time.replace(":", "")}.grb'
print(f'Downloading {filename}...')
But we can't identify his location
The text was updated successfully, but these errors were encountered: