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

Create configurable base year - so we can start from 2010 or 2020 and achieve the same result #384

Open
wants to merge 59 commits into
base: main
Choose a base branch
from

Conversation

lmz
Copy link
Member

@lmz lmz commented Oct 17, 2024

This PR includes changes so that BAUS can be started in 2010 or 2020 and the results will be the same. This is achieved by:

  1. Running a new debug model as the first simulation model. When 2020 is not the base_year but the model year is 2020, this was used to write an h5 store with 2020 snapshots of the input tables. This was used to create the input table, 2024_10_29_bayarea_2020start.h5
  2. Upgrade caching. A bunch of columns were set to cache=True, and weren't being updated when the tables were updated. These were modified to have cache_scope='step'. This also requires using a local version of urbansim_defaults: https://github.com/BayAreaMetro/urbansim_defaults/commits/master/
  3. Some small changes for compatibility:
    a. scheduled_development_events(): Convert special case from base_year + years_per_iter to 2010 + years_per_iter
    b. scheduled_development_events(): Don't add parcels to static_parcels until 2020.
    c. When base_year is 2020:
    1. store() reads 2024_10_29_bayarea_2020start.h5 rather than 2015_09_01_bayarea_v3.h5
    2. lump_sum_accounts(): Add 2015 lump sum to account to be consistent with 2010 start. (I think this can be removed).

Other changes:

  1. Made program argument, --run_setup_yaml, so multiple versions of BAUS can be tested simultaneously with the same code base via different run setup files.
  2. Add base_year and final_year into the run_setup_yaml.
  3. Remove run_name prefix from output filenames. This way output directories between runs can be diffed with other run output directories. The run_name prefix is still present when copied into the visualization directory.
  4. Rename some output files for clarity: disaggregate buildings, households, jobs, etc files that aren't summarized to a geography are called XX_table.csv rather than XX_summary.csv
  5. Send update message to slack at the end of each iteration
  6. Fix warnings by replacing yaml.load() with yaml.safe_load()
  7. Convert static_parcels list in configs/developer/developer_settings.yaml to parcel ids rather than geom_ids
  8. Add column, move_in_year, for households and jobs to understand when they located
  9. Debugging added to https://github.com/BayAreaMetro/urbansim/commits/master/ -- use this

lmz added 30 commits July 9, 2024 10:14
From M:\urban_modeling\baus\PBA50Plus\PBA50Plus_DraftBlueprint\PBA50Plus_Draft_Blueprint_v8_znupd_nodevfix\run_setup_PBA50Plus_Draft_Blueprint_v8_znupd_nodevfix.yaml
This commit reproduces PBA50+ DBP run
(baus-env-2023) E:\LUModel2Share\GitHub\bayarea_urbansim>git diff  M:\urban_modeling\baus\PBA50Plus\PBA50Plus_DraftBlueprint\PBA50Plus_Draft_Blueprint_v8_znupd_nodevfix\geographic_summaries\PBA50Plus_Draft_Blueprint_v8_znupd_nodevfix_county_summary_2025.csv E:\LUModel2Share\PBA50Plus_DraftBlueprint\PBA50Plus_DraftBlueprint_v01\geographic_summaries\PBA50Plus_DraftBlueprint_v01_county_summary_2025.csv
=> no diffs

(baus-env-2023) E:\LUModel2Share\GitHub\bayarea_urbansim>git diff  M:\urban_modeling\baus\PBA50Plus\PBA50Plus_DraftBlueprint\PBA50Plus_Draft_Blueprint_v8_znupd_nodevfix\geographic_summaries\PBA50Plus_Draft_Blueprint_v8_znupd_nodevfix_county_summary_2050.csv E:\LUModel2Share\PBA50Plus_DraftBlueprint\PBA50Plus_DraftBlueprint_v01\geographic_summaries\PBA50Plus_DraftBlueprint_v01_county_summary_2050.csv
=> no diffs
PBA50Plus_DraftBlueprint_v02 results are identical to PBA50+ DBP
(baus-env-2023) E:\LUModel2Share\GitHub\bayarea_urbansim>git diff M:\urban_modeling\baus\PBA50Plus\PBA50Plus_DraftBlueprint\PBA50Plus_Draft_Blueprint_v8_znupd_nodevfix\geographic_summaries\PBA50Plus_Draft_Blueprint_v8_znupd_nodevfix_county_summary_2050.csv E:\LUModel2Share\PBA50Plus_DraftBlueprint\PBA50Plus_DraftBlueprint_v03\geographic_summaries\county_summary_2050.csv
[no diffs]

