Skip to content

Commit a309969

Browse files
committed
further cleaning, move imp to helper to avoid circ imp
1 parent 6986629 commit a309969

4 files changed

Lines changed: 29 additions & 37 deletions

File tree

navicat_mikimo/helper.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,30 @@
66

77
import autograd.numpy as np
88
import pandas as pd
9+
from sklearn.experimental import enable_iterative_imputer
10+
from sklearn.impute import IterativeImputer, KNNImputer, SimpleImputer
11+
12+
13+
def call_imputter(imp_alg):
14+
"""
15+
Create an instance of the specified imputer type.
16+
17+
Parameters:
18+
imputer_type: Type of imputer. Options: "knn", "iterative", "simple".
19+
20+
Returns:
21+
An instance of the specified imputer type.
22+
"""
23+
if imp_alg == "knn":
24+
imputer = KNNImputer(n_neighbors=5, weights="uniform")
25+
elif imp_alg == "iterative":
26+
imputer = IterativeImputer(max_iter=10, random_state=0)
27+
elif imp_alg == "simple":
28+
imputer = SimpleImputer(missing_values=np.nan, strategy="mean")
29+
else:
30+
print("Invalid imputer type, use KNN imputer instead.")
31+
imputer = KNNImputer(n_neighbors=5, weights="uniform")
32+
return imputer
933

1034

1135
def yesno(question):

navicat_mikimo/km_k_volcanic.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,37 +4,32 @@
44
import os
55
import shutil
66
import sys
7-
from typing import List, Optional, Tuple, Union
87
import warnings
8+
from typing import List, Optional, Tuple, Union
99

1010
import h5py
1111
import matplotlib.pyplot as plt
1212
import numpy as np
1313
import pandas as pd
1414
import sklearn as sk
1515
from joblib import Parallel, delayed
16-
from navicat_volcanic.dv1 import curate_d
1716
from navicat_volcanic.dv2 import find_2_dv
1817
from navicat_volcanic.helpers import (
1918
bround,
2019
group_data_points,
2120
user_choose_1_dv,
2221
user_choose_2_dv,
2322
)
24-
from navicat_volcanic.plotting2d import calc_ci, plot_2d, plot_2d_lsfer, get_reg_targets
23+
from navicat_volcanic.plotting2d import calc_ci, get_reg_targets, plot_2d, plot_2d_lsfer
2524
from navicat_volcanic.plotting3d import (
2625
get_bases,
2726
plot_3d_contour,
2827
plot_3d_contour_regions,
29-
plot_3d_lsfer,
30-
plot_3d_scatter,
3128
)
3229
from scipy.interpolate import interp1d
33-
from sklearn.experimental import enable_iterative_imputer
34-
from sklearn.impute import IterativeImputer, KNNImputer, SimpleImputer
3530
from tqdm import tqdm
3631

37-
from .helper import check_km_inp, preprocess_data_mkm, process_data_mkm, yesno
32+
from .helper import process_data_mkm, yesno
3833
from .kinetic_solver import calc_km
3934
from .plot_function import (
4035
plot_2d_combo,
@@ -43,7 +38,6 @@
4338
plot_3d_np,
4439
plot_evo,
4540
)
46-
from .km_volcanic import call_imputter
4741

4842
warnings.filterwarnings("ignore")
4943

navicat_mikimo/km_volcanic.py

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,12 @@
2525
get_bases,
2626
plot_3d_contour,
2727
plot_3d_contour_regions,
28-
plot_3d_lsfer,
29-
plot_3d_scatter,
3028
)
3129
from scipy.interpolate import interp1d
32-
from sklearn.experimental import enable_iterative_imputer
33-
from sklearn.impute import IterativeImputer, KNNImputer, SimpleImputer
3430
from tqdm import tqdm
3531

3632
from . import km_k_volcanic
37-
from .helper import check_km_inp, preprocess_data_mkm, process_data_mkm, yesno
33+
from .helper import call_imputter, preprocess_data_mkm, process_data_mkm, yesno
3834
from .kinetic_solver import calc_km
3935
from .plot_function import (
4036
plot_2d_combo,
@@ -45,28 +41,6 @@
4541
)
4642

4743

48-
def call_imputter(imp_alg):
49-
"""
50-
Create an instance of the specified imputer type.
51-
52-
Parameters:
53-
imputer_type: Type of imputer. Options: "knn", "iterative", "simple".
54-
55-
Returns:
56-
An instance of the specified imputer type.
57-
"""
58-
if imp_alg == "knn":
59-
imputer = KNNImputer(n_neighbors=5, weights="uniform")
60-
elif imp_alg == "iterative":
61-
imputer = IterativeImputer(max_iter=10, random_state=0)
62-
elif imp_alg == "simple":
63-
imputer = SimpleImputer(missing_values=np.nan, strategy="mean")
64-
else:
65-
print("Invalid imputer type, use KNN imputer instead.")
66-
imputer = KNNImputer(n_neighbors=5, weights="uniform")
67-
return imputer
68-
69-
7044
def process_n_calc_2d(
7145
profile: List[float],
7246
sigma_p: float,

navicat_mikimo/plot_function.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -624,7 +624,7 @@ def plot_3d_contour_regions_np(
624624
plt.ylim(np.min(yticks), np.max(yticks))
625625
plt.xticks(np.arange(x1min, x1max + 0.1, x1base))
626626
plt.yticks(np.arange(x2min, x2max + 0.1, x2base))
627-
ax.contour(xint, yint, grid, cszet.levels, colors="black", linewidths=0.1)
627+
ax.contour(xint, yint, grid, cset.levels, colors="black", linewidths=0.1)
628628

629629
def fmt(x, pos):
630630
return "%.0f" % x

0 commit comments

Comments
 (0)