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

Bug fix in valid GIS names used to create water network models #452

Merged
merged 8 commits into from
Nov 12, 2024

Conversation

kaklise
Copy link
Collaborator

@kaklise kaklise commented Oct 7, 2024

Summary

The following PR addresses #448 and #449. node_type and link_type are no longer stored or used in the WaterNetworkGIS GeoDataFrames. The attributes are still included in the dictionary representation of WaterNetworkModels which are used to translate between WaterNetworkModels and the GIS data.

Bug fix: Missing commas resulted in errors in the valid GIS names

Bug fix: GeoDataFrames now include valid columns even when all entries in that column are None

Tests and documentation

  • Added a test to compare valid GIS names to gis data
  • Updated a test to remove node_type and link_type

Acknowledgement

By contributing to this software project, I acknowledge that I have reviewed the software quality assurance guidelines and that my contributions are submitted under the Revised BSD License.

@coveralls
Copy link

coveralls commented Oct 8, 2024

Coverage Status

coverage: 84.24% (+0.01%) from 84.227%
when pulling 57880bf on kaklise:valid_gis_names
into 576dc01 on USEPA:main.

@kaklise kaklise requested a review from kbonney October 15, 2024 16:46
Copy link
Collaborator

@kbonney kbonney left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My comments have been addressed so I approve.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From my understanding, _base_attributes are the attributes which are necessary to add the element to the model, and _optional_attributes can also be added to the element, but are not necessary for the code to run.

If that is the case, we should make sure all possible attributes for each element are included in _optional_attributes. For example, base_demand is not included for junctions, so when we do a GIS roundtrip we lose base_demand information.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking into it more, base_demand is not yet implemented in the read functions. It looks like we always assign a default value. Strangely, we do mention base_demand in the Network IO documentation in the Shapefile section.

We should probably change that example that if we aren't supporting base_demand as a valid column.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated example in kaklise#76

@@ -470,6 +495,17 @@ def _valid_names(self, complete_list=True, truncate_names=None):
if truncate_names is not None and truncate_names > 0:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it makes sense to change element_objects to have keys that match the syntax of the corresponding elements. Something like

        element_objects = {
            'Junction': wntr.network.elements.Junction,
            'Tank': wntr.network.elements.Tank,
            'Reservoir': wntr.network.elements.Reservoir,
            'Pipe': wntr.network.elements.Pipe,
            'Pump': wntr.network.elements.Pump,
            'Valve': wntr.network.elements.Valve}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I looked into doing this and it is a bit of a lift since it is used all over the code base and hard to track down. Best to keep it as is...

@@ -99,14 +99,18 @@ def _create_gis(self, wn, crs: str = None, pumps_as_points: bool = False,
Represent valves as points (True) or lines (False), by default False
"""

def _extract_geodataframe(df, crs=None, links_as_points=False):
# Drop any column with all NaN
def _extract_geodataframe(df, crs=None, valid_base_names=[],
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having mutable default arguments valid_base_names=[] can cause unexpected and hard to debug behavior in Python. I try to avoid this wherever I can. Instead we can default to None and check if it is None in the body of the function and then assign it to an empty list.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated default argument in kaklise#76

@@ -216,7 +216,7 @@ The following example returns valid base GeoJSON column names for junctions.

>>> geojson_column_names = wntr.network.io.valid_gis_names()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I looked back at this portion of the documentation and it is a little confusing how we talk about the valid_gis_names function. It is probably easiest for me to explain by making my suggest updates in a PR to your branch.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated discussion of the function in the user docs in kaklise#76

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

Successfully merging this pull request may close these issues.

3 participants