首页 > 解决方案 > 使用 ulmo usgs.nwis.get_site_data 函数时出现错误

问题描述

尝试使用 ulmo 库从 USGS 检索沉积物排放数据时出现错误

ulmo.usgs.nwis.get_site_data('08332010', parameter_code='80155', \
service="daily", start='1969-10-01', end='2016-09-30')

它返回

   processing data from request: https://waterservices.usgs.gov/nwis/dv/? 
   format=waterml&site=08332010&parameterCd=80155&startDT=1969-10- 
   01&endDT=2016-09-30
   ------------------------------------------------------------------------ 
   ValueError                         Traceback (most recent call last)
   <ipython-input-184-3ae1371577c1> in <module>()
   ----> 1 df = ulmo.usgs.nwis.get_site_data('08332010', 
   parameter_code='80155', service="daily", start='1969-10-01', end='2016- 
   09-30')

   /usr/local/lib/python3.6/dist-packages/ulmo/usgs/nwis/core.py in 
   get_site_data(site_code, service, parameter_code, statistic_code, start, 
   end, period, modified_since, input_file, methods, **kwargs)
   259         url_params.update(kwargs)
   260         values = _get_site_values(service, url_params, 
   input_file=input_file,
   --> 261                                   methods=methods)
   262     else:
   263         kw = dict(parameter_code=parameter_code, 
   statistic_code=statistic_code,

   /usr/local/lib/python3.6/dist-packages/ulmo/usgs/nwis/core.py in 
   _get_site_values(service, url_params, input_file, methods)
   336     with _open_input_file(input_file) as content_io:
    337         data_dict = wml.parse_site_values(content_io, query_isodate,
--> 338             methods=methods)
    339 
    340         for variable_dict in list(data_dict.values()):

/usr/local/lib/python3.6/dist-packages/ulmo/waterml/v1_1.py in parse_site_values(content_io, query_isodate, methods)
     14     return common.parse_site_values(
     15         content_io, WATERML_V1_1_NAMESPACE, query_isodate=query_isodate,
---> 16         methods=methods)
     17 
     18 

/usr/local/lib/python3.6/dist-packages/ulmo/waterml/common.py in parse_site_values(content_io, namespace, query_isodate, methods)
     41                     raise ValueError(
     42                         'found more than one method for %s. need to specify'
---> 43                         'specify code or "all".' % variable['code'])
     44                 values_element = values_elements[0]
     45                 values = _parse_values(values_element, namespace)

ValueError: found more than one method for 80155. need to specifyspecify code or "all".

我为所有人指定了该方法,但仍然遇到相同的错误。关于如何解决它的任何想法?

标签: python

解决方案


参见 Ulmo 的文档:

methods: ''None'', str 或 Python dict 如果没有(默认),则假定每个参数都有一个方法。如果遇到多个方法 ID,则会引发错误。如果是 str,这是请求参数的方法 id,如果事先不知道方法 id,则可以使用“all”。如果是 dict,则提供 parameter_code 到方法 id 映射。参数的方法 ID 特定于站点。

所以添加methods = "all"


推荐阅读