-
Notifications
You must be signed in to change notification settings - Fork 43
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
Add getter and setter for tags. #186
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -188,6 +188,7 @@ def conduits(self): | |
# create dataframes of relevant sections from the INP | ||
conduits_df = dataframe_from_inp(inp.path, "CONDUITS") | ||
xsections_df = dataframe_from_inp(inp.path, "XSECTIONS") | ||
tags = dataframe_from_inp(inp.path, "TAGS") | ||
conduits_df = conduits_df.join(xsections_df) | ||
|
||
if rpt: | ||
|
@@ -212,6 +213,10 @@ def conduits(self): | |
df.InletNode = df.InletNode.astype(str) | ||
df.OutletNode = df.OutletNode.astype(str) | ||
|
||
tags = dataframe_from_inp(inp.path, "TAGS") | ||
if "Link" in set(tags.index): | ||
df = df.merge(dataframe_from_inp(inp.path, "Tags"), left_on="Name", right_on="Name", how="left") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of re-instantiating a tags dataframe, you could reuse the df = df.merge(tags, left_on="Name", right_on="Name", how="left") |
||
|
||
self._conduits_df = df | ||
|
||
return df | ||
|
@@ -344,6 +349,7 @@ def subcatchments(self): | |
return self._subcatchments_df | ||
|
||
df = ModelSection(model=self, **COMPOSITE_OBJECTS['subcatchments']) | ||
|
||
self._subcatchments_df = df | ||
return df | ||
|
||
|
@@ -534,6 +540,7 @@ def __init__(self, file_path): | |
self._inflows_df = None | ||
self._curves_df = None | ||
self._timeseries_df = None | ||
self._tags_df = None | ||
|
||
SWMMIOFile.__init__(self, file_path) # run the superclass init | ||
|
||
|
@@ -568,7 +575,8 @@ def __init__(self, file_path): | |
'[HYDROGRAPHS]', | ||
'[INFLOWS]', | ||
'[Polygons]', | ||
'[TIMESERIES]' | ||
'[TIMESERIES]', | ||
'[TAGS]', | ||
] | ||
|
||
def save(self, target_path=None): | ||
|
@@ -1314,6 +1322,20 @@ def timeseries(self, df): | |
"""Set inp.timeseries DataFrame.""" | ||
self._timeseries_df = df | ||
|
||
@property | ||
def tags(self): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. perfect! |
||
""" | ||
Get/set tags section of the INP file. | ||
""" | ||
if self._tags_df is None: | ||
self._tags_df = dataframe_from_inp(self.path, "[TAGS]") | ||
return self._tags_df | ||
|
||
@tags.setter | ||
def tags(self, df): | ||
"""Set inp.tags DataFrame.""" | ||
self._tags_df = df | ||
|
||
|
||
def drop_invalid_model_elements(inp): | ||
""" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,11 @@ | ||
from swmmio import Model | ||
from swmmio.tests.data import (MODEL_A_PATH, MODEL_EX_1, MODEL_FULL_FEATURES_XY, | ||
MODEL_FULL_FEATURES__NET_PATH, MODEL_FULL_FEATURES_XY_B) | ||
MODEL_FULL_FEATURES__NET_PATH, MODEL_FULL_FEATURES_XY_B, MODEL_GREEN_AMPT) | ||
|
||
# example models | ||
philly = Model(MODEL_A_PATH, crs="+init=EPSG:2817") | ||
jersey = Model(MODEL_FULL_FEATURES_XY) | ||
jerzey = Model(MODEL_FULL_FEATURES_XY_B) | ||
spruce = Model(MODEL_FULL_FEATURES__NET_PATH) | ||
walnut = Model(MODEL_EX_1) | ||
green = Model(MODEL_GREEN_AMPT) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because you've added tags to the
inp
object, you can simplify this line to