我正在try 使用swmm_api包中的LID_USAGE为SWMM中的每个子汇流提取单独的LID设置.我遵循了https://markuspichler.gitlab.io/swmm_api/examples/how_to_add_LIDs.html的示例,然而,出现了一个错误.我想知道如何修复代码?我附上了SWMM模型供您参考,谢谢.

example SWMM model (input file)的售价为https://1drv.ms/u/s!AnVl_zW00EHemH5cu620m6vxqXdN?e=S5VSCA美元.我使用的是swmm-api 0.4.37.

from swmm_api import SwmmInput
from swmm_api.input_file.section_labels import SUBAREA,SUBCATCHMENTS,LID_CONTROLS,LID_USAGE
import numpy as np
import pandas as pd

inp = SwmmInput.read_file('Example2.inp')
inp.LID_CONTROLS  # LID_CONTROLS works smoothly!
inp.LID_USAGE     # LID_USAGE is not working...

enter image description here

inp.LID_USAGE
Traceback (most recent call last):

  File C:\ProgramData\miniconda3\envs\swmm\lib\site-packages\swmm_api\input_file\helpers.py:780 in from_inp_line
    return cls(*line_args)

TypeError: __init__() takes from 8 to 12 positional arguments but 17 were given


During handling of the above exception, another exception occurred:

Traceback (most recent call last):

  Cell In[6], line 1
    inp.LID_USAGE

  File C:\ProgramData\miniconda3\envs\swmm\lib\site-packages\swmm_api\input_file\inp.py:948 in LID_USAGE
    return self[LID_USAGE]

  File C:\ProgramData\miniconda3\envs\swmm\lib\site-packages\swmm_api\input_file\inp.py:193 in __getitem__
    self._convert_section(key)

  File C:\ProgramData\miniconda3\envs\swmm\lib\site-packages\swmm_api\input_file\inp.py:214 in _convert_section
    self._data[key] = convert_section(key, self._data[key], self._converter)

  File C:\ProgramData\miniconda3\envs\swmm\lib\site-packages\swmm_api\input_file\helpers.py:939 in convert_section
    return section_.from_inp_lines(lines)

  File C:\ProgramData\miniconda3\envs\swmm\lib\site-packages\swmm_api\input_file\helpers.py:849 in from_inp_lines
    return cls.create_section(lines)

  File C:\ProgramData\miniconda3\envs\swmm\lib\site-packages\swmm_api\input_file\helpers.py:831 in create_section
    sec.add_inp_lines(lines_iter)

  File C:\ProgramData\miniconda3\envs\swmm\lib\site-packages\swmm_api\input_file\helpers.py:360 in add_inp_lines
    self.add_multiple(*self._section_object._convert_lines(multi_line_args))

  File C:\ProgramData\miniconda3\envs\swmm\lib\site-packages\swmm_api\input_file\helpers.py:866 in _convert_lines
    yield cls.from_inp_line(*line_args)

  File C:\ProgramData\miniconda3\envs\swmm\lib\site-packages\swmm_api\input_file\helpers.py:782 in from_inp_line
    raise TypeError(f'{e} | {cls.__name__}{line_args}\n\n__init__{signature(cls.__init__)}\n\n{getdoc(cls.__init__)}')

TypeError: __init__() takes from 8 to 12 positional arguments but 17 were given | LIDUsage('2', 'Bioretention', '1', '5000', '0', '10', '70', '1', '"E:\\Python', 'Examples\\SWMM', 'Calibration\\Example-Yang\\For', 'Calibration\\LID', 'Reports\\S2', 'Bioretention.txt"', '*', '0')

__init__(self, subcatchment, lid, n_replicate, area, width, saturation_init, impervious_portion, route_to_pervious=0, fn_lid_report=nan, drain_to=nan, from_pervious=nan)

Assignment of LID controls to subcatchments.

