atc138 1.3.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. atc138-1.3.0/.gitignore +44 -0
  2. atc138-1.3.0/PKG-INFO +280 -0
  3. atc138-1.3.0/README.md +261 -0
  4. atc138-1.3.0/pyproject.toml +60 -0
  5. atc138-1.3.0/src/atc138/__init__.py +0 -0
  6. atc138-1.3.0/src/atc138/cli.py +27 -0
  7. atc138-1.3.0/src/atc138/data/README.md +148 -0
  8. atc138-1.3.0/src/atc138/data/component_attributes.csv +1558 -0
  9. atc138-1.3.0/src/atc138/data/damage_state_attribute_mapping.csv +550 -0
  10. atc138-1.3.0/src/atc138/data/default_inputs.json +81 -0
  11. atc138-1.3.0/src/atc138/data/impeding_factors.csv +11 -0
  12. atc138-1.3.0/src/atc138/data/subsystems.csv +26 -0
  13. atc138-1.3.0/src/atc138/data/systems.csv +12 -0
  14. atc138-1.3.0/src/atc138/data/temp_repair_class.csv +6 -0
  15. atc138-1.3.0/src/atc138/data/tenant_function_requirements.csv +5 -0
  16. atc138-1.3.0/src/atc138/driver.py +202 -0
  17. atc138-1.3.0/src/atc138/engine.py +103 -0
  18. atc138-1.3.0/src/atc138/functionality/__init__.py +0 -0
  19. atc138-1.3.0/src/atc138/functionality/fn_calculate_functionality.py +80 -0
  20. atc138-1.3.0/src/atc138/functionality/fn_calculate_reoccupancy.py +97 -0
  21. atc138-1.3.0/src/atc138/functionality/fn_check_habitability.py +59 -0
  22. atc138-1.3.0/src/atc138/functionality/main_functionality_function.py +65 -0
  23. atc138-1.3.0/src/atc138/functionality/other_functionality_functions.py +1691 -0
  24. atc138-1.3.0/src/atc138/impedance/__init__.py +0 -0
  25. atc138-1.3.0/src/atc138/impedance/main_impedance_function.py +317 -0
  26. atc138-1.3.0/src/atc138/impedance/other_impedance_functions.py +427 -0
  27. atc138-1.3.0/src/atc138/input_builder.py +1159 -0
  28. atc138-1.3.0/src/atc138/preprocessing/__init__.py +0 -0
  29. atc138-1.3.0/src/atc138/preprocessing/main_preprocessing.py +64 -0
  30. atc138-1.3.0/src/atc138/preprocessing/preprocessing_fns.py +358 -0
  31. atc138-1.3.0/src/atc138/red_tag.py +168 -0
  32. atc138-1.3.0/src/atc138/repair_schedule/__init__.py +0 -0
  33. atc138-1.3.0/src/atc138/repair_schedule/main_repair_schedule.py +160 -0
  34. atc138-1.3.0/src/atc138/repair_schedule/other_repair_schedule_functions.py +900 -0
