wsp-sag / Lasso

Python package of utilities for Network Wrangler
https://wsp-sag.github.io/Lasso/
Apache License 2.0
5 stars 3 forks source link

Parameters setting Lasso Base Directory #91

Closed DavidOry closed 4 years ago

DavidOry commented 4 years ago

In this line, should the code read:

    if 'lasso_base_dir' in kwargs:
      self.base_dir = get_base_dir(lasso_base_dir = lasso_base_dir)

The get_base_dir method as an argument named lasso_base_dir and the name of the variable in kwargs is lasso_base_dir.

DavidOry commented 4 years ago

Ah, no. I think the problem is in the get_base_dir method definition. How does this method allow an argument to be taken in?

DavidOry commented 4 years ago

The functionality I want is:

parameters = Parameters(lasso_base_dir = input_dir)
i-am-sijia commented 4 years ago

add this to your config yaml:

my_parameters:
    lasso_base_dir: "D:/lasso"           # or where your lasso directory is
e-lo commented 4 years ago

How does this method allow an argument to be taken in?

get_base_dir(lasso_base_dir = os.getcwd()) allows a keyword argument to be fed in (which you can do in the Parameters initialization), but it will default to the current working directory.

The parameters keyword lasso_base_dir is essentially put through a process to check and see if the met council data is where it should be and will search around a bit (3 levels for now) if it can't find it.

e-lo commented 4 years ago

@DavidOry - is this still an issue?

DavidOry commented 4 years ago

Yes. @i-am-sijia and I discussed. When passing a dir to Parameters, like this:

parameters = Parameters(lasso_base_dir = input_dir)

I want Parameters to use the defaults and update lasso_base_dir. This behavior works via the config file, but I don't want to use a config file.

i-am-sijia commented 4 years ago

I'm getting error when specifying this way:

parameters = Parameters(lasso_base_dir = "z:/Data/Users/Sijia/Met_Council/github/client_met_council_wrangler_utilities" )

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-385-34813c6beb5e> in <module>
      1 model_road_net = ModelRoadwayNetwork.from_RoadwayNetwork(
      2     my_scenario.road_net, #parameters=my_config.get("my_parameters", {}),
----> 3     parameters = Parameters(lasso_base_dir = "z:/Data/Users/Sijia/Met_Council/github/client_met_council_wrangler_utilities" )
      4 )
      5 

z:\data\users\sijia\met_council\github\client_met_council_wrangler_utilities\lasso\roadway.py in from_RoadwayNetwork(roadway_network_object, parameters)
    112             roadway_network_object.links_df,
    113             roadway_network_object.shapes_df,
--> 114             parameters=parameters,
    115         )
    116 

z:\data\users\sijia\met_council\github\client_met_council_wrangler_utilities\lasso\roadway.py in __init__(self, nodes, links, shapes, parameters)
     38 
     39         # will have to change if want to alter them
---> 40         self.parameters = Parameters(**parameters)
     41 
     42         self.links_metcouncil_df = None

TypeError: type object argument after ** must be a mapping, not Parameters

I'm looking at the piece here

https://github.com/wsp-sag/Lasso/blob/64189537e71ef49f0866186ced8ad972f9788708/lasso/roadway.py#L39-L40

DavidOry commented 4 years ago

Yes, that is my error as well.

DavidOry commented 4 years ago

Perhaps:

self.parameters = Parameters(**parameters.__dict__) 
e-lo commented 4 years ago
test_roadway_project = Project.create_project(
  base_roadway_dir=os.path.join(EX_DIR,"FullNet_72320"),
  roadway_log_file=os.path.join(EX_DIR,"FullNet_72320","randomtestedit.LOG"),
  parameters = {'lasso_base_dir' = YOUR_LASSO_DIRECTORY_HERE}
)

Works and I just added/pushed. a test to confirm.

The parameters kw accepts a dict, not a params instance.

I can update it to be more flexible as part of #92

e-lo commented 4 years ago

done with. this now?