10000 FIX: NiBabel 5, and NetworkX 3 and DIPY 1.6 compatibility by effigies · Pull Request #3538 · nipy/nipype · GitHub
[go: up one dir, main page]

Skip to content

FIX: NiBabel 5, and NetworkX 3 and DIPY 1.6 compatibility #3538

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

Merged
merged 9 commits into from
Jan 29, 2023
Merged
Prev Previous commit
Next Next commit
FIX: Purge nx.read_gpickle
  • Loading branch information
effigies committed Jan 28, 2023
commit f20035c303a88fba3e207ac60388397665bb97be
9 changes: 8 additions & 1 deletion nipype/interfaces/cmtk/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@
from .base import CFFBaseInterface, have_cfflib


def _read_pickle(fname):
import pickle

with open(fname, 'rb') as f:
return pickle.load(f)


class CFFConverterInputSpec(BaseInterfaceInputSpec):
graphml_networks = InputMultiPath(
File(exists=True), desc="list of graphML networks"
Expand Down Expand Up @@ -135,7 +142,7 @@ def _run_interface(self, runtime):
unpickled = []
for ntwk in self.inputs.gpickled_networks:
_, ntwk_name, _ = split_filename(ntwk)
unpickled = nx.read_gpickle(ntwk)
unpickled = _read_pickle(ntwk)
cnet = cf.CNetwork(name=ntwk_name)
cnet.set_with_nxgraph(unpickled)
a.add_connectome_network(cnet)
Expand Down
11 changes: 8 additions & 3 deletions nipype/interfaces/cmtk/nbs.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,18 @@
iflogger = logging.getLogger("nipype.interface")


def _read_pickle(fname):
with open(fname, 'rb') as f:
return pickle.load(f)


def ntwks_to_matrices(in_files, edge_key):
first = nx.read_gpickle(in_files[0])
first = _read_pickle(in_files[0])
files = len(in_files)
nodes = len(first.nodes())
matrix = np.zeros((nodes, nodes, files))
for idx, name in enumerate(in_files):
graph = nx.read_gpickle(name)
graph = _read_pickle(name)
for u, v, d in graph.edges(data=True):
try:
graph[u][v]["weight"] = d[
Expand Down Expand Up @@ -162,7 +167,7 @@ def _run_interface(self, runtime):
else:
node_ntwk_name = self.inputs.in_group1[0]

node_network = nx.read_gpickle(node_ntwk_name)
node_network = _read_pickle(node_ntwk_name)
iflogger.info(
"Populating node dictionaries with attributes from %s", node_ntwk_name
)
Expand Down
11 changes: 8 additions & 3 deletions nipype/interfaces/cmtk/nx.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,16 @@
iflogger = logging.getLogger("nipype.interface")


def _read_pickle(fname):
with open(fname, 'rb') as f:
return pickle.load(f)


def read_unknown_ntwk(ntwk):
if not isinstance(ntwk, nx.classes.graph.Graph):
_, _, ext = split_filename(ntwk)
if ext == ".pck":
ntwk = nx.read_gpickle(ntwk)
ntwk = _read_pickle(ntwk)
elif ext == ".graphml":
ntwk = nx.read_graphml(ntwk)
return ntwk
Expand Down Expand Up @@ -121,7 +126,7 @@ def average_networks(in_files, ntwk_res_file, group_id):
counting_ntwk = ntwk.copy()
# Sums all the relevant variables
for index, subject in enumerate(in_files):
tmp = nx.read_gpickle(subject)
tmp = _read_pickle(subject)
iflogger.info("File %s has %i edges", subject, tmp.number_of_edges())
edges = list(tmp.edges())
for edge in edges:
Expand Down Expand Up @@ -461,7 +466,7 @@ def _run_interface(self, runtime):
edgentwks = list()
kntwks = list()
matlab = list()
ntwk = nx.read_gpickle(self.inputs.in_file)
ntwk = _read_pickle(self.inputs.in_file)

# Each block computes, writes, and saves a measure
# The names are then added to the output .pck file list
Expand Down
0