antspymm 1.4.4__py3-none-any.whl → 1.4.6__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
antspymm/__init__.py CHANGED
@@ -131,5 +131,6 @@ from .mm import mm_match_by_qc_scoring_all
131
131
  from .mm import fix_LR_RL_stuff
132
132
  from .mm import segment_timeseries_by_bvalue
133
133
  from .mm import shorten_pymm_names
134
+ from .mm import pet3d_summary
134
135
 
135
136
 
antspymm/mm.py CHANGED
@@ -114,6 +114,7 @@ import re
114
114
  import datetime as dt
115
115
  from collections import Counter
116
116
  import tempfile
117
+ import uuid
117
118
  import warnings
118
119
 
119
120
  from dipy.core.histeq import histeq
@@ -287,6 +288,12 @@ def get_antsimage_keys(dictionary):
287
288
  """
288
289
  return [key for key, value in dictionary.items() if isinstance(value, ants.core.ants_image.ANTsImage)]
289
290
 
291
+ def to_nibabel(img: "ants.core.ants_image.ANTsImage"):
292
+ with tempfile.TemporaryDirectory() as tmp:
293
+ temp_file_name = os.path.join(tmp, str(uuid.uuid1()) + '.nii.gz')
294
+ ants.image_write(img, temp_file_name)
295
+ nibabel_image = nib.load(temp_file_name)
296
+ return(nibabel_image)
290
297
 
291
298
  def dict_to_dataframe(data_dict, convert_lists=True, convert_arrays=True, convert_images=True, verbose=False):
292
299
  """
