Пример #1
0
def run_with_base_class():
    client = IncoreClient(pyglobals.INCORE_API_DEV_URL)
    client.clear_cache()
    pipeline_restoration = PipelineRestoration(client)

    # shelby county pipelines
    pipeline_restoration.load_remote_input_dataset("pipeline",
                                                   "5a284f28c7d30d13bc081d14")
    pipeline_restoration.load_remote_input_dataset("pipeline_damage",
                                                   "61f36023c53b3620b6b614c6")

    # Load fragility mapping
    restoration_service = RestorationService(client)
    mapping_set = MappingSet(
        restoration_service.get_mapping("61f35f09903e515036cee106"))
    pipeline_restoration.set_input_dataset('dfr3_mapping_set', mapping_set)

    pipeline_restoration.set_parameter("result_name",
                                       "pipeline_restoration_times")

    pipeline_restoration.set_parameter("restoration_key",
                                       "Restoration ID Code")
    pipeline_restoration.set_parameter("num_available_workers", 4)
    pipeline_restoration.set_parameter("num_cpu", 4)

    # Run pipeline restoration analysis
    pipeline_restoration.run_analysis()
Пример #2
0
def run_with_base_class():
    client = IncoreClient(pyglobals.INCORE_API_DEV_URL)
    client.clear_cache()

    md = MeanDamage(client)

    md.load_remote_input_dataset("damage", "61044165ca3e973ce13c0526")
    md.load_remote_input_dataset("dmg_ratios", "5a284f2cc7d30d13bc081f96")
    md.set_parameter("result_name", "mean_damage_bridge")
    md.set_parameter("damage_interval_keys",
                     ["DS_0", "DS_1", "DS_2", "DS_3", "DS_4"])
    md.set_parameter("num_cpu", 1)

    # Run analysis
    md.run_analysis()
Пример #3
0
def test_road_failure():
    client = IncoreClient(INCORE_API_DEV_URL, token_file_name=".incrtesttoken")

    # road inventory for Galveston island
    road_dataset_id = "5f0dd5ecb922f96f4e962caf"
    # distance table for Galveston island
    distance_dataset_id = "5f1883abfeef2d758c4e857d"
    # road damage by hurricane inundation mapping
    mapping_id = "5f0cb04fe392b24d4800f316"
    # Galveston Deterministic Hurricane - Kriging inundationDuration
    hazard_type = "hurricane"
    hazard_id = "5f10837c01d3241d77729a4f"

    # Create road damage
    road_failure = RoadFailure(client)
    # Load input datasets
    road_failure.load_remote_input_dataset("roads", road_dataset_id)
    road_failure.load_remote_input_dataset("distance_table",
                                           distance_dataset_id)
    # Load fragility mapping
    fragility_service = FragilityService(client)
    mapping_set = MappingSet(fragility_service.get_mapping(mapping_id))
    road_failure.set_input_dataset('dfr3_mapping_set', mapping_set)
    # Specify the result name
    result_name = "road_result"
    # Set analysis parameters
    road_failure.set_parameter("result_name", result_name)
    road_failure.set_parameter("hazard_type", hazard_type)
    road_failure.set_parameter("hazard_id", hazard_id)
    road_failure.set_parameter("num_cpu", 4)

    # Run road damage by hurricane inundation analysis
    result = road_failure.run_analysis()

    assert result is True
Пример #4
0
def run_with_base_class():
    client = IncoreClient(pyglobals.INCORE_API_DEV_URL)

    population_dislocation = "60f098f502897f12fcda19ec"  # dev Galveston testbed
    transition_probability_matrix = "60ef513802897f12fcd9765c"
    initial_probability_vector = "60ef532e02897f12fcd9ac63"

    seed = 1234
    t_delta = 1.0
    t_final = 90.0

    housing_recovery = HousingRecoverySequential(client)

    # Parameter setup
    housing_recovery.set_parameter('seed', seed)
    housing_recovery.set_parameter('t_delta', t_delta)
    housing_recovery.set_parameter('t_final', t_final)

    # Dataset inputs
    housing_recovery.load_remote_input_dataset("population_dislocation_block",
                                               population_dislocation)
    housing_recovery.load_remote_input_dataset('tpm',
                                               transition_probability_matrix)
    housing_recovery.load_remote_input_dataset('initial_stage_probabilities',
                                               initial_probability_vector)

    housing_recovery.run()
