Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Relative imports for submodules #139

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions kymata/datasets/sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
from typing import Optional
from urllib import request

from kymata.entities.expression import HexelExpressionSet, SensorExpressionSet
from kymata.io.file import path_type
from kymata.io.nkg import load_expression_set
from ..entities.expression import HexelExpressionSet, SensorExpressionSet
from ..io.file import path_type
from ..io.nkg import load_expression_set

_DATA_PATH_ENVIRONMENT_VAR_NAME = "KYMATA_DATA_ROOT"
_DATA_DIR_NAME = "kymata-toolbox-data/tutorial_nkg_data"
Expand Down
6 changes: 3 additions & 3 deletions kymata/entities/expression.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
from sparse import SparseArray, COO
from xarray import DataArray, Dataset, concat

from kymata.entities.datatypes import HexelDType, SensorDType, LatencyDType, FunctionNameDType, Hexel, Sensor, \
from .datatypes import HexelDType, SensorDType, LatencyDType, FunctionNameDType, Hexel, Sensor, \
Latency
from kymata.entities.iterables import all_equal
from kymata.entities.sparse_data import expand_dims, densify_dataset, sparsify_log_pmatrix
from .iterables import all_equal
from .sparse_data import expand_dims, densify_dataset, sparsify_log_pmatrix

_InputDataArray = Union[ndarray, SparseArray] # Type alias for data which can be accepted

Expand Down
10 changes: 5 additions & 5 deletions kymata/gridsearch/plain.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import numpy as np
from numpy.typing import NDArray
from scipy import stats

from kymata.entities.functions import Function
from kymata.math.combinatorics import generate_derangement
from kymata.math.vector import normalize, get_stds
#from kymata.entities.expression import SensorExpressionSet, p_to_logp
import matplotlib.pyplot as plt

from ..entities.functions import Function
from ..math.combinatorics import generate_derangement
from ..math.vector import normalize, get_stds
#from ..entities.expression import SensorExpressionSet, p_to_logp


