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

Fixing lint errors #177

Merged
merged 5 commits into from
Feb 20, 2024
Merged
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
2 changes: 0 additions & 2 deletions invokers/invoker_estimate_noise_cov_matrix.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
from pathlib import Path
from colorama import Fore

from kymata.io.yaml import load_config
from kymata.io.cli import print_with_color
from kymata.preproc.data_cleansing import estimate_noise_cov


Expand Down
2 changes: 1 addition & 1 deletion invokers/invoker_run_hexel_current_estimation.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from kymata.io.yaml import load_config
from kymata.io.cli import print_with_color
from kymata.preproc.hexel_current_estimation import create_current_estimation_prerequisites, create_forward_model_and_inverse_solution, create_hexel_morph_maps
from kymata.preproc.hexel_current_estimation import create_forward_model_and_inverse_solution, create_hexel_morph_maps


# noinspection DuplicatedCode
Expand Down
7 changes: 3 additions & 4 deletions invokers/run_gridsearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from kymata.io.functions import load_function
from kymata.preproc.source import load_emeg_pack
from kymata.io.nkg import save_expression_set
from kymata.io.yaml import load_config
from kymata.plot.plot import expression_plot

_default_output_dir = Path(data_root_path(), "output")
Expand Down Expand Up @@ -64,7 +63,7 @@ def main():
args = parser.parse_args()

# TODO: use config for ppt lists etc
config = load_config(str(Path(Path(__file__).parent.parent, "kymata", "config", "dataset4.yaml")))
#config = load_config(str(Path(Path(__file__).parent.parent, "kymata", "config", "dataset4.yaml")))

participants = [
'pilot_01',
Expand Down Expand Up @@ -98,8 +97,8 @@ def main():

if (len(emeg_filenames) > 1) and (not args.morph) and (args.ave_mode == "ave") and (args.inverse_operator_dir is not None):
raise ValueError(
f"Averaging source-space results without morphing to a common space. "
f"If you are averaging over multiple participants you must morph to a common space.")
"Averaging source-space results without morphing to a common space. " +
"If you are averaging over multiple participants you must morph to a common space.")

