antspymm 1.3.4__py3-none-any.whl → 1.3.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/mm.py CHANGED
@@ -3451,6 +3451,9 @@ def dipy_dti_recon(
3451
3451
  bvals = bvalsfn.copy()
3452
3452
  bvecs = bvecsfn.copy()
3453
3453
 
3454
+ if bvals.max() < 1.0:
3455
+ raise ValueError("DTI recon error: maximum bvalues are too small.")
3456
+
3454
3457
  b0_idx = segment_timeseries_by_bvalue( bvals )['highermeans']
3455
3458
 
3456
3459
  b0 = ants.slice_image( image, axis=3, idx=b0_idx[0] )
@@ -7975,16 +7978,20 @@ def mm_csv(
7975
7978
  hier['dataframes'], identifier=None )
7976
7979
  t1wide.to_csv( hierfn + 'mmwide.csv' )
7977
7980
  ################# read the hierarchical data ###############################
7981
+ # over-write the rbp data with a consistent and recent approach ############
7982
+ myx = antspyt1w.inspect_raw_t1( t1, hierfn + 'rbp' , option='both' )
7983
+ myx['brain'].to_csv( hierfn + 'rbp.csv', index=False )
7984
+ myx['brain'].to_csv( hierfn + 'rbpbrain.csv', index=False )
7985
+ del myx
7978
7986
  hier = antspyt1w.read_hierarchical( hierfn )
7979
- if exists( hierfn + 'mmwide.csv' ) :
7980
- t1wide = pd.read_csv( hierfn + 'mmwide.csv' )
7981
- elif not testloop:
7982
- t1wide = antspyt1w.merge_hierarchical_csvs_to_wide_format(
7983
- hier['dataframes'], identifier=None )
7984
- if t1wide['resnetGrade'].iloc[0] < 0.35:
7985
- rgrade = str( t1wide['resnetGrade'].iloc[0] )
7987
+ t1wide = antspyt1w.merge_hierarchical_csvs_to_wide_format(
7988
+ hier['dataframes'], identifier=None )
7989
+ rgrade = str( t1wide['resnetGrade'].iloc[0] )
7990
+ if t1wide['resnetGrade'].iloc[0] < 0.20:
7986
7991
  warnings.warn('T1w quality check indicates failure: ' + rgrade + " will not process." )
7987
7992
  return
7993
+ else:
7994
+ print('T1w quality check indicates success: ' + rgrade + " will process." )
7988
7995
 
7989
7996
  if srmodel_T1 is not False :
7990
7997
  hierfntest = hierfnSR + 'mtl.csv'
@@ -8079,6 +8086,8 @@ def mm_csv(
8079
8086
  print( 'example image name is : ' )
8080
8087
  print( myimgsr )
8081
8088
  if overmodX == 'NM2DMT':
8089
+ dowrite = True
8090
+ visualize = True
8082
8091
  subjectpropath = os.path.dirname( mydoc['outprefix'] )
8083
8092
  if verbose:
8084
8093
  print("subjectpropath is")
@@ -8138,16 +8147,17 @@ def mm_csv(
8138
8147
  print(f"antspymmerror occurred while processing {overmodX}: {e}")
8139
8148
  pass
8140
8149
  if not test_run:
8141
- write_mm( output_prefix=mymm, mm=tabPro, mm_norm=normPro, t1wide=None, separator=mysep )
8142
- nmpro = tabPro['NM']
8143
- mysl = range( nmpro['NM_avg'].shape[2] )
8144
- if visualize:
8145
- mysl = range( nmpro['NM_avg'].shape[2] )
8146
- ants.plot( nmpro['NM_avg'], nmpro['t1_to_NM'], slices=mysl, axis=2, title='nm + t1', filename=mymm+mysep+"NMavg.png" )
8147
- mysl = range( nmpro['NM_avg_cropped'].shape[2] )
8148
- ants.plot( nmpro['NM_avg_cropped'], axis=2, slices=mysl, overlay_alpha=0.3, title='nm crop', filename=mymm+mysep+"NMavgcrop.png" )
8149
- 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" )
8150
- ants.plot( nmpro['NM_avg_cropped'], nmpro['NM_labels'], axis=2, slices=mysl, title='nm crop + labels', filename=mymm+mysep+"NMavgcroplabels.png" )
8150
+ if dowrite:
8151
+ write_mm( output_prefix=mymm, mm=tabPro,
8152
+ mm_norm=normPro, t1wide=None, separator=mysep )
8153
+ if visualize :
8154
+ nmpro = tabPro['NM']
8155
+ mysl = range( nmpro['NM_avg'].shape[2] )
8156
+ ants.plot( nmpro['NM_avg'], nmpro['t1_to_NM'], slices=mysl, axis=2, title='nm + t1', filename=mymm+mysep+"NMavg.png" )
8157
+ mysl = range( nmpro['NM_avg_cropped'].shape[2] )
8158
+ ants.plot( nmpro['NM_avg_cropped'], axis=2, slices=mysl, overlay_alpha=0.3, title='nm crop', filename=mymm+mysep+"NMavgcrop.png" )
8159
+ 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" )
8160
+ ants.plot( nmpro['NM_avg_cropped'], nmpro['NM_labels'], axis=2, slices=mysl, title='nm crop + labels', filename=mymm+mysep+"NMavgcroplabels.png" )
8151
8161
  else :
8152
8162
  if len( myimgsr ) > 0:
8153
8163
  dowrite=False
@@ -9544,6 +9554,7 @@ def blind_image_assessment(
9544
9554
  image_reference = ants.image_clone( image )
9545
9555
  ntimepoints = 1
9546
9556
  bvalueMax=None
9557
+ bvecnorm=None
9547
9558
  if image_reference.dimension == 4:
9548
9559
  ntimepoints = image_reference.shape[3]
9549
9560
  if "DTI" in image_filename:
@@ -9556,6 +9567,8 @@ def blind_image_assessment(
9556
9567
  if exists( bval_name ) and exists( bvec_name ):
9557
9568
  bvals, bvecs = read_bvals_bvecs( bval_name , bvec_name )
9558
9569
  bvalueMax = bvals.max()
9570
+ bvecnorm = np.linalg.norm(bvecs,axis=1).reshape( bvecs.shape[0],1 )
9571
+ bvecnorm = bvecnorm.max()
9559
9572
  else:
9560
9573
  image_b0 = ants.get_average_of_timeseries( image_reference ).iMath("Normalize")
9561
9574
  else:
@@ -9721,11 +9734,11 @@ def blind_image_assessment(
9721
9734
  noizlevel, snrref, cnrref, psnrref, ssimref, mymi, asym_err, myevr, msk_vol,
9722
9735
  spc[0], spc[1], spc[2],org[0], org[1], org[2],
9723
9736
  image.shape[0], image.shape[1], image.shape[2], ntimepoints,
9724
- jjj, modality, mriseries, mrimfg, mrimodel, MagneticFieldStrength, mriSAR, PixelBandwidth, BandwidthPerPixelPhaseEncode, bvalueMax ]],
9737
+ jjj, modality, mriseries, mrimfg, mrimodel, MagneticFieldStrength, mriSAR, PixelBandwidth, BandwidthPerPixelPhaseEncode, bvalueMax, bvecnorm ]],
9725
9738
  columns=[
9726
9739
  'filename',
9727
9740
  'dimensionality',
9728
- 'noise', 'snr', 'cnr', 'psnr', 'ssim', 'mi', 'reflection_err', 'EVR', 'msk_vol', 'spc0','spc1','spc2','org0','org1','org2','dimx','dimy','dimz','dimt','slice','modality', 'mriseries', 'mrimfg', 'mrimodel', 'mriMagneticFieldStrength', 'mriSAR', 'mriPixelBandwidth', 'mriPixelBandwidthPE', 'dti_bvalueMax' ])
9741
+ 'noise', 'snr', 'cnr', 'psnr', 'ssim', 'mi', 'reflection_err', 'EVR', 'msk_vol', 'spc0','spc1','spc2','org0','org1','org2','dimx','dimy','dimz','dimt','slice','modality', 'mriseries', 'mrimfg', 'mrimodel', 'mriMagneticFieldStrength', 'mriSAR', 'mriPixelBandwidth', 'mriPixelBandwidthPE', 'dti_bvalueMax', 'dti_bvecnorm' ])
9729
9742
  outdf = pd.concat( [outdf, df ], axis=0, ignore_index=False )
9730
9743
  if verbose:
9731
9744
  print( outdf )
@@ -10893,6 +10906,7 @@ def aggregate_antspymm_results_sdf(
10893
10906
  splitsep='-',
10894
10907
  idsep='-',
10895
10908
  wild_card_modality_id=False,
10909
+ second_split=False,
10896
10910
  verbose=False ):
10897
10911
  """
10898
10912
  Aggregate ANTsPyMM results from the specified study data frame and store the aggregated results in a new data frame. This assumes data is organized on disk
@@ -10911,6 +10925,7 @@ def aggregate_antspymm_results_sdf(
10911
10925
  - idsep (str): the separator used to partition subjectid date and imageid
10912
10926
  for example, if idsep is - then we have subjectid-date-imageid
10913
10927
  - wild_card_modality_id (bool): keep if False for safer execution
10928
+ - second_split (bool): this is a hack that will split the imageID by . and keep the first part of the split; may be needed when the input filenames contain .
10914
10929
  - verbose : boolean
10915
10930
 
10916
10931
  Note:
@@ -10992,12 +11007,24 @@ def aggregate_antspymm_results_sdf(
10992
11007
  myproj = str(df[project_col].iloc[x])
10993
11008
  mydate = str(df[date_col].iloc[x])
10994
11009
  myid = str(df[image_col].iloc[x])
11010
+ if second_split:
11011
+ myid = myid.split(".")[0]
10995
11012
  path_template = base_path + "/" + myproj + "/" + sid + "/" + mydate + '/' + hiervariable + '/' + str(myid) + "/"
10996
11013
  hierfn = sorted(glob( path_template + "*" + hiervariable + "*wide.csv" ) )
11014
+ if len( hierfn ) == 0:
11015
+ print( hierfn )
11016
+ print( path_template )
11017
+ print( myproj )
11018
+ print( sid )
11019
+ print( mydate )
11020
+ print( myid )
10997
11021
  if len( hierfn ) > 0:
10998
11022
  keep[x]=True
10999
11023
 
11000
- df=df[keep]
11024
+ # df=df[keep]
11025
+ if df.shape[0] == 0:
11026
+ warnings.warn("input data frame shape is filtered down to zero")
11027
+ return df
11001
11028
 
11002
11029
  if not df.index.is_unique:
11003
11030
  warnings.warn("data frame does not have unique indices. we therefore reset the index to allow the function to continue on." )
@@ -11030,7 +11057,8 @@ def aggregate_antspymm_results_sdf(
11030
11057
  myproj = str(df[project_col].iloc[x])
11031
11058
  mydate = str(df[date_col].iloc[x])
11032
11059
  myid = str(df[image_col].iloc[x])
11033
- myt1id = myid
11060
+ if second_split:
11061
+ myid = myid.split(".")[0]
11034
11062
  if verbose:
11035
11063
  print( myfn )
11036
11064
  print( temp )
@@ -11090,7 +11118,6 @@ def aggregate_antspymm_results_sdf(
11090
11118
  nlarge = len(t1wfn)
11091
11119
  t1wfn = find_most_recent_file( t1wfn )
11092
11120
  warnings.warn("there are " + str( nlarge ) + " number of wide fns with search path " + modsearch + " we take the most recent of these " + t1wfn[0] )
11093
- # raise ValueError("there are " + str( len( t1wfn ) ) + " number of wide fns with search path " + modsearch )
11094
11121
  if len( t1wfn ) == 1:
11095
11122
  if verbose:
11096
11123
  print(t1wfn)
@@ -11108,9 +11135,11 @@ def aggregate_antspymm_results_sdf(
11108
11135
  hdf.index = subdf.index.copy()
11109
11136
  subdf = pd.concat( [subdf,hdf], axis=1, ignore_index=False)
11110
11137
  dfout = pd.concat( [dfout,subdf], axis=0, ignore_index=False )
11111
- badnames = get_names_from_data_frame( ['Unnamed'], dfout )
11112
- dfout=dfout.drop(badnames, axis=1)
11113
- return( dfout )
11138
+
11139
+ if dfout.shape[0] > 0:
11140
+ badnames = get_names_from_data_frame( ['Unnamed'], dfout )
11141
+ dfout=dfout.drop(badnames, axis=1)
11142
+ return dfout
11114
11143
 
11115
11144
  def enantiomorphic_filling_without_mask( image, axis=0, intensity='low' ):
11116
11145
  """
@@ -1,18 +1,18 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: antspymm
3
- Version: 1.3.4
3
+ Version: 1.3.6
4
4
  Summary: multi-channel/time-series medical image processing with antspyx
5
- Home-page: https://github.com/stnava/ANTsPyMM
6
- Author: Avants, Gosselin, Tustison, Reardon
7
- Author-email: stnava@gmail.com
5
+ Author-email: "Avants, Gosselin, Tustison, Reardon" <stnava@gmail.com>
8
6
  License: Apache 2.0
9
- Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
7
+ Requires-Python: >=3.8
8
+ Description-Content-Type: text/markdown
10
9
  License-File: LICENSE
11
10
  Requires-Dist: h5py >=2.10.0
12
11
  Requires-Dist: numpy >=1.19.4
13
12
  Requires-Dist: pandas >=1.0.1
14
13
  Requires-Dist: antspyx
15
- Requires-Dist: antspyt1w >=0.2.3
14
+ Requires-Dist: antspynet >=0.2.5
15
+ Requires-Dist: antspyt1w >=0.9.3
16
16
  Requires-Dist: pathlib
17
17
  Requires-Dist: dipy
18
18
  Requires-Dist: nibabel
@@ -35,7 +35,7 @@ production environments.
35
35
  install the `dev` version by calling (within the source directory):
