cdsapi在尝试使用Python脚本下载ERA5数据时出现错误。

huangapple go评论147阅读模式
英文:

cdsapi error while trying to download era5 data using python script

问题

你正在尝试使用CDS API下载ERA5最佳路径数据(每小时,单层),但遇到了一些错误。以下是您提供的脚本和错误信息:

脚本部分:

  1. import cdsapi
  2. import numpy
  3. import urllib3
  4. urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
  5. c = cdsapi.Client()
  6. # Request parameters
  7. for year in range(1945, 2022):
  8. c.retrieve(
  9. 'reanalysis-era5-single-levels',
  10. {
  11. 'variable': 'total_precipitation',
  12. 'format': 'netcdf',
  13. 'year': str(year),
  14. 'month': [
  15. '01', '02', '03',
  16. '04', '05', '06',
  17. '07', '08', '09',
  18. '10', '11', '12',
  19. ],
  20. 'day': [
  21. '01', '02', '03',
  22. '04', '05', '06',
  23. '07', '08', '09',
  24. '10', '11', '12',
  25. '13', '14', '15',
  26. '16', '17', '18',
  27. '19', '20', '21',
  28. '22', '23', '24',
  29. '25', '26', '27',
  30. '28', '29', '30',
  31. '31',
  32. ],
  33. 'time': [
  34. '00:00', '01:00', '02:00',
  35. '03:00', '04:00', '05:00',
  36. '06:00', '07:00', '08:00',
  37. '09:00', '10:00', '11:00',
  38. '12:00', '13:00', '14:00',
  39. '15:00', '16:00', '17:00',
  40. '18:00', '19:00', '20:00',
  41. '21:00', '22:00', '23:00',
  42. ],
  43. 'area': [90, -180, -90, 180], # 全球范围
  44. },
  45. f'era5_{year}_precipitation.nc',
  46. )

