Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Instantiate a model from a URL that points to a INP file #233

Open
aerispaha opened this issue Dec 4, 2024 · 0 comments · May be fixed by #235
Open

Instantiate a model from a URL that points to a INP file #233

aerispaha opened this issue Dec 4, 2024 · 0 comments · May be fixed by #235

Comments

@aerispaha
Copy link
Member

Who's got the time to mAnUaLly download a SWMM file?

It would be cool if we could instantiate a swmmio Model by passing in a URL to a SWMM model somewhere on the internet. This could make our docs a little more concise, and also make it easier to run tests against models that are hosted in other GitHub repos.

For example, instead of having to manually download a SWMM model from a Github repo before working with it in swmmio, we could do something like this:

# url to an awesome inp file in another repo
url_to_inp = 'https://raw.githubusercontent.com/SWMMEnablement/NCIMM-Black-White-Box/25a7dc8fc58f67d15954679f294d09b9061766a4/SWMM5_NCIMM/10070_H_Elements.inp'

# instantiate as usual 
model = swmmio.Model(url_to_inp)
model.links.geodataframe.plot('Geom1', linewidth=model.links.dataframe['Geom1'])

image

This can be achieved pretty easily by downloading the model file to a temp location, then instantiating the swmmio.Model. Something like this, inside the swmmio.Model.__init__ :

# write some logic to validate that the in_file_path is a valid URL
if in_file_path is url: 
    # then download to a temp directory and instantiate from there
    r = requests.get(in_file_path)
    temp_path = f'{tempfile.gettempdir()}/10070_H_Elements.inp'
    with open(temp_path, 'wb') as f:
        f.write(r.content)

    self.inp(temp_path)
    ...
@aerispaha aerispaha linked a pull request Dec 18, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant