Skip to content

Commit

Permalink
Upload helper tools
Browse files Browse the repository at this point in the history
  • Loading branch information
kzhang81 authored Dec 17, 2024
1 parent ec01025 commit b5d13c8
Show file tree
Hide file tree
Showing 27 changed files with 6,313 additions and 1,969 deletions.
35 changes: 18 additions & 17 deletions helper_tools/base_year_run/base_year_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
import rdr_supporting
import rdr_CompileAE

VERSION_NUMBER = "2024.1"
VERSION_DATE = "5/22/2024"
VERSION_NUMBER = "2024.2"
VERSION_DATE = "12/16/2024"
# ---------------------------------------------------------------------------------------------------
# The following code processes an existing scenario configuration to automatically
# generate the outputs of all of the AequilibraE base year runs into one consolidated CSV file
Expand Down Expand Up @@ -99,14 +99,17 @@ def main():
raise Exception(("INSUFFICIENT HAZARD INPUT DATA ERROR: missing input files for " +
"scenario space defined by {}".format(model_params_file)))

model_params = pd.read_excel(model_params_file, sheet_name='UncertaintyParameters',
converters={'Hazard Events': str, 'Recovery Stages': str,
'Economic Scenarios': str, 'Trip Loss Elasticities': float,
'Project Groups': str})
hazard = pd.read_excel(model_params_file, sheet_name='Hazards',
usecols=['Hazard Event'],
converters={'Hazard Event': str})

recovery = pd.read_excel(model_params_file, sheet_name='RecoveryStages',
usecols=['Recovery Stages'],
converters={'Recovery Stages': str})

hazard = set(model_params['Hazard Events'].dropna().tolist())
hazard = set(hazard['Hazard Event'].dropna().tolist())
logger.config("List of hazards: \t{}".format(', '.join(str(e) for e in hazard)))
recovery = set(model_params['Recovery Stages'].dropna().tolist())
recovery = set(recovery['Recovery Stages'].dropna().tolist())
logger.config("List of recovery stages: \t{}".format(', '.join(str(e) for e in recovery)))