错误信息部分:

  1. 2023-05-14 17:42:20,413 INFO 欢迎使用CDS
  2. 2023-05-14 17:42:20,414 INFO 发送请求至https://cds.climate.copernicus.eu/api/v2/resources/reanalysis-era5-single-levels
  3. 2023-05-14 17:42:20,702 INFO 请求已排队
  4. 2023-05-14 17:42:21,986 INFO 请求失败
  5. 2023-05-14 17:42:21,986 ERROR 消息:您提交的请求无效
  6. 2023-05-14 17:42:21,986 ERROR 原因:Mars服务器任务以错误完成;UserError:月份重复值:1945-01 [mars];错误代码为-2;请求失败;报告了一些错误(最后一个错误为-2
  7. ...(更多错误信息)

您想知道如何在没有这些错误的情况下下载数据。

英文:

I'm trying to download ERA5 best-track data (hourly, single level) with CDS API.
I'm totally new to get this kind of dataset, so I've running into bunch of errors like this.

This is the script:

  1. import cdsapi
  2. import numpy
  3. import urllib3
  4. urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
  5. c = cdsapi.Client()
  6. # Request parameters
  7. for year in range(1945, 2022):
  8. c.retrieve(
  9. 'reanalysis-era5-single-levels',
  10. {
  11. 'variable': 'total_precipitation',
  12. 'format': 'netcdf',
  13. 'year': str(year),
  14. 'month': [
  15. '01', '02', '03',
  16. '04', '05', '06',
  17. '07', '08', '09',
  18. '10', '11', '12',
  19. ],
  20. 'day': [
  21. '01', '02', '03',
  22. '04', '05', '06',
  23. '07', '08', '09',
  24. '10', '11', '12',
  25. '13', '14', '15',
  26. '16', '17', '18',
  27. '19', '20', '21',
  28. '22', '23', '24',
  29. '25', '26', '27',
  30. '28', '29', '30',
  31. '31',
  32. ],
  33. 'time': [
  34. '00:00', '01:00', '02:00',
  35. '03:00', '04:00', '05:00',
  36. '06:00', '07:00', '08:00',
  37. '09:00', '10:00', '11:00',
  38. '12:00', '13:00', '14:00',
  39. '15:00', '16:00', '17:00',
  40. '18:00', '19:00', '20:00',
  41. '21:00', '22:00', '23:00',
  42. ],
  43. 'area': [90, -180, -90, 180], # Global
  44. },
  45. f'era5_{year}_precipitation.nc',
  46. )

And getting same error like this.

  1. 2023-05-14 17:42:20,413 INFO Welcome to the CDS
  2. 2023-05-14 17:42:20,414 INFO Sending request to https://cds.climate.copernicus.eu/api/v2/resources/reanalysis-era5-single-levels
  3. 2023-05-14 17:42:20,702 INFO Request is queued
  4. 2023-05-14 17:42:21,986 INFO Request is failed
  5. 2023-05-14 17:42:21,986 ERROR Message: the request you have submitted is not valid
  6. 2023-05-14 17:42:21,986 ERROR Reason: Mars server task finished in error; UserError: Duplicate value for month: 1945-01 [mars]; Error code is -2; Request failed; Some errors reported (last error -2)
  7. 2023-05-14 17:42:21,986 ERROR Traceback (most recent call last):
  8. 2023-05-14 17:42:21,986 ERROR File "/opt/cdstoolbox/cdscompute/cdscompute/cdshandlers/services/handler.py", line 59, in handle_request
  9. 2023-05-14 17:42:21,986 ERROR result = cached(context.method, proc, context, context.args, context.kwargs)
  10. 2023-05-14 17:42:21,986 ERROR File "/opt/cdstoolbox/cdscompute/cdscompute/caching.py", line 108, in cached
  11. 2023-05-14 17:42:21,986 ERROR result = proc(context, *context.args, **context.kwargs)
  12. 2023-05-14 17:42:21,986 ERROR File "/opt/cdstoolbox/cdscompute/cdscompute/services.py", line 124, in __call__
  13. 2023-05-14 17:42:21,986 ERROR return p(*args, **kwargs)
  14. 2023-05-14 17:42:21,987 ERROR File "/opt/cdstoolbox/cdscompute/cdscompute/services.py", line 60, in __call__
  15. 2023-05-14 17:42:21,987 ERROR return self.proc(context, *args, **kwargs)
  16. 2023-05-14 17:42:21,987 ERROR File "/home/cds/cdsservices/services/mars/mars.py", line 48, in internal
  17. 2023-05-14 17:42:21,987 ERROR return mars(context, request, **kwargs)
  18. 2023-05-14 17:42:21,987 ERROR File "/home/cds/cdsservices/services/mars/mars.py", line 20, in mars
  19. 2023-05-14 17:42:21,987 ERROR execute_mars(context, requests, info)
  20. 2023-05-14 17:42:21,987 ERROR File "/home/cds/cdsservices/services/mars/execute_mars.py", line 20, in execute_mars
  21. 2023-05-14 17:42:21,987 ERROR exception=MarsException)
  22. 2023-05-14 17:42:21,987 ERROR File "/opt/cdstoolbox/cdscompute/cdscompute/context.py", line 209, in run_command
  23. 2023-05-14 17:42:21,987 ERROR raise exception(call, proc.returncode, output)
  24. 2023-05-14 17:42:21,987 ERROR home.cds.cdsservices.services.mars.__init__.py.exceptions.MarsException: Mars server task finished in error; UserError: Duplicate value for month: 1945-01 [mars]; Error code is -2; Request failed; Some errors reported (last error -2)
  25. ---------------------------------------------------------------------------
  26. Exception Traceback (most recent call last)
  27. ~/RSCH/Globe/data2/ERA5_rainfall.py in <module>
  28. 9 # Request parameters
  29. 10 for year in range(1945, 2022):
  30. ---> 11 c.retrieve(
  31. 12 'reanalysis-era5-single-levels',
  32. 13 {
  33. /usr/local/miniconda3/lib/python3.8/site-packages/cdsapi/api.py in retrieve(self, name, request, target)
  34. 346
  35. 347 def retrieve(self, name, request, target=None):
  36. --> 348 result = self._api("%s/resources/%s" % (self.url, name), request, "POST")
  37. 349 if target is not None:
  38. 350 result.download(target)
  39. /usr/local/miniconda3/lib/python3.8/site-packages/cdsapi/api.py in _api(self, url, request, method)
  40. 504 break
  41. 505 self.error(" %s", n)
  42. --> 506 raise Exception(
  43. 507 "%s. %s."
  44. 508 % (reply["error"].get("message"), reply["error"].get("reason"))
  45. Exception: the request you have submitted is not valid. Mars server task finished in error; UserError: Duplicate value for month: 1945-01 [mars]; Error code is -2; Request failed; Some errors reported (last error -2).

I really don't know what the problem is here. How can I download the data without this error?

答案1

得分: 1

你在调用中没有定义产品类型。添加这一部分应该可以解决问题,至少对我来说是这样的:

  1. for year in range(1945, 2022):
  2. c.retrieve(
  3. 'reanalysis-era5-single-levels',
  4. {
  5. 'product_type': 'reanalysis',
  6. 'variable': 'total_precipitation',
  7. 'format': 'netcdf',
  8. 'year': str(year),
  9. 'month': [
  10. '01', '02', '03',
  11. '04', '05', '06',
  12. '07', '08', '09',
  13. '10', '11', '12',
  14. ],
  15. 'day': [
  16. '01', '02', '03',
  17. '04', '05', '06',
  18. '07', '08', '09',
  19. '10', '11', '12',
  20. '13', '14', '15',
  21. '16', '17', '18',
  22. '19', '20', '21',
  23. '22', '23', '24',
  24. '25', '26', '27',
  25. '28', '29', '30',
  26. '31',
  27. ],
  28. 'time': [
  29. '00:00', '01:00', '02:00',
  30. '03:00', '04:00', '05:00',
  31. '06:00', '07:00', '08:00',
  32. '09:00', '10:00', '11:00',
  33. '12:00', '13:00', '14:00',
  34. '15:00', '16:00', '17:00',
  35. '18:00', '19:00', '20:00',
  36. '21:00', '22:00', '23:00',
  37. ],
  38. 'area': [90, -180, -90, 180], # 全球范围
  39. },
  40. f'era5_{year}_precipitation.nc',
  41. )
英文:

You have not defined the product type in your call. Adding it in should work, at least it does for me:

  1. for year in range(1945, 2022):
  2. c.retrieve(
  3. 'reanalysis-era5-single-levels',
  4. {
  5. 'product_type': 'reanalysis',
  6. 'variable': 'total_precipitation',
  7. 'format': 'netcdf',
  8. 'year': str(year),
  9. 'month': [
  10. '01', '02', '03',
  11. '04', '05', '06',
  12. '07', '08', '09',
  13. '10', '11', '12',
  14. ],
  15. 'day': [
  16. '01', '02', '03',
  17. '04', '05', '06',
  18. '07', '08', '09',
  19. '10', '11', '12',
  20. '13', '14', '15',
  21. '16', '17', '18',
  22. '19', '20', '21',
  23. '22', '23', '24',
  24. '25', '26', '27',
  25. '28', '29', '30',
  26. '31',
  27. ],
  28. 'time': [
  29. '00:00', '01:00', '02:00',
  30. '03:00', '04:00', '05:00',
  31. '06:00', '07:00', '08:00',
  32. '09:00', '10:00', '11:00',
  33. '12:00', '13:00', '14:00',
  34. '15:00', '16:00', '17:00',
  35. '18:00', '19:00', '20:00',
  36. '21:00', '22:00', '23:00',
  37. ],
  38. 'area': [90, -180, -90, 180], # Global
  39. },
  40. f'era5_{year}_precipitation.nc',
  41. )

huangapple
  • 本文由 发表于 2023年5月14日 16:48:01
  • 转载请务必保留本文链接:https://go.coder-hub.com/76246602.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定