Args:
    subcatchment (str): Name of the subcatchment using the LID process.
    lid (str): Name of an LID process defined in the [LID_CONTROLS] section.
    n_replicate (int): Number of replicate LID units deployed.
    area (float): Area of each replicate unit (ft^2 or m^2 ).
    width (float): Width of the outflow face of each identical LID unit (in ft or m). This
        parameter applies to roofs, pavement, trenches, and swales that use
        overland flow to convey surface runoff off of the unit. It can be set to 0 for
        other LID processes, such as bio-retention cells, rain gardens, and rain
        barrels that simply spill any excess captured runoff over their berms.
    saturation_init (float): For bio-retention cells, rain gardens, and green roofs this is the degree to
        which the unit's soil is initially filled with water (0 % saturation
        corresponds to the wilting point moisture content, 100 % saturation has
        the moisture content equal to the porosity). The storage zone beneath
        the soil zone of the cell is assumed to be completely dry. For other types
        of LIDs it corresponds to the degree to which their storage zone is
        initially filled with water
    impervious_portion (float): Percent of the impervious portion of the subcatchment’s non-LID area
        whose runoff is treated by the LID practice. (E.g., if rain barrels are used
        to capture roof runoff and roofs represent 60% of the impervious area,
        then the impervious area treated is 60%). If the LID unit treats only direct
        rainfall, such as with a green roof, then this value should be 0. If the LID
        takes up the entire subcatchment then this field is ignored.
    route_to_pervious (int): A value of 1 indicates that the surface and drain flow from the LID unit
        should be routed back onto the pervious area of the subcatchment that
        contains it. This would be a common choice to make for rain barrels,
        rooftop disconnection, and possibly green roofs. The default value is 0.
    fn_lid_report (str): Optional name of a file to which detailed time series results for the LID
        will be written. Enclose the name in double quotes if it contains spaces
        and include the full path if it is different than the SWMM input file path.
        Use ‘*’ if not applicable and an entry for DrainTo follows
    drain_to (str): Optional name of subcatchment or node that receives flow from the unit’s
        drain line, if different from the outlet of the subcatchment that the LID is
        placed in.
    from_pervious (float): optional percent of the pervious portion of the subcatchment’s non-LID area
        whose runoff is treated by the LID practice. The default value is 0

.

推荐答案

此错误消息说明了问题所在:

TypeError: __init__() takes from 8 to 12 positional arguments but 17 were given

您提供的信息是程序不知道如何解析的,因为它只为8-12个参数设计.为什么要输入5个额外的参数-它们是用来做什么的?

您为输入文件提供的输入太多.您可以从第296页的documentation中找到输入文件的详细信息.以下是推荐的参数:

Subcat, LID, Number, Area, Width, InitSat, FromImp, ToPerv, RptFile, DrainTo

下面是如何为输入文件构建输入的示例:

[LID_USAGE]
;; assigning lid controls to subcatchments
;;Subcatchment   LID Process      Number  Area    Width   InitSat  FromImp  ToPerv  RptFile                 DrainTo  FromPerv
Sub1             BioCell          5       500     100     0        0        0       "example.txt"           *        0

EDIT:

上面的 comments 是准确的,但解决方案没有正确诊断您的问题.查看文件后,您的RptFile的文件路径如下所示:

"E:\Python Examples\SWMM Calibration\Example-Yang\For Calibration\LID Reports\S2 Bioretention.txt"

此处显示:

enter image description here

Python不能正确地解释这种路径,并且经常错误地将其拆分成多行;这就是为什么您会收到关于太多参数的错误.如果Python将其解释为单路径,则不会收到该错误.

这就是解决方案:调整文件路径使其不包含空格,然后相应地将其复制粘贴到您的输入文件中.我使用了以下文件路径:

/Users/USER/Desktop/swmm_example/example.txt

并且没有任何问题地运行您的代码.

Python相关问答推荐

对Numpy函数进行载体化

TARete错误:类型对象任务没有属性模型'

如何使用Python将工作表从一个Excel工作簿复制粘贴到另一个工作簿?

在线条上绘制表面

改进大型数据集的框架性能

在嵌套span下的span中擦除信息

Polars asof在下一个可用日期加入

AES—256—CBC加密在Python和PHP中返回不同的结果,HELPPP

基于Scipy插值法的三次样条系数

基于多个数组的多个条件将值添加到numpy数组

BeautifulSoup:超过24个字符(从a到z)的迭代失败:降低了首次深入了解数据集的复杂性:

计算机找不到已安装的库'

Js的查询结果可以在PC Chrome上显示,但不能在Android Chrome、OPERA和EDGE上显示,而两者都可以在Firefox上运行

Pandas:计数器的滚动和,复位

python3中np. divide(x,y)和x/y有什么区别?'

上传文件并使用Panda打开时的Flask 问题

从列表中分离数据的最佳方式

在不中断格式的情况下在文件的特定部分插入XML标签

我可以同时更改多个图像吗?

如何在不遇到IndexError的情况下将基数10的整数转换为基数80?