Skip to content
Snippets Groups Projects
Commit 6d10dc83 authored by Fidel Alfaro Almagro's avatar Fidel Alfaro Almagro :speech_balloon:
Browse files

Re-created bip repository

parent 222bf918
No related branches found
No related tags found
No related merge requests found
Showing
with 280 additions and 0 deletions
*.nii.gz filter=lfs diff=lfs merge=lfs -text
*.pyfix_model filter=lfs diff=lfs merge=lfs -text
*.lut filter=lfs diff=lfs merge=lfs -text
*.zip filter=lfs diff=lfs merge=lfs -text
bip/data/* filter=lfs diff=lfs merge=lfs -text
bip/data/** filter=lfs diff=lfs merge=lfs -text bip/data/** filter=lfs diff=lfs merge=lfs -text
...@@ -11,6 +11,8 @@ __pycache__/ ...@@ -11,6 +11,8 @@ __pycache__/
# Distribution / packaging # Distribution / packaging
.Python .Python
build/ build/
obsolete/
structure
develop-eggs/ develop-eggs/
dist/ dist/
downloads/ downloads/
...@@ -22,10 +24,14 @@ parts/ ...@@ -22,10 +24,14 @@ parts/
sdist/ sdist/
var/ var/
wheels/ wheels/
external/
bip/data/GDC/bb_GDC_*
bip/data/dMRI/kernels.zip*
*.egg-info/ *.egg-info/
.installed.cfg .installed.cfg
*.egg *.egg
.*.py .*.py
fsl_sub.yml
# PyInstaller # PyInstaller
# Usually these files are written by a python script from a template # Usually these files are written by a python script from a template
......
-------------------------------------------
BRAIN IMAGING PIPELINE
Fidel Alfaro Almagro, WIN-FMRIB
June, 2022
-------------------------------------------
Automated tool
Installation
------------
If you want to install everythong that is needed from scratch, run:
```cd /path-to-lib/install_dir/
python setup.py install```
import shutil
from fsl.wrappers.wrapperutils import cmdwrapper
installed_sienax = shutil.which('bb_sienax')
if installed_sienax:
@cmdwrapper
def bb_sienax(input, output=None, **kwargs):
return ['bb_sienax', input, output]
else:
def bb_sienax(input, output=None, **kwargs):
from . import sienax
sienax.bb_sienax(input, output)
#!/bin/env python
'''
Authors: Fidel Alfaro Almagro
FMRIB, Oxford University
$01-May-2014 11:44:20$
Version $1.0
ProjectDir =
'''
import sys
import argparse
import os.path
from fsl import wrappers
class MyParser(argparse.ArgumentParser):
def error(self, message):
sys.stderr.write('error: %s\n' % message)
self.print_help()
sys.exit(2)
class Usage(Exception):
def __init__(self, msg):
self.msg = msg
def bb_get_b0s(inputFile, bvalFilename, outputFile, outputIndFile,
desiredNumber, B0limit=100):
with open(bvalFilename, 'r', encoding="utf-8") as f:
line = f.readlines()
line = line[0].split()
indices = [i for i, x in enumerate(line) if int(x) < B0limit]
with open (outputIndFile ,'wt', encoding="utf-8") as f:
f.write(" ".join([str(x) for x in indices]))
indices = indices[0:desiredNumber]
wrappers.fslselectvols(src=inputFile, out=outputFile, vols=indices)
def main():
parser = MyParser(description='UKB tool to get a B0 of a set of B0 images')
parser.add_argument('-i', dest="inputFile", type=str, nargs=1,
help='Input File')
parser.add_argument('-o', dest="outputFile", type=str, nargs=1,
help='Output File')
parser.add_argument('-n', dest='desiredNumber',type=int, nargs=1,
help='Desired number of B0s from file. If none specified, all will be selected')
parser.add_argument('-l', dest='B0limit',type=int, default=[100], nargs=1,
help='Limit B0 value. (Default 100)')
parser.add_argument('-a', dest='bvalFilename',type=str, default='', nargs=1,
help='bval file. (Default: Same basename as the input file)')
argsa = parser.parse_args()
if argsa.inputFile is None:
parser.print_help()
sys.exit()
if argsa.outputFile is None:
parser.print_help()
sys.exit()
inputFile = argsa.inputFile[0]
outputFile = argsa.outputFile[0]
baseDir = os.path.dirname(inputFile)
outDir = os.path.dirname(outputFile)
baseN = os.path.basename(inputFile).split('.')[0]
outN = os.path.basename(outputFile).split('.')[0]
if argsa.bvalFilename == '':
bvalFilename = baseDir + "/" + baseN+".bval"
else:
bvalFilename = argsa.bvalFilename[0]
with open(bvalFilename, 'r', encoding="utf-8") as f:
line = f.readlines()
line = line[0].split()
B0limit = int(argsa.B0limit[0])
indices = [i for i, x in enumerate(line) if int(x) < B0limit]
if argsa.desiredNumber is None:
desiredNumber = len(indices)
else:
desiredNumber = argsa.desiredNumber[0]
if desiredNumber > len(indices):
print(("There are only %i B0. It is not possible to have %i" % (len(indices), desiredNumber)))
sys.exit()
if desiredNumber <= 0:
print("The number of B0 must be positive")
sys.exit()
outputIndFile = outDir + '/' + outN +'_indices.txt'
bb_get_b0s(inputFile, bvalFilename, outputFile, outputIndFile,
desiredNumber, B0limit)
if __name__ == "__main__":
main()
#!/bin/env python
'''
Authors: Fidel Alfaro Almagro
FMRIB, Oxford University
$15-Dec-2014 10:41:10$
Version $1.0
ProjectDir =
'''
import sys
import json
import numbers
import argparse
class MyParser(argparse.ArgumentParser):
def error(self, message):
sys.stderr.write('error: %s\n' % message)
self.print_help()
sys.exit(2)
class Usage(Exception):
def __init__(self, msg):
self.msg = msg
def bb_read_json_field(fileName, fieldName, rounding=0, multFactor=1):
result=[]
with open(fileName, 'r', encoding="utf-8") as data_file:
data=json.load(data_file)
if fieldName in data.keys():
value=data[fieldName]
if isinstance(value, numbers.Number):
if rounding !=0:
result=round(data[fieldName]*multFactor,rounding)
else:
result=data[fieldName]*multFactor
else:
result=str(data[fieldName])
return result
def main():
parser = MyParser(description='BioBank Dicom Header Reader')
parser.add_argument('-F', dest="file", type=str, nargs=1,
help='Read json file')
parser.add_argument('-f', dest="field", type=str, nargs=1, default="NONE",
help='Read field')
parser.add_argument('-r', dest="rounding", type=int, default=0,
help='Round the value the selected number of decimals (Default: No rounding')
parser.add_argument('-m', dest="multFactor", type=float, default=1,
help='Multiplication factor for the selected value (Default 1)')
argsa = parser.parse_args()
if argsa.file is None:
parser.print_help()
sys.exit()
if argsa.field is None:
parser.print_help()
sys.exit()
rounding=argsa.rounding
multFactor=argsa.multFactor
fileName = argsa.file[0]
fieldName = argsa.field[0]
res=bb_read_json_field(fileName, fieldName, rounding, multFactor)
print(str(res))
if __name__ == "__main__":
main()
import os
import nibabel as nib
from bip.commands.bb_read_json_field import bb_read_json_field
def get_dt(img, json):
if os.path.exists(json):
t = bb_read_json_field(fileName=json, fieldName="EffectiveEchoSpacing",
rounding=4, multFactor=1000)
if t in ["[]", ""]:
t = bb_read_json_field(fileName=json,
fieldName="EstimatedEffectiveEchoSpacing",
rounding=4, multFactor=1000)
return t
im = nib.load(img)
descrip = str(im.header['descrip'])
fields = descrip.split(";")
for field in fields:
t = field.split("=")
fieldName = t[0]
fieldValue = t[1]
if fieldName == "dwell":
return fieldValue
return 0
File added
Source diff could not be displayed: it is stored in LFS. Options to address this: view the blob.
File added
File added
File added
File added
File added
File added
Source diff could not be displayed: it is stored in LFS. Options to address this: view the blob.
Source diff could not be displayed: it is stored in LFS. Options to address this: view the blob.
File added
File added
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment