Skip to content

Commit

Permalink
Merge pull request #12 from climateintelligence/dev
Browse files Browse the repository at this point in the history
Small fixes
  • Loading branch information
PaoloBonettiPolimi authored Apr 16, 2024
2 parents 90472f2 + 81599c3 commit d76c2ba
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 146 deletions.
2 changes: 1 addition & 1 deletion environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ dependencies:
- psutil
- birdy
#- tigramite
#- tefs
#- tefs==0.3.1
- pandas
- scikit-learn
- numpy
Expand Down
2 changes: 1 addition & 1 deletion hawk/analysis/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
import os

import pandas as pd
from tefs.metrics import regression_analysis
from tigramite.independence_tests.cmiknn import CMIknn
from tigramite.independence_tests.parcorr import ParCorr

from .file_management import save_to_pkl_file
from .metrics import regression_analysis
from .pcmci_tools import initialize_tigramite_df
from .postprocessing import (
run_postprocessing_pcmci,
Expand Down
124 changes: 0 additions & 124 deletions hawk/analysis/metrics.py

This file was deleted.

8 changes: 5 additions & 3 deletions hawk/analysis/postprocessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
import numpy as np
import pandas as pd
import seaborn as sns
from tefs.metrics import regression_analysis

# from tigramite import plotting as tp
from .file_management import save_to_pkl_file
from .metrics import regression_analysis
from .pcmci_tools import get_connected_variables


Expand Down Expand Up @@ -257,7 +257,7 @@ def run_postprocessing_pcmci(
target_file_plots = {}
for image_format in image_formats:
target_file_plot = os.path.join(
destination_path, "algorithm_results", "pcmci", f"feature_presence.{image_format}"
destination_path, "algorithm_results", "pcmci", f"feature_presence_pcmci.{image_format}"
)
os.makedirs(os.path.dirname(target_file_plot), exist_ok=True)
plt.savefig(target_file_plot, bbox_inches="tight")
Expand Down Expand Up @@ -384,7 +384,9 @@ def run_postprocessing_tefs(
)
target_file_plots = {}
for image_format in image_formats:
target_file_plot = os.path.join(destination_path, "algorithm_results", "te", f"feature_presence.{image_format}")
target_file_plot = os.path.join(
destination_path, "algorithm_results", "te", f"feature_presence_tefs.{image_format}"
)
os.makedirs(os.path.dirname(target_file_plot), exist_ok=True)
plt.savefig(target_file_plot, bbox_inches="tight")
target_file_plots[image_format] = target_file_plot
Expand Down
18 changes: 7 additions & 11 deletions hawk/processes/simulation_interactive.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,20 @@
from birdy import WPSClient

train_file_path = "Emiliani1_train.csv"
test_file_path = "Emiliani1_test.csv"
target_column_name = "cyclostationary_mean_rr_4w_1"

# ----------------- WPS -----------------

wps = WPSClient("http://localhost:5002/wps", verify=False)
help(wps)

# Input some data for the causal process
resp = wps.causal(
dataset_train=open(train_file_path),
dataset_test=open(test_file_path),
target_column_name=target_column_name,
dataset_train="https://raw.githubusercontent.com/climateintelligence/hawk/main/hawk/demo/Ticino_train.csv",
dataset_test="https://raw.githubusercontent.com/climateintelligence/hawk/main/hawk/demo/Ticino_train.csv",
target_column_name="target",
pcmci_test_choice="ParCorr",
pcmci_max_lag="0",
tefs_direction="both",
tefs_use_contemporary_features="Yes",
tefs_max_lag_features="1",
pcmci_max_lag="1",
tefs_direction="forward",
tefs_use_contemporary_features=True,
tefs_max_lag_features="2",
tefs_max_lag_target="1",
)

Expand Down
12 changes: 9 additions & 3 deletions hawk/processes/wps_causal.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

FORMAT_PNG = Format("image/png", extension=".png", encoding="base64")
FORMAT_PDF = Format("application/pdf", extension=".pdf", encoding="utf-8")
FORMAT_PICKLE = Format("application/octet-stream", extension=".pkl", encoding="utf-8")
FORMAT_PICKLE = Format("application/octet-stream", extension=".pkl")


class Causal(Process):
Expand Down Expand Up @@ -39,12 +39,14 @@ def __init__(self):
"Target Column Name",
data_type="string",
abstract="Please enter the case-specific name of the target variable in the dataframe.",
default="target",
),
LiteralInput(
"pcmci_test_choice",
"PCMCI Test Choice",
data_type="string",
abstract="Choose the independence test to be used in PCMCI.",
default="ParCorr",
allowed_values=[
"ParCorr",
"CMIknn",
Expand All @@ -55,6 +57,7 @@ def __init__(self):
"PCMCI Max Lag",
data_type="string",
abstract="Choose the maximum lag to test used in PCMCI.",
default="1",
allowed_values=[
"0",
"1",
Expand All @@ -69,6 +72,7 @@ def __init__(self):
"TEFS Direction",
data_type="string",
abstract="Choose the direction of the TEFS algorithm.",
default="both",
allowed_values=[
"forward",
"backward",
Expand All @@ -79,14 +83,15 @@ def __init__(self):
"tefs_use_contemporary_features",
"TEFS Use Contemporary Features",
data_type="boolean",
abstract="Choose whether to use comtemporary features in the TEFS algorithm.",
default="Yes",
abstract="Choose whether to use contemporary features in the TEFS algorithm.",
default=True,
),
LiteralInput(
"tefs_max_lag_features",
"TEFS Max Lag Features",
data_type="string",
abstract="Choose the maximum lag of the features in the TEFS algorithm.",
default="1",
allowed_values=[
"no_lag",
"1",
Expand All @@ -101,6 +106,7 @@ def __init__(self):
"TEFS Max Lag Target",
data_type="string",
abstract="Choose the maximum lag of the target in the TEFS algorithm.",
default="1",
allowed_values=[
"1",
"2",
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ psutil
pywps>=4.5.1,<4.6
birdhouse-birdy
tigramite>=5.2.5.1
tefs
tefs==0.3.1
pandas
scikit-learn
numpy
4 changes: 2 additions & 2 deletions tests/test_causal_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ def test_causal_analysis():
df_test = pd.read_csv("hawk/demo/Ticino_test.csv", header=0)
target_column_name = "target"
pcmci_test_choice = "ParCorr"
pcmci_max_lag = 0
tefs_direction = "forward"
pcmci_max_lag = 2
tefs_direction = "both"
tefs_use_contemporary_features = True
tefs_max_lag_features = 1
tefs_max_lag_target = 1
Expand Down

0 comments on commit d76c2ba

Please sign in to comment.