diff --git a/.gitignore b/.gitignore index d1085d15d..8c4c6e9e8 100644 --- a/.gitignore +++ b/.gitignore @@ -47,6 +47,8 @@ original/ # possible output file *.csv +!pyincore/analyses/*/*.csv +!/tests/pyincore/analyses/*/*.csv # a pair of negation pattern; everything else except below will be ignored by git *.json !tests/data/*/*.json diff --git a/CHANGELOG.md b/CHANGELOG.md index aaf26e297..221f586ca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,14 +7,12 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ## [Unreleased] -### Changed -- Building Functionality column renaming [#510](https://github.com/IN-CORE/pyincore/issues/510) - - -## [Unreleased] +### Added +- Add MMSA Shelby County CGE ML analysis [#521](https://github.com/IN-CORE/pyincore/issues/521) ### Changed - Need to use left join so the building number stays the same [#514](https://github.com/IN-CORE/pyincore/issues/541) +- Building Functionality column renaming [#510](https://github.com/IN-CORE/pyincore/issues/510) ## [1.17.0] - 2024-02-22 diff --git a/pyincore/analyses/core_cge_ml/__init__.py b/pyincore/analyses/core_cge_ml/__init__.py new file mode 100644 index 000000000..4fef61978 --- /dev/null +++ b/pyincore/analyses/core_cge_ml/__init__.py @@ -0,0 +1,7 @@ +# Copyright (c) 2019 University of Illinois and others. All rights reserved. +# +# This program and the accompanying materials are made available under the +# terms of the Mozilla Public License v2.0 which accompanies this distribution, +# and is available at https://www.mozilla.org/en-US/MPL/2.0/ + +from pyincore.analyses.core_cge_ml.corecgeml import CoreCGEML \ No newline at end of file diff --git a/pyincore/analyses/core_cge_ml/corecgeml.py b/pyincore/analyses/core_cge_ml/corecgeml.py new file mode 100644 index 000000000..abf40a5b3 --- /dev/null +++ b/pyincore/analyses/core_cge_ml/corecgeml.py @@ -0,0 +1,252 @@ +""" Core CGE ML """ +from typing import List, Dict +from collections import defaultdict +import numpy as np +import pandas as pd + +from pyincore import BaseAnalysis +from pyincore import globals as pyglobals + +logger = pyglobals.LOGGER + + +class CoreCGEML(BaseAnalysis): + """Core CGE ML""" + + def __init__( + self, + incore_client, + sectors: Dict[str, List[str]], + ): + super(CoreCGEML, self).__init__(incore_client) + + self.factors = [ + "domestic_supply", + "gross_income", + "household_count", + "factor_demand", + ] + self.sectors = sectors + self.labor_groups = ["L1", "L2", "L3"] + + def construct_output(self, predictions: dict) -> Dict[str, Dict[str, list]]: + """construct_output will construct the output in the format required by the pyincore. + The output will be a tuple of 5 elements. Each element will be a dictionary according to the following format: + - Domestic Supply: + Sectors: list of domestic supply sectors + DS0: domestic supply values before disaster + DSL: domestic supply values after disaster + - Gross Income: + Household Group: list of houshold sectors + Y0: Household income before disaster + YL: Household income after disaster + - Household Count: + Household Group: list of houshold sectors + HH0: Household count before disaster + HHL: Household count after disaster + - Pre-Disaster Factor Demand: + Labor Group: list of labor groups + sector1: + sector2: + . + . + . + sectorN: + - Post-Disaster Factor Demand: + Labor Group: list of labor groups + sector1: + sector2: + . + . + . + sectorN: + + Parameters + ---------- + predictions : dict + This is a dictionary with keys as factors and values as a dictionary with keys "before" and "after". + + Returns + ------- + Dict[str, Dict[str, list]] + A dictionary of 5 dictionaries. + """ + constructed_outputs = {} + if predictions.get("ds", None) is not None: + constructed_outputs["ds"] = { + "Sectors": self.sectors["ds"], + "DS0": predictions["ds"]["before"], + "DSL": predictions["ds"]["after"], + } + if predictions.get("gi", None) is not None: + constructed_outputs["gi"] = { + "Household Group": self.sectors["gi"], + "Y0": predictions["gi"]["before"], + "YL": predictions["gi"]["after"], + } + if predictions.get("hh", None) is not None: + constructed_outputs["hh"] = { + "Household Group": self.sectors["hh"], + "HH0": predictions["hh"]["before"], + "HHL": predictions["hh"]["after"], + } + if ( + predictions.get("prefd", None) is not None + and predictions.get("postfd", None) is not None + ): + prefd = { + "Labor Group": self.labor_groups, + } + postfd = { + "Labor Group": self.labor_groups, + } + + temp_prefd: Dict[str, list] = defaultdict(list) + temp_postfd: Dict[str, list] = defaultdict(list) + for i, fd_sector in enumerate(self.sectors["fd"]): + sector, grp = fd_sector.split("_") + temp_prefd[sector].push((grp, predictions["fd"]["before"][i])) + temp_postfd[sector].push((grp, predictions["fd"]["after"][i])) + + for sector in temp_prefd.keys(): + prefd[sector] = [ + x[1] for x in sorted(temp_prefd[sector], key=lambda x: x[0]) + ] + postfd[sector] = [ + x[1] for x in sorted(temp_postfd[sector], key=lambda x: x[0]) + ] + + constructed_outputs["prefd"] = prefd + constructed_outputs["postfd"] = postfd + + return constructed_outputs + + def run_core_cge_ml( + self, + base_cap: np.ndarray, + capital_shocks: np.ndarray, + model_coeffs: Dict[str, np.ndarray], + base_cap_factors: List[np.ndarray], + ) -> None: + """run_core_cge_ml will use the model coefficients to predict the change in capital stock for each sector. + The predicted change will then be added to base_cap_factors to get the final capital stock for each sector after a disaster. + The model requires capital stock loss in dollar amount, hence the base_cap will be used to calculate the loss in dollar amount. + The capital_shocks is the percentage of capital stock that remains and hence to get the loss we use 1 - capital_shocks. + + Some variables for parameters: + - n: number of factors + - k_i: number of sectors (including subsectors) for factor i. + - K: number of sectors (including subsectors) for input to model. + - l_i: number of coefficients for a model for factor i. + + The length of model_coeffs == length of base_cap_factors == n. + + #TODO: Add detail about the length of base_cap being equal to K and l_i. Meaning K == l_i for i = 1, 2, ..., n. + + Parameters + ---------- + base_cap : (1 X K) np.ndarray + This is the base capital for each sector in dollar amount in Millions. This is a (1, K) array with K elements. + The shape should match the shape of capital_shocks. + capital_shocks : (1 X K) np.ndarray + This is the capital shock for each sector in percentage. This is a (1, K) array with K elements. + model_coeffs : Dict[str, np.ndarray] + This is a dictionary of 2D arrays with shape [n, (k_i, l_i)]. Each entry in the dictionary corresponds to a factor and each factor has k_i number of models. + It is assumed that the intercept term is included in the model coefficients and is at the 0th column. + base_cap_factors : List[np.ndarray] + This is a list of 1D array with each entry corresponding to a factor representing its base capital by sectors. + This is the base capital for each sector for a given factor. + The list would look like [(m_1, 1), (m_2, 1), ..., (m_n, 1)]. + """ + + # check if the shape of base_cap and capital_shocks match + if base_cap.shape != capital_shocks.shape: + raise ValueError( + "The shape of base_cap and capital_shocks do not match. Base Cap shape {}, Capital Shocks shape {}".format( + base_cap.shape, capital_shocks.shape + ) + ) + + # Convert capital_shocks to capital percent loss and then to capital loss in dollar amount + capital_loss = (1 - capital_shocks) * base_cap + + # add a bias term to the capital loss with value 1 resulting in a shape of (1, 1+K) + capital_loss = np.hstack((np.ones((1, 1)), capital_loss)) + + assert len(model_coeffs) == len( + base_cap_factors + ), "The length of model_coeffs and base_cap_factors do not match. required length {}, observed length {}".format( + len(model_coeffs), len(base_cap_factors) + ) + + predictions = {} + for factor_base_cap_before, (factor, factor_model_coeff) in zip( + base_cap_factors, model_coeffs.items() + ): + # multiply the capital loss with the model coefficients (k_i x 1) = (1, 1+K) . (k_i, l_i) + factor_capital_loss: np.ndarray = capital_loss.dot(factor_model_coeff.T).T + + assert ( + factor_capital_loss.shape == factor_base_cap_before.shape + ), "Number of sectors in models and base_cap_factors do not match. required shape {}, observed shape {}".format( + factor_capital_loss[1:, :].shape, factor_base_cap_before.shape + ) + # add the predicted change in capital stock to the base_cap_factors + factor_base_cap_after: np.ndarray = ( + factor_base_cap_before + factor_capital_loss + ) + + predictions[factor] = { + "before": np.squeeze(factor_base_cap_before).tolist(), + "after": np.squeeze(factor_base_cap_after).tolist(), + } + + constructed_outputs = self.construct_output(predictions) + + if constructed_outputs.get("ds", None) is not None: + self.set_result_csv_data( + "domestic-supply", + pd.DataFrame(constructed_outputs["ds"]), + name=self.get_parameter("domestic_supply_fname") + if self.get_parameter("domestic_supply_fname") is not None + else "domestic-supply", + source="dataframe", + ) + if constructed_outputs.get("gi", None) is not None: + self.set_result_csv_data( + "gross-income", + pd.DataFrame(constructed_outputs["gi"]), + name=self.get_parameter("gross_income_fname") + if self.get_parameter("gross_income_fname") is not None + else "gross-income", + source="dataframe", + ) + if constructed_outputs.get("hh", None) is not None: + self.set_result_csv_data( + "household-count", + pd.DataFrame(constructed_outputs["hh"]), + name=self.get_parameter("household_count_fname") + if self.get_parameter("household_count_fname") is not None + else "household-count", + source="dataframe", + ) + if constructed_outputs.get("prefd", None) is not None: + self.set_result_csv_data( + "pre-disaster-factor-demand", + pd.DataFrame(constructed_outputs["prefd"]), + name=self.get_parameter("pre_factor_demand_fname") + if self.get_parameter("pre_factor_demand_fname") is not None + else "pre-disaster-factor-demand", + source="dataframe", + ) + if constructed_outputs.get("postfd", None) is not None: + self.set_result_csv_data( + "post-disaster-factor-demand", + pd.DataFrame(constructed_outputs["postfd"]), + name=self.get_parameter("post_factor_demand_fname") + if self.get_parameter("post_factor_demand_fname") is not None + else "post-disaster-factor-demand", + source="dataframe", + ) + + return True diff --git a/pyincore/analyses/mmsacge/DDS_coefficients.csv b/pyincore/analyses/mmsacge/DDS_coefficients.csv new file mode 100644 index 000000000..8e9f834e8 --- /dev/null +++ b/pyincore/analyses/mmsacge/DDS_coefficients.csv @@ -0,0 +1,50 @@ +"Testbed","Hazard","Model_Type","Model_Name","(Intercept)","OtherA","OtherB","OtherC","OtherD","OtherE","OtherF","OtherG","OtherH","GoodsA","GoodsB","GoodsC","GoodsD","GoodsE","GoodsF","GoodsG","GoodsH","TradeA","TradeB","TradeC","TradeD","TradeE","TradeF","TradeG","TradeH","HS1A","HS1B","HS1C","HS1D","HS1E","HS1F","HS1G","HS1H","HS2A","HS2B","HS2C","HS2D","HS2E","HS2F","HS2G","HS2H","HS3A","HS3B","HS3C","HS3D","HS3E","HS3F","HS3G","HS3H" +"MMSA-shelby","earthquake","main_model","totDDS","1150.24225900833","-0.469397564672838","-0.251317635838262","-0.122525187408732","-0.485734426015534","-0.197068836067106","-0.41078872501748","-0.258231671813465","-0.351576254321406","-0.380682784658395","-0.234892974749486","-0.337456574232423","-0.170844588341475","-0.447035501420043","-0.248428787678782","-0.223721731365017","-0.208252411886617","-0.367872800253843","-0.237112537436605","-0.0598242947329094","-0.232657683175362","-0.370023730373975","-0.407430912775818","-0.249043446622789","-0.193513688640016","-0.0339417991324175","-0.0146261402771313","-0.0538254981388304","0.0887551607465906","-0.0341651948027368","-0.254318649140827","-0.0455780922997016","-0.0801043647912653","-0.603024352383374","-0.309105370055379","-0.313042382630906","-0.377632272592189","-0.338769805604395","-0.373107010382585","-0.252290467869905","-0.497582280526315","0.00926159655693948","-0.0162151967486561","-0.0523481773510383","-0.15423520377425","-0.151049560100798","-0.530661283573971","-0.0309622335952239","-0.0550131448072407" +"MMSA-shelby","earthquake","sectorPuma_model","DDS_ GoodsA","89.1837621992033","-0.0181362066250411","0.00470781202920808","0.000224851570466949","0","0.000732870657989694","-0.00556247654935972","0.00165642123709563","-0.0038375720782465","-0.186026526967361","-7.47734537776245e-05","-0.00786533538701561","0","-0.0144814125846879","-0.0179779704222491","-0.00977953050352346","0","-0.00885906445082392","0.00133778059137869","0.00896197540128942","0","-0.00678949989242287","-0.000493297366772851","0.000411517564899378","5.83969561009881e-05","0","0","-0.000952159585824025","0.0124399566535823","-0.00533220467483429","0","0.00999218359884625","-0.00278528948982239","-0.0194358745074369","-0.0080240457714306","-0.000825190843617311","-0.00964693866492782","-0.00764847415561888","-0.00638260240034363","-0.00726042105441877","-0.0370586001568994","0.000921774433731877","-0.00243966242659033","0","-0.00343807053022305","0.00528723793926974","-0.0136704958585594","0.00289639878977816","-0.0120936242533497" +"MMSA-shelby","earthquake","sectorPuma_model","DDS_ TradeA","149.009334496791","-0.0172678236861384","0.00270268427085253","0.000575434947837812","0","0.00185320151617263","0","0.00179893261552976","0","-0.0117205129937646","0","0","0.00172682123589703","0","0","0","0","-0.20879320245201","0.00102161616997138","0.00392654825038105","0","0","-0.000167981202835753","6.34820878962699e-05","0.00132937259646736","-0.0075085676375366","0.000196883665048105","0","0.00103923940136486","0","0","0.00121068391842438","-0.000568853556084796","-0.0292087201129921","-0.00537198023764248","-0.00263626359272462","-0.00659186882813554","-0.00385293683805047","-0.00230072801868621","-0.000870349609960696","-0.00530823037545697","-0.00504355681721805","0.000779554605822525","0","0","0","0","0","0" +"MMSA-shelby","earthquake","sectorPuma_model","DDS_ OtherA","381.162249556236","-0.327458454059147","-0.0139668683851753","0.00763731775799027","-0.056687246444072","-0.00959734998171385","-0.046271838823245","-0.0200075841379214","-0.0480736250289253","-0.113617759373791","-0.0105905449009958","-0.00975309765069934","0.00976741992292251","-0.0466632570069243","-0.0233816260768089","-0.0291994332168307","-0.0104287924943417","-0.117693117335722","-0.00699501379536526","0.0359819019775168","-0.0171359833546577","-0.0390477690709247","-0.0478548336675836","-0.0055377419042389","-0.00300079024893336","-0.0268486567991089","0.00994866794548583","-0.00192721391505633","0.0477426356806669","0","-0.0271591282474655","0.0171711550444253","-0.0118849394402434","-0.213361051628363","-0.0699980710784509","-0.0665573692004015","-0.0887971734363661","-0.0603440615618494","-0.0510479497339574","-0.036046776878911","-0.130266656302465","-0.00445014199586007","0.0177501919087797","0","-0.0147475059035315","-0.0140238596505514","-0.068595194454826","0.0138979748986614","0" +"MMSA-shelby","earthquake","sectorPuma_model","DDS_ GoodsB","6.36516690867687","-0.000207482443155184","-0.0140604340490566","0.00207706067060293","0","0.000160529861240231","0","0.000415725059165775","0","-0.00216633782292608","-0.162384632058125","-0.00264508964247052","5.08527931869019e-05","-0.00597769000510179","-0.000227821898263381","-0.00338046682071722","-0.00113933940823665","-0.000625862218545225","-0.00594534754599173","0.00224487008725322","5.84311867345281e-05","-0.0014669821213535","-0.000799739556375102","-0.000438569211644891","9.70037924705173e-05","0","0.0014099001444249","-0.000350939175983258","0.00266682128403337","0.00110087845654859","0","0","0","-0.00614151515714945","-0.00118878572598728","-0.00149649897630631","-0.00294458567697027","-0.00293294895206896","-0.00277631803866363","-0.00135245617718336","-0.00410882117811016","0","0.00236643322621765","0.00105156688643164","-0.00136521926335751","-0.00201667512701324","-0.00604934607646425","0.000194822836843395","0.0013491507876635" +"MMSA-shelby","earthquake","sectorPuma_model","DDS_ TradeB","53.3521909124663","0.000453322352656355","-0.0375064304925813","0.00182537612190109","0","0.000599681356559291","0","0.00150851313944616","0","0","-0.0113960177195151","0","0","0","0","0","0","6.05372165780903e-05","-0.20888031746588","0.00308202733259014","0.000954779382939897","-0.00179917272154456","0","0","0.00134340876347178","-0.000993983248820298","-0.00715866368366087","0.00011040606760581","0.00101478797301083","0","-0.00125322811410164","0.00145461428623555","0.000806200955520327","-0.0035570998387973","-0.0112280066302227","-0.00242103095754632","-0.0026617995569013","-0.00317582561957742","-0.00213634847083667","-0.00189785875835046","0","0","-0.0116623060328564","0.000375669998637537","0","-0.000385653629650183","0","0","0" +"MMSA-shelby","earthquake","sectorPuma_model","DDS_ OtherB","75.0606312114059","-0.0162495147735999","-0.229236346248735","0.00228254298485353","-0.0269201096196728","-0.00472471147121462","-0.00494672404800608","-0.00621394502761403","-0.00597152480659491","-0.00744013440870478","-0.0289513985277457","-0.0254565559997319","0.00223132299948519","-0.0112153688004908","-0.00816310463547984","-0.0110773259019313","-0.00197374013718626","-0.00794130337055021","-0.0587919361465233","0.00810866353236952","-0.00086367772929011","-0.0125840333483887","-0.00657992134979756","-0.00756071070660244","0","-8.94112940742364e-05","-0.00701988064227217","0.000241177720355557","0.0109876940920004","0.000756421600852127","-0.0199694848764108","0.00192216576542558","0.00158592680670897","-0.0326240110399839","-0.033233141104387","-0.0127816564704613","-0.016179188666534","-0.01484274667018","-0.0132040772926849","-0.0114550979393547","0.0015137531590561","0.000194831648411353","-0.0156080923844135","0.00124418614395912","-0.00509293386869323","-0.00230843396906491","-0.0151454849158176","0.00122776831170438","0.00247216760031042" +"MMSA-shelby","earthquake","sectorPuma_model","DDS_ GoodsC","10.477638982422","-0.000293108598831273","0.00116190796859425","-0.016948957469843","-0.00216762074017564","-9.00431194903534e-05","-0.000193135035029722","0.000551367954321655","-1.72621469458076e-08","-0.00236808210408099","-0.00131702009388077","-0.215379637572487","-0.0027854013538677","-0.00351403629505482","-2.92421856025634e-06","-0.000911942264925354","-0.00145189697195123","-0.000556656332975905","0.000320788268444611","-0.0135076800375605","-0.00221052146370368","-0.00240668591175975","-0.00109182628309728","0","-0.000116321701381252","0.000566496373166503","8.57951806324922e-06","0.00199688526356413","-0.00183682912656808","-0.00194771503971997","0","0.000551577345472693","0.000514895686985976","-0.00296693789245284","-0.00203363000911735","0.000687178198405504","-0.00618896571737597","-0.00365293458922993","-0.00168288389008833","-0.00129082617996629","-0.00221962147663084","0.00107787169731202","9.75714713205697e-05","0.00297665074103394","-0.0042884219224805","-0.00142128845207169","-0.00138951173865951","0","0.000795494538654544" +"MMSA-shelby","earthquake","sectorPuma_model","DDS_ TradeC","37.5264040580748","0","0.00165645436381415","-0.0373951949707992","-0.00145890985166902","0","0","0.00106123099061054","0","0","0.000267995428275673","-0.0245054474381838","-0.000201075961845612","0","0","0","0","0.000338760090868476","0.00102921357488184","-0.193529622657304","-0.00284435316600234","-0.00213416124324552","0.000213968874628279","4.49769651651479e-05","0.00115129996198271","0.000641761523379287","0","-0.0076220565910173","-0.00199340724753343","-0.00249712421438224","0","0.00106249237298759","0.00132876828071283","-0.000827682185620946","-0.00211363663456706","-0.00987159187895565","-0.00842219195718762","-0.00430418021368088","-0.000269581981517908","-0.000647197963514052","0","0.00100324345120423","0.000300405210924937","-0.00933231547614352","-0.00659019324862525","-0.00270325527148517","0","0","0.000701461826288266" +"MMSA-shelby","earthquake","sectorPuma_model","DDS_ OtherC","26.8506287154559","-0.00823326349315356","-0.00291185744593424","-0.189011080603942","-0.0119994794068798","-0.00319133017296768","-0.00469490166283643","-0.00335687725462629","-0.00574246458244839","-0.00325518619994054","-0.000954336116643492","-0.0365995868291599","0","-0.00347967250738399","-1.80318075363787e-06","-0.00237974019116131","-0.000699328206263567","-0.0033023070608906","-0.000850551523351334","-0.0486062532344532","-0.00590190778636905","-0.00698360405748566","-0.00381514329356209","-0.00123273097230398","0.000505768078408875","0.000643718303683965","-0.000194552444986259","-0.0117311807667062","-0.00385261959860156","-0.00385633497464637","-0.00138382402625487","0.00155320027536233","0.00107711456978523","-0.00795744019901907","-0.00592957462935668","-0.0266292242290998","-0.0146580145494253","-0.00877875617837426","-0.00372779767488551","-0.00335135157273578","-0.00410541124915356","0.00186192454549328","0.000289874665536963","-0.0144823049347106","-0.0112765543353412","-0.00592614055089829","-0.00377775086548257","0.000763202330610278","0.00145668514048292" +"MMSA-shelby","earthquake","sectorPuma_model","DDS_ GoodsD","15.8788368428674","-0.00121409851149732","0.00142961414881815","0.000967939170470479","-0.00475510542795952","-0.00142216406633347","-0.00214904851604706","0.000440092352241666","-0.00105197259006153","-0.00341708401352392","-0.00227952336726676","-0.00473671651714665","-0.154724786886673","-0.00375951375301885","-0.000815148325276624","-0.00177346822778506","-0.00205547650128044","-0.000691454304822897","0.00079354952604719","0.000858591277025703","-0.00943917889836538","-0.00388672908120295","-0.00266526805931123","0.000415234249040683","-0.000392626201426095","0.00148387866801966","0.000966344593431045","-0.0011548106509175","0.00406742054743135","-0.00109718321821677","0","0.00249376884991678","0.00103614393020752","-0.00468618312829202","-0.00266950110053024","-0.00505033168123231","-0.00460828886403923","-0.00650173920349112","-0.00301671838262283","-0.000663274045515842","-0.00197308025073983","0.00149192930972553","0.00110300598934681","-0.000217148740969146","0.000989561049622443","-0.00367934977382","-0.00426425800081319","0.000827331957531513","0.00162234427509702" +"MMSA-shelby","earthquake","sectorPuma_model","DDS_ TradeD","31.6046442901299","0.000705298692810259","0.00197891537094157","0.000277955487242644","-0.0188804228914295","-0.00106941510344724","0.00119493595862185","0.00143209164501423","0","0.00100859612277801","-0.000298034666517941","0.00202953753573245","-0.0370348516051524","-0.000331760370122779","-0.0032054958399405","0","-2.38567856971134e-05","0.000750034529328944","0.00175814730284683","0.00150575907668553","-0.179750544209051","-0.00372671062075694","0.000290340327716817","0.00183908054170699","0.00115994074834783","0.00171404016385912","0.000797008226086103","-0.00176052930682186","-0.016014520716009","0","0.000917357940391002","0.00470502289204509","0.00238880990862275","0.00363583943619676","-0.000699211628915201","-0.00163354226581244","-0.017833848975531","-0.00452879132812404","0.000342089015497241","0.000617908070844853","0.00303293484850109","0.000913417559947715","0.00153369034145554","-0.00160332157769524","-0.0215305148253914","-0.00818458466831481","0.00363053758205202","0","0.00119346537124409" +"MMSA-shelby","earthquake","sectorPuma_model","DDS_ OtherD","20.5610330259842","-0.00460518126697499","-0.000476598355791383","-0.000815088120396695","-0.226912081313284","-0.00275588347192065","-0.00181608193935314","-0.00117940346541328","-0.00281689459479287","-0.000920215018405992","0","0.000842061870753993","-0.0401491233350199","-0.00169689948912979","-0.000458058073918654","-0.000568514838724771","3.51757900570364e-05","-0.000852916323304727","0.00111807222578784","0.00149647514992178","-0.0309294385857546","-0.00505007346051126","-0.00178145886908662","0.000542324687518474","0.00096318510979807","0.00151570030993143","0.000606942577209832","-0.00332461204749512","-0.011288983444046","-0.00502568733049868","-0.000470961138295587","0.00348982409454173","0.00143039899105486","-0.00246047233297003","-0.00269276199054285","-0.00652887920721642","-0.0190642477818144","-0.00736371343126091","-0.00184278254778022","-0.000387471294696737","-0.000357514799113905","0.00184071605903523","0.00185104075676911","-0.0031953068407057","-0.0188244306248385","-0.00688059650490905","-0.00114049007777675","0.00104187434750606","0.00201656253011725" +"MMSA-shelby","earthquake","sectorPuma_model","DDS_ GoodsE","-2.07410644424411","-0.000783006077850267","0.0011385865611182","0.00228068110782285","-0.00179452691092318","-0.00915511262402665","-0.00193650282093477","0.00024115014740374","-0.000841970369798967","-0.00289363243725419","-0.0017838357436749","-0.00164347055232245","-0.00176698975381381","-0.12233342905133","-0.000892479061745985","-0.001742253419173","-0.00165833372157163","-0.000621584332894285","0.000370638310363987","0.00108630070793887","-0.00107992181098449","-0.00423586890232545","-0.00258114777205198","0","-0.000416289368283204","0.000885189588364661","0.000549615664715462","-3.88915121266965e-07","0.0010008076207932","0.00269198297437449","-0.000963263325928905","0.000636292115574044","0.000512646304361977","-0.00322603663759469","-0.00216381685044086","-0.00321200692439038","-0.00463302288694244","-0.000711848178901587","-0.0033379607476983","-0.00133987571657375","-0.00212843384334532","0.00101717691453766","0.000800142534564798","-0.000109471850588636","-0.00182741479686683","0.00138647475818141","-0.00530444871015514","0.000322336792464568","0.000724100243352653" +"MMSA-shelby","earthquake","sectorPuma_model","DDS_ TradeE","-0.135438561665867","0.000511673288178282","0.00295298046226215","0.00362526007735776","-0.00156012785854351","-0.0337414525886278","-0.000250117483193926","0.00160343144211027","-0.000240377725338165","0.000262246863127627","0.000316366254005359","0","0.00135392925882893","-0.0255488206339763","0.000724659136876372","0.000344951009365136","0.000498440045986503","0.00134106142860139","0.0023508170415211","0.00295085502438245","-0.000672072336765324","-0.180328498828832","-0.00149015595819268","0.000999969032584773","0.00156869473450681","0.00208284943185262","0.000985289748475128","-8.98966267302729e-05","0.000316297944694388","-0.019324413318364","-0.000911599693105699","0.00224510730810561","0.00181230875112556","0.00062141424874718","-0.00131702631905625","-0.00436601175815404","-0.0059264057995856","-0.0133810331778208","-0.00211775531231404","0","0","0.00206216900668437","0.00259498987696466","0","-0.00177970559006283","-0.0184091468236177","-0.00350821982088042","0.00176138823660458","0.00249128689478847" +"MMSA-shelby","earthquake","sectorPuma_model","DDS_ OtherE","-12.8206790162705","-0.00872397158229843","-0.00132432589121792","0","-0.003028603883739","-0.145964721094569","-0.0043976805887454","-0.00309559124675017","-0.00538796149937191","-0.00337741741328669","0","0","0","-0.0342639762649665","0","0","0","-0.00237177092832944","0","0.00225408414503374","-0.00198987464640291","-0.0398408565577555","-0.00367211810082237","0","0.00056103884979032","0.00143686310874246","0.000711848706779691","0","0","-0.0136846643470119","-0.00146719816203484","0","0.000851950266894653","-0.00292097706005178","-0.00477104198005292","-0.00728037136627721","-0.0118113768681944","-0.0237771953507794","-0.00652110982972825","-0.00185872831311546","-0.000208009240487272","0.00260021985280599","0.00233530915546353","0","-0.00160197096785593","-0.0185961322492558","-0.0055347387645748","0","0.000112003844279732" +"MMSA-shelby","earthquake","sectorPuma_model","DDS_ GoodsF","-2.6060825298607","-0.00135910545360728","0.0017128068758098","0.00469093414481718","-0.00243150843909189","0","-0.0129005640554992","-0.000129859855487664","-0.00176036631798637","-0.00498782824842327","-0.0030649234723556","-0.00257046880821561","-0.00155581111044429","-0.00644104036621166","-0.0710407095317571","-0.00249850546393128","-0.0032699250007372","-0.00116275773078061","0.000561529884285222","0.00357155892668123","-7.12522341148164e-05","-0.00339566761081018","-0.00620690873482608","-0.00045730312159972","-0.00109068130535404","0.00202111600841958","0.00128034029891921","0.00150607671519125","0.0034636465409553","0","-0.00249881670573933","0.000442430273977431","0.000829180079657724","-0.00610127218036803","-0.00410856231532806","-0.00279334763416221","-0.00453010138034714","-0.00547398522330917","-0.00490584662737882","-0.00333062285477912","-0.00448925184896324","0.00211175216966174","0.00159051010665802","0.00107058263312438","3.85942457208587e-05","-0.00241136914926192","-0.00853867571855987","0.000163055243516957","0.00149659938088492" +"MMSA-shelby","earthquake","sectorPuma_model","DDS_ TradeF","-31.2987413561735","0.000147434280593067","0.00630038901697643","0.0125313356224797","-0.00522405755519729","0.00343591744812529","-0.0465514872081284","0.00258667108038434","-0.00156123807529384","-3.6814835587513e-05","0.00172760169019082","0.00410845877851879","0.00552140348015345","-0.011329879702686","-0.0186490867932848","-0.00202786828675297","0.000668746290645918","0.00270808330043477","0.00568060299254311","0.0123740074117413","0.00505738524106298","-0.000718580602001103","-0.148759562289299","0.00205455031195773","0.00265422563359407","0.00587725196907589","0.0042744011311054","0.00511521132523661","0.00903434357241111","0.00936329267065679","-0.0250610809335243","0.00528761993657123","0.00383115629513704","0.0023269905763798","-0.00288198290201824","-0.000781051717483053","-0.00117850409127839","-0.0056643482045702","-0.0270638508390569","-0.00197749474943571","0.00247056751971177","0.0053324268156308","0.00869599883105085","0.00400649631883041","0.0087089939638711","0","-0.0459322494688952","0.00234296117222628","0.00502552310186859" +"MMSA-shelby","earthquake","sectorPuma_model","DDS_ OtherF","-25.8710434307886","-0.0134340539245072","0","0.0106321960088468","-0.018765218244781","-0.000282716092556839","-0.159706127134863","-0.00390679123637542","-0.0106850072354041","-0.00527019033714349","0","0.00152146654446185","0.00687245914550943","-0.0208409624925144","-0.0236843242053129","-0.00535500824657088","-0.000247969429076382","-0.00248080803462495","0.00425346069478581","0.0166076646134561","0.00429907002164789","-0.00587886520846977","-0.0502749549564685","-0.000175680508075821","0.00209350875808673","0.00771472640182441","0.00676539313890166","0.00684665526724246","0.0144498733926802","0.0140137137761513","-0.0272532587203396","0.0082227582827922","0.00478253005041804","-0.00760805520527137","-0.00905058351017539","-0.00606388467162256","-0.00831193902060564","-0.0129549189362484","-0.0456217221923859","-0.00620640216625553","-0.000695938002839724","0.00832895639683668","0.0127990958064899","0.00495334663092806","0.00993919859601186","-0.000748055482468602","-0.066682828408168","0.0043772026920344","0.00665201133290885" +"MMSA-shelby","earthquake","sectorPuma_model","DDS_ GoodsG","-3.52068738556466","-0.00119611274976471","0.00319563919250445","0.00656493389135736","-0.00484396807724111","0.0010954144618612","-0.0086106524667431","-0.0176115167452087","-0.00180087555444881","-0.00585261728984749","-0.00346214074081156","-0.00270236577564387","-0.000157863824564893","-0.0123909641403426","-0.00395387677456353","-0.0715907057151417","-0.00349415060922042","-0.000688100292244037","0.00134943103794641","0.0071586290109053","0.000592159803743766","-0.00358762849296905","-0.00974795599403623","-0.0114723973087634","-0.000113936524754047","0.00258688415553289","0.00188071487248201","0.00251541990352744","0.00515681221227246","0.00453609554473177","-0.00573525029988159","0.00506746096075125","0.00196693612364956","-0.00992757932089492","-0.00807362945872282","-0.0045532000630086","-0.00700315331461824","-0.00824818965548285","-0.0127144206738741","-0.00256690482211133","-0.00599324777016292","0.00362047668713167","0.00284959586637913","0.00150407125679575","0.00121177514017604","-0.00072639379479124","-0.0167733923417239","0.00355733819577605","0.00204644718233671" +"MMSA-shelby","earthquake","sectorPuma_model","DDS_ TradeG","12.1012321045043","-0.000294408869645885","0.00355438207680414","0.00652393876294591","-0.00392594276576451","0.00184095252956452","-0.00691624598840559","-0.0273219344100599","-0.000461703095699701","-0.000632181359625521","-0.000165246785383322","0.00212547006924106","0.00470358632761366","-0.00600130792937073","0","-0.0123559585806611","0.000182579281735444","0.000660193099231986","0.00212996495385837","0.00789435122530142","0.00181816350935631","-0.00181058701727741","-0.00807784626116998","-0.156323471353913","0.00212297177312598","0.00253546085963235","0.00143163798995638","0.00268699355415337","0.00432405825902781","0.00508771602162785","-0.0059180893493434","-0.0152324068338298","0.00241836237755841","-0.00550997646202121","-0.00720949085032557","-0.00358138916800995","-0.00511314996893292","-0.00674982522708734","-0.0111334953857512","-0.0117785258000741","-0.00179912736565039","0.00375401740065003","0.00357684224743973","0.00121824906384902","0.00285909258222162","9.31221536966021e-05","-0.0122569632048696","-0.00778471138002778","0.00230793662575668" +"MMSA-shelby","earthquake","sectorPuma_model","DDS_ OtherG","70.9912393754956","-0.0297368606804881","-0.00667700233462339","-0.00527377009965547","-0.0304135366893893","-0.00447787256538926","-0.0403519885237319","-0.183024895417908","-0.0171647672514041","-0.0140992822026244","-0.00432417488105229","-0.00156721164264846","0.0111871223561923","-0.0305494170061745","0","-0.030365129679217","-0.00328840136886925","-0.0146181311464553","-0.00323191966271924","0.0168484883434818","-0.0023346353128295","-0.0153054055763982","-0.0380170508131413","-0.0621767831902694","-0.000448112464192012","0.00664701096196723","0.00321345840011391","0.00348125926897608","0.00318769835049259","0.0127234625076267","-0.0240231780205408","-0.0119492361473429","0.0049184169351339","-0.0378536622368734","-0.0315549654428439","-0.0250380689694675","-0.0279660242275789","-0.029891272386693","-0.0416865980819798","-0.034347241003285","-0.0297463232624879","0.0157643337050967","0.00610605279955773","-0.000556409481930367","-0.00315950080672789","0.00315342055112493","-0.0367726852605311","-0.00478162577709171","0" +"MMSA-shelby","earthquake","sectorPuma_model","DDS_ GoodsH","28.7291077396898","-0.00478616807605463","0.00788467735642263","0.0137071450080604","-0.00938027937887634","0.00348262198434791","-0.0165377098126228","-0.000705354266885771","-0.0263538585649829","-0.0107354791602458","-0.00543385118108369","-0.00404268717965921","-0.00191145565857981","-0.0156090881483122","-0.0105392696420497","-0.00528317581619174","-0.120420049362336","-0.000588754954129728","0.0063358378814832","0.014689127122425","0.00293908800853942","-0.00546946959481034","-0.0183930761999064","-0.00287475506764846","-0.0279891659437099","0.00461286044849335","0.00381928853205027","0.0017913924966242","0.0147784661168583","0.0148062860596246","-0.00778030332567812","-0.0063254302554806","-0.00440398907410386","-0.0334016155450881","-0.0113588971489471","-0.0174829511145948","-0.0135102707939256","-0.0163633377467732","-0.024721805635915","-0.0198678096312321","-0.0379692092067068","0.00473542765096444","0.00776202356715994","0.00272637473664225","0.0045194672092968","-0.00016537195377379","-0.034880629713559","-0.00368849189589174","0.000786695121347445" +"MMSA-shelby","earthquake","sectorPuma_model","DDS_ TradeH","170.576036054621","-0.00521373819767018","0.0147981644874572","0.0224353975216293","-0.00668389421048703","0.00900300084525575","-0.0207578832406918","0.000494744703210683","-0.0559037416686832","0.00026305648054999","0.00338720092547153","0.0183749558283761","0.0122780788558627","-0.00606214540916881","-0.00341073137636771","-0.00529171411599979","-0.0429047052609285","0.00179502342828069","0.0130629982540464","0.0253856998500702","0.00911708412201477","-0.00196376405363285","-0.0270737787652628","-0.00212257413964339","-0.155463217756555","0.00689488890513387","0.00513433130165764","0.00192391412725801","0.0259519086157763","0.0272210012861587","-0.00208543381370856","-0.00814799511427188","-0.0222961064573111","-0.048273334680501","-0.0145231299861005","-0.0250938668891052","-0.0168347327835885","-0.0236135121265004","-0.0383832927440087","-0.0322868010272366","-0.07669193937583","0.00547297106860158","0.0176310568957348","0.0039817288245179","0.0143766302637419","0.00581516313779754","-0.0463930261198514","-0.00996999665033029","-0.0108516801653546" +"MMSA-shelby","earthquake","sectorPuma_model","DDS_ OtherH","24.0652354434152","-0.0115065334715063","-0.00176072080331983","0.00302068027911777","-0.0126639834447572","-0.00109762066408795","-0.0134661159903714","-0.00600694346058692","-0.15263996437554","-0.00253637330758654","-0.000111265580309323","0.00331022930015674","0.00534639413772949","-0.00567280321920759","-0.0019753970582033","-0.0033945306481388","-0.0142127900340701","-0.00234725205115581","0.00158142658952404","0.00912252440922087","0.000713031180465058","-0.00563547296143354","-0.0135099926625573","-0.00408603266206763","-0.0208537530635315","0.000200448171375289","0.000528852352865148","-0.000417420850178073","0.00876482828685259","0.00943810211572761","-0.00663675466145699","-0.00924537409328548","-0.0209868736987295","-0.023178449405223","-0.00910214377561195","-0.0126716482476753","-0.00989020946703665","-0.0115569477156365","-0.0162622992851466","-0.0143274256116407","-0.0562431557369191","0.0014331156604723","0.00323580666639075","0","0.00266792574100954","0","-0.0208219377386486","-0.00534175502585378","-0.0161184923722438" +"MMSA-shelby","earthquake","sectorPuma_model","DDS_ HS1A","-2.12012505073713","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","-0.0481242367048167","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0" +"MMSA-shelby","earthquake","sectorPuma_model","DDS_ HS2A","-2.49436674079616","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","-0.0888936083804363","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0" +"MMSA-shelby","earthquake","sectorPuma_model","DDS_ HS3A","-4.49013591371887","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","-0.0473377027849482","0","0","0","0","0","0","0" +"MMSA-shelby","earthquake","sectorPuma_model","DDS_ HS1B","-1.7574072157323","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","-0.0480457914625946","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0" +"MMSA-shelby","earthquake","sectorPuma_model","DDS_ HS2B","-1.80284398230146","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","-0.0511912169752017","0","0","0","0","0","0","0","0","0","0","0","0","0","0" +"MMSA-shelby","earthquake","sectorPuma_model","DDS_ HS3B","-2.10870256442604","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","-0.087861788928073","0","0","0","0","0","0" +"MMSA-shelby","earthquake","sectorPuma_model","DDS_ HS1C","-1.51992649616133","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","-0.0480807369265562","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0" +"MMSA-shelby","earthquake","sectorPuma_model","DDS_ HS2C","-1.75832828805117","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","-0.047717769916482","0","0","0","0","0","0","0","0","0","0","0","0","0" +"MMSA-shelby","earthquake","sectorPuma_model","DDS_ HS3C","-3.67764449018904","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","-0.0615334012012094","-0.000222654002565331","0","0","0","0" +"MMSA-shelby","earthquake","sectorPuma_model","DDS_ HS1D","-1.94029795327141","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","-0.0601206740428779","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0" +"MMSA-shelby","earthquake","sectorPuma_model","DDS_ HS2D","-2.332519194555","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","-0.0574698988145514","0","0","0","0","0","0","0","0","0","0","0","0" +"MMSA-shelby","earthquake","sectorPuma_model","DDS_ HS3D","-1.96335715888796","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","-0.087959551875644","0","0","0","0" +"MMSA-shelby","earthquake","sectorPuma_model","DDS_ HS1E","-2.70149894681421","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","-1.30220253119713e-05","0","0","0","0","0","0","0","0","-0.0758034276369055","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0" +"MMSA-shelby","earthquake","sectorPuma_model","DDS_ HS2E","-2.43811625922993","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","-0.0485917450951825","0","0","0","0","0","0","0","0","0","0","0" +"MMSA-shelby","earthquake","sectorPuma_model","DDS_ HS3E","-2.73821732601724","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","-0.0728375450521216","0","0","0" +"MMSA-shelby","earthquake","sectorPuma_model","DDS_ HS1F","-2.03576389376551","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","-0.0748305881787595","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0" +"MMSA-shelby","earthquake","sectorPuma_model","DDS_ HS2F","-2.97603235923378","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","-0.0477281639658756","0","0","0","0","0","0","0","0","0","0" +"MMSA-shelby","earthquake","sectorPuma_model","DDS_ HS3F","-1.97527265516505","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","-0.0929599813194392","0","0" +"MMSA-shelby","earthquake","sectorPuma_model","DDS_ HS1G","-1.66108637803583","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","-0.0778199604046131","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0" +"MMSA-shelby","earthquake","sectorPuma_model","DDS_ HS2G","-1.65997501619492","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","-0.0480291920071085","0","0","0","0","0","0","0","0","0" +"MMSA-shelby","earthquake","sectorPuma_model","DDS_ HS3G","-3.41559190127925","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","-0.0470599794380915","0" +"MMSA-shelby","earthquake","sectorPuma_model","DDS_ HS1H","-1.65062602238761","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","-0.049385973889283","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0" +"MMSA-shelby","earthquake","sectorPuma_model","DDS_ HS2H","-2.58196431118028","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","-0.0699307582781036","0","0","0","0","0","0","0","0" +"MMSA-shelby","earthquake","sectorPuma_model","DDS_ HS3H","-2.98433713696363","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","-0.0504814366434874" diff --git a/pyincore/analyses/mmsacge/DS_base_val.csv b/pyincore/analyses/mmsacge/DS_base_val.csv new file mode 100644 index 000000000..813bf40c1 --- /dev/null +++ b/pyincore/analyses/mmsacge/DS_base_val.csv @@ -0,0 +1,49 @@ +,sector,0 +0,GOODSA,1913.4476546943565 +1,TRADEA,2377.2730168424077 +2,OTHERA,14993.909068068418 +3,GOODSB,472.36596182732677 +4,TRADEB,1419.8708074135996 +5,OTHERB,3640.975070576724 +6,GOODSC,507.14967045368235 +7,TRADEC,1279.2568588582074 +8,OTHERC,1738.6215492049657 +9,GOODSD,798.8633868071415 +10,TRADED,996.0271700616491 +11,OTHERD,968.7850688286508 +12,GOODSE,470.16012683865495 +13,TRADEE,900.4847067636807 +14,OTHERE,2002.7617747250802 +15,GOODSF,748.0076150103974 +16,TRADEF,1364.1188305669234 +17,OTHERF,2922.2048211971482 +18,GOODSG,1229.983425963827 +19,TRADEG,1715.543768911129 +20,OTHERG,6303.010197571666 +21,GOODSH,3052.905376487562 +22,TRADEH,7886.419665307799 +23,OTHERH,2280.5761784552656 +24,HS1A,154.17727765 +25,HS2A,135.84211603 +26,HS3A,193.64678897 +27,HS1B,139.62388575 +28,HS2B,157.60436175 +29,HS3B,152.69792323000001 +30,HS1C,115.14916619 +31,HS2C,85.60219853000001 +32,HS3C,120.75010099 +33,HS1D,68.63761722699999 +34,HS2D,204.31382829 +35,HS3D,96.96587223099999 +36,HS1E,78.383423278 +37,HS2E,239.9963594 +38,HS3E,111.066031871 +39,HS1F,77.473526303 +40,HS2F,357.12474080000004 +41,HS3F,127.15930483 +42,HS1G,105.797119117 +43,HS2G,121.83272935 +44,HS3G,166.898857 +45,HS1H,136.61479686 +46,HS2H,59.96679308 +47,HS3H,107.105009295 diff --git a/pyincore/analyses/mmsacge/FD_base_val.csv b/pyincore/analyses/mmsacge/FD_base_val.csv new file mode 100644 index 000000000..a1c923da0 --- /dev/null +++ b/pyincore/analyses/mmsacge/FD_base_val.csv @@ -0,0 +1,73 @@ +,labor,0 +0,GOODSA_L1,1367 +1,GOODSA_L2,4481 +2,GOODSA_L3,6492 +3,TRADEA_L1,1856 +4,TRADEA_L2,3525 +5,TRADEA_L3,4531 +6,OTHERA_L1,14075 +7,OTHERA_L2,29827 +8,OTHERA_L3,45169 +9,GOODSB_L1,624 +10,GOODSB_L2,1244 +11,GOODSB_L3,1715 +12,TRADEB_L1,3970 +13,TRADEB_L2,3722 +14,TRADEB_L3,2754 +15,OTHERB_L1,8579 +16,OTHERB_L2,10222 +17,OTHERB_L3,8297 +18,GOODSC_L1,756 +19,GOODSC_L2,1865 +20,GOODSC_L3,1964 +21,TRADEC_L1,2250 +22,TRADEC_L2,3192 +23,TRADEC_L3,3070 +24,OTHERC_L1,4682 +25,OTHERC_L2,6393 +26,OTHERC_L3,3676 +27,GOODSD_L1,629 +28,GOODSD_L2,1896 +29,GOODSD_L3,3579 +30,TRADED_L1,2689 +31,TRADED_L2,3341 +32,TRADED_L3,2731 +33,OTHERD_L1,3343 +34,OTHERD_L2,4126 +35,OTHERD_L3,1962 +36,GOODSE_L1,582 +37,GOODSE_L2,1335 +38,GOODSE_L3,2058 +39,TRADEE_L1,1248 +40,TRADEE_L2,2349 +41,TRADEE_L3,2946 +42,OTHERE_L1,4378 +43,OTHERE_L2,6297 +44,OTHERE_L3,4443 +45,GOODSF_L1,557 +46,GOODSF_L2,1846 +47,GOODSF_L3,3031 +48,TRADEF_L1,3338 +49,TRADEF_L2,4602 +50,TRADEF_L3,4356 +51,OTHERF_L1,5304 +52,OTHERF_L2,6641 +53,OTHERF_L3,8270 +54,GOODSG_L1,678 +55,GOODSG_L2,2017 +56,GOODSG_L3,5545 +57,TRADEG_L1,2433 +58,TRADEG_L2,3724 +59,TRADEG_L3,4871 +60,OTHERG_L1,9984 +61,OTHERG_L2,15092 +62,OTHERG_L3,15345 +63,GOODSH_L1,2177 +64,GOODSH_L2,7934 +65,GOODSH_L3,12982 +66,TRADEH_L1,7879 +67,TRADEH_L2,21496 +68,TRADEH_L3,26117 +69,OTHERH_L1,9193 +70,OTHERH_L2,9885 +71,OTHERH_L3,4305 diff --git a/pyincore/analyses/mmsacge/GI_base_val.csv b/pyincore/analyses/mmsacge/GI_base_val.csv new file mode 100644 index 000000000..f67491bc8 --- /dev/null +++ b/pyincore/analyses/mmsacge/GI_base_val.csv @@ -0,0 +1,41 @@ +,household,0 +0,HH1A,105.55051750568757 +1,HH2A,372.38883654930714 +2,HH3A,623.8790313424828 +3,HH4A,664.955385757948 +4,HH5A,1110.5839862890532 +5,HH1B,75.65232571741798 +6,HH2B,308.55263652324453 +7,HH3B,596.0453173809306 +8,HH4B,698.9963336780165 +9,HH5B,1057.2052836638131 +10,HH1C,29.33988969682687 +11,HH2C,237.04809792300802 +12,HH3C,647.5163997026365 +13,HH4C,543.8732495047409 +14,HH5C,386.5727045849963 +15,HH1D,12.180549496986718 +16,HH2D,129.9734407085609 +17,HH3D,482.41517672279247 +18,HH4D,954.4339111193711 +19,HH5D,1115.9848972706463 +20,HH1E,20.824716448949378 +21,HH2E,199.32182535080045 +22,HH3E,591.9967888945642 +23,HH4E,1142.0355779707218 +24,HH5E,1383.9627417811912 +25,HH1F,4.650580512949763 +26,HH2F,86.7329645321991 +27,HH3F,619.3264235199917 +28,HH4F,1133.4912155905454 +29,HH5F,3253.760096880674 +30,HH1G,46.07630315923714 +31,HH2G,357.78219673258707 +32,HH3G,650.6986397138792 +33,HH4G,612.9827305062189 +34,HH5G,568.2212310412953 +35,HH1H,53.723713162114905 +36,HH2H,229.36087516276586 +37,HH3H,604.0565290414027 +38,HH4H,394.0171232813275 +39,HH5H,239.9655729679046 diff --git a/pyincore/analyses/mmsacge/HH_base_val.csv b/pyincore/analyses/mmsacge/HH_base_val.csv new file mode 100644 index 000000000..800315ff9 --- /dev/null +++ b/pyincore/analyses/mmsacge/HH_base_val.csv @@ -0,0 +1,41 @@ +,household,0 +0,HH1A,20516 +1,HH2A,16217 +2,HH3A,12213 +3,HH4A,6149 +4,HH5A,4539 +5,HH1B,11354 +6,HH2B,14818 +7,HH3B,11908 +8,HH4B,7739 +9,HH5B,4868 +10,HH1C,8510 +11,HH2C,11311 +12,HH3C,12714 +13,HH4C,5648 +14,HH5C,2076 +15,HH1D,2535 +16,HH2D,5883 +17,HH3D,9828 +18,HH4D,10204 +19,HH5D,6768 +20,HH1E,1304 +21,HH2E,8294 +22,HH3E,10882 +23,HH4E,11756 +24,HH5E,7584 +25,HH1F,1714 +26,HH2F,4723 +27,HH3F,12327 +28,HH4F,11077 +29,HH5F,14598 +30,HH1G,5641 +31,HH2G,14871 +32,HH3G,11876 +33,HH4G,5818 +34,HH5G,2459 +35,HH1H,8729 +36,HH2H,10690 +37,HH3H,10324 +38,HH4H,4131 +39,HH5H,1357 diff --git a/pyincore/analyses/mmsacge/__init__.py b/pyincore/analyses/mmsacge/__init__.py new file mode 100644 index 000000000..0b36051a0 --- /dev/null +++ b/pyincore/analyses/mmsacge/__init__.py @@ -0,0 +1,7 @@ +# Copyright (c) 2019 University of Illinois and others. All rights reserved. +# +# This program and the accompanying materials are made available under the +# terms of the Mozilla Public License v2.0 which accompanies this distribution, +# and is available at https://www.mozilla.org/en-US/MPL/2.0/ + +from pyincore.analyses.mmsacge.mmsacge import MMSACGE \ No newline at end of file diff --git a/pyincore/analyses/mmsacge/baseKAP.csv b/pyincore/analyses/mmsacge/baseKAP.csv new file mode 100644 index 000000000..28612fd26 --- /dev/null +++ b/pyincore/analyses/mmsacge/baseKAP.csv @@ -0,0 +1,49 @@ +,sector,baseKAP +0,GoodsA,2938.31635455936 +1,TradeA,5938.38180543304 +2,OtherA,6249.42725891704 +3,GoodsB,495.109947875138 +4,TradeB,2742.73191153162 +5,OtherB,2310.34693051725 +6,GoodsC,299.738477890607 +7,TradeC,2183.72682350614 +8,OtherC,1053.3520003263 +9,GoodsD,680.406028263022 +10,TradeD,1878.54579866302 +11,OtherD,854.572099755455 +12,GoodsE,173.526923278978 +13,TradeE,1040.26722414147 +14,OtherE,1799.60627318856 +15,GoodsF,510.624749 +16,TradeF,1385.484186 +17,OtherF,1941.455572 +18,GoodsG,149.807392 +19,TradeG,2399.28817373208 +20,OtherG,4460.27727366383 +21,GoodsH,2737.735689 +22,TradeH,12655.499861 +23,OtherH,1947.215698 +24,HS1A,2925.88135059953 +25,HS2A,1373.12892109697 +26,HS3A,3674.55738066752 +27,HS1B,2654.92936472622 +28,HS2B,2813.21985311375 +29,HS3B,1579.83108779089 +30,HS1C,2187.14407653677 +31,HS2C,1601.51082847812 +32,HS3C,1723.46795472868 +33,HS1D,1002.27132372166 +34,HS2D,3247.24645040422 +35,HS3D,989.729377262407 +36,HS1E,882.174099436754 +37,HS2E,4516.4742319318 +38,HS3E,1334.63638983798 +39,HS1F,874.940775 +40,HS2F,6847.283171 +41,HS3F,1209.557368 +42,HS1G,1222.32597007787 +43,HS2G,2297.2862692704 +44,HS3G,3160.37754423205 +45,HS1H,2528.177375 +46,HS2H,715.725348 +47,HS3H,1870.496934 diff --git a/pyincore/analyses/mmsacge/mmsacge.py b/pyincore/analyses/mmsacge/mmsacge.py new file mode 100644 index 000000000..15683fc83 --- /dev/null +++ b/pyincore/analyses/mmsacge/mmsacge.py @@ -0,0 +1,191 @@ +from typing import Tuple, List, Dict + +import numpy as np +import os +import pandas as pd + +from pyincore import globals as pyglobals +from pyincore.client import IncoreClient +from pyincore.analyses.core_cge_ml import CoreCGEML +from pyincore.utils import parse_coeff, parse_base_vals + +logger = pyglobals.LOGGER + + +class MMSACGE(CoreCGEML): + DDS_coefficients_file = "DDS_coefficients.csv" + DY_coefficients_file = "DY_coefficients.csv" + MIGT_coefficients_file = "MIGT_coefficients.csv" + DFFD_coefficients_file = "DFFD_coefficients.csv" + + DS_base_val_file = "DS_base_val.csv" + GI_base_val_file = "GI_base_val.csv" + HH_base_val_file = "HH_base_val.csv" + FD_base_val_file = "FD_base_val.csv" + + Base_KAP_file = "baseKAP.csv" + + base_file_path = os.path.join( + pyglobals.PYINCORE_PACKAGE_HOME, "analyses", "mmsacge" + ) + + def __init__(self, incore_client: IncoreClient): + sectors, base_cap_factors, base_cap, model_coeffs = self.parse_files() + self.base_cap_factors = base_cap_factors + self.base_cap = base_cap + self.model_coeffs = model_coeffs + super(MMSACGE, self).__init__(incore_client, sectors) + + def get_spec(self): + return { + "name": "mmsa-shelby-cge-ml", + "description": "CGE ML model for MMSA Shelby County.", + "input_parameters": [ + { + "id": "domestic_supply_fname", + "required": False, + "description": "Name of the domestic supply output file with extension", + "type": str, + }, + { + "id": "gross_income_fname", + "required": False, + "description": "Name of gross income output file with extension", + "type": str, + }, + { + "id": "household_count_fname", + "required": False, + "description": "Name of the household count output file with extension", + "type": str, + }, + { + "id": "pre_factor_demand_fname", + "required": False, + "description": "Name of the pre-factor demand output file with extension", + "type": str, + }, + { + "id": "post_factor_demand_fname", + "required": False, + "description": "Name of the post-factor demand output file with extension", + "type": str, + }, + ], + "input_datasets": [ + { + "id": "sector_shocks", + "required": True, + "description": "Aggregation of building functionality states to capital shocks per sector", + "type": ["incore:capitalShocks"], + } + ], + "output_datasets": [ + { + "id": "domestic-supply", + "parent_type": "", + "description": "CSV file of resulting domestic supply", + "type": "incore:Employment", + }, + { + "id": "gross-income", + "parent_type": "", + "description": "CSV file of resulting gross income", + "type": "incore:Employment", + }, + { + "id": "pre-disaster-factor-demand", + "parent_type": "", + "description": "CSV file of factor demand before disaster", + "type": "incore:FactorDemand", + }, + { + "id": "post-disaster-factor-demand", + "parent_type": "", + "description": "CSV file of resulting factor-demand", + "type": "incore:FactorDemand", + }, + { + "id": "household-count", + "parent_type": "", + "description": "CSV file of household count", + "type": "incore:HouseholdCount", + }, + ], + } + + def parse_files( + self, + ) -> Tuple[Dict[str, List[str]], np.ndarray, np.ndarray, Dict[str, np.ndarray]]: + """parse_files Utility function to parse the input files + + Returns + ------- + Tuple[Dict[str, List[str]], np.ndarray, np.ndarray, Dict[str, np.ndarray]] + Returns a tuple containing the following: + 1. sectors: Dictionary containing the sectors for each factor + 2. base_cap_factors: List of numpy arrays containing the base capital for each factor + 3. base_cap: Numpy array containing the base capital + 4. model_coeffs: Dictionary containing the model coefficients for each factor + """ + logger.info("Parsing input files...") + model_filenames = { + "ds": os.path.join( + self.base_file_path, + self.DDS_coefficients_file, + ) + } + model_coeffs, sectors, base_cap_sector_ordering = parse_coeff(model_filenames) + filenames = [ + os.path.join( + self.base_file_path, + self.DS_base_val_file, + ), + os.path.join( + self.base_file_path, + self.GI_base_val_file, + ), + os.path.join( + self.base_file_path, + self.HH_base_val_file, + ), + os.path.join( + self.base_file_path, + self.FD_base_val_file, + ), + os.path.join( + self.base_file_path, + self.Base_KAP_file, + ), + ] + + base_cap_factors, base_cap = parse_base_vals( + filenames, sectors["ds"], base_cap_sector_ordering + ) + logger.info("Parsing input files completed.") + + return base_cap_sector_ordering, base_cap_factors, base_cap, model_coeffs + + def run_analysis(self) -> None: + logger.info("Running MMSA CGE model...") + sector_shocks = pd.read_csv( + self.get_input_dataset("sector_shocks").get_file_path("csv") + ) + # arrange the capital shocks in the same order as the sectors + shocks = [] + for sector in self.sectors["ds"]: + if sector.lower() not in [v.lower() for v in sector_shocks["sector"]]: + raise ValueError( + f"Sector {sector} not found in the sector shocks file. Please make sure you have used the correct capital shocks" + ) + shocks.append( + sector_shocks.loc[sector_shocks["sector"] == sector.upper()]["shock"] + ) + capital_shocks = np.array(shocks, dtype=np.float32).reshape(1, -1) + super().run_core_cge_ml( + self.base_cap, + capital_shocks, + self.model_coeffs, + self.base_cap_factors[:1], # need to remove this slice for full release + ) + logger.info("Running MMSA CGE model completed.") diff --git a/pyincore/utils/__init__.py b/pyincore/utils/__init__.py index 93eb09efa..0b7db57b7 100644 --- a/pyincore/utils/__init__.py +++ b/pyincore/utils/__init__.py @@ -1 +1,2 @@ -from pyincore.utils.http_util import return_http_response \ No newline at end of file +from pyincore.utils.http_util import return_http_response +from pyincore.utils.cge_ml_file_util import parse_coeff, parse_csv, parse_base_vals \ No newline at end of file diff --git a/pyincore/utils/cge_ml_file_util.py b/pyincore/utils/cge_ml_file_util.py new file mode 100644 index 000000000..1ef4b2745 --- /dev/null +++ b/pyincore/utils/cge_ml_file_util.py @@ -0,0 +1,106 @@ +from typing import Tuple, List, Dict + +import pandas as pd +import numpy as np + +from pyincore import globals as pyglobals + +logger = pyglobals.LOGGER +from pprint import pprint + + +def parse_coeff( + filenames: Dict[str, str] +) -> Tuple[Dict[str, np.ndarray], Dict[str, List[str]], Dict[str, List[str]]]: + """parse_coeff Function to parse the model coefficients. + + Parameters + ---------- + filenames : Dict[str, str] + Dictionary containing the factor name and the path to the coefficient file + + Returns + ------- + Tuple[Dict[str, np.ndarray], Dict[str, List[str]], Dict[str, List[str]]] + Tuple containing three dictionaries. The first dictionary contains the model coefficients for + each factor, the second dictionary contains the sectors for each factor, and the third dictionary + contains the order of the sectors for each factor for models. + """ + + model_coeffs: Dict[str, np.ndarray] = {} + sectors: Dict[str, List[str]] = {} + base_cap_sector_order: Dict[str, List[str]] = {} + + for factor, filename in filenames.items(): + logger.info(f"Parsing {filename}") + model_coeff_df: pd.DataFrame = pd.read_csv(filename) + sectors[factor] = list(model_coeff_df.columns[5:]) + base_cap_sector_order[factor] = [s.split(" ")[-1].upper() for s in list(model_coeff_df["Model_Name"])[1:]] + model_coeffs[factor] = np.float32(model_coeff_df[model_coeff_df.columns[4:]].to_numpy()[ + 1:, : + ]) # skip the first row as it contains the total value model and its not needed in output + + return model_coeffs, sectors, base_cap_sector_order + + +def parse_csv(file_name: str, sectors: List[str]) -> np.ndarray: + """parse_csv Utility function to parse the csv files + + Parameters + ---------- + file_name : str + Path to the csv file + + Returns + ------- + np.ndarray + Numpy array containing the data from the csv file + """ + + logger.info(f"Parsing {file_name}") + df = pd.read_csv(file_name) + + col_name = df.columns[1] + val_col = df.columns[2] + + # Convert 'sectors' column to categorical with the desired order + df[col_name] = pd.Categorical(df[col_name], categories=sectors, ordered=True) + + # Sort the DataFrame based on the 'names' column + df = df.sort_values(by=col_name) + + return np.array(df[val_col], dtype= np.float32) + + +def parse_base_vals( + filenames: List[str], ds_sectors: List[str], base_cap_sector_order: Dict[str, List[str]] +) -> Tuple[List[np.ndarray], np.ndarray]: + """parse_base_vals parse_base_vals will parse the base values from the input file and return them as numpy arrays + + Parameters + ---------- + file_name : str + Paths to the .csv files containing the base values. It has to be organized this order, starting from: + 1. Domestic Supply + 2. Gross Income + 3. Household Count + 4. Factor Demand + 5. Base Capital + Returns + ------- + + Tuple[np.ndarray, np.ndarray] + Tuple containing two numpy arrays. The first array is the base capital for different factors and the second is the base capital + """ + + base_cap_factors: List[np.ndarray] = [] + base_cap: np.ndarray = parse_csv(filenames[-1], ds_sectors).reshape( + 1, -1 + ) # 1 x K array K = number of sectors in the model + + for filename, sector_order in zip(filenames[:-1], base_cap_sector_order.values()): + base_cap_factors.append( + parse_csv(filename, sector_order).reshape(-1, 1) + ) # k_i x 1 array k_i = number of sectors k for a factor i + + return base_cap_factors, base_cap diff --git a/requirements.min b/requirements.min index 24624a10b..9c7bffe03 100644 --- a/requirements.min +++ b/requirements.min @@ -16,4 +16,5 @@ requests>=2.31.0 rtree>=1.1.0 scipy>=1.11.3 shapely>=2.0.2 +openpyxl>=3.1.2 openssl<=3.2.0 diff --git a/requirements.txt b/requirements.txt index 1c769cd14..b27228443 100644 --- a/requirements.txt +++ b/requirements.txt @@ -14,4 +14,5 @@ rasterio>=1.3.9 requests>=2.31.0 rtree>=1.1.0 scipy>=1.11.3 -shapely>=2.0.2 \ No newline at end of file +shapely>=2.0.2 +openpyxl>=3.1.2 diff --git a/setup.py b/setup.py index c289a9706..e7d9ed8a0 100644 --- a/setup.py +++ b/setup.py @@ -49,7 +49,7 @@ packages=find_packages(where=".", exclude=["*.tests", "*.tests.*", "tests.*", "tests"]), include_package_data=True, package_data={ - '': ['*.ini'] + '': ['*.ini', "*.csv"] }, python_requires=">=3.9", diff --git a/tests/pyincore/analyses/mmsacge/mmsa_capital_shocks.csv b/tests/pyincore/analyses/mmsacge/mmsa_capital_shocks.csv new file mode 100644 index 000000000..2ee1ab4ab --- /dev/null +++ b/tests/pyincore/analyses/mmsacge/mmsa_capital_shocks.csv @@ -0,0 +1,49 @@ +sector,shock +HS2F,0.3814178741163376 +HS1A,0.441914047670641 +HS2E,0.3210069915936159 +HS2A,0.2980716166818221 +HS2C,0.2999142275646257 +OTHERG,0.1594609852859964 +HS2D,0.2423518213446305 +HS1B,0.4494605458798874 +HS1G,0.4759444867259513 +HS1H,0.5218235372025891 +HS3G,0.2354352034341608 +HS2G,0.3439110652524618 +HS1C,0.3769991677641695 +HS3H,0.2456128497248694 +HS3C,0.1835154877256543 +HS3A,0.216674609237866 +HS1E,0.3970793677138909 +TRADEA,0.1813939558286917 +HS2B,0.3568775596019876 +HS1D,0.3283892487869675 +TRADEF,0.2922078063155617 +HS3B,0.2345771267082573 +HS2H,0.4373352668058273 +OTHERA,0.2130813324068216 +OTHERF,0.3320483071261566 +TRADEH,0.3261546551270147 +HS1F,0.5583778075509281 +TRADED,0.1495920320367731 +OTHERC,0.2134117955201139 +TRADEC,0.1207422422413331 +GOODSC,0.1608450886511487 +GOODSA,0.1159304916101041 +HS3E,0.2454421237403486 +TRADEB,0.1382607755583362 +OTHERH,0.2326381397515079 +OTHERB,0.1965972821691839 +OTHERE,0.1963675943082921 +HS3F,0.379604039580862 +OTHERD,0.1898828655296653 +TRADEE,0.2022722262108508 +GOODSH,0.1301197197584153 +HS3D,0.1637637626131083 +GOODSB,0.0695338022288151 +GOODSF,0.2109422647342815 +TRADEG,0.2630452554347375 +GOODSD,0.0834575334172509 +GOODSE,0.1894928915493545 +GOODSG,0.1125344179623751 diff --git a/tests/pyincore/analyses/mmsacge/test_mmsacge.py b/tests/pyincore/analyses/mmsacge/test_mmsacge.py new file mode 100644 index 000000000..48b0889f2 --- /dev/null +++ b/tests/pyincore/analyses/mmsacge/test_mmsacge.py @@ -0,0 +1,23 @@ +import os + +from pyincore import IncoreClient, Dataset, globals as pyglobals +from pyincore.analyses.mmsacge import MMSACGE + +client = IncoreClient() + +mmsacge = MMSACGE(client) + +curr_dir = os.path.dirname(__file__) +capital_shocks = Dataset.from_file( + os.path.join( + curr_dir, + "mmsa_capital_shocks.csv", + ), + data_type="incore:capitalShocks", +) + + +mmsacge.set_input_dataset("sector_shocks", capital_shocks) +mmsacge.set_parameter("domestic_supply_fname", "mmsa_shelby_county_domestic_supply.csv") + +mmsacge.run_analysis() \ No newline at end of file