Skip to content

Commit

Permalink
updates to sampler and zone aggregator
Browse files Browse the repository at this point in the history
  • Loading branch information
AshishKuls committed Mar 3, 2023
1 parent 2d7b343 commit f0de671
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 17 deletions.
20 changes: 7 additions & 13 deletions rsm/sampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,10 @@ def rsm_household_sampler(
prev_iter_access : Path-like or pandas.DataFrame
Accessibility in an old (default, no treatment, etc) run is given (preloaded)
or read in from here. Give as a relative path (from `input_dir`) or an
absolute path. If given as a path and the file does not exist, assume no delta-accessibility update info
is available and ignore this aspect of sampling.
absolute path.
curr_iter_access : Path-like or pandas.DataFrame
Accessibility in the latest run is given (preloaded) or read in from here.
Give as a relative path (from `input_dir`) or an absolute path. If given as a
path and the file does not exist, assume no delta-accessibility update info
is available and ignore this aspect of sampling.
Give as a relative path (from `input_dir`) or an absolute path.
study_area : array-like
Array of RSM zone id's in the study area. These zones are sampled at 100%.
input_household : Path-like or pandas.DataFrame
Expand Down Expand Up @@ -79,7 +76,7 @@ def rsm_household_sampler(
logger.debug(f" {input_dir=}")
logger.debug(f" {output_dir=}")

def _resolve_df(x, directory, must_exist=True, make_index=None):
def _resolve_df(x, directory, make_index=None):
if isinstance(x, (str, Path)):
# read in the file to a pandas DataFrame
x = Path(x).expanduser()
Expand All @@ -88,13 +85,10 @@ def _resolve_df(x, directory, must_exist=True, make_index=None):
try:
result = pd.read_csv(x)
except FileNotFoundError:
if must_exist:
raise
else:
result = None
raise
elif isinstance(x, pd.DataFrame):
result = x
elif x is None and not must_exist:
elif x is None:
result = None
else:
raise TypeError("must be path-like or DataFrame")
Expand All @@ -114,10 +108,10 @@ def _resolve_out_filename(x):
return x

prev_iter_access_df = _resolve_df(
prev_iter_access, input_dir, must_exist=False, make_index="MGRA"
prev_iter_access, input_dir, make_index="MGRA"
)
curr_iter_access_df = _resolve_df(
curr_iter_access, input_dir, must_exist=False, make_index="MGRA"
curr_iter_access, input_dir, make_index="MGRA"
)
rsm_zones = _resolve_df(taz_crosswalk, input_dir)
dict_clusters = dict(zip(rsm_zones["taz"], rsm_zones["cluster_id"]))
Expand Down
9 changes: 6 additions & 3 deletions scripts/rsm_sampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@
logging_start(
filename=os.path.join(rsm_dir, "logFiles", "rsm-logging.log"), level=logging.INFO
)
logging.info(f"start logging rsm_sampler for {iteration}")
logging.info(f"start logging rsm_sampler for iteration {iteration}")

run_rsm_sampling = get_property(ABM_PROPERTIES, "run.rsm.sampling")
run_rsm_sampling = int(get_property(ABM_PROPERTIES, "run.rsm.sampling"))
sampling_rate = float(get_property(ABM_PROPERTIES, "rsm.default.sampling.rate"))
min_sampling_rate = float(get_property(ABM_PROPERTIES, "rsm.min.sampling.rate"))
baseline_run_dir = get_property(ABM_PROPERTIES, "rsm.baseline.run.dir")
Expand All @@ -66,6 +66,9 @@
PREV_ITER_ACCESS = None
CURR_ITER_ACCESS = None

logging.info(f"Current Iteration Accessibility File: {CURR_ITER_ACCESS}")
logging.info(f"Previous Iteration Accessibility File: {PREV_ITER_ACCESS}")

rsm_household_sampler(
input_dir=rsm_dir,
output_dir=rsm_dir,
Expand All @@ -81,4 +84,4 @@
output_person=OUTPUT_RSM_SAMPLED_PERSONS,
)

logging.info(f"finished logging rsm_sampler for {iteration}")
logging.info(f"finished logging rsm_sampler for iteration {iteration}")
2 changes: 1 addition & 1 deletion scripts/rsm_zone_aggregator.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
logging.info("loading mgra data")
mgra = load_mgra_data(
shapefilename=FULL_ABM_MGRA_SHAPEFILE,
supplemental_features=FULL_ABM_MGRA,
supplemental_features=FULL_ABM_MGRA_FILE,
simplify_tolerance=10,
topo=True,
)
Expand Down

0 comments on commit f0de671

Please sign in to comment.