Пример #5
0
def run_with_base_class():
    client = IncoreClient(pyglobals.INCORE_API_DEV_URL)
    wf_rest = WaterFacilityRestoration(client)

    # Load restoration mapping
    restorationsvc = RestorationService(client)
    mapping_set = MappingSet(
        restorationsvc.get_mapping(
            "61f075ee903e515036cee0a5"))  # new format of mapping
    wf_rest.load_remote_input_dataset(
        "water_facilities", "5a284f2ac7d30d13bc081e52")  # water facility
    wf_rest.set_input_dataset('dfr3_mapping_set', mapping_set)
    wf_rest.set_parameter("result_name", "wf_restoration")
    wf_rest.set_parameter("restoration_key", "Restoration ID Code")
    wf_rest.set_parameter("end_time", 100.0)
    wf_rest.set_parameter("time_interval", 1.0)
    wf_rest.set_parameter("pf_interval", 0.05)

    wf_rest.run_analysis()

    # test utility function
    wf_util = WaterFacilityRestorationUtil(wf_rest)
    functionality = wf_util.get_percentage_func(
        guid="e1bce78d-00a1-4605-95f3-3776ff907f73",
        damage_state="DS_0",
        time=2.0)
    time = wf_util.get_restoration_time(
        guid="e1bce78d-00a1-4605-95f3-3776ff907f73",
        damage_state="DS_1",
        pf=0.81)
    print(functionality, time)
Пример #6
0
def run_base_analysis():
    client = IncoreClient(pyglobals.INCORE_API_DEV_URL)
    seaside_cge = SeasideCGEModel(client)

    # SAM
    sam = "5f6127105060967d84ab0f99"

    # CAPITAL COMP
    bb = "5f6132ad5060967d84abdfd3"

    # MISC TABLES
    employ = "5f6127e85060967d84ab0feb"
    jobcr = "5f61284d5060967d84ab1014"
    hhtable = "5f6128b85060967d84ab103d"
    sims = "5f6129035060967d84ab1066"
    sector_shocks = "5f6123e35060967d84ab0f70"

    seaside_cge.set_parameter("print_solver_output", False)

    seaside_cge.load_remote_input_dataset("SAM", sam)
    seaside_cge.load_remote_input_dataset("BB", bb)
    seaside_cge.load_remote_input_dataset("EMPLOY", employ)
    seaside_cge.load_remote_input_dataset("JOBCR", jobcr)
    seaside_cge.load_remote_input_dataset("HHTABLE", hhtable)
    seaside_cge.load_remote_input_dataset("SIMS", sims)
    seaside_cge.load_remote_input_dataset("sector_shocks", sector_shocks)

    seaside_cge.run_analysis()
def run_with_base_class():
    client = IncoreClient(INCORE_API_DEV_URL)
    hazard_type = "earthquake"
    hazard_id = "5b902cb273c3371e1236b36b"
    facility_datasetid = "5a284f2ac7d30d13bc081e52"

    mapping_id = "5b47c3b1337d4a387e85564b"  # Hazus Potable Water Facility Fragility Mapping - Only PGA

    liq_geology_dataset_id = "5a284f53c7d30d13bc08249c"

    uncertainty = False
    liquefaction = False
    liq_fragility_key = "pgd"

    wf_dmg = WaterFacilityDamage(client)
    wf_dmg.load_remote_input_dataset("water_facilities", facility_datasetid)

    # Load fragility mapping
    fragility_service = FragilityService(client)
    mapping_set = MappingSet(fragility_service.get_mapping(mapping_id))
    wf_dmg.set_input_dataset('dfr3_mapping_set', mapping_set)

    result_name = "wf-dmg-results.csv"
    wf_dmg.set_parameter("result_name", result_name)
    wf_dmg.set_parameter("hazard_type", hazard_type)
    wf_dmg.set_parameter("hazard_id", hazard_id)
    wf_dmg.set_parameter("fragility_key", "pga")
    wf_dmg.set_parameter("use_liquefaction", liquefaction)
    wf_dmg.set_parameter("liquefaction_geology_dataset_id",
                         liq_geology_dataset_id)
    wf_dmg.set_parameter("liquefaction_fragility_key", liq_fragility_key)
    wf_dmg.set_parameter("use_hazard_uncertainty", uncertainty)
    wf_dmg.set_parameter("num_cpu", 4)

    wf_dmg.run_analysis()
def run_with_base_class():
    client = IncoreClient()
    transportation_recovery = TransportationRecovery(client)

    nodes = "5c5de1dec5c0e488fc0355f7"
    transportation_recovery.load_remote_input_dataset("nodes", nodes)

    links = "5c5de25ec5c0e488fc035613"
    transportation_recovery.load_remote_input_dataset("links", links)

    bridges = "5a284f2dc7d30d13bc082040"
    transportation_recovery.load_remote_input_dataset('bridges', bridges)

    bridge_damage = "5c5ddff0c5c0e488fc0355df"
    transportation_recovery.load_remote_input_dataset('bridge_damage_value',
                                                      bridge_damage)

    unrepaired = "5c5de0c5c5c0e488fc0355eb"
    transportation_recovery.load_remote_input_dataset('unrepaired_bridge',
                                                      unrepaired)

    ADT_data = "5c5dde00c5c0e488fc032d7f"
    transportation_recovery.load_remote_input_dataset('ADT', ADT_data)

    transportation_recovery.set_parameter("num_cpu", 4)
    transportation_recovery.set_parameter("pm", 1)
    transportation_recovery.set_parameter('ini_num_population', 5)
    transportation_recovery.set_parameter("population_size", 3)
    transportation_recovery.set_parameter("num_generation", 2)
    transportation_recovery.set_parameter("mutation_rate", 0.1)
    transportation_recovery.set_parameter("crossover_rate", 1.0)

    transportation_recovery.run_analysis()
