Skip to content

Commit

Permalink
Merge pull request #18 from NYU-DiffusionMRI/rpg_multithread
Browse files Browse the repository at this point in the history
Rpg multithread
  • Loading branch information
jchen33344 authored Aug 29, 2024
2 parents 02b4e75 + 952be6e commit 3c449d4
Show file tree
Hide file tree
Showing 18 changed files with 261 additions and 120 deletions.
26 changes: 20 additions & 6 deletions .github/workflows/build_wheels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,28 +94,42 @@ jobs:
- name: Build x86_64 wheel
env:
ARCHFLAGS: "-arch x86_64"
CFLAGS: "-arch x86_64"
LDFLAGS: "-arch x86_64"
MACOSX_DEPLOYMENT_TARGET: "11.0"
run: |
mkdir -p $GITHUB_WORKSPACE/dist
mkdir -p $GITHUB_WORKSPACE/dist/x86_64
python setup.py bdist_wheel
mv dist/*.whl $GITHUB_WORKSPACE/dist/x86_64/
- name: Repair x86_64 wheel
run: |
pip install delocate
delocate-wheel dist/*-macosx_11_0_x86_64.whl
delocate-wheel $GITHUB_WORKSPACE/dist/x86_64/*.whl
- name: Build arm64 wheel
env:
ARCHFLAGS: "-arch arm64"
CFLAGS: "-arch arm64"
LDFLAGS: "-arch arm64"
MACOSX_DEPLOYMENT_TARGET: "11.0"
run: |
mkdir -p $GITHUB_WORKSPACE/dist/arm64
python setup.py bdist_wheel
mv dist/*.whl $GITHUB_WORKSPACE/dist/arm64/
- name: Repair arm64 wheel
run: |
delocate-wheel dist/*-macosx_11_0_arm64.whl
delocate-wheel dist/*.whl
- name: Verify repaired wheels
run: |
ls -al $GITHUB_WORKSPACE/dist/
- name: Upload to PyPI
ls -al $GITHUB_WORKSPACE/dist/x86_64/
ls -al $GITHUB_WORKSPACE/dist/arm64/
- name: Upload x86_64 wheel to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
packages_dir: $GITHUB_WORKSPACE/dist/x86_64
password: ${{ secrets.PYPI_API_TOKEN }}

- name: Upload arm64 wheel to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
packages_dir: dist
packages_dir: $GITHUB_WORKSPACE/dist/arm64
password: ${{ secrets.PYPI_API_TOKEN }}
24 changes: 17 additions & 7 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,26 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Python Debugger: Current File with Arguments",
"name": "Attach to Python Script",
"type": "debugpy",
"request": "attach",
"connect": {
"host": "localhost",
"port": 5678
},
"pathMappings": [
{
"localRoot": "/Users/benaron/Documents/DESIGNER-v2/lib", // Update with your Python script directory
"remoteRoot": "/path_to_your_python_script_on_remote_if_any"
}
]
},
{
"name": "Debug Shell Script",
"type": "bashdb",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
"args": "${command:pickArgs}"
"program": "/Users/benaron/Documents/scripts/test_d2.sh",
}
]
}
21 changes: 10 additions & 11 deletions designer2/tmi.py
Original file line number Diff line number Diff line change
Expand Up @@ -582,16 +582,15 @@ def execute(): #pylint: disable=unused-variable

logger.info("Initializing SMI fitting...")
echo_times = dwi_metadata['echo_time_per_volume']
if np.max(echo_times) > 1.0:
logger.info("Echo times in ms, converting to seconds.")
echo_times /= 1000
if (np.min(echo_times) < 1.0) and (np.min(echo_times) > 0):
logger.info("Echo times in s, converting to ms.")
echo_times *= 1000

if multi_te_beta:
smi = SMI(bval=bval_orig, bvec=bvec_orig, rotinv_lmax=lmax)
smi.set_compartments(compartments)
smi = SMI(bval=bval_orig, bvec=bvec_orig, rotinv_lmax=lmax,
compartments=compartments, echo_time=echo_times,
beta=dwi_metadata['bshape_per_volume'])

smi.set_echotime(echo_times)
smi.set_bshape(dwi_metadata['bshape_per_volume'])
logger.info("SMI model initialized for multi-TE/beta data.")

params_smi = smi.fit(dwi_orig, mask=mask, sigma=sigma)
Expand All @@ -600,10 +599,10 @@ def execute(): #pylint: disable=unused-variable
save_params(params_smi, nii, model='smi', outdir=outdir)
logger.info("SMI parameters saved for multi-TE/beta data.", extra={"outdir": outdir})
else:
smi = SMI(bval=bval, bvec=bvec, rotinv_lmax=lmax)
smi.set_compartments(compartments)
smi.set_echotime(echo_times)
smi.set_bshape(dwi_metadata['bshape_per_volume'])
smi = SMI(bval=bval, bvec=bvec, rotinv_lmax=lmax,
compartments=compartments, echo_time=echo_times,
beta=dwi_metadata['bshape_per_volume'])

logger.info("SMI model initialized for single-TE/beta data.")

params_smi = smi.fit(dwi, mask=mask, sigma=sigma)
Expand Down
18 changes: 10 additions & 8 deletions lib/smi.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,18 @@ def __init__(self, bval, bvec, beta=None, echo_time=None, merge_distance=None, c
self.rotinv_lmax = rotinv_lmax
self.n_training = int(n_training)

# set up required inputs
self.set_compartments(compartments)
self.set_bvals_bvecs(bval, bvec)
self.set_bshape(beta)
self.set_echotime(echo_time)

if not l_max_training:
self.l_max_training = 6
else:
self.l_max_training = l_max_training

if training_bounds is not None and training_prior is not None:
if (training_bounds is not None) and (training_prior is not None):
self.prior = training_prior
if not self.fit_T2:
self.prior = np.hstack(
Expand All @@ -69,17 +73,15 @@ def __init__(self, bval, bvec, beta=None, echo_time=None, merge_distance=None, c
elif noise_bias == 'rician':
self.flag_rician_bias = True

if self.fit_T2:
self.n_training = int(2e5)

if seed is not None:
self.seed = seed
np.random.seed(self.seed)
else:
self.seed = None

# set up required inputs
self.set_bvals_bvecs(bval, bvec)
self.set_bshape(beta)
self.set_echotime(echo_time)

def set_mask(self, mask):
"""
Function to add a brain mask to the class if the mask was input
Expand Down Expand Up @@ -290,9 +292,9 @@ def get_uniformly_distributed_SM_prior(self):
for i in range(len(dims) - 1):
dim = dims[i]
dim_next = dims[i + 1]
px = self.l2norm(plm[dim:(dim+dim_next+1), :])
px = self.l2norm(plm[dim+1:(dim+dim_next+1), :])
prior = np.vstack((prior, px))

return prior.T

def vectorize(self, image, mask):
Expand Down
Binary file modified rpg_cpp/fftw-3.3.10/api/.libs/libapi.a
Binary file not shown.
Binary file modified rpg_cpp/fftw-3.3.10/dft/.libs/libdft.a
Binary file not shown.
Binary file modified rpg_cpp/fftw-3.3.10/dft/scalar/.libs/libdft_scalar.a
Binary file not shown.
Binary file not shown.
Binary file modified rpg_cpp/fftw-3.3.10/kernel/.libs/libkernel.a
Binary file not shown.
Binary file modified rpg_cpp/fftw-3.3.10/libbench2/libbench2.a
Binary file not shown.
Binary file modified rpg_cpp/fftw-3.3.10/rdft/.libs/librdft.a
Binary file not shown.
Binary file modified rpg_cpp/fftw-3.3.10/rdft/scalar/.libs/librdft_scalar.a
Binary file not shown.
Binary file modified rpg_cpp/fftw-3.3.10/rdft/scalar/r2cb/.libs/librdft_scalar_r2cb.a
Binary file not shown.
Binary file modified rpg_cpp/fftw-3.3.10/rdft/scalar/r2cf/.libs/librdft_scalar_r2cf.a
Binary file not shown.
Binary file modified rpg_cpp/fftw-3.3.10/rdft/scalar/r2r/.libs/librdft_scalar_r2r.a
Binary file not shown.
Binary file modified rpg_cpp/fftw-3.3.10/reodft/.libs/libreodft.a
Binary file not shown.
Binary file modified rpg_cpp/fftw-3.3.10/simd-support/.libs/libsimd_support.a
Binary file not shown.
Loading

0 comments on commit 3c449d4

Please sign in to comment.