@@ -447,6 +454,8 @@ def docsamson(locmod, studycsv, outputdir, projid, sid, dtid, mysep, t1iid=None,
447
454
  imfns=['flairid']
448
455
  elif locmod == 'perf':
449
456
  imfns=['perfid']
457
+ elif locmod == 'pet3d':
458
+ imfns=['pet3did']
450
459
  elif locmod == 'NM2DMT':
451
460
  imfns=[]
452
461
  for i in range(11):
@@ -459,6 +468,8 @@ def docsamson(locmod, studycsv, outputdir, projid, sid, dtid, mysep, t1iid=None,
459
468
  imfns=[]
460
469
  for i in range(4):
461
470
  imfns.append('dtid' + str(i))
471
+ else:
472
+ raise ValueError("docsamson: no match of modality to filename id " + locmod )
462
473
 
463
474
  # Process each file name
464
475
  for i in imfns:
@@ -504,11 +515,11 @@ def get_valid_modalities( long=False, asString=False, qc=False ):
504
515
  asString - concat list to string
505
516
  """
506
517
  if long:
507
- mymod = ["T1w", "NM2DMT", "rsfMRI", "rsfMRI_LR", "rsfMRI_RL", "rsfMRILR", "rsfMRIRL", "DTI", "DTI_LR","DTI_RL", "DTILR","DTIRL","T2Flair", "dwi", "dwi_ap", "dwi_pa", "func", "func_ap", "func_pa", "perf"]
518
+ mymod = ["T1w", "NM2DMT", "rsfMRI", "rsfMRI_LR", "rsfMRI_RL", "rsfMRILR", "rsfMRIRL", "DTI", "DTI_LR","DTI_RL", "DTILR","DTIRL","T2Flair", "dwi", "dwi_ap", "dwi_pa", "func", "func_ap", "func_pa", "perf", 'pet3d']
508
519
  elif qc:
509
- mymod = [ 'T1w', 'T2Flair', 'NM2DMT', 'DTI', 'DTIdwi','DTIb0', 'rsfMRI', "perf" ]
520
+ mymod = [ 'T1w', 'T2Flair', 'NM2DMT', 'DTI', 'DTIdwi','DTIb0', 'rsfMRI', "perf", 'pet3d' ]
510
521
  else:
511
- mymod = ["T1w", "NM2DMT", "DTI","T2Flair", "rsfMRI", "perf" ]
522
+ mymod = ["T1w", "NM2DMT", "DTI","T2Flair", "rsfMRI", "perf", 'pet3d' ]
512
523
  if not asString:
513
524
  return mymod
514
525
  else:
@@ -531,7 +542,8 @@ def generate_mm_dataframe(
531
542
  rsf_filenames=[],
532
543
  dti_filenames=[],
533
544
  nm_filenames=[],
534
- perf_filename=[]
545
+ perf_filename=[],
546
+ pet3d_filename=[],
535
547
  ):
536
548
  """
537
549
  Generate a DataFrame for medical imaging data with extensive validation of input parameters.
@@ -555,6 +567,7 @@ def generate_mm_dataframe(
555
567
  - dti_filenames (list): List of filenames for DTI images.
556
568
  - nm_filenames (list): List of filenames for NM images.
557
569
  - perf_filename (list): List of filenames for perfusion images.
570
+ - pet3d_filename (list): List of filenames for pet3d images.
558
571
 
559
572
  Returns:
560
573
  - pandas.DataFrame: A DataFrame containing the validated imaging study information.
@@ -617,6 +630,16 @@ def generate_mm_dataframe(
617
630
  perf_filename=perf_filename[0]
618
631
  if perf_filename is not None and not "perf" in perf_filename:
619
632
  raise ValueError("perf_filename is not perf filename " + perf_filename)
633
+
634
+ if pet3d_filename is not None:
635
+ if isinstance(pet3d_filename,list):
636
+ if (len(pet3d_filename) == 0):
637
+ pet3d_filename=None
638
+ else:
639
+ print("Take first entry from pet3d_filename list")
640
+ pet3d_filename=pet3d_filename[0]
641
+ if pet3d_filename is not None and not "pet" in pet3d_filename:
642
+ raise ValueError("pet3d_filename is not pet filename " + pet3d_filename)
620
643
 
621
644
  for k in nm_filenames:
622
645
  if k is not None:
@@ -633,7 +656,7 @@ def generate_mm_dataframe(
633
656
  if perf_filename is not None:
634
657
  if not "perf" in perf_filename:
635
658
  raise ValueError("perf_filename is not a valid perfusion (perf) filename " + k)
636
- allfns = [t1_filename] + [flair_filename] + nm_filenames + dti_filenames + rsf_filenames + [perf_filename]
659
+ allfns = [t1_filename] + [flair_filename] + nm_filenames + dti_filenames + rsf_filenames + [perf_filename] + [pet3d_filename]
637
660
  for k in allfns:
638
661
  if k is not None:
639
662
  if not isinstance(k, str):
@@ -650,7 +673,8 @@ def generate_mm_dataframe(
650
673
  output_image_directory,
651
674
  t1_filename,
652
675
  flair_filename,
653
- perf_filename]
676
+ perf_filename,
677
+ pet3d_filename]
654
678
  mydata0 = coredata + rsf_filenames + dti_filenames
655
679
  mydata = mydata0 + nm_filenames
656
680
  corecols = [
@@ -663,16 +687,21 @@ def generate_mm_dataframe(
663
687
  'outputdir',
664
688
  'filename',
665
689
  'flairid',
666
- 'perfid']
690
+ 'perfid',
691
+ 'pet3did']
667
692
  mycols0 = corecols + [
668
693
  'rsfid1', 'rsfid2',
669
694
  'dtid1', 'dtid2','dtid3']
670
695
  nmext = [
671
- 'nmid1', 'nmid2' 'nmid3', 'nmid4', 'nmid5',
672
- 'nmid6', 'nmid7','nmid8', 'nmid9', 'nmid10', 'nmid11'
696
+ 'nmid1', 'nmid2', 'nmid3', 'nmid4', 'nmid5',
697
+ 'nmid6', 'nmid7','nmid8', 'nmid9', 'nmid10' #, 'nmid11'
673
698
  ]
674
699
  mycols = mycols0 + nmext
675
700
  if not check_pd_construction( [mydata], mycols ) :
701
+ # print( mydata )
702
+ # print( len(mydata ))
703
+ # print( mycols )
704
+ # print( len(mycols ))
676
705
  raise ValueError( "Error in generate_mm_dataframe: len( mycols ) != len( mydata ) which indicates a bad input parameter to this function." )
677
706
  studycsv = pd.DataFrame([ mydata ], columns=mycols)
678
707
  return studycsv
@@ -4170,8 +4199,10 @@ def dwi_deterministic_tracking(
4170
4199
  from dipy.tracking.utils import path_length
4171
4200
  if verbose:
4172
4201
  print("begin tracking",flush=True)
4173
- dwi_img = dwi.to_nibabel()
4202
+
4203
+ dwi_img = to_nibabel(dwi)
4174
4204
  affine = dwi_img.affine
4205
+
4175
4206
  if isinstance( bvals, str ) or isinstance( bvecs, str ):
4176
4207
  bvals, bvecs = read_bvals_bvecs(bvals, bvecs)
4177
4208
  bvecs = repair_bvecs( bvecs )
@@ -4348,7 +4379,8 @@ def dwi_closest_peak_tracking(
4348
4379
 
4349
4380
  if verbose:
4350
4381
  print("begin tracking",flush=True)
4351
- dwi_img = dwi.to_nibabel()
4382
+
4383
+ dwi_img = to_nibabel(dwi)
4352
4384
  affine = dwi_img.affine
4353
4385
  if isinstance( bvals, str ) or isinstance( bvecs, str ):
4354
4386
  bvals, bvecs = read_bvals_bvecs(bvals, bvecs)
@@ -4428,7 +4460,10 @@ def dwi_streamline_pairwise_connectivity( streamlines, label_image, labels_to_co
4428
4460
  """
4429
4461
  from dipy.tracking.streamline import Streamlines
4430
4462
  keep_streamlines = Streamlines()
4431
- affine = label_image.to_nibabel().affine
4463
+
4464
+
4465
+ affine = to_nibabel(label_image).affine
4466
+
4432
4467
  lin_T, offset = utils._mapping_to_voxel(affine)
4433
4468
  label_image_np = label_image.numpy()
4434
4469
  def check_it( sl, target_label, label_image, index, full=False ):
@@ -4486,7 +4521,9 @@ def dwi_streamline_pairwise_connectivity_old(
4486
4521
  from dipy.tracking.streamline import Streamlines
4487
4522
  volUnit = np.prod( ants.get_spacing( label_image ) )
4488
4523
  labels = label_image.numpy()
4489
- affine = label_image.to_nibabel().affine
4524
+
4525
+ affine = to_nibabel(label_image).affine
4526
+
4490
4527
  import numpy as np
4491
4528
  from dipy.io.image import load_nifti_data, load_nifti, save_nifti
4492
4529
  import pandas as pd
@@ -4576,7 +4613,9 @@ def dwi_streamline_connectivity(
4576
4613
  from dipy.tracking.streamline import Streamlines
4577
4614
  volUnit = np.prod( ants.get_spacing( label_image ) )
4578
4615
  labels = label_image.numpy()
4579
- affine = label_image.to_nibabel().affine
4616
+
4617
+ affine = to_nibabel(label_image).affine
4618
+
4580
4619
  import numpy as np
4581
4620
  from dipy.io.image import load_nifti_data, load_nifti, save_nifti
4582
4621
  import pandas as pd
@@ -4664,7 +4703,8 @@ def dwi_streamline_connectivity_old(
4664
4703
 
4665
4704
  volUnit = np.prod( ants.get_spacing( label_image ) )
4666
4705
  labels = label_image.numpy()
4667
- affine = label_image.to_nibabel().affine
4706
+
4707
+ affine = to_nibabel(label_image).affine
4668
4708
 
4669
4709
  if verbose:
4670
4710
  print("path length begin ... volUnit = " + str( volUnit ) )
@@ -5315,6 +5355,7 @@ def PerAF( x, mask, globalmean=True ):
5315
5355
  return outimg
5316
5356
 
5317
5357
 
5358
+
5318
5359
  def resting_state_fmri_networks( fmri, fmri_template, t1, t1segmentation,
5319
5360
  f=[0.03, 0.08],
5320
5361
  FD_threshold=5.0,
@@ -6249,8 +6290,6 @@ def bold_perfusion( fmri, t1head, t1, t1segmentation, t1dktcit,
6249
6290
  ---------
6250
6291
  fmri : BOLD fmri antsImage
6251
6292
 
6252
- fmri_template : reference space for BOLD
6253
-
6254
6293
  t1head : ANTsImage
6255
6294
  input 3-D T1 brain image (not brain extracted)
6256
6295
 
@@ -6635,6 +6674,115 @@ Where:
6635
6674
  return convert_np_in_dict( outdict )
6636
6675
 
6637
6676
 
6677
+ def pet3d_summary( pet3d, t1head, t1, t1segmentation, t1dktcit,
6678
+ spa = (0., 0., 0.),
6679
+ type_of_transform='Rigid',
6680
+ upsample=True,
6681
+ verbose=False ):
6682
+ """
6683
+ Estimate perfusion from a BOLD time series image. Will attempt to figure out the T-C labels from the data. The function uses defaults to quantify CBF but these will usually not be correct for your own data. See the function calculate_CBF for an example of how one might do quantification based on the outputs of this function specifically the perfusion, m0 and mask images that are part of the output dictionary.
6684
+
6685
+ Arguments
6686
+ ---------
6687
+ pet3d : 3D PET antsImage
6688
+
6689
+ t1head : ANTsImage
6690
+ input 3-D T1 brain image (not brain extracted)
6691
+
6692
+ t1 : ANTsImage
6693
+ input 3-D T1 brain image (brain extracted)
6694
+
6695
+ t1segmentation : ANTsImage
6696
+ t1 segmentation - a six tissue segmentation image in T1 space
6697
+
6698
+ t1dktcit : ANTsImage
6699
+ t1 dkt cortex plus cit parcellation
6700
+
6701
+ type_of_transform : SyN or Rigid
6702
+
6703
+ upsample: boolean
6704
+
6705
+ verbose : boolean
6706
+
6707
+ Returns
6708
+ ---------
6709
+ a dictionary containing the derived network maps
6710
+
6711
+ """
6712
+ import numpy as np
6713
+ import pandas as pd
6714
+ import re
6715
+ import math
6716
+
6717
+ ex_path = os.path.expanduser( "~/.antspyt1w/" )
6718
+ cnxcsvfn = ex_path + "dkt_cortex_cit_deep_brain.csv"
6719
+
6720
+ pet3dr=pet3d
6721
+ if upsample:
6722
+ spc = ants.get_spacing( pet3d )
6723
+ minspc = 1.0
6724
+ if min(spc) < minspc:
6725
+ minspc = min(spc)
6726
+ newspc = [minspc,minspc,minspc]
6727
+ pet3dr = ants.resample_image( pet3d, newspc, interp_type=0 )
6728
+
6729
+ rig = ants.registration( pet3dr, t1head, 'BOLDRigid' )
6730
+ bmask = ants.apply_transforms( pet3dr,
6731
+ ants.threshold_image(t1segmentation,1,6),
6732
+ rig['fwdtransforms'][0],
6733
+ interpolator='genericLabel' )
6734
+ if verbose:
6735
+ print("End t1=>pet registration")
6736
+
6737
+ und = pet3dr * bmask
6738
+ # t1reg = ants.registration( und, t1, "antsRegistrationSyNQuickRepro[s]" )
6739
+ t1reg = rig # ants.registration( und, t1, "Rigid" )
6740
+ gmseg = ants.threshold_image( t1segmentation, 2, 2 )
6741
+ gmseg = gmseg + ants.threshold_image( t1segmentation, 4, 4 )
6742
+ gmseg = ants.threshold_image( gmseg, 1, 4 )
6743
+ gmseg = ants.iMath( gmseg, 'MD', 1 )
6744
+ gmseg = ants.apply_transforms( und, gmseg,
6745
+ t1reg['fwdtransforms'], interpolator = 'genericLabel' ) * bmask
6746
+ csfseg = ants.threshold_image( t1segmentation, 1, 1 )
6747
+ wmseg = ants.threshold_image( t1segmentation, 3, 3 )
6748
+ csfAndWM = ( csfseg + wmseg ).morphology("erode",1)
6749
+ csfAndWM = ants.apply_transforms( und, csfAndWM,
6750
+ t1reg['fwdtransforms'], interpolator = 'nearestNeighbor' ) * bmask
6751
+ csfseg = ants.apply_transforms( und, csfseg,
6752
+ t1reg['fwdtransforms'], interpolator = 'nearestNeighbor' ) * bmask
6753
+ wmseg = ants.apply_transforms( und, wmseg,
6754
+ t1reg['fwdtransforms'], interpolator = 'nearestNeighbor' ) * bmask
6755
+ wmsignal = pet3dr[ ants.iMath(wmseg,"ME",1) == 1 ].mean()
6756
+ gmsignal = pet3dr[ gmseg == 1 ].mean()
6757
+ csfsignal = pet3dr[ csfseg == 1 ].mean()
6758
+ if verbose:
6759
+ print("pet3dr.max() " + str( pet3dr.max() ) )
6760
+ if verbose:
6761
+ print("pet3d dataframe begin")
6762
+ dktseg = ants.apply_transforms( und, t1dktcit,
6763
+ t1reg['fwdtransforms'], interpolator = 'genericLabel' ) * bmask
6764
+ df_pet3d = antspyt1w.map_intensity_to_dataframe(
6765
+ 'dkt_cortex_cit_deep_brain',
6766
+ und,
6767
+ dktseg)
6768
+ df_pet3d = antspyt1w.merge_hierarchical_csvs_to_wide_format(
6769
+ {'pet3d' : df_pet3d},
6770
+ col_names = ['Mean'] )
6771
+ if verbose:
6772
+ print("pet3d dataframe end")
6773
+
6774
+ outdict = {}
6775
+ outdict['pet3d_dataframe']=df_pet3d
6776
+ outdict['pet3d'] = pet3dr
6777
+ outdict['brainmask'] = bmask
6778
+ outdict['gm_mean']=gmsignal
6779
+ outdict['wm_mean']=wmsignal
6780
+ outdict['csf_mean']=csfsignal
6781
+ outdict['pet3d_dataframe']=df_pet3d
6782
+ outdict['t1reg'] = t1reg
6783
+ return convert_np_in_dict( outdict )
6784
+
6785
+
6638
6786
  def write_bvals_bvecs(bvals, bvecs, prefix ):
6639
6787
  ''' Write FSL FDT bvals and bvecs files
6640
6788
 
@@ -6719,6 +6867,7 @@ def mm(
6719
6867
  perfusion_m0_image=None,
6720
6868
  perfusion_m0=None,
6721
6869
  rsf_upsampling=3.0,
6870
+ pet_3d_image=None,
6722
6871
  test_run = False,
6723
6872
  verbose = False ):
6724
6873
  """
@@ -6778,6 +6927,9 @@ def mm(
6778
6927
 
6779
6928
  rsf_upsampling : optional upsampling parameter value in mm; if set to zero, no upsampling is done
6780
6929
 
6930
+ pet_3d_image : optional antsImage for a 3D pet; we make no assumptions about the contents of
6931
+ this image. we just process it and provide summary information.
6932
+
6781
6933
  test_run : boolean
6782
6934
 
6783
6935
  verbose : boolean
@@ -6825,6 +6977,7 @@ def mm(
6825
6977
  'tractography' : None,
6826
6978
  'tractography_connectivity' : None,
6827
6979
  'perf' : None,
6980
+ 'pet3d' : None,
6828
6981
  }
6829
6982
  normalization_dict = {
6830
6983
  'kk_norm': None,
@@ -6843,7 +6996,8 @@ def mm(
6843
6996
  'FrontoparietalTaskControl_norm' : None,
6844
6997
  'Salience_norm' : None,
6845
6998
  'Subcortical_norm' : None,
6846
- 'DorsalAttention_norm' : None
6999
+ 'DorsalAttention_norm' : None,
7000
+ 'pet3d_norm' : None
6847
7001
  }
6848
7002
  if test_run:
6849
7003
  return output_dict, normalization_dict
@@ -6853,7 +7007,7 @@ def mm(
6853
7007
  print('kk')
6854
7008
  output_dict['kk'] = antspyt1w.kelly_kapowski_thickness( hier['brain_n4_dnz'],
6855
7009
  labels=hier['dkt_parc']['dkt_cortex'], iterations=45 )
6856
- if perfusion_image is not None:
7010
+ if perfusion_image is not None:
6857
7011
  if perfusion_image.shape[3] > 1: # FIXME - better heuristic?
6858
7012
  output_dict['perf'] = bold_perfusion(
6859
7013
  perfusion_image,
@@ -6865,6 +7019,16 @@ def mm(
6865
7019
  m0_image = perfusion_m0_image,
6866
7020
  m0_indices = perfusion_m0,
6867
7021
  verbose=verbose )
7022
+
7023
+ if pet_3d_image is not None:
7024
+ if pet_3d_image.dimension == 3: # FIXME - better heuristic?
7025
+ output_dict['pet3d'] = pet3d_summary(
7026
+ pet_3d_image,
7027
+ t1_image,
7028
+ hier['brain_n4_dnz'],
7029
+ t1atropos,
7030
+ hier['dkt_parc']['dkt_cortex'] + hier['cit168lab'],
7031
+ verbose=verbose )
6868
7032
  ################################## do the rsf .....
6869
7033
  if len(rsf_image) > 0:
6870
7034
  my_motion_tx = 'Rigid'
@@ -7058,7 +7222,7 @@ def mm(
7058
7222
  if verbose:
7059
7223
  print("We have only one DTI: " + str(len(dw_image)))
7060
7224
  dw_image = dw_image[0]
7061
- btpB0,btpDW=get_average_dwi_b0(dw_image)
7225
+ btpB0, btpDW = get_average_dwi_b0(dw_image)
7062
7226
  initrig = ants.registration( btpDW, hier['brain_n4_dnz'], 'BOLDRigid' )['fwdtransforms'][0]
7063
7227
  tempreg = ants.registration( btpDW, hier['brain_n4_dnz'], 'SyNOnly',
7064
7228
  syn_metric='mattes', syn_sampling=32,
@@ -7218,6 +7382,16 @@ def mm(
7218
7382
  normalization_dict['cbf_norm'] = ants.apply_transforms( group_template,
7219
7383
  output_dict['perf']['cbf'], comptx,
7220
7384
  whichtoinvert=[False,False,True,False] )
7385
+ if output_dict['pet3d'] is not None: # zizzer
7386
+ secondTx=output_dict['pet3d']['t1reg']['invtransforms']
7387
+ comptx = group_transform + secondTx
7388
+ if len( secondTx ) == 2:
7389
+ wti=[False,False,True,False]
7390
+ else:
7391
+ wti=[False,False,True]
7392
+ normalization_dict['pet3d_norm'] = ants.apply_transforms( group_template,
7393
+ output_dict['pet3d']['pet3d'], comptx,
7394
+ whichtoinvert=wti )
7221
7395
  if nm_image_list is not None:
7222
7396
  nmpro = output_dict['NM']
7223
7397
  nmrig = nmpro['t1_to_NM_transform'] # this is an inverse tx
@@ -7407,6 +7581,23 @@ def write_mm( output_prefix, mm, mm_norm=None, t1wide=None, separator='_', verbo
7407
7581
  tempfn = output_prefix + separator + mykey + '.nii.gz'
7408
7582
  image_write_with_thumbnail( mm['perf'][mykey], tempfn, thumb=False )
7409
7583
 
7584
+ if 'pet3d' in mm:
7585
+ if mm['pet3d'] is not None:
7586
+ pet3dpro = mm['pet3d']
7587
+ prwide = dict_to_dataframe( pet3dpro )
7588
+ if mm_wide.shape[0] > 0 and prwide.shape[0] > 0:
7589
+ prwide.set_index( mm_wide.index, inplace=True )
7590
+ mm_wide = pd.concat( [mm_wide, prwide ], axis=1, ignore_index=False )
7591
+ if 'pet3d_dataframe' in pet3dpro.keys():
7592
+ pderk = pet3dpro['pet3d_dataframe'].iloc[: , 1:]
7593
+ pderk.set_index( mm_wide.index, inplace=True )
7594
+ mm_wide = pd.concat( [ mm_wide, pderk ], axis=1, ignore_index=False )
7595
+ else:
7596
+ print("FIXME - pet3dusion dataframe")
7597
+ for mykey in get_antsimage_keys( mm['pet3d'] ):
7598
+ tempfn = output_prefix + separator + mykey + '.nii.gz'
7599
+ image_write_with_thumbnail( mm['pet3d'][mykey], tempfn, thumb=False )
7600
+
7410
7601
  mmwidefn = output_prefix + separator + 'mmwide.csv'
7411
7602
  mm_wide.to_csv( mmwidefn )
7412
7603
  if verbose:
@@ -7941,7 +8132,8 @@ def mm_csv(
7941
8132
  perfusion_trim = 10,
7942
8133
  perfusion_m0_image = None,
7943
8134
  perfusion_m0 = None,
7944
- rsf_upsampling = 3.0
8135
+ rsf_upsampling = 3.0,
8136
+ pet3d = None,
7945
8137
  ):
7946
8138
  """
7947
8139
  too dangerous to document ... use with care.
@@ -8022,6 +8214,8 @@ def mm_csv(
8022
8214
 
8023
8215
  rsf_upsampling : optional upsampling parameter value in mm; if set to zero, no upsampling is done
8024
8216
 
8217
+ pet3d : optional antsImage for PET (or other 3d scalar) data which we want to summarize
8218
+
8025
8219
  Returns
8026
8220
  ---------
8027
8221
 
@@ -8131,10 +8325,13 @@ def mm_csv(
8131
8325
  t1wide.to_csv( hierfn + 'mmwide.csv' )
8132
8326
  ################# read the hierarchical data ###############################
8133
8327
  # over-write the rbp data with a consistent and recent approach ############
8134
- myx = antspyt1w.inspect_raw_t1( t1, hierfn + 'rbp' , option='both' )
8135
- myx['brain'].to_csv( hierfn + 'rbp.csv', index=False )
8136
- myx['brain'].to_csv( hierfn + 'rbpbrain.csv', index=False )
8137
- del myx
8328
+ redograding = True
8329
+ if redograding:
8330
+ myx = antspyt1w.inspect_raw_t1( t1, hierfn + 'rbp' , option='both' )
8331
+ myx['brain'].to_csv( hierfn + 'rbp.csv', index=False )
8332
+ myx['brain'].to_csv( hierfn + 'rbpbrain.csv', index=False )
8333
+ del myx
8334
+
8138
8335
  hier = antspyt1w.read_hierarchical( hierfn )
8139
8336
  t1wide = antspyt1w.merge_hierarchical_csvs_to_wide_format(
8140
8337
  hier['dataframes'], identifier=None )
@@ -8311,11 +8508,11 @@ def mm_csv(
8311
8508
  ants.plot( nmpro['NM_avg_cropped'], nmpro['t1_to_NM'], axis=2, slices=mysl, overlay_alpha=0.3, title='nm crop + t1', filename=mymm+mysep+"NMavgcropt1.png" )
8312
8509
  ants.plot( nmpro['NM_avg_cropped'], nmpro['NM_labels'], axis=2, slices=mysl, title='nm crop + labels', filename=mymm+mysep+"NMavgcroplabels.png" )
8313
8510
  else :
8314
- if len( myimgsr ) > 0:
8511
+ if len( myimgsr ) > 0 :
8315
8512
  dowrite=False
8316
8513
  myimgcount=0
8317
8514
  if len( myimgsr ) > 0 :
8318
- myimg = myimgsr[myimgcount]
8515
+ myimg = myimgsr[ myimgcount ]
8319
8516
  subjectpropath = os.path.dirname( mydoc['outprefix'] )
8320
8517
  if verbose:
8321
8518
  print("subjectpropath is")
@@ -8323,19 +8520,19 @@ def mm_csv(
8323
8520
  os.makedirs( subjectpropath, exist_ok=True )
8324
8521
  mymmout = makewideout( mymm )
8325
8522
  if verbose and not exists( mymmout ):
8326
- print("Modality specific processing: " + mymod + " execution " )
8523
+ print( "Modality specific processing: " + mymod + " execution " )
8327
8524
  print( mymm )
8328
8525
  elif verbose and exists( mymmout ) :
8329
8526
  print("Modality specific processing: " + mymod + " complete " )
8330
8527
  if exists( mymmout ) :
8331
8528
  continue
8332
8529
  if verbose:
8333
- print(subjectpropath)
8530
+ print( subjectpropath )
8334
8531
  print( myimg )
8335
8532
  if not testloop:
8336
8533
  img = mm_read( myimg )
8337
8534
  ishapelen = len( img.shape )
8338
- if mymod == 'T1w' and ishapelen == 3: # for a real run, set to True
8535
+ if mymod == 'T1w' and ishapelen == 3:
8339
8536
  if not exists( mymm + mysep + "kk_norm.nii.gz" ):
8340
8537
  dowrite=True
8341
8538
  if verbose:
@@ -8468,6 +8665,32 @@ def mm_csv(
8468
8665
  axis=2, nslices=maxslice, ncol=7, crop=True, title='CBF image', filename=mymm+mysep+"cbf.png" )
8469
8666
  ants.plot( tabPro['perf']['m0'],
8470
8667
  axis=2, nslices=maxslice, ncol=7, crop=True, title='M0 image', filename=mymm+mysep+"m0.png" )
8668
+
8669
+ if ( mymod == 'pet3d' ) and ishapelen == 3:
8670
+ dowrite=True
8671
+ try:
8672
+ tabPro, normPro = mm( t1, hier,
8673
+ srmodel=None,
8674
+ do_tractography=False,
8675
+ do_kk=False,
8676
+ do_normalization=templateTx,
8677
+ group_template = normalization_template,
8678
+ group_transform = groupTx,
8679
+ test_run=test_run,
8680
+ pet_3d_image=img,
8681
+ verbose=True )
8682
+ except Exception as e:
8683
+ error_info = traceback.format_exc()
8684
+ print(error_info)
8685
+ visualize=False
8686
+ dowrite=False
8687
+ tabPro={'pet3d':None}
8688
+ print(f"antspymmerror occurred while processing {overmodX}: {e}")
8689
+ pass
8690
+ if tabPro['pet3d'] is not None and visualize:
8691
+ maxslice = np.min( [21, tabPro['pet3d']['pet3d'].shape[2] ] )
8692
+ ants.plot( tabPro['pet3d']['pet3d'],
8693
+ axis=2, nslices=maxslice, ncol=7, crop=True, title='PET image', filename=mymm+mysep+"pet3d.png" )
8471
8694
  if ( mymod == 'DTI_LR' or mymod == 'DTI_RL' or mymod == 'DTI' ) and ishapelen == 4:
8472
8695
  bvalfn = re.sub( '.nii.gz', '.bval' , myimg )
8473
8696
  bvecfn = re.sub( '.nii.gz', '.bvec' , myimg )
@@ -10962,6 +11185,7 @@ def brainmap_figure(statistical_df, data_dictionary, output_prefix, brain_image,
10962
11185
  anatsear=re.sub("post.limb.of.internal.capsule","post.int.cap",anatsear)
10963
11186
  anatsear=re.sub("ant.limb.of.internal.capsule","ant.int.cap",anatsear)
10964
11187
  anatsear=re.sub("sagittal.stratum.include.inferior.longitidinal.fasciculus.and.inferior.fronto.occipital.fasciculus","ilf.and.ifo",anatsear)
11188
+ anatsear=re.sub("post.thalamic.radiation.optic.rad","post.thalamic.radiation",anatsear)
10965
11189
  atlassearch = mydict['tidynames'].str.contains(anatsear)
10966
11190
  if atlassearch.sum() == 0:
10967
11191
  atlassearch = mydict2['tidynames'].str.contains(anatsear)
@@ -10993,6 +11217,7 @@ def brainmap_figure(statistical_df, data_dictionary, output_prefix, brain_image,
10993
11217
  elif 'cerebellum' in anattoshow[k]:
10994
11218
  myext = 'cerebellum'
10995
11219
  oglabelname=re.sub('cerebellum', '',anatsear)
11220
+ oglabelname=re.sub('t1.vo','',oglabelname)
10996
11221
  # oglabelname=oglabelname[2:]
10997
11222
  elif 'brainstem' in anattoshow[k] or is_bst_region(anatsear):
10998
11223
  myext = 'brainstem'
@@ -11463,6 +11688,7 @@ def aggregate_antspymm_results_sdf(
11463
11688
  vmoddict['imageID'] = 'T1w'
11464
11689
  vmoddict['flairid'] = 'T2Flair'
11465
11690
  vmoddict['perfid'] = 'perf'
11691
+ vmoddict['pet3did'] = 'pet3d'
11466
11692
  vmoddict['rsfid1'] = 'rsfMRI'
11467
11693
  # vmoddict['rsfid2'] = 'rsfMRI'
11468
11694
  vmoddict['dtid1'] = 'DTI'
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.4
2
2
  Name: antspymm
3
- Version: 1.4.4
3
+ Version: 1.4.6
4
4
  Summary: multi-channel/time-series medical image processing with antspyx
5
5
  Author-email: "Avants, Gosselin, Tustison, Reardon" <stnava@gmail.com>
6
6
  License: Apache 2.0
@@ -19,6 +19,7 @@ Requires-Dist: nibabel
19
19
  Requires-Dist: scipy
20
20
  Requires-Dist: siq
21
21
  Requires-Dist: scikit-learn
22
+ Dynamic: license-file
22
23
 
23
24
  # ANTsPyMM
24
25
 
@@ -0,0 +1,7 @@
1
+ antspymm/__init__.py,sha256=ZdNJyHwS6rzq59v0OK3tE3qSTD0za2iULzSLGkM_0uc,4527
2
+ antspymm/mm.py,sha256=XXEbuqcFKR-f9zaFfQG53qzGMbm2hGzw7ai_Z6jPcx4,513312
3
+ antspymm-1.4.6.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
4
+ antspymm-1.4.6.dist-info/METADATA,sha256=Edy68PT2PRJsLt55BIlx49m_1n_4bJI9NpKGxIVk4r8,25690
5
+ antspymm-1.4.6.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
6
+ antspymm-1.4.6.dist-info/top_level.txt,sha256=iyD1sRhCKzfwKRJLq5ZUeV9xsv1cGQl8Ejp6QwXM1Zg,9
7
+ antspymm-1.4.6.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (75.6.0)
2
+ Generator: setuptools (78.1.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
@@ -1,7 +0,0 @@
1
- antspymm/__init__.py,sha256=qUzRd3GmYB8hSO7GNaBuP7Jlm0QNMttTaUfvIpeeAig,4497
2
- antspymm/mm.py,sha256=2X6zZaERE8tPbzkcyNGD8vIZcpA1T3ej24_jGOnESRA,504283
3
- antspymm-1.4.4.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
4
- antspymm-1.4.4.dist-info/METADATA,sha256=hZlu52Pd7QVbYX3meAwe_I3rguqa27BK_xHt9VelKU8,25668
5
- antspymm-1.4.4.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
6
- antspymm-1.4.4.dist-info/top_level.txt,sha256=iyD1sRhCKzfwKRJLq5ZUeV9xsv1cGQl8Ejp6QwXM1Zg,9
7
- antspymm-1.4.4.dist-info/RECORD,,