def run_with_base_class():
    # client = IncoreClient()
    client = IncoreClient(INCORE_API_DEV_URL)

    # Building inventory shapefile, Seaside, OR
    # bldg_dataset_id = "5bcf2fcbf242fe047ce79dad"
    # original ERGO Building inventory shapefile
    bldg_dataset_id = "5f518b76301b3c1b569d7e9c"
    # Building structural damage, csv file, earthquake Seaside - kube
    # bldg_dmg_id = "5f514554bd2164309e79f67c"
    # original ERGO Building structural damage, csv file
    bldg_dmg_id = "5f5191763f9bbf5a2bbbb4a9"

    bldg_econ_dmg = BuildingEconLoss(client)
    bldg_econ_dmg.load_remote_input_dataset("buildings", bldg_dataset_id)
    bldg_econ_dmg.load_remote_input_dataset("building_mean_dmg", bldg_dmg_id)

    result_name = "seaside_bldg_econ_loss"
    bldg_econ_dmg.set_parameter("result_name", result_name)
    # Inflation factor. A user must supply the inflation percentage between
    # building appraisal year and a year of interest (current, date of hazard etc.)
    bldg_econ_dmg.set_parameter("inflation_factor", 6.1648745519713215)

    # Run Analysis
    bldg_econ_dmg.run_analysis()
Пример #10
0
def run_with_base_class():
    year = 2019
    state = "kansas"
    county = "douglas"
    census_geo_level = "tract"

    # For a full example, datasets should be obtained using the Census API in pyincore_data
    national_vulnerability_feature_averages = "6241d9c653302c512d67ef26"
    social_vulnerability_demographic_factors = "6241e58653302c512d67fb38"

    client = IncoreClient(pyglobals.INCORE_API_DEV_URL)
    social_vulnerability = SocialVulnerability(client)

    social_vulnerability.set_parameter("result_name", "social_vulnerabilty")
    social_vulnerability.set_parameter("year", year)
    social_vulnerability.set_parameter("state", state)
    social_vulnerability.set_parameter("county", county)
    social_vulnerability.set_parameter("census_geo_level", census_geo_level)

    social_vulnerability.load_remote_input_dataset(
        "national_vulnerability_feature_averages",
        national_vulnerability_feature_averages)
    social_vulnerability.load_remote_input_dataset(
        "social_vulnerability_demographic_factors",
        social_vulnerability_demographic_factors)

    # Run pipeline damage analysis
    result = social_vulnerability.run_analysis()
Пример #11
0
def pytest_sessionstart(session):
    """
    Called after the Session object has been created and
    before performing collection and entering the run test loop.
    """
    try:
        with open(
                os.path.join(os.path.dirname(__file__), "pyincore/.incorepw"),
                'r') as f:
            cred = f.read().splitlines()
    except EnvironmentError:
        assert False
    credentials = jwt.decode(cred[0], cred[1])

    monkeypatch = MonkeyPatch()
    monkeypatch.setattr("builtins.input", lambda x: credentials["username"])
    monkeypatch.setattr("getpass.getpass", lambda y: credentials["password"])
    client = IncoreClient(service_url=pyglobals.INCORE_API_DEV_URL,
                          token_file_name=".incrtesttoken")
    pytest.client = client
    pytest.datasvc = DataService(client)
    pytest.fragilitysvc = FragilityService(client)
    pytest.repairsvc = RepairService(client)
    pytest.restorationsvc = RestorationService(client)
    pytest.hazardsvc = HazardService(client)
    pytest.spacesvc = SpaceService(client)
    print(
        f"Successfully initialized Incore client and services. Using {pyglobals.INCORE_API_DEV_URL}"
    )
Пример #12
0
def run_with_base_class():
    client = IncoreClient(pyglobals.INCORE_API_DEV_URL)
    epf_rest = EpfRestoration(client)
    restorationsvc = RestorationService(client)
    mapping_set = MappingSet(
        restorationsvc.get_mapping(
            "61f302e6e3a03e465500b3eb"))  # new format of mapping
    epf_rest.load_remote_input_dataset('epfs', '6189c103d5b02930aa3efc35')
    epf_rest.set_input_dataset('dfr3_mapping_set', mapping_set)
    epf_rest.set_parameter("result_name", "epf_restoration.csv")
    epf_rest.set_parameter("restoration_key", "Restoration ID Code")
    epf_rest.set_parameter("end_time", 100.0)
    epf_rest.set_parameter("time_interval", 1.0)
    epf_rest.set_parameter("pf_interval", 0.01)

    epf_rest.run_analysis()

    # test utility function
    epf_rest_util = EpfRestorationUtil(epf_rest)
    functionality = epf_rest_util.get_percentage_func(
        guid="60748fbd-67c3-4f8d-beb9-26685a53d3c5",
        damage_state="DS_0",
        time=2.0)
    time = epf_rest_util.get_restoration_time(
        guid="60748fbd-67c3-4f8d-beb9-26685a53d3c5",
        damage_state="DS_1",
        pf=0.81)
    print(functionality, time)
Пример #13
0
def run_with_base_class():
    client = IncoreClient(pyglobals.INCORE_API_DEV_URL)

    # Joplin population dislocation
    # incore-dev
    building_dmg = "602d96e4b1db9c28aeeebdce"  # dev Joplin
    # building_dmg = "602d975db1db9c28aeeebe35" # 15 guids test - dev Joplin
    housing_unit_alloc = "61563545483ecb19e4304c2a"  # dev Joplin
    bg_data = "5df7cb0b425e0b00092c9464"  # Joplin 2ev2
    value_loss = "602d508fb1db9c28aeedb2a5"

    result_name = "joplin-pop-disl-results"
    seed = 1111

    pop_dis = PopulationDislocation(client)

    pop_dis.load_remote_input_dataset("building_dmg", building_dmg)
    pop_dis.load_remote_input_dataset("housing_unit_allocation",
                                      housing_unit_alloc)
    pop_dis.load_remote_input_dataset("block_group_data", bg_data)
    pop_dis.load_remote_input_dataset("value_poss_param", value_loss)

    pop_dis.set_parameter("result_name", result_name)
    pop_dis.set_parameter("seed", seed)

    pop_dis.run_analysis()

    return True
def run_with_base_class():
    client = IncoreClient()

    # Setting up Id's for Dataset inputs: Earthquake building damage, Tsunami Building Damage and Damage Ratios
    eq_bldg_dmg_id = "5c5c9686c5c0e488fcf91903"
    tsunami_bldg_dmg_id = "5c5c96f6c5c0e488fcf9190f"

    # Create cumulative Building Damage
    cumulative_bldg_dmg = CumulativeBuildingDamage(client)

    # Load input datasets
    cumulative_bldg_dmg.load_remote_input_dataset("eq_bldg_dmg",
                                                  eq_bldg_dmg_id)
    cumulative_bldg_dmg.load_remote_input_dataset("tsunami_bldg_dmg",
                                                  tsunami_bldg_dmg_id)

    # Specify the result name
    result_name = "Cumulative_Bldg_Dmg_Result"

    # Set analysis parameters
    cumulative_bldg_dmg.set_parameter("num_cpu", 4)
    cumulative_bldg_dmg.set_parameter("result_name", result_name)

    # Run Cumulative Building Damage Analysis
    cumulative_bldg_dmg.run_analysis()
def run_with_base_class():
    client = IncoreClient()

    # Joplin
    # kube-dev
    building_dmg = "5df815ec425e0b00092daee1"
    housing_unit_alloc = "5df7c989425e0b00092c5eb4"
    bg_data = "5df7cb0b425e0b00092c9464"
    value_loss = "5df8384a425e0b00092de799"

    pop_dis = PopulationDislocation(client)

    pop_dis.load_remote_input_dataset("building_dmg", building_dmg)
    pop_dis.load_remote_input_dataset("housing_unit_allocation", housing_unit_alloc)
    pop_dis.load_remote_input_dataset("block_group_data", bg_data)
    pop_dis.load_remote_input_dataset("value_poss_param", value_loss)

    # pop_dis.show_gdocstr_docs()

    result_name = "pop-dislocation-results"
    seed = 1111

    pop_dis.set_parameter("result_name", result_name)
    pop_dis.set_parameter("seed", seed)

    pop_dis.run_analysis()
Пример #16
0
def test_pipeline_dmg():
    client = IncoreClient(service_url=INCORE_API_DEV_URL, token_file_name=".incrtesttoken")
    pipeline_dmg = PipelineDamage(client)

    # test tsunami pipeline
    pipeline_dmg.load_remote_input_dataset("pipeline",
                                           "5ef1171b2367ff111d082f0c")

    # Load fragility mapping
    fragility_service = FragilityService(client)
    mapping_set = MappingSet(fragility_service.get_mapping("5ef11888da15730b13b84353"))
    pipeline_dmg.set_input_dataset('dfr3_mapping_set', mapping_set)

    pipeline_dmg.set_parameter("result_name",
                               "seaside_tsunami_pipeline_result")
    pipeline_dmg.set_parameter("hazard_type", "tsunami")
    pipeline_dmg.set_parameter("fragility_key",
                               "Non-Retrofit inundationDepth Fragility ID Code")
    pipeline_dmg.set_parameter("hazard_id", "5bc9eaf7f7b08533c7e610e1")
    pipeline_dmg.set_parameter("num_cpu", 4)

    # Run pipeline damage analysis
    result = pipeline_dmg.run_analysis()

    assert result is True
Пример #17
0
def run_with_base_class():
    client = IncoreClient(pyglobals.INCORE_API_DEV_URL)
    pipeline_dmg = PipelineDamage(client)

    # test tsunami pipeline
    pipeline_dmg.load_remote_input_dataset("pipeline",
                                           "5ef1171b2367ff111d082f0c")

    # Load fragility mapping
    fragility_service = FragilityService(client)
    mapping_set = MappingSet(
        fragility_service.get_mapping(
            "60b124e01f2b7d4a916ba456"))  # new format fragility curves
    # mapping_set = MappingSet(fragility_service.get_mapping("5ef11888da15730b13b84353")) # legacy fragility curves
    pipeline_dmg.set_input_dataset('dfr3_mapping_set', mapping_set)

    pipeline_dmg.set_parameter("result_name",
                               "seaside_tsunami_pipeline_result")
    pipeline_dmg.set_parameter("hazard_type", "tsunami")
    pipeline_dmg.set_parameter(
        "fragility_key", "Non-Retrofit inundationDepth Fragility ID Code")
    pipeline_dmg.set_parameter("hazard_id", "5bc9eaf7f7b08533c7e610e1")
    pipeline_dmg.set_parameter("num_cpu", 4)

    # Run pipeline damage analysis
    result = pipeline_dmg.run_analysis()
Пример #18
0
def test_client_fail(monkeypatch):
    """
    testing failed login
    """
    with pytest.raises(SystemExit):
        monkeypatch.setattr("builtins.input", lambda x: "incrtest")
        monkeypatch.setattr("getpass.getpass", lambda y: "invalid-password")
        IncoreClient(token_file_name=".none")
Пример #19
0
def run_with_base_class():
    client = IncoreClient(INCORE_API_DEV_URL)

    # EQ Road Dataset - Seaside roads
    road_dataset_id = "5ee7af50772cf80008577ae3"

    hazard_type = "tsunami"
    liq_geology_dataset_id = None

    if hazard_type == 'earthquake':
        # Seaside Earthquake
        hazard_id = "5ba8f379ec2309043520906f"

        # Earthquake mapping
        mapping_id = "5ee7b145c54361000148dcc5"

        fragility_key = "pgd"
        liquefaction = False
    elif hazard_type == 'tsunami':
        # Seaside Tsunami
        hazard_id = "5bc9eaf7f7b08533c7e610e1"

        # Tsunami Mapping for Seaside
        mapping_id = "5ee7b2c9c54361000148de37"

        fragility_key = "Non-Retrofit inundationDepth Fragility ID Code"
        liquefaction = False
    else:
        raise ValueError(
            "Earthquake and tsunami are the only testable hazards with road damage currently"
        )

    uncertainty = False

    # Run Seaside earthquake road damage
    road_dmg = RoadDamage(client)
    road_dmg.load_remote_input_dataset("roads", road_dataset_id)

    # Load fragility mapping
    fragility_service = FragilityService(client)
    mapping_set = MappingSet(fragility_service.get_mapping(mapping_id))
    road_dmg.set_input_dataset('dfr3_mapping_set', mapping_set)

    road_dmg.set_parameter("result_name", "seaside_road_dmg_" + hazard_type)
    road_dmg.set_parameter("hazard_type", hazard_type)
    road_dmg.set_parameter("hazard_id", hazard_id)
    if fragility_key is not None:
        road_dmg.set_parameter("fragility_key", fragility_key)
    road_dmg.set_parameter("num_cpu", 1)
    road_dmg.set_parameter("use_liquefaction", liquefaction)
    if liquefaction and liq_geology_dataset_id is not None:
        road_dmg.set_parameter("liquefaction_geology_dataset_id",
                               liq_geology_dataset_id)
    road_dmg.set_parameter("use_hazard_uncertainty", uncertainty)

    # Run Analysis
    road_dmg.run_analysis()
Пример #20
0
def run_with_base_class():
    client = IncoreClient(INCORE_API_DEV_URL)

    hazard_type = "earthquake"

    hazard_id = "5eebcbb08f80fe3899ad6039"

    epf_dataset_id = "5eebcaa17a00803abc85ec11"

    # Earthquake mapping
    mapping_id = "5eebcc13e7226233ce4ef0d7"

    # Run epf damage
    epf_dmg = EpfDamage(client)

    epf_dmg.load_remote_input_dataset("epfs", epf_dataset_id)

    # Load fragility mapping
    fragility_service = FragilityService(client)
    mapping_set = MappingSet(fragility_service.get_mapping(mapping_id))
    epf_dmg.set_input_dataset('dfr3_mapping_set', mapping_set)

    epf_dmg.set_parameter("result_name", "earthquake_epf_dmg_result")
    epf_dmg.set_parameter("hazard_type", hazard_type)
    epf_dmg.set_parameter("hazard_id", hazard_id)
    epf_dmg.set_parameter("num_cpu", 1)

    # Run Analysis
    epf_dmg.run_analysis()

    hazard_type = "tsunami"

    hazard_id = "5bc9eaf7f7b08533c7e610e1"

    epf_dataset_id = "5eebcaa17a00803abc85ec11"

    # Tsunami mapping
    mapping_id = "5eebce11e7226233ce4ef305"

    # Run epf damage
    epf_dmg = EpfDamage(client)
    epf_dmg.load_remote_input_dataset("epfs", epf_dataset_id)

    # Load fragility mapping
    fragility_service = FragilityService(client)
    mapping_set = MappingSet(fragility_service.get_mapping(mapping_id))
    epf_dmg.set_input_dataset('dfr3_mapping_set', mapping_set)

    epf_dmg.set_parameter("fragility_key", "Non-Retrofit inundationDepth Fragility ID Code")
    epf_dmg.set_parameter("result_name", "tsunami_epf_dmg_result")
    epf_dmg.set_parameter("hazard_type", hazard_type)
    epf_dmg.set_parameter("hazard_id", hazard_id)
    epf_dmg.set_parameter("num_cpu", 1)

    # Run Analysis
    epf_dmg.run_analysis()
def run_with_base_class():
    client = IncoreClient(INCORE_API_DEV_URL)

    # Memphis Earthquake damage
    # New madrid earthquake using Atkinson Boore 1995
    hazard_type = "earthquake"
    hazard_id = "5b902cb273c3371e1236b36b"

    # Building dataset
    # 5a284f0bc7d30d13bc081a28  5kb
    # 5bcf2fcbf242fe047ce79dad 300kb
    # 5a284f37c7d30d13bc08219c 20mb
    bldg_dataset_id = "5a284f0bc7d30d13bc081a28"

    bldg_dmg = BuildingDamage(client)
    bldg_dmg.load_remote_input_dataset("buildings", bldg_dataset_id)

    # Earthquake mapping
    mapping_id = "5b47b350337d4a3629076f2c"
    fragility_service = FragilityService(client)
    mapping_set = MappingSet(fragility_service.get_mapping(mapping_id))
    bldg_dmg.set_input_dataset('dfr3_mapping_set', mapping_set)

    result_name = "memphis_eq_bldg_dmg_result"
    bldg_dmg.set_parameter("result_name", result_name)
    bldg_dmg.set_parameter("hazard_type", hazard_type)
    bldg_dmg.set_parameter("hazard_id", hazard_id)
    bldg_dmg.set_parameter("num_cpu", 4)

    # Run Analysis
    bldg_dmg.run_analysis()

    # TSUNAMI

    hazard_type = "tsunami"
    hazard_id = "5bc9e25ef7b08533c7e610dc"

    # Seaside building dataset
    bldg_dataset_id = "5bcf2fcbf242fe047ce79dad"

    # Run seaside tsunami building damage
    bldg_dmg = BuildingDamage(client)
    bldg_dmg.load_remote_input_dataset("buildings", bldg_dataset_id)

    # Tsunami mapping
    mapping_id = "5b48fb1f337d4a478e7bd54d"
    fragility_service = FragilityService(client)
    mapping_set = MappingSet(fragility_service.get_mapping(mapping_id))
    bldg_dmg.set_input_dataset('dfr3_mapping_set', mapping_set)

    result_name = "seaside_tsunami_dmg_result"
    bldg_dmg.set_parameter("result_name", result_name)
    bldg_dmg.set_parameter("hazard_type", hazard_type)
    bldg_dmg.set_parameter("hazard_id", hazard_id)
    bldg_dmg.set_parameter("num_cpu", 4)
    bldg_dmg.run_analysis()
Пример #22
0
def run_convert_cge_json_chained():
    client = IncoreClient(pyglobals.INCORE_API_DEV_URL)
    joplin_cge = JoplinCGEModel(client)

    # SAM
    sam = "5cdc7b585648c4048fb53062"

    # CAPITAL COMP
    bb = "5cdc7d295648c4048fb53089"

    # MISC TABLES
    iout = "5cdc7e965648c4048fb530ef"
    misc = "5cdc7f4f5648c4048fb53150"
    misch = "5cdc7fa05648c4048fb53172"
    landcap = "5cdc7f0a5648c4048fb5312e"
    employ = "5cdc7df65648c4048fb530ab"
    igtd = "5cdc7e405648c4048fb530cd"
    tauff = "5cdc81da5648c4048fb532b7"
    jobcr = "5cdc7ed25648c4048fb5310c"
    outcr = "5cdc7fde5648c4048fb53194"
    sector_shocks = "5f20653e7887544479c6b94a"

    joplin_cge.set_parameter("model_iterations", 1)

    joplin_cge.load_remote_input_dataset("SAM", sam)
    joplin_cge.load_remote_input_dataset("BB", bb)
    joplin_cge.load_remote_input_dataset("IOUT", iout)
    joplin_cge.load_remote_input_dataset("MISC", misc)
    joplin_cge.load_remote_input_dataset("MISCH", misch)
    joplin_cge.load_remote_input_dataset("LANDCAP", landcap)
    joplin_cge.load_remote_input_dataset("EMPLOY", employ)
    joplin_cge.load_remote_input_dataset("IGTD", igtd)
    joplin_cge.load_remote_input_dataset("TAUFF", tauff)
    joplin_cge.load_remote_input_dataset("JOBCR", jobcr)
    joplin_cge.load_remote_input_dataset("OUTCR", outcr)
    joplin_cge.load_remote_input_dataset("sector_shocks", sector_shocks)

    joplin_cge.run_analysis()

    domestic_supply_result = joplin_cge.get_output_dataset("domestic-supply")
    # household_count_result = joplin_cge.get_output_dataset("household-count")
    gross_income_result = joplin_cge.get_output_dataset("gross-income")
    pre_demand_result = joplin_cge.get_output_dataset("pre-disaster-factor-demand")
    post_demand_result = joplin_cge.get_output_dataset("post-disaster-factor-demand")

    cge_json = CGEOutputProcess()
    cge_json.get_cge_domestic_supply(domestic_supply_result, None, "cge_domestic_supply.json")
    # cge_json.get_cge_household_count(household_count_result, None, "cge_total_household_count.json")
    cge_json.get_cge_gross_income(gross_income_result, None, "cge_total_household_income.json")
    cge_json.get_cge_employment(pre_demand_result, post_demand_result, None, None, "cge_employment.json")

    return True
Пример #23
0
def run_with_base_class():
    client = IncoreClient(pyglobals.INCORE_API_DEV_URL)

    md = MeanDamage(client)

    md.load_remote_input_dataset("damage", "61044192ca3e973ce13c054a")
    md.load_remote_input_dataset("dmg_ratios", "5a284f2ec7d30d13bc08209a")
    md.set_parameter("result_name", "mean_damage_building")
    md.set_parameter("damage_interval_keys", ["DS_0", "DS_1", "DS_2", "DS_3"])
    md.set_parameter("num_cpu", 1)

    # Run analysis
    md.run_analysis()
Пример #24
0
def run_with_base_class():
    client = IncoreClient()

    md = MeanDamage(client)

    md.load_remote_input_dataset("damage", "5a29782fc7d30d4af537ace5")
    md.load_remote_input_dataset("dmg_ratios", "5a284f2ec7d30d13bc08209a")
    md.set_parameter("result_name", "mean_damage")
    md.set_parameter("damage_interval_keys",
                     ["insignific", "moderate", "heavy", "complete"])
    md.set_parameter("num_cpu", 1)

    # Run analysis
    md.run_analysis()
Пример #25
0
def client(monkeypatch):
    try:
        with open(os.path.join(os.path.dirname(__file__), ".incorepw"),
                  'r') as f:
            cred = f.read().splitlines()
    except EnvironmentError:
        assert False
    credentials = jwt.decode(cred[0], cred[1])
    monkeypatch.setattr("builtins.input", lambda x: credentials["username"])
    monkeypatch.setattr("getpass.getpass", lambda y: credentials["password"])
    client = IncoreClient(service_url=INCORE_API_DEV_URL,
                          token_file_name=".incrtesttoken")

    return client
