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

SWMM .inp File loses information by writing, running and reading in a for loop #64

Open
fcfunke opened this issue Jun 25, 2021 · 5 comments

Comments

@fcfunke
Copy link

fcfunke commented Jun 25, 2021

Hi everyone!
I am struggling with a problem reading, writing and running the same SWMM .inp File in a for-loop several times.
The problem appears in the $outfalls part of the SWMM .inp File, affecting the "Tide Gate" and "Route To" parameters.
The data is switching columns in the tibble and losing information, resulting in a SWMM error.
I reproduced the problem by reading and writing the same .inp file 3 times without changing anything. (see below)
Interestingly if I run the .inp file without the "Route To" Parameter (SG31) it still works.

`> input_test <- swmmr::read_inp(x = "D://Uni_Innsbruck/Dauerstufen_Jaehrlichkeiten_Analyse/SWMM_Modell_Berlin/inp_test/Mulde5_0.inp")
Warnmeldungen:
1: Expected 6 pieces. Additional pieces discarded in 14 rows [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14].
2: Expected 9 pieces. Additional pieces discarded in 14 rows [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14].

input_test$outfalls

A tibble: 3 x 6

Name Elevation Type Stage Data Gated Route To

1 Out5 46.7 FREE NA O ""
2 Out2 47.6 FREE NA NO "SG31"
3 Out1 0 FREE NA NO ""

swmmr::write_inp(input_test, "D://Uni_Innsbruck/Dauerstufen_Jaehrlichkeiten_Analyse/SWMM_Modell_Berlin/inp_test/Mulde5_0.inp")
input_test <- swmmr::read_inp(x = "D://Uni_Innsbruck/Dauerstufen_Jaehrlichkeiten_Analyse/SWMM_Modell_Berlin/inp_test/Mulde5_0.inp")
input_test$outfalls

A tibble: 3 x 6

Name Elevation Type Stage Data Gated Route To

1 Out5 46.7 FREE "O" NA NA NA
2 Out2 47.6 FREE "NO SG31" NA NA NA
3 Out1 0 FREE NO "" NA NA NA

swmmr::write_inp(input_test, "D://Uni_Innsbruck/Dauerstufen_Jaehrlichkeiten_Analyse/SWMM_Modell_Berlin/inp_test/Mulde5_0.inp")
input_test <- swmmr::read_inp(x = "D://Uni_Innsbruck/Dauerstufen_Jaehrlichkeiten_Analyse/SWMM_Modell_Berlin/inp_test/Mulde5_0.inp")
input_test$outfalls

A tibble: 3 x 6

Name Elevation Type Stage Data Gated Route To

1 Out5 46.7 FREE "" NA NA NA
2 Out2 47.6 FREE "O SG31" NA NA NA
3 Out1 0 FREE NO "" NA NA NA `

Thanks for any help!

with best regards
Fabian

@dleutnant
Copy link
Owner

@fcfunke Thanks for spotting this. I somehow can reproduce the issue with the SWMM examples shipped with the swmmr package. However, I am currently on paternity leave and thus it may take a while.

@dleutnant
Copy link
Owner

issue potentially here:

swmmr/R/parse_section.R

Lines 224 to 233 in 3e373e6

parse_section.outfalls <- function(x, ...) {
separate_into(x, c("Name", "value")) %>%
separate_into(
sep = base::cumsum(c(10, 1, 10, 1, 10, 1, 10, 1)), extra = "warn",
fill = "warn", into = c(
"Elevation", "tab2", "Type", "tab3", "Stage Data", "tab4", "Gated",
"tab5", "Route To"
))
}

@dleutnant
Copy link
Owner

dleutnant commented Jul 13, 2021

@fcfunke:
Could you please substitute NA with ' ' (double whitespace character) before you write the .inp file? And then read again?
The issue might be related to the write_inp function and the way NA values are handled.

@fcfunke
Copy link
Author

fcfunke commented Jan 12, 2022

@dleutnant
Sorry to come back to the problem so late, helped myself by saving the input$outfalls tibble before the first run and then just changing it every run to the initial version.
Today I stumbled over the problem again and made the following discovery. Not sure if this helps to solve the problem.

When reading the input file for the first time, input$outfalls$Elevation is of type "dbl" and just contains the Elevation values:

input$outfalls

A tibble: 20 x 6

Name Elevation Type Stage Data Gated Route To

1 2DOut 373. FREE NA NO NA
2 OF1 377. FREE NA NO NA
3 OF10 377. FREE NA NO NA

After the first write, run and read process input$outfalls$Elevation is of type "chr" and contains both Elevation and Type values:

input$outfalls

A tibble: 20 x 6

Name Elevation Type Stage Data Gated Route To

1 2DOut 373.1 FREE NO NA NA NA
2 OF1 376.6 FREE NO NA NA NA
3 OF10 376.7 FREE NO NA NA NA

with best regards
Fabian

@dleutnant
Copy link
Owner

Thanks for your report. Would you be able to file a reproducible example using one of SWMM's model examples shipped with the package?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants