使用ulmo usgs.nwis.get_site_data函数获取USGS数据时遇ValueError
Hey there, I’ve run into this exact issue with USGS parameter 80155 (suspended sediment discharge) before—let’s break down how to fix it.
The Root Cause
USGS uses different statistical methods to calculate suspended sediment discharge (parameter code 80155) for daily data, and ulmo requires you to explicitly specify which method you want. Your initial attempt to use methods='all' didn’t work because you used the wrong parameter name—ulmo expects method_code, not methods.
Step-by-Step Solution
First, check all available methods for your site and parameter
Run this code to list every valid method code for site08332010and parameter80155:import ulmo methods = ulmo.usgs.nwis.get_methods('08332010', parameter_code='80155') print(methods)This will return a dictionary with method codes (like
00003) as keys and their descriptions (e.g., "Mean") as values.Choose either a specific method or fetch all methods
- Option 1: Use a specific method code
Pick one of the codes from the output above and pass it tomethod_code:ulmo.usgs.nwis.get_site_data( '08332010', parameter_code='80155', service="daily", start='1969-10-01', end='2016-09-30', method_code='00003' # Replace with your preferred method code ) - Option 2: Fetch all available methods
Correct the parameter name tomethod_code='all'(this is what you tried to do earlier, but with the wrong parameter key):ulmo.usgs.nwis.get_site_data( '08332010', parameter_code='80155', service="daily", start='1969-10-01', end='2016-09-30', method_code='all' )
- Option 1: Use a specific method code
Why This Works
The original error occurred because ulmo couldn’t resolve which calculation method to use for 80155. By either specifying a concrete method code or using method_code='all' (with the correct parameter name), you’re telling ulmo exactly how to handle the multiple available methods for this parameter.
内容的提问来源于stack exchange,提问作者John Yang