def run_with_base_class():
    client = IncoreClient(pyglobals.INCORE_API_DEV_URL)

    # Joplin tornado building damage
    bldg_dataset_id = "5df7d0de425e0b00092d0082"  # joplin building v6

    bldg_dmg = BuildingDamage(client)
    bldg_dmg.load_remote_input_dataset("buildings", bldg_dataset_id)

    mapping_id = "5e8e3a21eaa8b80001f04f1c"  # 19 archetype, non-retrofit
    fragility_service = FragilityService(client)
    mapping_set = MappingSet(fragility_service.get_mapping(mapping_id))
    bldg_dmg.set_input_dataset("dfr3_mapping_set", mapping_set)
    bldg_dmg.set_parameter("fragility_key", "Non-Retrofit Fragility ID Code")

    # The simulated EF-5 tornado shows geographical locations and the range of wind speed
    # of tornado hazard in Joplin.
    hazard_type = "tornado"
    hazard_id = "5dfa32bbc0601200080893fb"

    result_name = "joplin_tornado_dmg_result"
    bldg_dmg.set_parameter("result_name", result_name)
    bldg_dmg.set_parameter("hazard_type", hazard_type)
    bldg_dmg.set_parameter("hazard_id", hazard_id)
    bldg_dmg.set_parameter("num_cpu", 4)
    bldg_dmg.set_parameter("seed", 1000)
    bldg_dmg.run_analysis()
    # end of Building damage analysis

    # get csv results from Building damage analysis
    building_dmg_result = bldg_dmg.get_output_dataset("ds_result")
    building_dmg_result.get_dataframe_from_csv()

    restoration = JoplinEmpiricalRestoration(client)
    # Building final target level dataset defining custom final restoration values
    building_fl_id = "61a68979d5b02930aa43ae39"

    restoration.load_remote_input_dataset("buildings", bldg_dataset_id)
    # restoration.load_remote_input_dataset("building_dmg", building_dmg_result)
    restoration.set_input_dataset("building_dmg", building_dmg_result)
    restoration.load_remote_input_dataset("building_functionality_level", building_fl_id)

    result_name = "Joplin_empirical_restoration_result"
    restoration.set_parameter("result_name", result_name)
    restoration.set_parameter("target_functionality_level", 0)
    # restoration.set_parameter("seed", 1234)

    # Run Analysis
    restoration.run_analysis()
Пример #27
0
def run_with_base_class():
    client = IncoreClient(pyglobals.INCORE_API_DEV_URL)
    epf_rest = ElectricPowerFacilityRestoration(client)
    restorationsvc = RestorationService(client)
    mapping_set = MappingSet(
        restorationsvc.get_mapping(
            "61f302e6e3a03e465500b3eb"))  # new format of mapping
    epf_rest.set_input_dataset('dfr3_mapping_set', mapping_set)
    epf_rest.set_parameter("result_name", "epf_restoration.csv")
    epf_rest.set_parameter("restoration_key", "Restoration ID Code")
    epf_rest.set_parameter("end_time", 100.0)
    epf_rest.set_parameter("time_interval", 1.0)
    epf_rest.set_parameter("pf_interval", 0.01)

    epf_rest.run_analysis()
Пример #28
0
def run_with_base_class():
    client = IncoreClient(pyglobals.INCORE_API_DEV_URL)
    bldg_func = BuildingFunctionality(client)

    # load datasets remotely
    bldg_func.load_remote_input_dataset("building_damage_mcs_samples", "5f0f6fbfb922f96f4e989ed8")
    bldg_func.load_remote_input_dataset("substations_damage_mcs_samples", "5f0f71bab922f96f4e9a7511")
    bldg_func.load_remote_input_dataset("poles_damage_mcs_samples", "5f0f7231b922f96f4e9a7538")
    bldg_func.load_remote_input_dataset("interdependency_dictionary", "5f0f7311feef2d758c47cfab")

    bldg_func.set_parameter("result_name", "Joplin_mcs")

    start_time = time.time()
    bldg_func.run_analysis()
    print("--- %s seconds ---" % (time.time() - start_time))
Пример #29
0
def run_base_analysis():
    client = IncoreClient(pyglobals.INCORE_API_DEV_URL)
    capital_shocks = CapitalShocks(client)

    # Building inventory
    building_inventory = "5f218e36114b783cb0b01833"
    building_to_sectors = "5f218fa47887544479c8629f"
    failure_probability = "5f21909b7887544479c862c6"

    capital_shocks.set_parameter("result_name", "sector_shocks")

    capital_shocks.load_remote_input_dataset("buildings", building_inventory)
    capital_shocks.load_remote_input_dataset("buildings_to_sectors", building_to_sectors)
    capital_shocks.load_remote_input_dataset("failure_probability", failure_probability)
    capital_shocks.run_analysis()
Пример #30
0
def run_with_base_class():
    client = IncoreClient(pyglobals.INCORE_API_DEV_URL)
    wf_rest = WaterFacilityRestoration(client)

    # Load restoration mapping
    restorationsvc = RestorationService(client)
    mapping_set = MappingSet(
        restorationsvc.get_mapping(
            "61f075ee903e515036cee0a5"))  # new format of mapping
    wf_rest.set_input_dataset('dfr3_mapping_set', mapping_set)
    wf_rest.set_parameter("result_name", "wf_restoration")
    wf_rest.set_parameter("restoration_key", "Restoration ID Code")
    wf_rest.set_parameter("end_time", 100.0)
    wf_rest.set_parameter("time_interval", 1.0)
    wf_rest.set_parameter("pf_interval", 0.05)

    wf_rest.run_analysis()