36
36
 
37
37
  ```
38
- python setup.py install
38
+ python3 -m build .
39
39
  ```
40
40
 
41
41
  or install the latest release via
@@ -450,9 +450,12 @@ ssl._create_default_https_context = ssl._create_unverified_context
450
450
 
451
451
  ## to publish a release
452
452
 
453
+ before doing this - make sure you have a recent run of `pip-compile pyproject.toml`
454
+
453
455
  ```
454
456
  rm -r -f build/ antspymm.egg-info/ dist/
455
- python3 setup.py sdist bdist_wheel
456
- twine upload --repository antspymm dist/*
457
+ python3 -m build .
458
+ python3 -m pip install --upgrade twine
459
+ python3 -m twine upload --repository antspymm dist/*
457
460
  ```
458
461
 
@@ -0,0 +1,7 @@
1
+ antspymm/__init__.py,sha256=1fHqufHndrkJwz473av8qOf5-1xm5r-aKHuMAETGIiE,4462
2
+ antspymm/mm.py,sha256=4g15BkmRyIn-ZTB7DOT9ggTDt-Ma3be44zKpCTALikY,479806
3
+ antspymm-1.3.6.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
4
+ antspymm-1.3.6.dist-info/METADATA,sha256=CRZs-L_1fv4rQPaKsMDPK0_9SHr6BLEyieHo30fLctw,14684
5
+ antspymm-1.3.6.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
6
+ antspymm-1.3.6.dist-info/top_level.txt,sha256=iyD1sRhCKzfwKRJLq5ZUeV9xsv1cGQl8Ejp6QwXM1Zg,9
7
+ antspymm-1.3.6.dist-info/RECORD,,
@@ -1,7 +0,0 @@
1
- antspymm/__init__.py,sha256=1fHqufHndrkJwz473av8qOf5-1xm5r-aKHuMAETGIiE,4462
2
- antspymm/mm.py,sha256=FbboL-Mdg6KTzWvAm770qaKEMLB9wK_isrBmqVbqyQw,478666
3
- antspymm-1.3.4.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
4
- antspymm-1.3.4.dist-info/METADATA,sha256=EwUjVut7HWbQQlz-kUaf5qFrfYXXuPXPL5mmeiXdW3A,14590
5
- antspymm-1.3.4.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
6
- antspymm-1.3.4.dist-info/top_level.txt,sha256=iyD1sRhCKzfwKRJLq5ZUeV9xsv1cGQl8Ejp6QwXM1Zg,9
7
- antspymm-1.3.4.dist-info/RECORD,,