From d45bfa375ba13baa4b5fb9f106b52ebc01e3d51e Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 1 Sep 2023 19:33:43 +0000 Subject: [PATCH] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/probeinterface/generator.py | 22 ++++++----- src/probeinterface/io.py | 22 ++++++++--- src/probeinterface/library.py | 6 +-- src/probeinterface/probe.py | 66 ++++++++++++++++++--------------- src/probeinterface/utils.py | 4 +- src/probeinterface/wiring.py | 4 +- 6 files changed, 72 insertions(+), 52 deletions(-) diff --git a/src/probeinterface/generator.py b/src/probeinterface/generator.py index f690b1d..cd3f8e6 100644 --- a/src/probeinterface/generator.py +++ b/src/probeinterface/generator.py @@ -10,7 +10,7 @@ from .utils import combine_probes -def generate_dummy_probe(elec_shapes:str ="circle"): +def generate_dummy_probe(elec_shapes: str = "circle"): """ Generate a dummy probe with 3 columns and 32 contacts. Mainly used for testing and examples. @@ -72,7 +72,7 @@ def generate_dummy_probe_group(): return probegroup -def generate_tetrode(r:float=10): +def generate_tetrode(r: float = 10): """ Generate a tetrode Probe. Parameters @@ -92,13 +92,13 @@ def generate_tetrode(r:float=10): def generate_multi_columns_probe( - num_columns:int=3, - num_contact_per_column:int =10, - xpitch:float=20, - ypitch:float=20, + num_columns: int = 3, + num_contact_per_column: int = 10, + xpitch: float = 20, + ypitch: float = 20, y_shift_per_column=None, - contact_shapes:str="circle", - contact_shape_params:dict={"radius": 6}, + contact_shapes: str = "circle", + contact_shape_params: dict = {"radius": 6}, ): """Generate a Probe with several columns. @@ -150,7 +150,9 @@ def generate_multi_columns_probe( return probe -def generate_linear_probe(num_elec: int =16, ypitch:float=20, contact_shapes:str="circle", contact_shape_params:dict={"radius": 6}): +def generate_linear_probe( + num_elec: int = 16, ypitch: float = 20, contact_shapes: str = "circle", contact_shape_params: dict = {"radius": 6} +): """Generate a one-column linear probe. Parameters @@ -184,7 +186,7 @@ def generate_linear_probe(num_elec: int =16, ypitch:float=20, contact_shapes:str return probe -def generate_multi_shank(num_shank:int=2, shank_pitch:list=[150, 0], **kargs): +def generate_multi_shank(num_shank: int = 2, shank_pitch: list = [150, 0], **kargs): """Generate a multi-shank probe. Internally, calls generate_multi_columns_probe and combine_probes. diff --git a/src/probeinterface/io.py b/src/probeinterface/io.py index f60dca4..5499af9 100644 --- a/src/probeinterface/io.py +++ b/src/probeinterface/io.py @@ -32,7 +32,7 @@ def _probeinterface_format_check_version(d): pass -def read_probeinterface(file:Union[str, Path])-> ProbeGroup: +def read_probeinterface(file: Union[str, Path]) -> ProbeGroup: """ Read probeinterface JSON-based format. @@ -175,7 +175,10 @@ def read_BIDS_probe(folder: Union[str, Path], prefix: Optional[str] = None) -> P if "contact_shapes" not in df_probe: df_probe["contact_shapes"] = "circle" df_probe["radius"] = 1 - print(f"There is no contact shape provided for probe {probe_id}, a " f"dummy circle with 1um radius will be used.") + print( + f"There is no contact shape provided for probe {probe_id}, a " + f"dummy circle with 1um radius will be used." + ) if "x" not in df_probe: df_probe["x"] = np.arange(len(df_probe.index), dtype=float) @@ -186,7 +189,8 @@ def read_BIDS_probe(folder: Union[str, Path], prefix: Optional[str] = None) -> P if "y" not in df_probe: df_probe["y"] = 0.0 print( - f"There is no y coordinate provided for probe {probe_id}, a " f"dummy constant y coordinate will be used." + f"There is no y coordinate provided for probe {probe_id}, a " + f"dummy constant y coordinate will be used." ) if "si_units" not in df_probe: @@ -290,7 +294,7 @@ def read_BIDS_probe(folder: Union[str, Path], prefix: Optional[str] = None) -> P return probegroup -def write_BIDS_probe(folder: Union[str, Path], probe_or_probegroup: Union[Probe, ProbeGroup], prefix:str=""): +def write_BIDS_probe(folder: Union[str, Path], probe_or_probegroup: Union[Probe, ProbeGroup], prefix: str = ""): """ Write to probe and contact formats as proposed for ephy BIDS extension (tsv & json based). @@ -577,7 +581,13 @@ def read_3brain(file: Union[str, Path], mea_pitch: float = 42, electrode_width: return probe -def write_prb(file:str, probegroup:ProbeGroup, total_nb_channels:Optional[int]=None, radius:Optional[float]=None, group_mode:str="by_probe"): +def write_prb( + file: str, + probegroup: ProbeGroup, + total_nb_channels: Optional[int] = None, + radius: Optional[float] = None, + group_mode: str = "by_probe", +): """ Write ProbeGroup into a prb file. @@ -656,7 +666,7 @@ def write_prb(file:str, probegroup:ProbeGroup, total_nb_channels:Optional[int]=N f.write("}\n") -def read_csv(file:Union[str, Path]): +def read_csv(file: Union[str, Path]): """ Return a 2 or 3 columns csv file with contact positions """ diff --git a/src/probeinterface/library.py b/src/probeinterface/library.py index 20c0b15..07fc791 100644 --- a/src/probeinterface/library.py +++ b/src/probeinterface/library.py @@ -25,7 +25,7 @@ cache_folder = Path(os.path.expanduser("~")) / ".config" / "probeinterface" / "library" -def download_probeinterface_file(manufacturer:str, probe_name:str): +def download_probeinterface_file(manufacturer: str, probe_name: str): """Download the probeinterface file to the cache directory. Note that the file is itself a ProbeGroup but on the repo each file represents one probe. @@ -45,7 +45,7 @@ def download_probeinterface_file(manufacturer:str, probe_name:str): f.write(dist.read()) -def get_from_cache(manufacturer:str, probe_name:str)-> Optional["Probe"]: +def get_from_cache(manufacturer: str, probe_name: str) -> Optional["Probe"]: """ Get Probe from local cache @@ -72,7 +72,7 @@ def get_from_cache(manufacturer:str, probe_name:str)-> Optional["Probe"]: return probe -def get_probe(manufacturer:str, probe_name:str)-> "Probe": +def get_probe(manufacturer: str, probe_name: str) -> "Probe": """ Get probe from ProbeInterface library diff --git a/src/probeinterface/probe.py b/src/probeinterface/probe.py index ff11258..a32f1d7 100644 --- a/src/probeinterface/probe.py +++ b/src/probeinterface/probe.py @@ -16,7 +16,7 @@ class Probe: """ - def __init__(self, ndim:int=2, si_units:int="um"): + def __init__(self, ndim: int = 2, si_units: int = "um"): """ Some attributes are protected and have to be set with setters: * set_contacts(...) @@ -91,7 +91,7 @@ def contact_ids(self): def shank_ids(self): return self._shank_ids - def get_title(self)->str: + def get_title(self) -> str: if self.contact_positions is None: txt = "Undefined probe" else: @@ -132,14 +132,14 @@ def check_annotations(self): if "first_index" in d: assert d["first_index"] in (0, 1) - def get_contact_count(self)->int: + def get_contact_count(self) -> int: """ Return the number of contacts on the probe. """ assert self.contact_positions is not None return len(self.contact_positions) - def get_shank_count(self)->int: + def get_shank_count(self) -> int: """ Return the number of shanks for this probe. """ @@ -212,7 +212,7 @@ def set_contacts(self, positions, shapes="circle", shape_params={"radius": 10}, shape_params = [shape_params] * n self._contact_shape_params = np.array(shape_params) - def set_planar_contour(self, contour_polygon:list): + def set_planar_contour(self, contour_polygon: list): """Set the planar countour (the shape) of the probe. Parameters @@ -225,7 +225,7 @@ def set_planar_contour(self, contour_polygon:list): raise ValueError("contour_polygon.shape[1] and ndim do not match!") self.probe_planar_contour = contour_polygon - def create_auto_shape(self, probe_type:str="tip", margin:float=20.0): + def create_auto_shape(self, probe_type: str = "tip", margin: float = 20.0): """Create planar contour automatically based on probe contact positions. Parameters @@ -280,7 +280,7 @@ def create_auto_shape(self, probe_type:str="tip", margin:float=20.0): self.set_planar_contour(polygon) - def set_device_channel_indices(self, channel_indices:Sequence[int]): + def set_device_channel_indices(self, channel_indices: Sequence[int]): """ Manually set the device channel indices. @@ -298,7 +298,7 @@ def set_device_channel_indices(self, channel_indices:Sequence[int]): if self._probe_group is not None: self._probe_group.check_global_device_wiring_and_ids() - def wiring_to_device(self, pathway:str, channel_offset:int=0): + def wiring_to_device(self, pathway: str, channel_offset: int = 0): """ Automatically set device_channel_indices based on a pathway. @@ -315,7 +315,7 @@ def wiring_to_device(self, pathway:str, channel_offset:int=0): wire_probe(self, pathway, channel_offset=channel_offset) - def set_contact_ids(self, contact_ids:Sequence[Union[int, float, str]]): + def set_contact_ids(self, contact_ids: Sequence[Union[int, float, str]]): """ Set contact ids. Channel ids are converted to strings. Contact ids must be **unique** for the **Probe** @@ -339,7 +339,7 @@ def set_contact_ids(self, contact_ids:Sequence[Union[int, float, str]]): if self._probe_group is not None: self._probe_group.check_global_device_wiring_and_ids() - def set_shank_ids(self, shank_ids:Sequence[Union[int, float, str]]): + def set_shank_ids(self, shank_ids: Sequence[Union[int, float, str]]): """ Set shank ids. @@ -385,7 +385,7 @@ def copy(self): # channel_indices are not copied return other - def to_3d(self, axes:str="xz"): + def to_3d(self, axes: str = "xz"): """ Transform 2d probe to 3d probe. @@ -422,7 +422,7 @@ def to_3d(self, axes:str="xz"): return probe3d - def to_2d(self, axes:str="xy"): + def to_2d(self, axes: str = "xy"): """ Transform 3d probe to 2d probe. @@ -453,7 +453,7 @@ def to_2d(self, axes:str="xy"): return probe2d - def get_contact_vertices(self)->list: + def get_contact_vertices(self) -> list: """ Return a list of contact vertices. """ @@ -493,7 +493,7 @@ def get_contact_vertices(self)->list: vertices.append(one_vertice) return vertices - def move(self, translation_vector:Sequence[int]): + def move(self, translation_vector: Sequence[int]): """ Translate the probe in one direction. @@ -511,7 +511,7 @@ def move(self, translation_vector:Sequence[int]): if self.probe_planar_contour is not None: self.probe_planar_contour += translation_vector - def rotate(self, theta:float, center=None, axis=None): + def rotate(self, theta: float, center=None, axis=None): """ Rotate the probe around a specified axis. @@ -559,7 +559,7 @@ def rotate(self, theta:float, center=None, axis=None): new_vertices = (self.probe_planar_contour - center) @ R + center self.probe_planar_contour = new_vertices - def rotate_contacts(self, thetas:Union[float, Sequence[float]]): + def rotate_contacts(self, thetas: Union[float, Sequence[float]]): """ Rotate each contact of the probe. Internally, it modifies the contact_plane_axes. @@ -602,7 +602,7 @@ def rotate_contacts(self, thetas:Union[float, Sequence[float]]): "_shank_ids", ] - def to_dict(self, array_as_list:bool=False)->dict: + def to_dict(self, array_as_list: bool = False) -> dict: """Create a dictionary of all necessary attributes. Useful for dumping and saving to json. @@ -633,7 +633,7 @@ def to_dict(self, array_as_list:bool=False)->dict: return d @staticmethod - def from_dict(d:dict): + def from_dict(d: dict): """Instantiate a Probe from a dictionary Parameters @@ -678,7 +678,7 @@ def from_dict(d:dict): return probe - def to_numpy(self, complete:bool=False)->np.array: + def to_numpy(self, complete: bool = False) -> np.array: """ Export to a numpy vector (structured array). This vector handles all contact attributes. @@ -759,7 +759,7 @@ def to_numpy(self, complete:bool=False)->np.array: return arr @staticmethod - def from_numpy(arr:np.ndarray): + def from_numpy(arr: np.ndarray): """ Create Probe from a complex numpy array see Probe.to_numpy() @@ -830,7 +830,7 @@ def from_numpy(arr:np.ndarray): return probe - def to_dataframe(self, complete:bool=False)-> "pandas.DataFrame": + def to_dataframe(self, complete: bool = False) -> "pandas.DataFrame": """ Export the probe to a pandas dataframe @@ -854,7 +854,7 @@ def to_dataframe(self, complete:bool=False)-> "pandas.DataFrame": return df @staticmethod - def from_dataframe(df:"pandas.DataFrame"): + def from_dataframe(df: "pandas.DataFrame"): """ Create Probe from a pandas.DataFrame see Probe.to_dataframe() @@ -872,7 +872,15 @@ def from_dataframe(df:"pandas.DataFrame"): arr = df.to_records(index=False) return Probe.from_numpy(arr) - def to_image(self, values:Sequence, pixel_size:float=0.5, num_pixel:Optional[int]=None, method:str="linear", xlims:Optional[tuple]=None, ylims:Optional[tuple]=None)-> tuple[np.ndarray, tuple, tuple]: + def to_image( + self, + values: Sequence, + pixel_size: float = 0.5, + num_pixel: Optional[int] = None, + method: str = "linear", + xlims: Optional[tuple] = None, + ylims: Optional[tuple] = None, + ) -> tuple[np.ndarray, tuple, tuple]: """ Generated a 2d (image) from a values vector with an interpolation into a grid mesh. @@ -935,7 +943,7 @@ def to_image(self, values:Sequence, pixel_size:float=0.5, num_pixel:Optional[int return image, xlims, ylims - def get_slice(self, selection:np.ndarray[Union[bool, int]]): + def get_slice(self, selection: np.ndarray[Union[bool, int]]): """ Get a copy of the Probe with a sub selection of contacts. @@ -985,7 +993,7 @@ def get_slice(self, selection:np.ndarray[Union[bool, int]]): return sliced_probe -def _2d_to_3d(data2d:np.ndarray, axes:str)-> np.ndarray: +def _2d_to_3d(data2d: np.ndarray, axes: str) -> np.ndarray: """ Add a third dimension @@ -1007,7 +1015,7 @@ def _2d_to_3d(data2d:np.ndarray, axes:str)-> np.ndarray: return data3d -def select_axes(data:np.ndarray, axes:str="xy")->np.ndarray: +def select_axes(data: np.ndarray, axes: str = "xy") -> np.ndarray: """ Select axes in a 3d or 2d array. @@ -1028,7 +1036,7 @@ def select_axes(data:np.ndarray, axes:str="xy")->np.ndarray: return data[:, dims] -def _3d_to_2d(data3d:np.ndarray, axes:str="xy")-> np.ndarray: +def _3d_to_2d(data3d: np.ndarray, axes: str = "xy") -> np.ndarray: """ Reduce 3d array to 2d array on given axes. @@ -1049,7 +1057,7 @@ def _3d_to_2d(data3d:np.ndarray, axes:str="xy")-> np.ndarray: return select_axes(data3d, axes=axes) -def _rotation_matrix_2d(theta:float)->np.ndarray: +def _rotation_matrix_2d(theta: float) -> np.ndarray: """ Returns 2D rotation matrix @@ -1067,7 +1075,7 @@ def _rotation_matrix_2d(theta:float)->np.ndarray: return R -def _rotation_matrix_3d(axis:Sequence, theta:float)->np.ndarray: +def _rotation_matrix_3d(axis: Sequence, theta: float) -> np.ndarray: """ Returns 3D rotation matrix diff --git a/src/probeinterface/utils.py b/src/probeinterface/utils.py index d484580..69e23d9 100644 --- a/src/probeinterface/utils.py +++ b/src/probeinterface/utils.py @@ -47,7 +47,7 @@ def import_safely(module: str) -> ModuleType: return module_obj -def combine_probes(probes:Probe, connect_shape:bool=True): +def combine_probes(probes: Probe, connect_shape: bool = True): """ Combine several Probe objects into a unique multi-shank Probe object. @@ -102,7 +102,7 @@ def combine_probes(probes:Probe, connect_shape:bool=True): return multi_shank -def generate_unique_ids(min:int, max:int, n:int, trials:int=20)-> np.array: +def generate_unique_ids(min: int, max: int, n: int, trials: int = 20) -> np.array: """ Create n unique identifiers. Creates `n` unique integer identifiers between `min` and `max` within a diff --git a/src/probeinterface/wiring.py b/src/probeinterface/wiring.py index 105c8dc..d35df7c 100644 --- a/src/probeinterface/wiring.py +++ b/src/probeinterface/wiring.py @@ -50,7 +50,7 @@ # fmt: on -def get_available_pathways()->list: +def get_available_pathways() -> list: """Return available pathways Returns @@ -61,7 +61,7 @@ def get_available_pathways()->list: return list(pathways.keys()) -def wire_probe(probe:"Probe", pathway:str, channel_offset:int=0): +def wire_probe(probe: "Probe", pathway: str, channel_offset: int = 0): """Inplace wiring for a Probe using a pathway Parameters