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

Allow kwargs in network creation to override Class-level variables for Roadway and Transit #312

Closed
wants to merge 2 commits into from

Conversation

e-lo
Copy link
Collaborator

@e-lo e-lo commented Mar 2, 2023

This PR adds steps to the read() function for both RoadwayNetwork and TransitNetwork which will read in kwargs from the read() variables and will update any matching (upper-case) class-level variables to the specified values.

This is useful for when an agency might need to use a different unique ID or variable set from the defaults.

Also:

  • added util method: class_vars()
  • test network links which use different Key than model_link_id

Tested via: test_kwarg_instantiation()

Closes Issue #290

e-lo added 2 commits March 1, 2023 17:11
…roadway network.

Also:
- added util method: class_vars()
- test network links which use different Key than model_link_id

Tested via: test_kwarg_instantiation()
@e-lo e-lo added the enhancement New feature or request label Mar 2, 2023
@e-lo e-lo added this to the v1.0 milestone Mar 2, 2023
@e-lo e-lo requested review from lmz, DavidOry and i-am-sijia March 2, 2023 01:17
@e-lo e-lo self-assigned this Mar 2, 2023
@e-lo e-lo linked an issue Mar 3, 2023 that may be closed by this pull request
4 tasks
}

net = RoadwayNetwork.read(
link_file=SMALL_LINK_FILE,
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't we be testing with the link_diffIDs.json?

Copy link
Member

Choose a reason for hiding this comment

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

Test fails when using the link_diffIDs.json. Error:

2023-07-06 15:20:19, ERROR: Network doesn't contain unique link identifier: model_link_id

@@ -163,17 +163,17 @@ class RoadwayNetwork(object):

UNIQUE_LINK_KEY = "model_link_id"
UNIQUE_NODE_KEY = "model_node_id"
UNIQUE_MODEL_LINK_IDENTIFIERS = ["model_link_id"]
UNIQUE_MODEL_LINK_IDENTIFIERS = [UNIQUE_LINK_KEY]
Copy link
Member

Choose a reason for hiding this comment

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

In the example test test_kwarg_instantiation() in test_roadway.py, we update the UNIQUE_LINK_KEY to "different_link_id", which works, but it does not automatically update the reference of UNIQUE_LINK_KEY in the class, i.e., the UNIQUE_MODEL_LINK_IDENTIFIEDS here would still be ["model_link_id"], which is causing the test using "links_DiffIDs.json" to fail.

We need to refresh all class attrs whenever setattr() is called.

WranglerLogger.warning(f"{k} specified in TransitNetwork kwargs but does not match a Class-level variable.")
continue
WranglerLogger.debug(f"Updating TransityNetwork.{k.upper()} to: {v}")
setattr(RoadwayNetwork,k.upper(),v)
Copy link
Member

Choose a reason for hiding this comment

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

Here for the same issue in roadwaynetwork.py

WranglerLogger.warning(f"{k} specified in RoadwayNetwork kwargs but does not match a Class-level variable.")
continue
WranglerLogger.debug(f"Updating RoadwayNetwork.{k.upper()} to: {v}")
setattr(RoadwayNetwork,k.upper(),v)
Copy link
Member

Choose a reason for hiding this comment

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

after this setattr(), can we refresh all the attrs?

@e-lo
Copy link
Collaborator Author

e-lo commented Aug 21, 2024

Closing this as this approach has been superceeded by aligning on a string model for IDs across all tables in the selection-refactor branch.

@e-lo e-lo closed this Aug 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[FEATURE] Allow kwargs for roadway network creation
2 participants