USEPA / WNTR

An EPANET compatible python package to simulate and analyze water distribution networks under disaster scenarios.
Other
320 stars 185 forks source link

Defaults > Hydraulics > Pattern #333

Open s-u-m-a-n-t-h opened 1 year ago

s-u-m-a-n-t-h commented 1 year ago

Summary

In epanet, under project defaults>Hydraulics>Pattern , if the value is a string like 'time' or if it is a number that's not '1' , the wntr io does not allow importing the file. I found the following lines in wntr io relevant to this issue :

ln no 235 : class InpFile(object): """ EPANET INP file reader and writer class. This class provides read and write functionality for EPANET INP files. The EPANET Users Manual provides full documentation for the INP file format. """ . . . .

ln no 342 : self._read_patterns() . . . . ln no 973: def _read_patterns(self): _patterns = OrderedDict() for lnum, line in self.sections['[PATTERNS]']:

        # read the lines for each pattern -- patterns can be multiple lines of arbitrary length

        line = line.split(';')[0]
        current = line.split()
        if current == []:
            continue
        pattern_name = current[0]
        if pattern_name not in _patterns:
            _patterns[pattern_name] = []
            for i in current[1:]:
                _patterns[pattern_name].append(float(i))
        else:
            for i in current[1:]:
                _patterns[pattern_name].append(float(i))
    for pattern_name, pattern in _patterns.items():
        # add the patterns to the water newtork model
        self.wn.add_pattern(pattern_name, pattern)
    **if not self.wn.options.hydraulic.pattern and '1' in _patterns.keys():
        # If there is a pattern called "1", then it is the default pattern if no other is supplied
        self.wn.options.hydraulic.pattern = '1'
    elif self.wn.options.hydraulic.pattern not in _patterns.keys():

        # Sanity check - if the default pattern does not exist and it is not '1' then balk
        # If default is '1' but it does not exist, then it is constant
        # Any other default that does not exist is an error

        if self.wn.options.hydraulic.pattern is not None and self.wn.options.hydraulic.pattern != '1':
            raise KeyError('Default pattern {} is undefined'.format(self.wn.options.hydraulic.pattern))**
        self.wn.options.hydraulic.pattern = None

Environment

Python version, WNTR version, operating system

Example

s-u-m-a-n-t-h commented 1 year ago

Any response to this please ?

dbhart commented 1 year ago

I'm sorry, I totally thought I had responded, and it looks like it never sent.

Can you provide us with just the [PATTERNS] section (or the part of it that is causing issues) that your .inp file is using? We are having trouble replicating the error, and that would probably help us get there quicker. We definitely don't want the whole file or proprietary data, but if you can give some of the patterns section lines, it would be very helpful. Thanks

dbhart commented 1 year ago

@s-u-m-a-n-t-h can I see the options section of the .inp file that you got out of EPANET that has the default pattern? Thanks!

s-u-m-a-n-t-h commented 1 year ago

@dbhart Please find below the [OPTIONS] section of the .inp file when opened with a text editor :

[OPTIONS] Units LPS Headloss H-W Specific Gravity 1 Viscosity 1 Trials 500 Accuracy 0.001 Unbalanced Continue 10 Pattern time Demand Multiplier 1.0 Emitter Exponent 0.5 Quality Cloro mg/L Diffusivity 1 Tolerance 0.01

Please note that it says time against Pattern.

s-u-m-a-n-t-h commented 1 year ago

Hi @dbhart , were you able to look at the options section of my input file ?