@@ -0,0 +1,44 @@
1
+ # Compiled python modules
2
+ *.pyc
3
+ __pycache__/
4
+
5
+ # macOS metadata
6
+ .DS_Store
7
+
8
+ # Build artifacts
9
+ /dist/
10
+ /build/
11
+
12
+ # VSCode folders
13
+ /.vscode
14
+
15
+ # PyCharm folders
16
+ /.idea
17
+ /.cache
18
+
19
+ # coverage
20
+ .coverage
21
+
22
+ # Python egg metadata, regenerated from source files by setuptools
23
+ *.egg-info/
24
+ .eggs/
25
+ *.egg
26
+
27
+ # Temporary jupyter files
28
+ /.ipynb_checkpoints/
29
+ *.ipynb_checkpoints
30
+
31
+ # Output folder
32
+ outputs/
33
+
34
+ # Folder with original Matlab code
35
+ /Matlab_code/
36
+
37
+ .ai/
38
+ Comparison_scripts/
39
+
40
+ # All new files coming out of buildInputs
41
+ inputs/example_inputs/*/optional_inputs.json
42
+ inputs/example_inputs/*/optional_inputs.py
43
+ inputs/example_inputs/*/simulated_inputs.json
44
+ inputs/example_inputs/*/build_input.py
atc138-1.3.0/PKG-INFO ADDED
@@ -0,0 +1,280 @@
1
+ Metadata-Version: 2.4
2
+ Name: atc138
3
+ Version: 1.3.0
4
+ Summary: Functional Recovery Assessment (ATC-138)
5
+ Project-URL: Homepage, https://github.com/NHERI-SimCenter/Functional-Recovery-Python
6
+ Project-URL: Bug Tracker, https://github.com/NHERI-SimCenter/Functional-Recovery-Python/issues
7
+ Author-email: Dustin Cook <dustin.cook@nist.gov>
8
+ Classifier: Operating System :: OS Independent
9
+ Classifier: Programming Language :: Python :: 3
10
+ Requires-Python: >=3.9
11
+ Requires-Dist: matplotlib
12
+ Requires-Dist: numpy~=2.0
13
+ Requires-Dist: pandas
14
+ Requires-Dist: scipy
15
+ Requires-Dist: seaborn
16
+ Provides-Extra: test
17
+ Requires-Dist: pytest>=7.0; extra == 'test'
18
+ Description-Content-Type: text/markdown
19
+
20
+ # Functional-Recovery---Python
21
+ This is translation of Matlab codebase into Python for quantifying building-specific functional recovery and reoccupancy based on a probabilistic performance-based earthquake engineering framework.
22
+
23
+ ## Requirements
24
+
25
+ - **Python Version**: 3.9 or later (recommend 3.9)
26
+ - **Package Manager**: pip (comes with Python)
27
+
28
+ ### Installation
29
+
30
+ The ATC-138 Functional Recovery Assessment tool is distributed as a Python package. Install it using pip:
31
+
32
+
33
+ ```bash
34
+ # Create and activate a virtual environment (recommended)
35
+ python -m venv .venv
36
+
37
+ # Activate virtual environment
38
+ # On Windows (PowerShell):
39
+ .\.venv\Scripts\Activate.ps1
40
+ # On macOS/Linux:
41
+ source .venv/bin/activate
42
+
43
+ # Install the package in editable mode
44
+ pip install -e .
45
+ ```
46
+
47
+
48
+ ### Verify Installation
49
+
50
+ After installation, verify that the CLI is available:
51
+
52
+ ```bash
53
+ atc138 --help
54
+ ```
55
+
56
+ You should see the command help output with available options.
57
+
58
+ ## Running an Assessment
59
+
60
+ An assessment can be run directly from the command line, or as imported within a Python workflow. If `simulated_inputs.json` does not exist, it will be created using default inputs within `src/atc138/data`. Various assessment options can be overridden by placing them in file `optional_inputs.json` file within the input directory. This file can be customized for each assessment if desired and will be set as default values if not specified.
61
+
62
+ If `simulated_inputs.json` exists, the input builder will not re-run unless `--force_rebuild` is used in the CLI command.
63
+
64
+ ### Running from the command line
65
+
66
+ With the input directory containing the necessary inputs, perform an assessment by running:
67
+
68
+ ```bash
69
+ python -m atc138.cli dir/to/inputs dir/to/outputs [options]
70
+ ```
71
+
72
+ Available options:
73
+ - `--seed SEED`: Random seed for reproducible results (integer)
74
+ - `--force_rebuild`: Force regeneration of `simulated_inputs.json` even if it exists
75
+
76
+ For example, the ICSB example case is run with:
77
+
78
+ ```bash
79
+ python -m atc138.cli ./examples/ICSB ./examples/ICSB/output
80
+ ```
81
+
82
+ Or with custom options:
83
+
84
+ ```bash
85
+ python -m atc138.cli ./examples/ICSB ./examples/ICSB/output --seed 12345 --force_rebuild
86
+ ```
87
+
88
+ ### Imported via Python script
89
+
90
+ Ensure that the `src/` directory is on the path of the main script. Then:
91
+
92
+ ```python
93
+ from src.atc138 import driver
94
+
95
+ example_dir = './examples/ICSB'
96
+ output_dir = './examples/ICSB/output'
97
+
98
+ driver.run_analysis(example_dir, output_dir, seed=985)
99
+ ```
100
+
101
+ If `simulated_inputs.json` exists, the input builder will not re-run unless the argument `force_rebuild=True` is used for `driver.run_analysis`.
102
+
103
+ ### Plotting outputs
104
+
105
+ Several basic plotting tools are provided in `plotters/`, which can be used after an analysis generates results. This is run with
106
+
107
+ ```python
108
+ from plotters.main_plot_functionality import plot_results
109
+ output_dir = './examples/ICSB/output'
110
+ plot_results(output_dir, p_gantt=50) # plot median realization
111
+ ```
112
+
113
+ which will plot:
114
+ - Component and system-level breakdowns of hinderance to reoccupancy and functional status per day
115
+ - Distribution of realizations achieving reoccupancy and functional status per day
116
+ - Mean and per-realization breakdown of recovery trajectories
117
+ - Gantt chart of impeding factors, repair work, number of workers, and recovery status of building per day for the realization with `p_gantt`-th percentile of functional recovery day.
118
+
119
+ ## Inputs
120
+ A brief description of the various input variables are provided below. A detailed schema of all expected input and output subfields is provided in [src/atc138/data/default_inputs.json](src/atc138/data/default_inputs.json).
121
+
122
+ ### Example Inputs
123
+ Four example inputs are provided to help illustrate both the construction of the inputs file and the implementation. These files are located in the `examples/` directory and can be run through the assessment by setting the variable names accordingly above.
124
+
125
+ ### Required Building Specific Data
126
+ Each file listed below contains data specific to the building performance model and simulated damage given for a specific level of shaking. Each file listed will need to be created for each unique assessment and saved in the root directory of the build script. Data are contained in either json or csv format.
127
+ - **building_model.json**: Basic properties of the building and performance model. Contains all variables within the _building_model_ structure defined in the inputs schema.
128
+ - **tenant_unit_list.csv**: Table that lists each tenant unit within the building; one row per tenant unit. This table requires the following attributes:
129
+ - id: [int or string] unique identifier for this tenant unit
130
+ - story: [int] building story where this tenant unit is located (ground floor is listed at 1)
131
+ - area: [number] total gross plan area of the tenant unit, in square feet
132
+ - perim_area: [number] total exterior perimeter area (elevation) of the tenant unit, is square feet
133
+ - occupancy_id: [int] foreign key to the _occupancy_id_ attribute of the tenant_function_requirements.csv table in the _data_ directory
134
+ - **comp_ds_list.csv**: Table that lists each component and damage state populated in the building performance model; one row per each component's damage state. This table requires the following attributes:
135
+ - comp_id: [string] unique FEMA P-58 component identifier
136
+ - ds_seq_id: [int] interger index of the sequential parent damage state (i.e., damage state 1, 2, 3, 4);
137
+ - ds_sub_id: [int] interger index for the mutually exlusive of simeltaneous sub damage state; use 1 to indicate a sequential damage state with no sub damage state.
138
+ - **damage_consequences.json**: Building-level and story-level simulated properties of building damage. Contains all variables within the _damage_consequences_ structure defined in the inputs schema.
139
+ - **simulated_damage.json**: Component-level simulated damage properties. Contains all variables within the _damage.tenant_units_ structure defined in the inputs schema. Each variable containing realization of component damage should be defined uniquely for each tenant unit (shown as "tu" below). Each tenant_unit cell should contain the following variables:
140
+ - tenant_unit{tu}.qnt_damaged: [array: simulations × damage states] The number of damaged components in each component damage state for each realization of the simulation.
141
+ - tenant_unit{tu}.worker_days: [array: simulations × damage states] The number of single worker days required to repair all damage to this damage state of this component at this story for each realization.
142
+ - tenant_unit{tu}.qnt_damaged_side_1: [array: simulations × damage states] The number of damaged components in each component damage state assocaited with side 1 of the building; set to zero if not associated with a particular side. This is only for exterior cladding components.
143
+ - tenant_unit{tu}.qnt_damaged_side_2: [array: simulations × damage states] The number of damaged components in each component damage state assocaited with side 2 of the building; set to zero if not associated with a particular side. This is only for exterior cladding components.
144
+ - tenant_unit{tu}.qnt_damaged_side_3: [array: simulations × damage states] The number of damaged components in each component damage state assocaited with side 3 of the building; set to zero if not associated with a particular side. This is only for exterior cladding components.
145
+ - tenant_unit{tu}.qnt_damaged_side_4: [array: simulations × damage states] The number of damaged components in each component damage state associated with side 4 of the building; set to zero if not associated with a particular side. This is only for exterior cladding components.
146
+ - tenant_unit{tu}.num_comps: [array: 1 × damage states] The total number of components associated with each damage state (should be uniform for damage state of the same component stack).
147
+
148
+ ### Additional Assessment Options
149
+ These options control various aspects of the functional recovery assessment and can be customized via `optional_inputs.json`. To customize assessment options, create an `optional_inputs.json` file in your input directory (can copy over from examples) with only the fields you want to override. Default analysis options are defined from [src/atc138/data/default_inputs.json](src/atc138/data/default_inputs.json)
150
+
151
+ - **impedance_options**: Python dictionary containing method inputs for assessing impeding factors (delays in starting repairs). Key fields include:
152
+ - `include_impedance`: Enable/disable different delay types (inspection, financing, permitting, engineering, contractor)
153
+ - `system_design_time`: Engineering design duration parameters (f, r, t, w for lognormal distribution)
154
+ - `eng_design_min_days`/`eng_design_max_days`: Bounds on engineering design time
155
+ - `mitigation`: Building-specific factors (essential facility status, contractor relationships, funding source)
156
+ - `impedance_beta`: Uncertainty parameter for delay distributions
157
+ - `default_lead_time`: Default procurement time for materials (182 days)
158
+ - `demand_surge`: Regional demand surge effects based on urban density and ground motion
159
+
160
+ - **repair_time_options**: Python dictionary containing method inputs for the repair schedule. Key fields include:
161
+ - `max_workers_per_sqft_story`: Maximum workers per square foot per story
162
+ - `max_workers_per_sqft_story_temp_repair`: Maximum workers for temporary repairs
163
+ - `max_workers_building_min`/`max_workers_building_max`: Bounds on total building workforce
164
+ - `allow_tmp_repairs`: Enable/disable temporary repair capabilities
165
+ - `allow_shoring`: Enable/disable shoring during repairs
166
+
167
+ - **functionality_options**: Python dictionary containing method inputs for building function assessment. Key fields include:
168
+ - `calculate_red_tag`: Enable/disable red tag assessment
169
+ - `red_tag_clear_time`: Days to clear red tags (default: 7)
170
+ - `egress_threshold`: Minimum fraction of egress paths required (default: 0.5)
171
+ - `fire_watch`: Enable/disable fire watch requirements
172
+ - `habitability_requirements`: Utility requirements for habitability (electrical, water, HVAC)
173
+ - `water_pressure_max_story`: Maximum stories affected by water pressure loss
174
+ - `heat_utility`: Fuel type for heating ("gas" or "electric")
175
+
176
+ ### Optional Building Specific Data
177
+ The file(s) listed below contain data that is optional for the assessment. If the files do not exist, the method will make simplifying assumptions to account for the missing data (as noted below). Save in the input directory of your analysis.
178
+ - **utility_downtime.json**: Regional utility simulated downtimes for gas, water, and electrical power networks. Should contain arrays for each utility type with downtime in days per realization. If missing, assumes zero downtime for all utilities.
179
+
180
+ ### Overriding Default Inputs
181
+
182
+ The assessment uses a hierarchy of input sources, with later sources taking precedence over earlier ones:
183
+
184
+ 1. **Built-in defaults** from [src/atc138/data/default_inputs.json](src/atc138/data/default_inputs.json)
185
+ 2. **Custom static tables** (CSV files copied to input directory)
186
+ 3. **optional_inputs.json** (highest priority for assessment options)
187
+
188
+ ### Customizing Static Tables
189
+
190
+ To override default component, system, or tenant attributes, copy the relevant CSV file from `src/atc138/data/` to your input directory and modify it:
191
+
192
+ - **component_attributes.csv**: Component properties (repair costs, crew sizes, system assignments)
193
+ - **damage_state_attribute_mapping.csv**: How damage states affect function and reoccupancy
194
+ - **systems.csv**: System definitions and functional requirements
195
+ - **subsystems.csv**: Subsystem groupings
196
+ - **tenant_function_requirements.csv**: Occupancy-specific functional thresholds
197
+ - **temp_repair_class.csv**: Temporary repair capabilities
198
+
199
+ For example, to modify component repair times, copy `component_attributes.csv` to your input directory and edit the relevant rows.
200
+
201
+ ## Outputs
202
+ A brief description of the various output variables are provided below. A detailed schema of all expected input and output subfields is provided in [src/atc138/data/default_inputs.json](src/atc138/data/default_inputs.json).
203
+
204
+ - **functionality['recovery']**: Python dictionary
205
+ Python dictionary containing the simulated tenant- and building-level functional recovery and reoccupancy outcomes
206
+ - **functionality['building_repair_schedule']**: Python dictionary
207
+ Python dictionary containing the simulated building repair schedule
208
+ - **functionality['worker_data']**: Python dictionary
209
+ Python dictionary containing the simulation of allocated workers throughout the repair process
210
+ - **functionality['impeding_factors']**: Python dictionary
211
+ Python dictionary containing the simulated impeding factors delaying the start of system repair
212
+
213
+ ## Building from Pelicun Outputs
214
+
215
+ Use this workflow when you have FEMA P-58 damage and loss results from Pelicun and want to assess functional recovery. This is an alternative to manually creating the raw input files described above.
216
+
217
+ **Requirements**: PBE Application version ~=4.4 and pelicun~=3.5 (optional dependency - install with `pip install pelicun~=3.5` if needed)
218
+
219
+ To use Pelicun outputs, ensure `simulated_inputs.json` does not exist in your model directory. Place the following Pelicun output files in your input directory:
220
+
221
+ ### Required Pelicun Files
222
+ - **CMP_QNT.csv**: Component quantities and properties
223
+ - **DL_summary.csv**: Damage and loss summary (for irreparable cases)
224
+ - **DMG_sample.csv**: Damage realizations for all components
225
+ - **DV_repair_sample.csv**: Repair decision variables (legacy name `DV_bldg_repair_sample.csv` also supported)
226
+ - **general_inputs.json**: Building properties (egress, occupancy, dimensions, cost ratios)
227
+ - **input.json**: Basic building information (stories, replacement cost, plan area)
228
+
229
+ ### Optional Pelicun Files
230
+ - **side_damage_ratio.csv**: Custom cladding damage distribution (num_reals × 2 array)
231
+
232
+ ### Additional Required Files
233
+ - **tenant_unit_list.csv**: Tenant unit definitions (same format as manual workflow)
234
+
235
+ The assessment will automatically detect Pelicun files and convert them to the standard ATC-138 format. Use the same CLI or Python API as normal:
236
+
237
+ ```python
238
+ from src.atc138 import driver
239
+
240
+ example_dir = './examples/RCSW_4story_pelicun'
241
+ output_dir = './examples/RCSW_4story_pelicun/output'
242
+
243
+ driver.run_analysis(example_dir, output_dir, seed=985)
244
+ ```
245
+
246
+ **Note**: Cladding damage is currently distributed randomly across building sides. Custom side assignment is planned for future versions.
247
+
248
+ ## Testing
249
+
250
+ Install the package with test dependencies:
251
+
252
+ ```bash
253
+ pip install -e ".[test]"
254
+ ```
255
+
256
+ Run the integration tests, which compare Python outputs against stored reference data for each model in `tests/fixtures/models/`:
257
+
258
+ ```bash
259
+ pytest tests/test_integration.py -v
260
+ ```
261
+
262
+ Integration tests are marked with `@pytest.mark.integration` and can be filtered:
263
+
264
+ ```bash
265
+ # Run only integration tests
266
+ pytest -m integration
267
+
268
+ # Skip integration tests
269
+ pytest -m "not integration"
270
+ ```
271
+
272
+ The comparison engine can also be used standalone for detailed inspection:
273
+
274
+ ```bash
275
+ python tests/compare_runs.py <reference_dir> <python_output_dir>
276
+ ```
277
+
278
+ ### Validation Testing Against MATLAB
279
+
280
+ For detailed guidance on validating the Python implementation against the original MATLAB framework, see [tests/detailed_inspection_guide.md](tests/detailed_inspection_guide.md).
atc138-1.3.0/README.md ADDED
@@ -0,0 +1,261 @@
1
+ # Functional-Recovery---Python
2
+ This is translation of Matlab codebase into Python for quantifying building-specific functional recovery and reoccupancy based on a probabilistic performance-based earthquake engineering framework.
3
+
4
+ ## Requirements
5
+
6
+ - **Python Version**: 3.9 or later (recommend 3.9)
7
+ - **Package Manager**: pip (comes with Python)
8
+
9
+ ### Installation
10
+
11
+ The ATC-138 Functional Recovery Assessment tool is distributed as a Python package. Install it using pip:
12
+
13
+
14
+ ```bash
15
+ # Create and activate a virtual environment (recommended)
16
+ python -m venv .venv
17
+
18
+ # Activate virtual environment
19
+ # On Windows (PowerShell):
20
+ .\.venv\Scripts\Activate.ps1
21
+ # On macOS/Linux:
22
+ source .venv/bin/activate
23
+
24
+ # Install the package in editable mode
25
+ pip install -e .
26
+ ```
27
+
28
+
29
+ ### Verify Installation
30
+
31
+ After installation, verify that the CLI is available:
32
+
33
+ ```bash
34
+ atc138 --help
35
+ ```
36
+
37
+ You should see the command help output with available options.
38
+
39
+ ## Running an Assessment
40
+
41
+ An assessment can be run directly from the command line, or as imported within a Python workflow. If `simulated_inputs.json` does not exist, it will be created using default inputs within `src/atc138/data`. Various assessment options can be overridden by placing them in file `optional_inputs.json` file within the input directory. This file can be customized for each assessment if desired and will be set as default values if not specified.
42
+
43
+ If `simulated_inputs.json` exists, the input builder will not re-run unless `--force_rebuild` is used in the CLI command.
44
+
45
+ ### Running from the command line
46
+
47
+ With the input directory containing the necessary inputs, perform an assessment by running:
48
+
49
+ ```bash
50
+ python -m atc138.cli dir/to/inputs dir/to/outputs [options]
51
+ ```
52
+
53
+ Available options:
54
+ - `--seed SEED`: Random seed for reproducible results (integer)
55
+ - `--force_rebuild`: Force regeneration of `simulated_inputs.json` even if it exists
56
+
57
+ For example, the ICSB example case is run with:
58
+
59
+ ```bash
60
+ python -m atc138.cli ./examples/ICSB ./examples/ICSB/output
61
+ ```
62
+
63
+ Or with custom options:
64
+
65
+ ```bash
66
+ python -m atc138.cli ./examples/ICSB ./examples/ICSB/output --seed 12345 --force_rebuild
67
+ ```
68
+
69
+ ### Imported via Python script
70
+
71
+ Ensure that the `src/` directory is on the path of the main script. Then:
72
+
73
+ ```python
74
+ from src.atc138 import driver
75
+
76
+ example_dir = './examples/ICSB'
77
+ output_dir = './examples/ICSB/output'
78
+
79
+ driver.run_analysis(example_dir, output_dir, seed=985)
80
+ ```
81
+
82
+ If `simulated_inputs.json` exists, the input builder will not re-run unless the argument `force_rebuild=True` is used for `driver.run_analysis`.
83
+
84
+ ### Plotting outputs
85
+
86
+ Several basic plotting tools are provided in `plotters/`, which can be used after an analysis generates results. This is run with
87
+
88
+ ```python
89
+ from plotters.main_plot_functionality import plot_results
90
+ output_dir = './examples/ICSB/output'
91
+ plot_results(output_dir, p_gantt=50) # plot median realization
92
+ ```
93
+
94
+ which will plot:
95
+ - Component and system-level breakdowns of hinderance to reoccupancy and functional status per day
96
+ - Distribution of realizations achieving reoccupancy and functional status per day
97
+ - Mean and per-realization breakdown of recovery trajectories
98
+ - Gantt chart of impeding factors, repair work, number of workers, and recovery status of building per day for the realization with `p_gantt`-th percentile of functional recovery day.
99
+
100
+ ## Inputs
101
+ A brief description of the various input variables are provided below. A detailed schema of all expected input and output subfields is provided in [src/atc138/data/default_inputs.json](src/atc138/data/default_inputs.json).
102
+
103
+ ### Example Inputs
104
+ Four example inputs are provided to help illustrate both the construction of the inputs file and the implementation. These files are located in the `examples/` directory and can be run through the assessment by setting the variable names accordingly above.
105
+
106
+ ### Required Building Specific Data
107
+ Each file listed below contains data specific to the building performance model and simulated damage given for a specific level of shaking. Each file listed will need to be created for each unique assessment and saved in the root directory of the build script. Data are contained in either json or csv format.
108
+ - **building_model.json**: Basic properties of the building and performance model. Contains all variables within the _building_model_ structure defined in the inputs schema.
109
+ - **tenant_unit_list.csv**: Table that lists each tenant unit within the building; one row per tenant unit. This table requires the following attributes:
110
+ - id: [int or string] unique identifier for this tenant unit
111
+ - story: [int] building story where this tenant unit is located (ground floor is listed at 1)
112
+ - area: [number] total gross plan area of the tenant unit, in square feet
113
+ - perim_area: [number] total exterior perimeter area (elevation) of the tenant unit, is square feet
114
+ - occupancy_id: [int] foreign key to the _occupancy_id_ attribute of the tenant_function_requirements.csv table in the _data_ directory
115
+ - **comp_ds_list.csv**: Table that lists each component and damage state populated in the building performance model; one row per each component's damage state. This table requires the following attributes:
116
+ - comp_id: [string] unique FEMA P-58 component identifier
117
+ - ds_seq_id: [int] interger index of the sequential parent damage state (i.e., damage state 1, 2, 3, 4);
118
+ - ds_sub_id: [int] interger index for the mutually exlusive of simeltaneous sub damage state; use 1 to indicate a sequential damage state with no sub damage state.
119
+ - **damage_consequences.json**: Building-level and story-level simulated properties of building damage. Contains all variables within the _damage_consequences_ structure defined in the inputs schema.
120
+ - **simulated_damage.json**: Component-level simulated damage properties. Contains all variables within the _damage.tenant_units_ structure defined in the inputs schema. Each variable containing realization of component damage should be defined uniquely for each tenant unit (shown as "tu" below). Each tenant_unit cell should contain the following variables:
121
+ - tenant_unit{tu}.qnt_damaged: [array: simulations × damage states] The number of damaged components in each component damage state for each realization of the simulation.
122
+ - tenant_unit{tu}.worker_days: [array: simulations × damage states] The number of single worker days required to repair all damage to this damage state of this component at this story for each realization.
123
+ - tenant_unit{tu}.qnt_damaged_side_1: [array: simulations × damage states] The number of damaged components in each component damage state assocaited with side 1 of the building; set to zero if not associated with a particular side. This is only for exterior cladding components.
124
+ - tenant_unit{tu}.qnt_damaged_side_2: [array: simulations × damage states] The number of damaged components in each component damage state assocaited with side 2 of the building; set to zero if not associated with a particular side. This is only for exterior cladding components.
125
+ - tenant_unit{tu}.qnt_damaged_side_3: [array: simulations × damage states] The number of damaged components in each component damage state assocaited with side 3 of the building; set to zero if not associated with a particular side. This is only for exterior cladding components.
126
+ - tenant_unit{tu}.qnt_damaged_side_4: [array: simulations × damage states] The number of damaged components in each component damage state associated with side 4 of the building; set to zero if not associated with a particular side. This is only for exterior cladding components.
127
+ - tenant_unit{tu}.num_comps: [array: 1 × damage states] The total number of components associated with each damage state (should be uniform for damage state of the same component stack).
128
+
129
+ ### Additional Assessment Options
130
+ These options control various aspects of the functional recovery assessment and can be customized via `optional_inputs.json`. To customize assessment options, create an `optional_inputs.json` file in your input directory (can copy over from examples) with only the fields you want to override. Default analysis options are defined from [src/atc138/data/default_inputs.json](src/atc138/data/default_inputs.json)
131
+
132
+ - **impedance_options**: Python dictionary containing method inputs for assessing impeding factors (delays in starting repairs). Key fields include:
133
+ - `include_impedance`: Enable/disable different delay types (inspection, financing, permitting, engineering, contractor)
134
+ - `system_design_time`: Engineering design duration parameters (f, r, t, w for lognormal distribution)
135
+ - `eng_design_min_days`/`eng_design_max_days`: Bounds on engineering design time
136
+ - `mitigation`: Building-specific factors (essential facility status, contractor relationships, funding source)
137
+ - `impedance_beta`: Uncertainty parameter for delay distributions
138
+ - `default_lead_time`: Default procurement time for materials (182 days)
139
+ - `demand_surge`: Regional demand surge effects based on urban density and ground motion
140
+
141
+ - **repair_time_options**: Python dictionary containing method inputs for the repair schedule. Key fields include:
142
+ - `max_workers_per_sqft_story`: Maximum workers per square foot per story
143
+ - `max_workers_per_sqft_story_temp_repair`: Maximum workers for temporary repairs
144
+ - `max_workers_building_min`/`max_workers_building_max`: Bounds on total building workforce
145
+ - `allow_tmp_repairs`: Enable/disable temporary repair capabilities
146
+ - `allow_shoring`: Enable/disable shoring during repairs
147
+
148
+ - **functionality_options**: Python dictionary containing method inputs for building function assessment. Key fields include:
149
+ - `calculate_red_tag`: Enable/disable red tag assessment
150
+ - `red_tag_clear_time`: Days to clear red tags (default: 7)
151
+ - `egress_threshold`: Minimum fraction of egress paths required (default: 0.5)
152
+ - `fire_watch`: Enable/disable fire watch requirements
153
+ - `habitability_requirements`: Utility requirements for habitability (electrical, water, HVAC)
154
+ - `water_pressure_max_story`: Maximum stories affected by water pressure loss
155
+ - `heat_utility`: Fuel type for heating ("gas" or "electric")
156
+
157
+ ### Optional Building Specific Data
158
+ The file(s) listed below contain data that is optional for the assessment. If the files do not exist, the method will make simplifying assumptions to account for the missing data (as noted below). Save in the input directory of your analysis.
159
+ - **utility_downtime.json**: Regional utility simulated downtimes for gas, water, and electrical power networks. Should contain arrays for each utility type with downtime in days per realization. If missing, assumes zero downtime for all utilities.
160
+
161
+ ### Overriding Default Inputs
162
+
163
+ The assessment uses a hierarchy of input sources, with later sources taking precedence over earlier ones:
164
+
165
+ 1. **Built-in defaults** from [src/atc138/data/default_inputs.json](src/atc138/data/default_inputs.json)
166
+ 2. **Custom static tables** (CSV files copied to input directory)
167
+ 3. **optional_inputs.json** (highest priority for assessment options)
168
+
169
+ ### Customizing Static Tables
170
+
171
+ To override default component, system, or tenant attributes, copy the relevant CSV file from `src/atc138/data/` to your input directory and modify it:
172
+
173
+ - **component_attributes.csv**: Component properties (repair costs, crew sizes, system assignments)
174
+ - **damage_state_attribute_mapping.csv**: How damage states affect function and reoccupancy
175
+ - **systems.csv**: System definitions and functional requirements
176
+ - **subsystems.csv**: Subsystem groupings
177
+ - **tenant_function_requirements.csv**: Occupancy-specific functional thresholds
178
+ - **temp_repair_class.csv**: Temporary repair capabilities
179
+
180
+ For example, to modify component repair times, copy `component_attributes.csv` to your input directory and edit the relevant rows.
181
+
182
+ ## Outputs
183
+ A brief description of the various output variables are provided below. A detailed schema of all expected input and output subfields is provided in [src/atc138/data/default_inputs.json](src/atc138/data/default_inputs.json).
184
+
185
+ - **functionality['recovery']**: Python dictionary
186
+ Python dictionary containing the simulated tenant- and building-level functional recovery and reoccupancy outcomes
187
+ - **functionality['building_repair_schedule']**: Python dictionary
188
+ Python dictionary containing the simulated building repair schedule
189
+ - **functionality['worker_data']**: Python dictionary
190
+ Python dictionary containing the simulation of allocated workers throughout the repair process
191
+ - **functionality['impeding_factors']**: Python dictionary
192
+ Python dictionary containing the simulated impeding factors delaying the start of system repair
193
+
194
+ ## Building from Pelicun Outputs
195
+
196
+ Use this workflow when you have FEMA P-58 damage and loss results from Pelicun and want to assess functional recovery. This is an alternative to manually creating the raw input files described above.
197
+
198
+ **Requirements**: PBE Application version ~=4.4 and pelicun~=3.5 (optional dependency - install with `pip install pelicun~=3.5` if needed)
199
+
200
+ To use Pelicun outputs, ensure `simulated_inputs.json` does not exist in your model directory. Place the following Pelicun output files in your input directory:
201
+
202
+ ### Required Pelicun Files
203
+ - **CMP_QNT.csv**: Component quantities and properties
204
+ - **DL_summary.csv**: Damage and loss summary (for irreparable cases)
205
+ - **DMG_sample.csv**: Damage realizations for all components
206
+ - **DV_repair_sample.csv**: Repair decision variables (legacy name `DV_bldg_repair_sample.csv` also supported)
207
+ - **general_inputs.json**: Building properties (egress, occupancy, dimensions, cost ratios)
208
+ - **input.json**: Basic building information (stories, replacement cost, plan area)
209
+
210
+ ### Optional Pelicun Files
211
+ - **side_damage_ratio.csv**: Custom cladding damage distribution (num_reals × 2 array)
212
+
213
+ ### Additional Required Files
214
+ - **tenant_unit_list.csv**: Tenant unit definitions (same format as manual workflow)
215
+
216
+ The assessment will automatically detect Pelicun files and convert them to the standard ATC-138 format. Use the same CLI or Python API as normal:
217
+
218
+ ```python
219
+ from src.atc138 import driver
220
+
221
+ example_dir = './examples/RCSW_4story_pelicun'
222
+ output_dir = './examples/RCSW_4story_pelicun/output'
223
+
224
+ driver.run_analysis(example_dir, output_dir, seed=985)
225
+ ```
226
+
227
+ **Note**: Cladding damage is currently distributed randomly across building sides. Custom side assignment is planned for future versions.
228
+
229
+ ## Testing
230
+
231
+ Install the package with test dependencies:
232
+
233
+ ```bash
234
+ pip install -e ".[test]"
235
+ ```
236
+
237
+ Run the integration tests, which compare Python outputs against stored reference data for each model in `tests/fixtures/models/`:
238
+
239
+ ```bash
240
+ pytest tests/test_integration.py -v
241
+ ```
242
+
243
+ Integration tests are marked with `@pytest.mark.integration` and can be filtered:
244
+
245
+ ```bash
246
+ # Run only integration tests
247
+ pytest -m integration
248
+
249
+ # Skip integration tests
250
+ pytest -m "not integration"
251
+ ```
252
+
253
+ The comparison engine can also be used standalone for detailed inspection:
254
+
255
+ ```bash
256
+ python tests/compare_runs.py <reference_dir> <python_output_dir>
257
+ ```
258
+
259
+ ### Validation Testing Against MATLAB
260
+
261
+ For detailed guidance on validating the Python implementation against the original MATLAB framework, see [tests/detailed_inspection_guide.md](tests/detailed_inspection_guide.md).
@@ -0,0 +1,60 @@
1
+ [build-system]
2
+ requires = ["hatchling"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "atc138"
7
+ version = "1.3.0"
8
+ description = "Functional Recovery Assessment (ATC-138)"
9
+ readme = "README.md"
10
+ requires-python = ">=3.9"
11
+ authors = [
12
+ {name = "Dustin Cook", email = "dustin.cook@nist.gov"},
13
+ ]
14
+ classifiers = [
15
+ "Programming Language :: Python :: 3",
16
+ "Operating System :: OS Independent",
17
+ ]
18
+ dependencies = [
19
+ "numpy~=2.0",
20
+ "pandas",
21
+ "scipy",
22
+ "matplotlib",
23
+ "seaborn",
24
+ ]
25
+
26
+ [project.scripts]
27
+ atc138 = "atc138.cli:main"
28
+
29
+ [project.optional-dependencies]
30
+ test = ["pytest>=7.0"]
31
+
32
+ [project.urls]
33
+ "Homepage" = "https://github.com/NHERI-SimCenter/Functional-Recovery-Python"
34
+ "Bug Tracker" = "https://github.com/NHERI-SimCenter/Functional-Recovery-Python/issues"
35
+
36
+ [tool.hatch.build.targets.wheel]
37
+ packages = ["src/atc138"]
38
+ exclude = [
39
+ "**/__pycache__",
40
+ "**/*.pyc",
41
+ "**/.DS_Store",
42
+ ]
43
+
44
+ [tool.hatch.build.targets.sdist]
45
+ include = [
46
+ "/src/atc138",
47
+ "/README.md",
48
+ "/pyproject.toml",
49
+ ]
50
+ exclude = [
51
+ "**/__pycache__",
52
+ "**/*.pyc",
53
+ "**/.DS_Store",
54
+ ]
55
+
56
+ [tool.pytest.ini_options]
57
+ pythonpath = ["tests"]
58
+ markers = [
59
+ "integration: long-running tests comparing full model runs against reference data",
60
+ ]
File without changes