(baus-env-2023) E:\LUModel2Share\GitHub\bayarea_urbansim>git diff M:\urban_modeling\baus\PBA50Plus\PBA50Plus_DraftBlueprint\PBA50Plus_Draft_Blueprint_v8_znupd_nodevfix\travel_model_summaries\PBA50Plus_Draft_Blueprint_v8_znupd_nodevfix_taz1_summary_2050.csv E:\LUModel2Share\PBA50Plus_DraftBlueprint\PBA50Plus_DraftBlueprint_v03\travel_model_summaries\taz1_summary_2050.csv
[no diffs[
Also add urbansim logging (but turn it off)
Since it's not really a summary
Also add disaggregate households, jobs, and static parcels
parcel_id is the standard parcel identifier
As well as vacant_job_spaces and jobs index
@lmz lmz requested a review from akselx November 9, 2024 22:32
Copy link

@akselx akselx left a comment

Choose a reason for hiding this comment

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

Looks like a major improvement. I assume this runs from snout to tail - I like the many efficiencies and cleanings - will need to adjust off-model scripts to handle the simplified naming convensions, but seems worthwhile.

@@ -28,8 +28,10 @@
# this is similar to the code for settings in urbansim_defaults
@orca.injectable('run_setup', cache=True)
def run_setup():
with open("run_setup.yaml") as f:
return yaml.load(f)
run_setup_yaml = orca.get_injectable('run_setup_yaml')
Copy link

Choose a reason for hiding this comment

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

This is a very useful addition

def developer_settings(base_year):
developer_settings_yaml = "developer_settings.yaml"
full_path = os.path.join(misc.configs_dir(), "developer", developer_settings_yaml)
logger.info("Reading developer settings from {}".format(full_path))
Copy link

Choose a reason for hiding this comment

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

I like this addition - logging the files loaded at run time. It is not always clear from the setup file and the setup file is more likely to get corrupted than the log file. I may do that for all the yaml settings loaded.

static_parcels_list = developer_settings["static_parcels"]
print("static_parcels(): {}".format(static_parcels_list))

return static_parcels_list
Copy link

Choose a reason for hiding this comment

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

Nice simplification - and I see you got the corresponding source file, as appropriate too for consistency.

rates = rates.reset_index(drop=True)

df = pd.merge(households.to_frame(["zone_id", "base_income_quartile", "tenure"]), rates, on=["zone_id", "base_income_quartile", "tenure"], how="left")
df = pd.merge(households.to_frame(["zone_id", "base_income_quartile", "tenure", "move_in_year"]),
Copy link

Choose a reason for hiding this comment

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

Love the move_in_year addition


l1 = len(buildings)
# the following function has `demolish` as an input, but it is not removing the buildings in the 'demolish' table,
# instead, it removes existing buildings on parcels to be occupied by buildings in 'demolish'
buildings = utils._remove_developed_buildings(buildings.to_frame(buildings.local_columns), demolish,
unplace_agents=["households", "jobs"])
orca.add_injectable('static_parcels', np.append(static_parcels, demolish.loc[demolish.action == 'build', 'parcel_id']))
# TODO: I don't know if this line makes sense; why would this go on static_parcels?
Copy link

Choose a reason for hiding this comment

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

Ya, that ended up being a long list - instead of just handling on the developer model config side where you can set filters.

Copy link

Choose a reason for hiding this comment

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

This looks useful. Do you have downstream steps for more or less systematically inspecting the outputs? I could imagine a bunch of vizzes built on top of these.

@@ -162,311 +170,281 @@ def run_models(mode, run_setup, years_to_run):

elif mode == "simulation":
Copy link

Choose a reason for hiding this comment

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

We should really move all the run lists to a separate module, or config file, out of baus.py

@@ -141,7 +141,7 @@ def acct_settings(account_strategies):


@orca.step()
def lump_sum_accounts(year, years_per_iter, run_setup):
def lump_sum_accounts(year, base_year, years_per_iter, run_setup, logger):
Copy link

Choose a reason for hiding this comment

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

Convention: when do we pass logger as an arg as opposed to invoking at the top, like getlogger?

@@ -26,7 +26,7 @@
#####################


@orca.column('households', cache=True)
@orca.column('households', cache=True, cache_scope='step')
Copy link

Choose a reason for hiding this comment

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

So this is the secret - much smaller caching scope.

# which ignore this list
static_parcels:
- 2489683204304 # ala fairgrounds 378337
Copy link

Choose a reason for hiding this comment

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

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants