Skip to content

Commit

Permalink
Pass filename instead of corr_dict to read_correlations
Browse files Browse the repository at this point in the history
  • Loading branch information
dafeda committed Nov 30, 2024
1 parent 4a99906 commit e8438a7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/semeio/fmudesign/create_design.py
Original file line number Diff line number Diff line change
Expand Up @@ -758,7 +758,7 @@ def generate(self, realnums, parameters, seedvalues, corrdict, rng):
if len(corr_group) == 1:
_printwarning(corr_group_name)
df_correlations = design_dist.read_correlations(
corrdict, corr_group_name
corrdict["inputfile"], corr_group_name
)
multivariate_parameters = df_correlations.index.values
correlations = df_correlations.values
Expand Down
19 changes: 7 additions & 12 deletions src/semeio/fmudesign/design_distributions.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"""

import re
from pathlib import Path

import numpy as np
import pandas as pd
Expand Down Expand Up @@ -513,32 +514,26 @@ def is_number(teststring):
return False


def read_correlations(corr_dict, corr_sheet: str):
def read_correlations(excel_filename: Path, corr_sheet: str):
"""Reading correlation info for a
monte carlo sensitivity
Args:
corr_dict (OrderedDict): correlation info
excel_filename (Path): Path to Excel file containing correlation matrix
corr_sheet (str): name of sheet containing correlation matrix
Returns:
pd.DataFrame: Dataframe with correlations, parameter names
as column and index
"""
correlations = None
filename = corr_dict["inputfile"]

if not str(filename).endswith(".xlsx"):
if not str(excel_filename).endswith(".xlsx"):
raise ValueError(
"Correlation matrix filename should be on Excel format and end with .xlsx"
)

if corr_sheet not in corr_dict["sheetnames"]:
raise ValueError(
f"Corr_sheet {corr_sheet} specified but cannot be found in list of sheetnames"
)

correlations = pd.read_excel(filename, corr_sheet, index_col=0, engine="openpyxl")
correlations = pd.read_excel(
excel_filename, corr_sheet, index_col=0, engine="openpyxl"
)
correlations.dropna(axis=0, how="all", inplace=True)
# Remove any 'Unnamed' columns that Excel/pandas may have automatically added.
correlations = correlations.loc[:, ~correlations.columns.str.contains("^Unnamed")]
Expand Down

0 comments on commit e8438a7

Please sign in to comment.