-
Notifications
You must be signed in to change notification settings - Fork 0
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
Added documentation for PyBTLS interface #49
base: main
Are you sure you want to change the base?
Conversation
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.
Lots of good functions here, but there seems to be a lot of replication of the internals of the C++ code which should be unnecessary. Each class/function should have a clear need in an identified workflow.
Some naming is counter to python conventions.
Use of files...a clear use-case workflow is needed since when run through python most outputs should be just in memory perhaps?
""" | ||
Private method to get influence lines. | ||
IL computed using PyCBA, then compressed using the maxdistance algorithm. | ||
""" | ||
# IL to be compressed | ||
ils = cba.InfluenceLines(self.L, np.ones(len(self.L)), self.R) |
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.
This means pycba is a dependency for PyBTLS. It's not a good idea to have too many dependencies. Surely a user could work out their own IL outside PyBTLS and just pass it in; it would avoid a hard dependency.
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.
I'll try to add a method (in a separate PR) to manually add IL. Perhaps we can save this method, by checking if PyCBA is installed, then users can use this method. Else throw an exception?
class Bridge: | ||
""" | ||
Python side Bridge Class. |
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.
Is this just a wrapper of the PyBTLS class?
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.
It doesn't directly interface with the Bridge class in c++. It simply wraps the txt/csv file creation.
with open(path, "w") as f: | ||
f.write(self._create_il_txt()) | ||
|
||
def write_as_txt(self, il_path="IL.txt", bridge_path="bridge.txt"): | ||
""" | ||
Method to write both the bridge and influence line text file for BTLS to run. | ||
""" | ||
self.write_bridge_as_txt(bridge_path) | ||
self.write_il_as_txt(il_path) |
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.
Once something is defined in memory, we should be able to avoid needing to write to HDD.
# via DataFrame (base class has this covered) | ||
# or via file, which needs to be redefined to not use the _from_txt_to_dataframe_kwargs() method | ||
# And block the _from_txt_to_dataframe_kwargs() method from working | ||
|
||
def _from_txt_to_dataframe_kwargs(self, txt, *args, **kwargs): |
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.
Is there a required format of the dataframe and/or textfile?
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.
The default Lane Flow files are all in csv, which this class can load.
It's only blocking the _from_txt_to_dataframe_kwargs
as this method strictly initializes using a txt file, loading it as string, parsing it line by line, and then create a dataframe. It's too complicated this way; the pandas csv loader can do the job just fine.
Also just a quick note the reason _from_txt_to_dataframe_kwargs
is there is because it's inherited from DFBased
class.
py/PyBTLS/py/bridge/flow.py
Outdated
|
||
""" | ||
|
||
|
||
class BridgeFlow(_ListLike): |
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.
I think this is an internal class of PyBTLS. Not sure why a user would need access to it?
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.
Yes, I'm still not happy with how the lane flows are defined in python right now. Hopefully Ziyi and I can reach a better workflow soon. Ziyi will let you know.
py/PyBTLS/py/output/output.py
Outdated
@@ -8,6 +8,11 @@ | |||
|
|||
|
|||
class _BtlsWrapper_DefaultOutputs: |
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.
Seems unnecessary. Also naming convention - stick to PEP.
py/PyBTLS/py/output/output.py
Outdated
@@ -18,6 +23,17 @@ def __str__(self): | |||
|
|||
|
|||
class CumulativeStatistics(_DfBased): |
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.
Is this for reading in a file output from PyBTLS C++?
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.
Right now it's only reading from output txt/csv file.
This file provide functions to import BTLS ouput for a given bridge span. | ||
These functions are for convenience; | ||
the output file names from BTLS are sometimes inconsistent. | ||
To import directly from a know file path, please use the appropriate Classes directly. |
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.
I guess in normal python useage, we won't need to read from files; but probably useful to have these anyway. Should "OutputReader" not be a class perhaps?
@@ -11,6 +11,11 @@ | |||
|
|||
|
|||
class BaseTrafficFile: |
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.
This seems an internal class to the C++ code and not for users to interface with?
Not wholly supported after initialisation, though user can manipulate the existing DataFrame like regular | ||
""" | ||
|
||
|
||
class _DfBased(pd.DataFrame): |
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.
Stick to naming conventions.
Thanks Colin. We (mostly Ziyi) is trying to resolve the replicated functions. This PR is just the documentations for the wrapper of the old method writing to txt/csv files, but in more python friendly ways (e.g., using DataFrame, etc.). There's an example workflow in the On the outputs, I find it useful to have the output written to HDD, as I often run multiple instances of BTLS, then merge the outputs (very easily using the classes written here using I also changed the class names to follow the convention better, should be in the next commit soon. |
Hi all,
This pull request adds the (severely needed) documentation for the interface modules, as requested by @CaiZhou2.