antspymm 1.4.3__py3-none-any.whl → 1.4.5__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 ) )
@@ -6249,8 +6289,6 @@ def bold_perfusion( fmri, t1head, t1, t1segmentation, t1dktcit,
6249
6289
  ---------
6250
6290
  fmri : BOLD fmri antsImage
6251
6291
 
6252
- fmri_template : reference space for BOLD
6253
-
6254
6292
  t1head : ANTsImage
6255
6293
  input 3-D T1 brain image (not brain extracted)
6256
6294
 
@@ -6635,6 +6673,115 @@ Where:
6635
6673
  return convert_np_in_dict( outdict )
6636
6674
 
6637
6675
 
6676
+ def pet3d_summary( pet3d, t1head, t1, t1segmentation, t1dktcit,
6677
+ spa = (0., 0., 0.),
6678
+ type_of_transform='Rigid',
6679
+ upsample=True,
6680
+ verbose=False ):
6681
+ """
6682
+ 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.
6683
+
6684
+ Arguments
6685
+ ---------
6686
+ pet3d : 3D PET antsImage
6687
+
6688
+ t1head : ANTsImage
6689
+ input 3-D T1 brain image (not brain extracted)
6690
+
6691
+ t1 : ANTsImage
6692
+ input 3-D T1 brain image (brain extracted)
6693
+
6694
+ t1segmentation : ANTsImage
6695
+ t1 segmentation - a six tissue segmentation image in T1 space
6696
+
6697
+ t1dktcit : ANTsImage
6698
+ t1 dkt cortex plus cit parcellation
6699
+
6700
+ type_of_transform : SyN or Rigid
6701
+
6702
+ upsample: boolean
6703
+
6704
+ verbose : boolean
6705
+
6706
+ Returns
6707
+ ---------
6708
+ a dictionary containing the derived network maps
6709
+
6710
+ """
6711
+ import numpy as np
6712
+ import pandas as pd
6713
+ import re
6714
+ import math
6715
+
6716
+ ex_path = os.path.expanduser( "~/.antspyt1w/" )
6717
+ cnxcsvfn = ex_path + "dkt_cortex_cit_deep_brain.csv"
6718
+
6719
+ pet3dr=pet3d
6720
+ if upsample:
6721
+ spc = ants.get_spacing( pet3d )
6722
+ minspc = 1.0
6723
+ if min(spc) < minspc:
6724
+ minspc = min(spc)
6725
+ newspc = [minspc,minspc,minspc]
6726
+ pet3dr = ants.resample_image( pet3d, newspc, interp_type=0 )
6727
+
6728
+ rig = ants.registration( pet3dr, t1head, 'BOLDRigid' )
6729
+ bmask = ants.apply_transforms( pet3dr,
6730
+ ants.threshold_image(t1segmentation,1,6),
6731
+ rig['fwdtransforms'][0],
6732
+ interpolator='genericLabel' )
6733
+ if verbose:
6734
+ print("End t1=>pet registration")
6735
+
6736
+ und = pet3dr * bmask
6737
+ # t1reg = ants.registration( und, t1, "antsRegistrationSyNQuickRepro[s]" )
6738
+ t1reg = rig # ants.registration( und, t1, "Rigid" )
6739
+ gmseg = ants.threshold_image( t1segmentation, 2, 2 )
6740
+ gmseg = gmseg + ants.threshold_image( t1segmentation, 4, 4 )
6741
+ gmseg = ants.threshold_image( gmseg, 1, 4 )
6742
+ gmseg = ants.iMath( gmseg, 'MD', 1 )
6743
+ gmseg = ants.apply_transforms( und, gmseg,
6744
+ t1reg['fwdtransforms'], interpolator = 'genericLabel' ) * bmask
6745
+ csfseg = ants.threshold_image( t1segmentation, 1, 1 )
6746
+ wmseg = ants.threshold_image( t1segmentation, 3, 3 )
6747
+ csfAndWM = ( csfseg + wmseg ).morphology("erode",1)
6748
+ csfAndWM = ants.apply_transforms( und, csfAndWM,
6749
+ t1reg['fwdtransforms'], interpolator = 'nearestNeighbor' ) * bmask
6750
+ csfseg = ants.apply_transforms( und, csfseg,
6751
+ t1reg['fwdtransforms'], interpolator = 'nearestNeighbor' ) * bmask
6752
+ wmseg = ants.apply_transforms( und, wmseg,
6753
+ t1reg['fwdtransforms'], interpolator = 'nearestNeighbor' ) * bmask
6754
+ wmsignal = pet3dr[ ants.iMath(wmseg,"ME",1) == 1 ].mean()
6755
+ gmsignal = pet3dr[ gmseg == 1 ].mean()
6756
+ csfsignal = pet3dr[ csfseg == 1 ].mean()
6757
+ if verbose:
6758
+ print("pet3dr.max() " + str( pet3dr.max() ) )
6759
+ if verbose:
6760
+ print("pet3d dataframe begin")
6761
+ dktseg = ants.apply_transforms( und, t1dktcit,
6762
+ t1reg['fwdtransforms'], interpolator = 'genericLabel' ) * bmask
6763
+ df_pet3d = antspyt1w.map_intensity_to_dataframe(
6764
+ 'dkt_cortex_cit_deep_brain',
6765
+ und,
6766
+ dktseg)
6767
+ df_pet3d = antspyt1w.merge_hierarchical_csvs_to_wide_format(
6768
+ {'pet3d' : df_pet3d},
6769
+ col_names = ['Mean'] )
6770
+ if verbose:
6771
+ print("pet3d dataframe end")
6772
+
6773
+ outdict = {}
6774
+ outdict['pet3d_dataframe']=df_pet3d
6775
+ outdict['pet3d'] = pet3dr
6776
+ outdict['brainmask'] = bmask
6777
+ outdict['gm_mean']=gmsignal
6778
+ outdict['wm_mean']=wmsignal
6779
+ outdict['csf_mean']=csfsignal
6780
+ outdict['pet3d_dataframe']=df_pet3d
6781
+ outdict['t1reg'] = t1reg
6782
+ return convert_np_in_dict( outdict )
6783
+
6784
+
6638
6785
  def write_bvals_bvecs(bvals, bvecs, prefix ):
6639
6786
  ''' Write FSL FDT bvals and bvecs files
6640
6787
 
@@ -6719,6 +6866,7 @@ def mm(
6719
6866
  perfusion_m0_image=None,
6720
6867
  perfusion_m0=None,
6721
6868
  rsf_upsampling=3.0,
6869
+ pet_3d_image=None,
6722
6870
  test_run = False,
6723
6871
  verbose = False ):
6724
6872
  """
@@ -6778,6 +6926,9 @@ def mm(
6778
6926
 
6779
6927
  rsf_upsampling : optional upsampling parameter value in mm; if set to zero, no upsampling is done
6780
6928
 
6929
+ pet_3d_image : optional antsImage for a 3D pet; we make no assumptions about the contents of
6930
+ this image. we just process it and provide summary information.
6931
+
6781
6932
  test_run : boolean
6782
6933
 
6783
6934
  verbose : boolean
@@ -6825,6 +6976,7 @@ def mm(
6825
6976
  'tractography' : None,
6826
6977
  'tractography_connectivity' : None,
6827
6978
  'perf' : None,
6979
+ 'pet3d' : None,
6828
6980
  }
6829
6981
  normalization_dict = {
6830
6982
  'kk_norm': None,
@@ -6843,7 +6995,8 @@ def mm(
6843
6995
  'FrontoparietalTaskControl_norm' : None,
6844
6996
  'Salience_norm' : None,
6845
6997
  'Subcortical_norm' : None,
6846
- 'DorsalAttention_norm' : None
6998
+ 'DorsalAttention_norm' : None,
6999
+ 'pet3d_norm' : None
6847
7000
  }
6848
7001
  if test_run:
6849
7002
  return output_dict, normalization_dict
@@ -6853,7 +7006,7 @@ def mm(
6853
7006
  print('kk')
6854
7007
  output_dict['kk'] = antspyt1w.kelly_kapowski_thickness( hier['brain_n4_dnz'],
6855
7008
  labels=hier['dkt_parc']['dkt_cortex'], iterations=45 )
6856
- if perfusion_image is not None:
7009
+ if perfusion_image is not None:
6857
7010
  if perfusion_image.shape[3] > 1: # FIXME - better heuristic?
6858
7011
  output_dict['perf'] = bold_perfusion(
6859
7012
  perfusion_image,
@@ -6865,6 +7018,16 @@ def mm(
6865
7018
  m0_image = perfusion_m0_image,
6866
7019
  m0_indices = perfusion_m0,
6867
7020
  verbose=verbose )
7021
+
7022
+ if pet_3d_image is not None:
7023
+ if pet_3d_image.dimension == 3: # FIXME - better heuristic?
7024
+ output_dict['pet3d'] = pet3d_summary(
7025
+ pet_3d_image,
7026
+ t1_image,
7027
+ hier['brain_n4_dnz'],
7028
+ t1atropos,
7029
+ hier['dkt_parc']['dkt_cortex'] + hier['cit168lab'],
7030
+ verbose=verbose )
6868
7031
  ################################## do the rsf .....
6869
7032
  if len(rsf_image) > 0:
6870
7033
  my_motion_tx = 'Rigid'
@@ -7058,7 +7221,7 @@ def mm(
7058
7221
  if verbose:
7059
7222
  print("We have only one DTI: " + str(len(dw_image)))
7060
7223
  dw_image = dw_image[0]
7061
- btpB0,btpDW=get_average_dwi_b0(dw_image)
7224
+ btpB0, btpDW = get_average_dwi_b0(dw_image)
7062
7225
  initrig = ants.registration( btpDW, hier['brain_n4_dnz'], 'BOLDRigid' )['fwdtransforms'][0]
7063
7226
  tempreg = ants.registration( btpDW, hier['brain_n4_dnz'], 'SyNOnly',
7064
7227
  syn_metric='mattes', syn_sampling=32,
@@ -7218,6 +7381,16 @@ def mm(
7218
7381
  normalization_dict['cbf_norm'] = ants.apply_transforms( group_template,
7219
7382
  output_dict['perf']['cbf'], comptx,
7220
7383
  whichtoinvert=[False,False,True,False] )
7384
+ if output_dict['pet3d'] is not None: # zizzer
7385
+ secondTx=output_dict['pet3d']['t1reg']['invtransforms']
7386
+ comptx = group_transform + secondTx
7387
+ if len( secondTx ) == 2:
7388
+ wti=[False,False,True,False]
7389
+ else:
7390
+ wti=[False,False,True]
7391
+ normalization_dict['pet3d_norm'] = ants.apply_transforms( group_template,
7392
+ output_dict['pet3d']['pet3d'], comptx,
7393
+ whichtoinvert=wti )
7221
7394
  if nm_image_list is not None:
7222
7395
  nmpro = output_dict['NM']
7223
7396
  nmrig = nmpro['t1_to_NM_transform'] # this is an inverse tx
@@ -7407,6 +7580,23 @@ def write_mm( output_prefix, mm, mm_norm=None, t1wide=None, separator='_', verbo
7407
7580
  tempfn = output_prefix + separator + mykey + '.nii.gz'
7408
7581
  image_write_with_thumbnail( mm['perf'][mykey], tempfn, thumb=False )
7409
7582
 
7583
+ if 'pet3d' in mm:
7584
+ if mm['pet3d'] is not None:
7585
+ pet3dpro = mm['pet3d']
7586
+ prwide = dict_to_dataframe( pet3dpro )
7587
+ if mm_wide.shape[0] > 0 and prwide.shape[0] > 0:
7588
+ prwide.set_index( mm_wide.index, inplace=True )
7589
+ mm_wide = pd.concat( [mm_wide, prwide ], axis=1, ignore_index=False )
7590
+ if 'pet3d_dataframe' in pet3dpro.keys():
7591
+ pderk = pet3dpro['pet3d_dataframe'].iloc[: , 1:]
7592
+ pderk.set_index( mm_wide.index, inplace=True )
7593
+ mm_wide = pd.concat( [ mm_wide, pderk ], axis=1, ignore_index=False )
7594
+ else:
7595
+ print("FIXME - pet3dusion dataframe")
7596
+ for mykey in get_antsimage_keys( mm['pet3d'] ):
7597
+ tempfn = output_prefix + separator + mykey + '.nii.gz'
7598
+ image_write_with_thumbnail( mm['pet3d'][mykey], tempfn, thumb=False )
7599
+
7410
7600
  mmwidefn = output_prefix + separator + 'mmwide.csv'
7411
7601
  mm_wide.to_csv( mmwidefn )
7412
7602
  if verbose:
@@ -7941,7 +8131,8 @@ def mm_csv(
7941
8131
  perfusion_trim = 10,
7942
8132
  perfusion_m0_image = None,
7943
8133
  perfusion_m0 = None,
7944
- rsf_upsampling = 3.0
8134
+ rsf_upsampling = 3.0,
8135
+ pet3d = None,
7945
8136
  ):
7946
8137
  """
7947
8138
  too dangerous to document ... use with care.
@@ -8022,6 +8213,8 @@ def mm_csv(
8022
8213
 
8023
8214
  rsf_upsampling : optional upsampling parameter value in mm; if set to zero, no upsampling is done
8024
8215
 
8216
+ pet3d : optional antsImage for PET (or other 3d scalar) data which we want to summarize
8217
+
8025
8218
  Returns
8026
8219
  ---------
8027
8220
 
@@ -8131,10 +8324,13 @@ def mm_csv(
8131
8324
  t1wide.to_csv( hierfn + 'mmwide.csv' )
8132
8325
  ################# read the hierarchical data ###############################
8133
8326
  # 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
8327
+ redograding = True
8328
+ if redograding:
8329
+ myx = antspyt1w.inspect_raw_t1( t1, hierfn + 'rbp' , option='both' )
8330
+ myx['brain'].to_csv( hierfn + 'rbp.csv', index=False )
8331
+ myx['brain'].to_csv( hierfn + 'rbpbrain.csv', index=False )
8332
+ del myx
8333
+
8138
8334
  hier = antspyt1w.read_hierarchical( hierfn )
8139
8335
  t1wide = antspyt1w.merge_hierarchical_csvs_to_wide_format(
8140
8336
  hier['dataframes'], identifier=None )
@@ -8311,11 +8507,11 @@ def mm_csv(
8311
8507
  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
8508
  ants.plot( nmpro['NM_avg_cropped'], nmpro['NM_labels'], axis=2, slices=mysl, title='nm crop + labels', filename=mymm+mysep+"NMavgcroplabels.png" )
8313
8509
  else :
8314
- if len( myimgsr ) > 0:
8510
+ if len( myimgsr ) > 0 :
8315
8511
  dowrite=False
8316
8512
  myimgcount=0
8317
8513
  if len( myimgsr ) > 0 :
8318
- myimg = myimgsr[myimgcount]
8514
+ myimg = myimgsr[ myimgcount ]
8319
8515
  subjectpropath = os.path.dirname( mydoc['outprefix'] )
8320
8516
  if verbose:
8321
8517
  print("subjectpropath is")
@@ -8323,19 +8519,19 @@ def mm_csv(
8323
8519
  os.makedirs( subjectpropath, exist_ok=True )
8324
8520
  mymmout = makewideout( mymm )
8325
8521
  if verbose and not exists( mymmout ):
8326
- print("Modality specific processing: " + mymod + " execution " )
8522
+ print( "Modality specific processing: " + mymod + " execution " )
8327
8523
  print( mymm )
8328
8524
  elif verbose and exists( mymmout ) :
8329
8525
  print("Modality specific processing: " + mymod + " complete " )
8330
8526
  if exists( mymmout ) :
8331
8527
  continue
8332
8528
  if verbose:
8333
- print(subjectpropath)
8529
+ print( subjectpropath )
8334
8530
  print( myimg )
8335
8531
  if not testloop:
8336
8532
  img = mm_read( myimg )
8337
8533
  ishapelen = len( img.shape )
8338
- if mymod == 'T1w' and ishapelen == 3: # for a real run, set to True
8534
+ if mymod == 'T1w' and ishapelen == 3:
8339
8535
  if not exists( mymm + mysep + "kk_norm.nii.gz" ):
8340
8536
  dowrite=True
8341
8537
  if verbose:
@@ -8468,6 +8664,32 @@ def mm_csv(
8468
8664
  axis=2, nslices=maxslice, ncol=7, crop=True, title='CBF image', filename=mymm+mysep+"cbf.png" )
8469
8665
  ants.plot( tabPro['perf']['m0'],
8470
8666
  axis=2, nslices=maxslice, ncol=7, crop=True, title='M0 image', filename=mymm+mysep+"m0.png" )
8667
+
8668
+ if ( mymod == 'pet3d' ) and ishapelen == 3:
8669
+ dowrite=True
8670
+ try:
8671
+ tabPro, normPro = mm( t1, hier,
8672
+ srmodel=None,
8673
+ do_tractography=False,
8674
+ do_kk=False,
8675
+ do_normalization=templateTx,
8676
+ group_template = normalization_template,
8677
+ group_transform = groupTx,
8678
+ test_run=test_run,
8679
+ pet_3d_image=img,
8680
+ verbose=True )
8681
+ except Exception as e:
8682
+ error_info = traceback.format_exc()
8683
+ print(error_info)
8684
+ visualize=False
8685
+ dowrite=False
8686
+ tabPro={'pet3d':None}
8687
+ print(f"antspymmerror occurred while processing {overmodX}: {e}")
8688
+ pass
8689
+ if tabPro['pet3d'] is not None and visualize:
8690
+ maxslice = np.min( [21, tabPro['pet3d']['pet3d'].shape[2] ] )
8691
+ ants.plot( tabPro['pet3d']['pet3d'],
8692
+ axis=2, nslices=maxslice, ncol=7, crop=True, title='PET image', filename=mymm+mysep+"pet3d.png" )
8471
8693
  if ( mymod == 'DTI_LR' or mymod == 'DTI_RL' or mymod == 'DTI' ) and ishapelen == 4:
8472
8694
  bvalfn = re.sub( '.nii.gz', '.bval' , myimg )
8473
8695
  bvecfn = re.sub( '.nii.gz', '.bvec' , myimg )
@@ -10962,6 +11184,7 @@ def brainmap_figure(statistical_df, data_dictionary, output_prefix, brain_image,
10962
11184
  anatsear=re.sub("post.limb.of.internal.capsule","post.int.cap",anatsear)
10963
11185
  anatsear=re.sub("ant.limb.of.internal.capsule","ant.int.cap",anatsear)
10964
11186
  anatsear=re.sub("sagittal.stratum.include.inferior.longitidinal.fasciculus.and.inferior.fronto.occipital.fasciculus","ilf.and.ifo",anatsear)
11187
+ anatsear=re.sub("post.thalamic.radiation.optic.rad","post.thalamic.radiation",anatsear)
10965
11188
  atlassearch = mydict['tidynames'].str.contains(anatsear)
10966
11189
  if atlassearch.sum() == 0:
10967
11190
  atlassearch = mydict2['tidynames'].str.contains(anatsear)
@@ -10993,6 +11216,7 @@ def brainmap_figure(statistical_df, data_dictionary, output_prefix, brain_image,
10993
11216
  elif 'cerebellum' in anattoshow[k]:
10994
11217
  myext = 'cerebellum'
10995
11218
  oglabelname=re.sub('cerebellum', '',anatsear)
11219
+ oglabelname=re.sub('t1.vo','',oglabelname)
10996
11220
  # oglabelname=oglabelname[2:]
10997
11221
  elif 'brainstem' in anattoshow[k] or is_bst_region(anatsear):
10998
11222
  myext = 'brainstem'
@@ -11463,6 +11687,7 @@ def aggregate_antspymm_results_sdf(
11463
11687
  vmoddict['imageID'] = 'T1w'
11464
11688
  vmoddict['flairid'] = 'T2Flair'
11465
11689
  vmoddict['perfid'] = 'perf'
11690
+ vmoddict['pet3did'] = 'pet3d'
11466
11691
  vmoddict['rsfid1'] = 'rsfMRI'
11467
11692
  # vmoddict['rsfid2'] = 'rsfMRI'
11468
11693
  vmoddict['dtid1'] = 'DTI'
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: antspymm
3
- Version: 1.4.3
3
+ Version: 1.4.5
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
@@ -0,0 +1,7 @@
1
+ antspymm/__init__.py,sha256=ZdNJyHwS6rzq59v0OK3tE3qSTD0za2iULzSLGkM_0uc,4527
2
+ antspymm/mm.py,sha256=CKNLB3F00E5BOvNHTLoHXGN7l3fXzr9Tt3Oc-BiSvfM,513311
3
+ antspymm-1.4.5.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
4
+ antspymm-1.4.5.dist-info/METADATA,sha256=68JOQDfbTRq3y5NrC3R_BsELpzGbupAYA55L72wektY,25668
5
+ antspymm-1.4.5.dist-info/WHEEL,sha256=A3WOREP4zgxI0fKrHUG8DC8013e3dK3n7a6HDbcEIwE,91
6
+ antspymm-1.4.5.dist-info/top_level.txt,sha256=iyD1sRhCKzfwKRJLq5ZUeV9xsv1cGQl8Ejp6QwXM1Zg,9
7
+ antspymm-1.4.5.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (75.6.0)
2
+ Generator: setuptools (75.7.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.3.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
4
- antspymm-1.4.3.dist-info/METADATA,sha256=YSSsqoF26p_IVPzEtiShVaNwBc5Bue3FPfZY6iVaCnY,25668
5
- antspymm-1.4.3.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
6
- antspymm-1.4.3.dist-info/top_level.txt,sha256=iyD1sRhCKzfwKRJLq5ZUeV9xsv1cGQl8Ejp6QwXM1Zg,9
7
- antspymm-1.4.3.dist-info/RECORD,,