Skip to content

Commit de307a8

Browse files
Refactor: Further enhance Python packaging and modularity
This commit implements further refactoring based on feedback to improve the project's structure as a Python library: - Removed `if __name__ == "__main__"` blocks from `FreeTSE/FreeTSE.py` and `FreeTSE/gui.py` to ensure they act as importable modules without side effects. - Refactored `FreeTSE/gui.py` to encapsulate its primary functionality within a callable `run_gui_application()` function. This makes the GUI behavior explicitly invokable rather than running on import. - Updated `FreeTSE/__init__.py` to only export the core `FreeTSE` class by default. The `run_gui_application` function can be imported directly from `FreeTSE.gui` if needed. This change prevents `PySimpleGUIWx` (a GUI dependency) from becoming a core dependency for non-GUI uses of the library. - Adjusted test imports in `tests/test_freetse_integration.py` to `from FreeTSE import FreeTSE`. - Confirmed all tests pass after these changes.
1 parent 1e72c36 commit de307a8

24 files changed

+1291
-230
lines changed

FreeTSE.py renamed to FreeTSE/FreeTSE.py

Lines changed: 2 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#coding:utf-8
2-
from util import *
2+
from .util import *
33

44
import random as pyrand
55
from pylab import *
@@ -785,47 +785,4 @@ def visualize(self, speed=0, prior=0, posterior=0, smooth=0, posterior_stddev=0,
785785
if save:
786786
savefig("%s_timeseries_%d.png"%(fname, x))
787787

788-
show()
789-
790-
if __name__ == "__main__":
791-
tse = FreeTSE()
792-
tse.set_scenario(
793-
name = "ngsim_trajectory",
794-
dt = 4,
795-
dx = 100,
796-
mint = 0,
797-
maxt = 800,
798-
minx = 0,
799-
maxx = 500,
800-
number_of_lanes = 5,
801-
speed_data_name = "./dat/ngsim_sampled_trajectories.csv",
802-
speed_label_t = "t",
803-
speed_label_x = "x",
804-
speed_label_v = "v",
805-
density_data_name = None,
806-
density_label_t = "t",
807-
density_label_x = "x",
808-
density_label_k = "k",
809-
flow_data_name = "./dat/ngsim_grid_flow_200m.csv",
810-
flow_label_t = "t",
811-
flow_label_x = "x",
812-
flow_label_q = "q",
813-
density_dat_true_name = None,
814-
true_density_label_t = "t",
815-
true_density_label_x = "x",
816-
true_density_label_k = "k",
817-
flow_dat_true_name = "./dat/ngsim_grid_flow_400m.csv",
818-
true_flow_label_t = "t",
819-
true_flow_label_x = "x",
820-
true_flow_label_q = "q"
821-
)
822-
tse.estimation()
823-
tse.accuracy_evaluation()
824-
fname = "res_test"
825-
tse.save_results(fname+".csv")
826-
tse.visualize(smooth=1, true=1, speed=1, timeseries=1, inputdata=1, save=1, fname=fname)
827-
828-
q, k, v = tse.get_results()
829-
print("flow", q)
830-
print("density", k)
831-
print("speed", v)
788+
show()

FreeTSE/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from .FreeTSE import FreeTSE
2+
3+
__all__ = ['FreeTSE']
4+
# Users who want run_gui_application can import it directly:
5+
# from FreeTSE.gui import run_gui_application
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)