From 9b496a6a983a34b64edca5fd99443002fb904b56 Mon Sep 17 00:00:00 2001
From: polarbean <harry.carey95@gmail.com>
Date: Mon, 17 Mar 2025 20:48:33 +0100
Subject: [PATCH] remove unused functions
---
PyNutil/io/read_and_write.py | 73 -------------------------
PyNutil/processing/counting_and_load.py | 42 --------------
PyNutil/processing/data_analysis.py | 2 -
3 files changed, 117 deletions(-)
diff --git a/PyNutil/io/read_and_write.py b/PyNutil/io/read_and_write.py
index c4c5e22..133fc58 100644
--- a/PyNutil/io/read_and_write.py
+++ b/PyNutil/io/read_and_write.py
@@ -208,79 +208,6 @@ def write_points_to_meshview(points, point_names, filename, info_file):
write_points(region_dict, filename, info_file)
-# I think this might not need to be its own function :)
-def save_dataframe_as_csv(df_to_save, output_csv):
- """Function for saving a df as a CSV file"""
- df_to_save.to_csv(output_csv, sep=";", na_rep="", index=False)
-
-
-def flat_to_array(file, labelfile):
- """Read flat file, write into an np array, assign label file values, return array"""
- if file.endswith(".flat"):
- with open(file, "rb") as f:
- # I don't know what b is, w and h are the width and height that we get from the
- # flat file header
- b, w, h = struct.unpack(">BII", f.read(9))
- # Data is a one dimensional list of values
- # It has the shape width times height
- data = struct.unpack(">" + ("xBH"[b] * (w * h)), f.read(b * w * h))
- elif file.endswith(".seg"):
- with open(file, "rb") as f:
-
- def byte():
- return f.read(1)[0]
-
- def code():
- c = byte()
- if c < 0:
- raise "!"
- return c if c < 128 else (c & 127) | (code() << 7)
-
- if "SegRLEv1" != f.read(8).decode():
- raise "Header mismatch"
- atlas = f.read(code()).decode()
- codes = [code() for x in range(code())]
- w = code()
- h = code()
- data = []
- while len(data) < w * h:
- data += [codes[byte() if len(codes) <= 256 else code()]] * (code() + 1)
-
- # convert flat file data into an array, previously data was a tuple
- imagedata = np.array(data)
-
- # create an empty image array in the right shape, write imagedata into image_array
- image = np.zeros((h, w))
- for x in range(w):
- for y in range(h):
- image[y, x] = imagedata[x + y * w]
-
- image_arr = np.array(image)
- # return image_arr
-
- """assign label file values into image array"""
- labelfile = pd.read_csv(labelfile)
- allen_id_image = np.zeros((h, w)) # create an empty image array
- coordsy, coordsx = np.meshgrid(list(range(w)), list(range(h)))
- values = image_arr[
- coordsx, coordsy
- ] # assign x,y coords from image_array into values
- lbidx = labelfile["idx"].values
- allen_id_image = lbidx[values.astype(int)]
- return allen_id_image
-
-
-def files_in_directory(directory):
- """return list of flat file names in a directory"""
- list_of_files = []
- for file in os.scandir(directory):
- if file.path.endswith(".flat") and file.is_file:
- filename = os.path.basename(file)
- newfilename, file_ext = os.path.splitext(filename)
- list_of_files.append(newfilename)
- return list_of_files
-
-
def read_atlas_volume(atlas_volume_path):
"""return data from atlas volume"""
data, header = nrrd.read(atlas_volume_path)
diff --git a/PyNutil/processing/counting_and_load.py b/PyNutil/processing/counting_and_load.py
index 0b549e6..f86af43 100644
--- a/PyNutil/processing/counting_and_load.py
+++ b/PyNutil/processing/counting_and_load.py
@@ -6,48 +6,6 @@ from .generate_target_slice import generate_target_slice
from .visualign_deformations import transform_vec
-# related to counting and load
-def label_points(points, label_volume, scale_factor=1):
- """
- Assigns points to regions based on the label_volume.
-
- Args:
- points (list): List of points.
- label_volume (ndarray): Volume with region labels.
- scale_factor (int, optional): Scaling factor for points. Defaults to 1.
-
- Returns:
- ndarray: Labels for each point.
- """
- # First convert the points to 3 columns
- points = np.reshape(points, (-1, 3))
- # Scale the points
- points = points * scale_factor
- # Round the points to the nearest whole number
- points = np.round(points).astype(int)
- x = points[:, 0]
- y = points[:, 1]
- z = points[:, 2]
-
- # make sure the points are within the volume
- x[x < 0] = 0
- y[y < 0] = 0
- z[z < 0] = 0
- mask = (
- (x > label_volume.shape[0] - 1)
- | (y > label_volume.shape[1] - 1)
- | (z > label_volume.shape[2] - 1)
- )
- x[mask] = 0
- y[mask] = 0
- z[mask] = 0
-
- # Get the label value for each point
- labels = label_volume[x, y, z]
-
- return labels
-
-
# related to counting_and_load
def pixel_count_per_region(
labels_dict_points,
diff --git a/PyNutil/processing/data_analysis.py b/PyNutil/processing/data_analysis.py
index dc7816a..d2cfccc 100644
--- a/PyNutil/processing/data_analysis.py
+++ b/PyNutil/processing/data_analysis.py
@@ -111,8 +111,6 @@ def quantify_labeled_points(
Returns:
tuple: Labeled points, labeled centroids, label DataFrame, per section DataFrame.
"""
- # labeled_points_centroids = label_points(centroids, atlas_volume)
- # labeled_points = label_points(pixel_points, atlas_volume, scale_factor=1)
per_section_df = _quantify_per_section(
labeled_points,
--
GitLab