From 386cd7218ff1e9d7bec8617cff017746c2a930c4 Mon Sep 17 00:00:00 2001 From: jvivian Date: Sun, 9 Jun 2024 18:46:44 -0700 Subject: [PATCH] hotfix for batch var --- .../data/processed/test_input_2state.csv | 73 +++++++++++++++++++ .../streamlit/pages/0_Dynamic_Factor_Model.py | 11 ++- 2 files changed, 78 insertions(+), 6 deletions(-) create mode 100644 covid19_drdfm/data/processed/test_input_2state.csv diff --git a/covid19_drdfm/data/processed/test_input_2state.csv b/covid19_drdfm/data/processed/test_input_2state.csv new file mode 100644 index 0000000..e3c4a26 --- /dev/null +++ b/covid19_drdfm/data/processed/test_input_2state.csv @@ -0,0 +1,73 @@ +Time,Pandemic_10,Pandemic_9,Pandemic_1,Pandemic_7,State +1/1/2020,0,0,0,0,AK +2/1/2020,0,0,0,0,AK +3/1/2020,0.0058740602,0.0397350993,0.0042229655,0.0609357998,AK +4/1/2020,0.0693139098,0.0198675497,0.0024131231,0.0282916213,AK +5/1/2020,0.1379229323,0.0264900662,0.0025728151,0.0304678999,AK +6/1/2020,0.1734022556,0.0264900662,0.0108767976,0.0631120783,AK +7/1/2020,0.4814379699,0.1059602649,0.040277864,0.1828073993,AK +8/1/2020,0.313674812,0.1258278146,0.0370130504,0.204570185,AK +9/1/2020,0.1459116541,0.1125827815,0.0532484009,0.1566920566,AK +10/1/2020,0.0773026316,0.3112582781,0.1582192571,0.4243743199,AK +11/1/2020,0.155075188,0.5894039735,0.3026162868,0.752992383,AK +12/1/2020,0.5227913534,0.5033112583,0.1744191205,0.5571273123,AK +1/1/2021,1,0.178807947,0.0982904087,0.2176278564,AK +2/1/2021,0.6719924812,0.0993377483,0.0558034724,0.1523394995,AK +3/1/2021,0.2319078947,0.1125827815,0.072748565,0.2241566921,AK +4/1/2021,0.0838815789,0.0066225166,0.0778320928,0.289445049,AK +5/1/2021,0.0714285714,0.1390728477,0.0299511165,0.1284004353,AK +6/1/2021,0.0723684211,0.0529801325,0.0149666865,0.0957562568,AK +7/1/2021,0.0728383459,0.0794701987,0.0817711614,0.39390642,AK +8/1/2021,0.1268796992,0.3245033113,0.26157545,0.8019586507,AK +9/1/2021,0.2814849624,0.8278145695,0.4060079669,1,AK +10/1/2021,0.274906015,0.9470198675,0.3689594294,0.8335146899,AK +11/1/2021,0.2709116541,1,0.1806914662,0.4494015234,AK +12/1/2021,0.4515977444,0.1059602649,0.1362261238,0.2655059848,AK +1/1/2022,0.4642857143,0.2847682119,1,0.478781284,AK +2/1/2022,0.4090695489,0.5165562914,0.2854316563,0.2491838955,AK +3/1/2022,0.3106203008,0.4304635762,0.1077388504,0.1284004353,AK +4/1/2022,0.1604793233,0.1589403974,0.0940142126,0.0718171926,AK +5/1/2022,0.0817669173,0.2185430464,0.1257574279,0.1099020675,AK +6/1/2022,0.0507518797,0,0.1572433617,0.1077257889,AK +7/1/2022,0.0594454887,0.1523178808,0.1569505931,0.1088139282,AK +8/1/2022,0.0812969925,0.1920529801,0.0951143128,0.112078346,AK +9/1/2022,0.0601503759,0.1655629139,0.0211769298,0.0402611534,AK +10/1/2022,0,0,0.0135738176,0.0293797606,AK +11/1/2022,0,0,0.0134850999,0.0054406964,AK +12/1/2022,0,0,0.0121365899,0.0087051143,AK +1/1/2020,0,0,0,0,CA +2/1/2020,0,0,0,0,CA +3/1/2020,0.0058740602,0.0397350993,0.0042229655,0.0609357998,CA +4/1/2020,0.0693139098,0.0198675497,0.0024131231,0.0282916213,CA +5/1/2020,0.1379229323,0.0264900662,0.0025728151,0.0304678999,CA +6/1/2020,0.1734022556,0.0264900662,0.0108767976,0.0631120783,CA +7/1/2020,0.4814379699,0.1059602649,0.040277864,0.1828073993,CA +8/1/2020,0.313674812,0.1258278146,0.0370130504,0.204570185,CA +9/1/2020,0.1459116541,0.1125827815,0.0532484009,0.1566920566,CA +10/1/2020,0.0773026316,0.3112582781,0.1582192571,0.4243743199,CA +11/1/2020,0.155075188,0.5894039735,0.3026162868,0.752992383,CA +12/1/2020,0.5227913534,0.5033112583,0.1744191205,0.5571273123,CA +1/1/2021,1,0.178807947,0.0982904087,0.2176278564,CA +2/1/2021,0.6719924812,0.0993377483,0.0558034724,0.1523394995,CA +3/1/2021,0.2319078947,0.1125827815,0.072748565,0.2241566921,CA +4/1/2021,0.0838815789,0.0066225166,0.0778320928,0.289445049,CA +5/1/2021,0.0714285714,0.1390728477,0.0299511165,0.1284004353,CA +6/1/2021,0.0723684211,0.0529801325,0.0149666865,0.0957562568,CA +7/1/2021,0.0728383459,0.0794701987,0.0817711614,0.39390642,CA +8/1/2021,0.1268796992,0.3245033113,0.26157545,0.8019586507,CA +9/1/2021,0.2814849624,0.8278145695,0.4060079669,1,CA +10/1/2021,0.274906015,0.9470198675,0.3689594294,0.8335146899,CA +11/1/2021,0.2709116541,1,0.1806914662,0.4494015234,CA +12/1/2021,0.4515977444,0.1059602649,0.1362261238,0.2655059848,CA +1/1/2022,0.4642857143,0.2847682119,1,0.478781284,CA +2/1/2022,0.4090695489,0.5165562914,0.2854316563,0.2491838955,CA +3/1/2022,0.3106203008,0.4304635762,0.1077388504,0.1284004353,CA +4/1/2022,0.1604793233,0.1589403974,0.0940142126,0.0718171926,CA +5/1/2022,0.0817669173,0.2185430464,0.1257574279,0.1099020675,CA +6/1/2022,0.0507518797,0,0.1572433617,0.1077257889,CA +7/1/2022,0.0594454887,0.1523178808,0.1569505931,0.1088139282,CA +8/1/2022,0.0812969925,0.1920529801,0.0951143128,0.112078346,CA +9/1/2022,0.0601503759,0.1655629139,0.0211769298,0.0402611534,CA +10/1/2022,0,0,0.0135738176,0.0293797606,CA +11/1/2022,0,0,0.0134850999,0.0054406964,CA +12/1/2022,0,0,0.0121365899,0.0087051143,CA diff --git a/covid19_drdfm/streamlit/pages/0_Dynamic_Factor_Model.py b/covid19_drdfm/streamlit/pages/0_Dynamic_Factor_Model.py index e79c412..4752982 100644 --- a/covid19_drdfm/streamlit/pages/0_Dynamic_Factor_Model.py +++ b/covid19_drdfm/streamlit/pages/0_Dynamic_Factor_Model.py @@ -51,10 +51,10 @@ def file_uploader(self) -> "DataHandler": if self.df is None: st.error("DataFrame is empty! Check input data") st.stop() - batch_col = st.sidebar.selectbox("Select a batch column (optional):", ["None", *list(self.df.columns)]) - if batch_col == "None": + self.batch_col = st.sidebar.selectbox("Select a batch column (optional):", ["None", *list(self.df.columns)]) + if self.batch_col == "None": self.batch_col = None - self.non_batch_cols = [col for col in self.df.columns if col != batch_col] + self.non_batch_cols = [col for col in self.df.columns if col != self.batch_col] return self @staticmethod @@ -137,12 +137,11 @@ def create_anndata(self) -> ann.AnnData: An AnnData object with additional metadata. """ if self.batch_col and self.batch_col in self.df.columns: - ad = ann.AnnData(self.df.drop(columns=self.batch_col)) + ad = ann.AnnData(self.df.drop(columns=[self.batch_col])) ad.obs[self.batch_col] = self.df[self.batch_col] else: ad = ann.AnnData(self.df) - - ad.var["factor"] = [self.factor_mappings[x] for x in ad.var.index] + ad.var["factor"] = [self.factor_mappings[x] for x in self.non_batch_cols] self.ad = ad return ad