Skip to content

Commit

Permalink
Fix numpy deprecations
Browse files Browse the repository at this point in the history
  • Loading branch information
edeno committed Jul 1, 2023
1 parent 8d0c09b commit 916d556
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 17 deletions.
2 changes: 1 addition & 1 deletion loren_frank_data_processing/multiunit.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def get_multiunit_dataframe2(tetrode_key, animals):
time = pd.TimedeltaIndex(
multiunit_data["times"][0, 0].squeeze(), unit="s", name="time"
)
multiunit = multiunit_data["marks"][0, 0].astype(np.float)
multiunit = multiunit_data["marks"][0, 0].astype(float)
column_names = [
"channel_{number}_max".format(number=number + 1)
for number in np.arange(multiunit.shape[1])
Expand Down
2 changes: 1 addition & 1 deletion loren_frank_data_processing/neurons.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ def get_all_spike_indicators(neuron_keys, animals, time_function=get_trial_time)
)
)
except IndexError:
bin_counts.append(np.zeros_like(time, dtype=np.float64))
bin_counts.append(np.zeros_like(time, dtype=float))

return pd.DataFrame(np.stack(bin_counts, axis=1), columns=neuron_names, index=time)

Expand Down
14 changes: 8 additions & 6 deletions loren_frank_data_processing/position.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,6 @@ def _get_linpos_dataframe(
def calculate_linear_velocity(
linear_distance, smooth_duration=0.500, sampling_frequency=29
):

smoothed_linear_distance = gaussian_filter1d(
linear_distance, smooth_duration * sampling_frequency
)
Expand All @@ -184,7 +183,9 @@ def convert_linear_distance_to_linear_position(
linear_position = linear_distance.copy()
n_edges = len(edge_order)
if isinstance(spacing, int) | isinstance(spacing, float):
spacing = [spacing,] * (n_edges - 1)
spacing = [
spacing,
] * (n_edges - 1)

for prev_edge, cur_edge, space in zip(edge_order[:-1], edge_order[1:], spacing):
is_cur_edge = edge_id == cur_edge
Expand Down Expand Up @@ -256,7 +257,9 @@ def _calulcate_linear_position(

n_edges = len(edge_order)
if isinstance(edge_spacing, int) | isinstance(edge_spacing, float):
edge_spacing = [edge_spacing,] * (n_edges - 1)
edge_spacing = [
edge_spacing,
] * (n_edges - 1)

for start_linear_position, start_linear_distance, cur_edge in zip(
node_linear_position[:, 0], node_linear_distance[:, 0], edge_order
Expand Down Expand Up @@ -417,8 +420,7 @@ def get_interpolated_position_dataframe(


def get_well_locations(epoch_key, animals):
"""Retrieves the 2D coordinates for each well.
"""
"""Retrieves the 2D coordinates for each well."""
animal, day, epoch = epoch_key
task_file = get_data_structure(animals[animal], day, "task", "task")
linearcoord = task_file[epoch - 1]["linearcoord"][0, 0].squeeze(axis=0)
Expand Down Expand Up @@ -476,7 +478,7 @@ def make_track_graph(epoch_key, animals):
_, unique_ind = np.unique(nodes, return_index=True, axis=0)
nodes = nodes[np.sort(unique_ind)]

edges = np.zeros(track_segments.shape[:2], dtype=np.int)
edges = np.zeros(track_segments.shape[:2], dtype=int)
for node_id, node in enumerate(nodes):
edge_ind = np.nonzero(np.isin(track_segments, node).sum(axis=2) > 1)
edges[edge_ind] = node_id
Expand Down
13 changes: 4 additions & 9 deletions loren_frank_data_processing/track_segment_classification.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
import numpy as np
import scipy.stats

np.warnings.filterwarnings("ignore")


def get_track_segments_from_graph(track_graph):
"""
Expand Down Expand Up @@ -59,7 +57,7 @@ def project_points_to_segment(track_segments, position):
"""
segment_diff = np.diff(track_segments, axis=1).squeeze(axis=1)
sum_squares = np.sum(segment_diff ** 2, axis=1)
sum_squares = np.sum(segment_diff**2, axis=1)
node1 = track_segments[:, 0, :]
nx = (
np.sum(segment_diff * (position[:, np.newaxis, :] - node1), axis=2)
Expand All @@ -73,8 +71,7 @@ def project_points_to_segment(track_segments, position):


def find_projected_point_distance(track_segments, position):
"""
"""
""" """
return np.linalg.norm(
position[:, np.newaxis, :]
- project_points_to_segment(track_segments, position),
Expand Down Expand Up @@ -301,7 +298,7 @@ def viterbi(initial_conditions, state_transition, likelihood):

n_time, n_states = log_likelihood.shape
posterior = np.zeros((n_time, n_states))
max_state_ind = np.zeros((n_time, n_states), dtype=np.int)
max_state_ind = np.zeros((n_time, n_states), dtype=int)

# initialization
posterior[0] = np.log(initial_conditions) + log_likelihood[0]
Expand All @@ -316,7 +313,7 @@ def viterbi(initial_conditions, state_transition, likelihood):
)

# termination
most_probable_state_ind = np.zeros((n_time,), dtype=np.int)
most_probable_state_ind = np.zeros((n_time,), dtype=int)
most_probable_state_ind[n_time - 1] = np.argmax(posterior[n_time - 1])

# path back-tracking
Expand Down Expand Up @@ -383,12 +380,10 @@ def classify_track_segments(


def batch_linear_distance(track_graph, projected_track_positions, edge_ids, well_id):

copy_graph = track_graph.copy()
linear_distance = []

for (x3, y3), (node1, node2) in zip(projected_track_positions, edge_ids):

x1, y1 = copy_graph.nodes[node1]["pos"]
left_distance = sqrt((x3 - x1) ** 2 + (y3 - y1) ** 2)
nx.add_path(copy_graph, [node1, "projected"], distance=left_distance)
Expand Down

0 comments on commit 916d556

Please sign in to comment.