Metadata-Version: 2.4
Name: fastmri_tools
Version: 0.1.0
Summary: Standalone fastMRI prostate T2 and diffusion regridding, GRAPPA filling, and complex IFFT outputs.
Author: meis-01
Project-URL: Homepage, https://github.com/meis-01/fastmri_tools
Project-URL: Repository, https://github.com/meis-01/fastmri_tools
Project-URL: Issues, https://github.com/meis-01/fastmri_tools/issues
Keywords: fastmri,mri,reconstruction,grappa,diffusion
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Science/Research
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Topic :: Scientific/Engineering :: Image Processing
Classifier: Topic :: Scientific/Engineering :: Medical Science Apps.
Requires-Python: >=3.9
Description-Content-Type: text/markdown
Requires-Dist: h5py>=3.8
Requires-Dist: numpy>=1.23
Provides-Extra: dev
Requires-Dist: build>=1.2; extra == "dev"
Requires-Dist: pytest>=8; extra == "dev"
Requires-Dist: twine>=5; extra == "dev"

# fastmri_tools

Standalone reconstruction helper for fastMRI prostate T2 and diffusion HDF5 files.

The project is intentionally self-contained: it does not import anything from the
parent repository. Runtime dependencies are ordinary pip packages listed in
`pyproject.toml`.

## What it does

For each input MRI HDF5 file, the pipeline:

1. Loads `kspace`, `calibration_data`, and the ISMRMRD header.
2. Detects T2 or diffusion data, or uses the sequence passed on the command line.
3. Applies trapezoidal EPI regridding for diffusion data when header parameters
   are present. T2 data keeps its Cartesian readout grid.
4. Fills missing samples with GRAPPA using the calibration data.
5. Computes a centered complex inverse FFT from the filled k-space.
6. Writes complex outputs with the same dimensions as the original input
   k-space: `(averages, slices, coils, readout, phase)`.

The output HDF5 contains:

- `kspace_regridded`: complex k-space after diffusion regridding, or a copy of
  the input k-space for T2.
- `kspace_grappa`: complex GRAPPA-filled k-space.
- `image_complex`: complex centered inverse FFT of `kspace_grappa`.
- `image_complex_coil_combined`: diffusion only, when `coil_sens_maps` is
  available in the source file. This is still complex and has shape
  `(averages, slices, readout, phase)`.

## Install

From PyPI, once the first release has been published:

```powershell
python -m pip install fastmri_tools
```

From GitHub:

```powershell
python -m pip install git+https://github.com/meis-01/fastmri_tools.git
```

For local development:

```powershell
python -m venv .venv
.\.venv\Scripts\python -m pip install -U pip
.\.venv\Scripts\python -m pip install -e ".[dev]"
```

## Run one file

```powershell
fastmri-tools reconstruct `
  --input C:\path\to\file.h5 `
  --output C:\path\to\recon_complex.h5 `
  --sequence auto
```

Use `--sequence t2` or `--sequence dwi` to override auto-detection.

## Run a folder

```powershell
fastmri-tools reconstruct `
  --input C:\path\to\h5_folder `
  --output C:\path\to\output_folder `
  --sequence auto
```

The command writes one output HDF5 per input file.

## Quick synthetic check

This creates a tiny synthetic T2-like file and reconstructs it:

```powershell
fastmri-tools make-synthetic --output .\synthetic_t2.h5 --sequence t2
fastmri-tools reconstruct --input .\synthetic_t2.h5 --output .\synthetic_t2_recon.h5 --sequence t2
```

Inspect the output:

```powershell
fastmri-tools inspect .\synthetic_t2_recon.h5
```

The module entry points also work:

```powershell
python -m fastmri_tools inspect .\synthetic_t2_recon.h5
```

## Publish a release

This repository includes GitHub Actions for CI and PyPI publishing.

1. Create a PyPI project or pending publisher for `fastmri_tools`.
2. Configure PyPI Trusted Publishing with:
   - Owner: `meis-01`
   - Repository name: `fastmri_tools`
   - Workflow name: `publish.yml`
   - Environment name: `pypi`
3. Create and publish a GitHub release such as `v0.1.0`.

GitHub Actions will build the source distribution and wheel, then publish them
to PyPI without storing a PyPI API token in GitHub secrets.

## Notes

- The complex inverse FFT is intentionally not converted to RSS magnitude. This
  preserves phase and coil information.
- Output spatial dimensions match the loaded k-space dimensions. No T2 zero
  padding or center cropping is applied.
- Diffusion regridding is skipped automatically if the ISMRMRD header does not
  contain the needed EPI timing fields.