product1 = pd.DataFrame(list(product(hazard, recovery)),
Expand Down Expand Up @@ -178,22 +181,16 @@ def main():


# ---------------------------------------------------------------------------------------------------


def check_hazards_coverage(model_params_file, input_folder, logger):
logger.info("Start: check_hazards_coverage")
is_covered = 1
model_params = pd.read_excel(model_params_file, sheet_name='UncertaintyParameters',
usecols=['Hazard Events'],
converters={'Hazard Events': str})
hazard_events = pd.read_excel(model_params_file, sheet_name='Hazards',
usecols=['Hazard Event', 'Filename'],
converters={'Hazard Event': str, 'Filename': str})

# Read in column 'Hazard Events'
hazard = set(model_params['Hazard Events'].dropna().tolist())

hazards_list = pd.merge(pd.DataFrame(hazard, columns=['Hazard Event']),
hazard_events, how='left', on='Hazard Event')
for index, row in hazards_list.iterrows():
for index, row in hazard_events.iterrows():
filename = os.path.join(input_folder, 'Hazards', str(row['Filename']) + '.csv')
if not os.path.exists(filename):
is_covered = 0
Expand All @@ -204,6 +201,8 @@ def check_hazards_coverage(model_params_file, input_folder, logger):


# ---------------------------------------------------------------------------------------------------


def setup_sql_nodes(input_dir, logger):
# Aequilibrae requires a SQLite database to be setup first--this code is copied from rdr_RunAE.py
# Set up AEMaster SQLite database with node information
Expand Down Expand Up @@ -238,5 +237,7 @@ def setup_sql_nodes(input_dir, logger):


# ---------------------------------------------------------------------------------------------------


if __name__ == "__main__":
main()
4 changes: 2 additions & 2 deletions helper_tools/baseline_network_run/baseline_network_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
import rdr_setup
import rdr_supporting

VERSION_NUMBER = "2024.1"
VERSION_DATE = "5/22/2024"
VERSION_NUMBER = "2024.2"
VERSION_DATE = "12/16/2024"
# ---------------------------------------------------------------------------------------------------
# The following code generates AequilibraE outputs for a baseline scenario configuration
# with no hazard disruption and no resilience project improvements. Users can run this helper tool
Expand Down
1,247 changes: 1,247 additions & 0 deletions helper_tools/benefits_analysis/MetricsByTAZ_categorical.ipynb

Large diffs are not rendered by default.

922 changes: 922 additions & 0 deletions helper_tools/benefits_analysis/MetricsByTAZ_continuous.ipynb

Large diffs are not rendered by default.

102 changes: 102 additions & 0 deletions helper_tools/benefits_analysis/TAZ_metrics.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@

# Configuration file for running equity_overlay.py and TAZ_metrics.py

# Configuration Summary: To run an equity overlay for an RDR scenario, update the [common] and [equity_overlay] sections to match your scenario specifications
# Similarly, to run the TAZ metrics analysis for an RDR scenario, update the [common] and [benefits_analysis] sections to match your scenario specifications

# ==============================================================================

[common]

# Location to store the results of the benefits analysis helper tools
benefits_analysis_dir = "C:\GitHub\RDR\Data\benefits_analysis\generated_files"

# Run name
# Used to name output folders and log files for distinction between various benefits analyses
run_id = 'SampleBenefitsAnalysis'

# Name of the TAZ ID column in the TAZ source
TAZ_col_name = 'TAZ_ID'

# ==============================================================================

[equity_overlay]

# Full file path to the TAZ shapefile (do not include the SHP file extension)
# This is a file stored on the user's local machine
# Future versions may support feature service layer
TAZ_source = "C:\GitHub\RDR\Data\benefits_analysis\inputs\TAZ\TAZ_Layer"

# Source of the equity layer and the feature of that layer which should be used to categorize areas of equity emphasis
# If using a file stored on the user's local machine, provide the full path to the shapefile as the equity_source parameter
# If using the default layer, enter 'CEJST' to use the categorization developed by the Council on Environmental Quality (CEQ)
# Climate and Economic Justice Screening Tool (CEJST)
# Note: Default setting provides a binary composite indicator of equity emphasis areas ('SN_C'), where 1 = disadvantaged and 0 = not disadvantaged
equity_source = 'CEJST'
equity_feature = 'SN_C'

# Equity source coordinate reference system
# Defines the coordinate reference system (crs) of the equity source shapefile if provided
# Typically in the format of 'EPSG:XXXX' where XXXX is four digits
# Default layer uses the WGS84 Geographic Coordinate System, which is 'EPSG:4326'
equity_crs = 'EPSG:4326'

# Minimum area to include during overlay
# Indicates the percentile (as a decimal) of smallest overlay intersected polygons to drop before assigning equity emphasis categories to TAZs
# Note: Setting this below 0.05 may result in very small fragments of overlay being used to assign equity emphasis category to TAZ
min_percentile_include = 0.05

# Name of CSV file created as output (do not include CSV file extension)
output_name = 'Equity_TAZ_Mapping'

# ==============================================================================

[benefits_analysis]
# Configuration file for corresponding RDR Metamodel run
# This is used in TAZ_metrics.py to identify the AequilibraE input files and parameters to use
path_to_RDR_config_file = "C:\GitHub\RDR\Data\sample_run\SampleRun.config"

# Full file path of CSV file containing the TAZ metric data by TAZ
# This file must contain a TAZ ID column named according to the TAZ_col_name parameter above and a TAZ category column
# specified by the TAZ_feature parameter
TAZ_mapping = "C:\GitHub\RDR\Data\benefits_analysis\inputs\Equity_TAZ_Mapping.csv"
TAZ_feature = 'SN_C'

# Resilience project to analyze in the TAZ metrics helper tool
# Enter the project name corresponding to RDR input files, e.g., 'HighwayProject1'
resil = 'HighwayProject1'

# Hazard to analyze in the TAZ metrics helper tool
# Enter the hazard name corresponding to RDR input files, e.g., '100yr3SLR'
hazard = 'haz1'

# Project group corresponding to resilience project
# Enter the project group name corresponding to above resilience project in RDR input files, e.g., '04', '30'
projgroup = '00'

# Socioeconomic future to analyze in the TAZ metrics helper tool
# Enter the economic future name corresponding to RDR input files, e.g., 'base', 'urban', 'suburban'
socio = 'base'

# Elasticity value used by AequilibraE, e.g., 0, -0.5, -1
elasticity = -1

# Always set to 'no' for the TAZ metrics helper tool
baseline = 'no'

# Always set to '0' for the TAZ metrics helper tool
recovery = '0'

# Mini-Equilibrium Run
# User can select 1 to run mini-equilibrium setup for routing code or 0 to run routing code only once (default).
run_minieq = 0

# Defines the type of AequilibraE run used in the TAZ metrics helper tool
# Select 'SP' for shortest path or 'RT' for routing (default)
run_type = 'RT'

# Constant used as an upper bound for travel times in disruption analysis
largeval = 99999

# P-value used in statistical tests for determining "significance"
pval = 0.05
Loading

0 comments on commit b5d13c8

Please sign in to comment.