# Load data
emeg_path = Path(args.base_dir, args.emeg_dir)
Expand Down
2 changes: 1 addition & 1 deletion kymata/datasets/sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def delete_dataset(local_dataset: SampleDataset):
# Make sure it's not silent
print(f"Deleting dataset {local_dataset.name}")
# Only allow deletion if the specified url is within the data dir
assert data_root_path() in local_dataset.path.parents, f"Cannot delete dataset outside of data root directory"
assert data_root_path() in local_dataset.path.parents, "Cannot delete dataset outside of data root directory"
if not local_dataset.path.exists():
# Nothing to delete
print(f"{str(local_dataset.path)} doesn't exist")
Expand Down
4 changes: 3 additions & 1 deletion kymata/gridsearch/plain.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ def do_gridsearch(
n_samples_per_split = int(seconds_per_split * emeg_sample_rate * 2 // downsample_rate)

if ave_mode == 'add':
n_reps = len(EMEG_paths)
# TODO: hard-code hack, fix as part of https://github.com/kymata-atlas/kymata-toolbox/issues/128
#n_reps = len(EMEG_paths)
n_reps = 1
else:
n_reps = 1

Expand Down
2 changes: 0 additions & 2 deletions kymata/io/functions.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
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
Expand All @@ -26,7 +25,6 @@ def load_function(function_path_without_suffix: path_type, func_name: str, n_der
n_chans = func.shape[0]
new_mr_arr = np.zeros((n_chans, 400_000))
new_ft_arr = np.zeros((n_chans, 400_000))
T_end = tt[0, -1]
if func_name == 'neurogram_mr':
for i in range(n_chans):
new_mr_arr[i] = np.interp(np.linspace(0, 400, 400_000 + 1)[:-1], tt[0], func[i])
Expand Down
2 changes: 1 addition & 1 deletion kymata/io/nkg.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ def _load_data_current(from_path_or_file: path_type | file_type) -> dict[str, An
with TextIOWrapper(zf.open("_metadata/expression-set-type.txt"), encoding="utf-8") as f:
return_dict[_Keys.expressionset_type] = str(f.read()).strip()
with TextIOWrapper(zf.open("/blocks.txt"), encoding="utf-8") as f:
blocks = [str(l.strip()) for l in f.readlines()]
blocks = [str(line.strip()) for line in f.readlines()]
with TextIOWrapper(zf.open("/latencies.txt"), encoding="utf-8") as f:
return_dict[_Keys.latencies] = [LatencyDType(lat.strip()) for lat in f.readlines()]
with TextIOWrapper(zf.open("/functions.txt"), encoding="utf-8") as f:
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 @@ -37,7 +37,7 @@ def _load_data_0_3(from_path_or_file: path_type | file_type) -> dict[str, Any]:
with TextIOWrapper(zf.open("_metadata/expression-set-type.txt"), encoding="utf-8") as f:
return_dict["expressionset-type"] = str(f.read()).strip()
with TextIOWrapper(zf.open("/layers.txt"), encoding="utf-8") as f:
layers = [str(l.strip()) for l in f.readlines()]
layers = [str(line.strip()) for line in f.readlines()]
with TextIOWrapper(zf.open("/channels.txt"), encoding="utf-8") as f:
return_dict["channels"] = [c.strip() for c in f.readlines()]
with TextIOWrapper(zf.open("/latencies.txt"), encoding="utf-8") as f:
Expand Down Expand Up @@ -76,7 +76,7 @@ def _load_data_0_2(from_path_or_file: path_type | file_type) -> dict[str, Any]:
with TextIOWrapper(zf.open("_metadata/expression-set-type.txt"), encoding="utf-8") as f:
return_dict["expressionset-type"] = str(f.read()).strip()
with TextIOWrapper(zf.open("/layers.txt"), encoding="utf-8") as f:
layers = [str(l.strip()) for l in f.readlines()]
layers = [str(line.strip()) for line in f.readlines()]
with TextIOWrapper(zf.open("/channels.txt"), encoding="utf-8") as f:
return_dict["channels"] = [c.strip() for c in f.readlines()]
with TextIOWrapper(zf.open("/latencies.txt"), encoding="utf-8") as f:
Expand Down
1 change: 1 addition & 0 deletions kymata/ippm/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

11 changes: 5 additions & 6 deletions kymata/ippm/data_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
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
Expand Down Expand Up @@ -102,7 +101,7 @@ def build_hexel_dict_from_expression_set(expression_set: HexelExpressionSet) ->
func = row[DIM_FUNCTION]
latency = row[DIM_LATENCY] * 1000 # convert to ms
pval = row["value"]
if not func in hexels:
if func not in hexels:
hexels[func] = IPPMHexel(func)
hexels[func].add_pairing(hemi, (latency, pval))
return hexels
Expand All @@ -127,7 +126,7 @@ def build_hexel_dict_from_api_response(dict_: Dict) -> Dict[str, IPPMHexel]:
for (_, latency, pval, func) in dict_[hemi]:
# we have id, latency (ms), pvalue (log_10), function name.
# discard id as it conveys no useful information
if not func in hexels:
if func not in hexels:
# first time seeing function, so create key and hexel object.
hexels[func] = IPPMHexel(func)

Expand Down Expand Up @@ -209,7 +208,7 @@ def stem_plot(
right_hem_expression_plot.invert_yaxis()
left_hem_expression_plot.text(-180, y_limit * 10000000, 'left hemisphere', style='italic', verticalalignment='center')
right_hem_expression_plot.text(-180, y_limit * 10000000, 'right hemisphere', style='italic', verticalalignment='center')
y_axis_label = f'p-value (with α at 5-sigma, Bonferroni corrected)'
y_axis_label = 'p-value (with α at 5-sigma, Bonferroni corrected)'
left_hem_expression_plot.text(-275, 1, y_axis_label, verticalalignment='center',rotation='vertical')
right_hem_expression_plot.text(0, 1, ' onset of environment ', color='white', fontsize='x-small', bbox={'facecolor': 'grey', 'edgecolor': 'none'}, verticalalignment='center', horizontalalignment='center', rotation='vertical')
left_hem_expression_plot.legend(handles=custom_handles, labels=custom_labels, fontsize='x-small', bbox_to_anchor=(1.2, 1))
Expand Down Expand Up @@ -265,7 +264,7 @@ def function_recall(hexels: Dict[str, IPPMHexel], funcs: List[str], ippm_dict: D
for func in funcs:
pairings = hexels[func].right_best_pairings if hemi == 'rightHemisphere' else hexels[func].left_best_pairings
for latency, spike in pairings:
if spike <= alpha:
if spike <= bonferroni_corrected_alpha:
funcs_present_in_data += 1

# Step 2: Found a function, look in ippm_dict.keys() for the function.
Expand All @@ -291,7 +290,7 @@ def convert_to_power10(hexels: Dict[str, IPPMHexel]) -> Dict[str, IPPMHexel]:
def remove_excess_funcs(to_retain: List[str], hexels: Dict[str, IPPMHexel]) -> Dict[str, IPPMHexel]:
funcs = list(hexels.keys())
for func in funcs:
if not func in to_retain:
if func not in to_retain:
# delete
hexels.pop(func)
return hexels
Expand Down
Loading
Loading