def do_gridsearch(
emeg_values: NDArray, # chan x time
Expand Down
5 changes: 2 additions & 3 deletions kymata/io/functions.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
from pathlib import Path

from numpy import array, float16, convolve, mean
import numpy as np
from numpy.typing import NDArray
from scipy.io import loadmat

from kymata.entities.functions import Function
from kymata.io.file import path_type
from ..entities.functions import Function
from .file import path_type


def load_function(function_path_without_suffix: path_type, func_name: str, n_derivatives: int = 0, bruce_neurons: tuple = (0, 10)) -> Function:
Expand Down
4 changes: 2 additions & 2 deletions kymata/io/matlab.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
from scipy.io import loadmat as loadmat_pre_73
from mat73 import loadmat as loadmat_post_73

from kymata.entities.expression import HexelExpressionSet, p_to_logp
from kymata.entities.iterables import all_equal
from ..entities.expression import HexelExpressionSet, p_to_logp
from ..entities.iterables import all_equal


def load_mat(path):
Expand Down
5 changes: 0 additions & 5 deletions kymata/io/mne.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
from pathlib import Path

from mne import read_evokeds, minimum_norm, set_eeg_reference
import numpy as np
from numpy.typing import NDArray
from os.path import isfile

from kymata.io.file import path_type



def load_single_emeg(emeg_path, need_names=False, inverse_operator=None, snr=4):
emeg_path_npy = f"{emeg_path}.npy"
Expand Down
8 changes: 4 additions & 4 deletions kymata/io/nkg.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
from numpy import ndarray, frombuffer
from sparse import COO

from kymata.entities.datatypes import HexelDType, LatencyDType, FunctionNameDType, SensorDType
from kymata.entities.expression import ExpressionSet, LAYER_LEFT, LAYER_RIGHT, LAYER_SCALP, HexelExpressionSet, \
from ..entities.datatypes import HexelDType, LatencyDType, FunctionNameDType, SensorDType
from ..entities.expression import ExpressionSet, LAYER_LEFT, LAYER_RIGHT, LAYER_SCALP, HexelExpressionSet, \
SensorExpressionSet, p_to_logp
from kymata.entities.sparse_data import expand_dims
from kymata.io.file import path_type, file_type, open_or_use
from ..entities.sparse_data import expand_dims
from .file import path_type, file_type, open_or_use


class _Keys(StrEnum):
Expand Down
4 changes: 2 additions & 2 deletions kymata/io/nkg_compatibility.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
from numpy import frombuffer
from numpy.typing import NDArray

from kymata.entities.datatypes import LatencyDType, FunctionNameDType, HexelDType
from kymata.io.file import path_type, file_type, open_or_use
from ..entities.datatypes import LatencyDType, FunctionNameDType, HexelDType
from .file import path_type, file_type, open_or_use


# Version 0.3: moved to log p-values.
Expand Down
11 changes: 6 additions & 5 deletions kymata/ippm/data_tools.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
import json
import math
from itertools import cycle
from statistics import NormalDist
from typing import Tuple, Dict, List

import matplotlib.colors
import matplotlib.pyplot as plt
from matplotlib.lines import Line2D
import matplotlib.colors
import numpy as np
import pandas as pd
from sklearn.preprocessing import normalize
from sklearn.metrics.pairwise import euclidean_distances
from copy import deepcopy
import requests
import seaborn as sns
from matplotlib.lines import Line2D
import math
from kymata.entities.expression import HexelExpressionSet, DIM_FUNCTION, DIM_LATENCY

from ..entities.expression import HexelExpressionSet, DIM_FUNCTION, DIM_LATENCY


class IPPMHexel(object):
"""
Expand Down
2 changes: 1 addition & 1 deletion kymata/ippm/denoiser.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import pandas as pd
from sklearn.cluster import DBSCAN as DBSCAN_, MeanShift as MeanShift_
from sklearn.mixture import GaussianMixture
from sklearn.preprocessing import StandardScaler, normalize
from sklearn.preprocessing import normalize

from .data_tools import IPPMHexel

Expand Down
12 changes: 7 additions & 5 deletions kymata/ippm/experiments.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,19 @@
"outputs": [],
"source": [
"from copy import deepcopy\n",
"from typing import Dict, List, Tuple\n",
"from typing import Dict\n",
"\n",
"import numpy as np\n",
"import pandas as pd\n",
"from kymata.ippm.data_tools import IPPMHexel, stem_plot, build_hexel_dict_from_expression_set, convert_to_power10, remove_excess_funcs, plot_4_dist, plot_k_dist_1D, copy_hemisphere, plot_denoised_vs_noisy\n",
"from kymata.ippm.denoiser import DenoisingStrategy, AdaptiveMaxPooler, MaxPooler\n",
"\n",
"from kymata.datasets.sample import KymataMirror2023Q3Dataset\n",
"from kymata.entities.expression import HexelExpressionSet\n",
"from kymata.ippm.builder import IPPMBuilder\n",
"from kymata.ippm.data_tools import IPPMHexel, stem_plot, build_hexel_dict_from_expression_set, convert_to_power10, \\\n",
" remove_excess_funcs, plot_k_dist_1D, plot_denoised_vs_noisy\n",
"from kymata.ippm.denoiser import DenoisingStrategy, MaxPooler\n",
"from kymata.ippm.plotter import IPPMPlotter\n",
"\n",
"\n",
"class AdaptiveMaxPooler(DenoisingStrategy):\n",
" def cluster(self, hexels: Dict[str, IPPMHexel], hemi: str, normalise: bool = False) -> Dict[str, IPPMHexel]:\n",
" hexels = deepcopy(hexels)\n",
Expand Down Expand Up @@ -480,7 +482,7 @@
}
],
"source": [
"from kymata.ippm.denoiser import MaxPooler\n",
"\n",
"\n",
"clusterer = DBSCANv2(eps=5, min_samples=2)\n",
"denoised_hexels = clusterer.cluster(hexels, 'leftHemisphere')\n",
Expand Down
4 changes: 2 additions & 2 deletions kymata/plot/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
from pandas import DataFrame
from seaborn import color_palette

from kymata.entities.expression import HexelExpressionSet, ExpressionSet, SensorExpressionSet, DIM_SENSOR, DIM_FUNCTION, \
from ..entities.expression import HexelExpressionSet, ExpressionSet, SensorExpressionSet, DIM_SENSOR, DIM_FUNCTION, \
p_to_logp
from kymata.plot.layouts import get_meg_sensor_xy, eeg_sensors
from .layouts import get_meg_sensor_xy, eeg_sensors

# log scale: 10 ** -this will be the ytick interval and also the resolution to which the ylims will be rounded
_MAJOR_TICK_SIZE = 50
Expand Down
4 changes: 2 additions & 2 deletions kymata/preproc/data_cleansing.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
from pathlib import Path
from matplotlib import pyplot as plt

from kymata.io.cli import print_with_color, input_with_color
from kymata.io.yaml import load_config, modify_param_config
from ..io.cli import print_with_color, input_with_color
from ..io.yaml import load_config, modify_param_config


def run_first_pass_cleansing_and_maxwell_filtering(list_of_participants: list[str],
Expand Down
2 changes: 1 addition & 1 deletion submit_gridsearch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ conda activate mne_venv
args=(5) # 2 3 4 5 6 7 8 9 10)
ARG=${args[$SLURM_ARRAY_TASK_ID - 1]}

python invokers/run_gridsearch.py
python -m invokers.run_gridsearch
# --snr $ARG # >> result3.txt

conda deactivate
Loading