Skip to content

Commit

Permalink
exposing parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
mcencini committed Oct 30, 2024
1 parent 04f7350 commit aa46bcb
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 19 deletions.
2 changes: 1 addition & 1 deletion src/pulserver/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
from pypulseq import Opts # noqa

from . import blocks # noqa
from . import parsing # noqa
from . import plan # noqa
from . import sequences # noqa

from . import _server # noqa

from ._core import Sequence # noqa
from ._opts import get_opts # noqa
from ._parsing import ParamsParser # noqa

__all__.extend(["Opts", "get_opts"])
__all__.extend(["Sequence", "ParamsParser"])
2 changes: 1 addition & 1 deletion src/pulserver/_server/_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

from datetime import datetime

from .._parsing import ParamsParser
from ..parsing import ParamsParser

# Location of home
HOME_DIR = pathlib.Path.home()
Expand Down
File renamed without changes.
25 changes: 23 additions & 2 deletions src/pulserver/_parsing/_base.py → src/pulserver/parsing/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def __init__(

self.opts = get_opts(_opts_dict)

def asdict(self):
def asdict(self): # noqa
return vars(self)


Expand Down Expand Up @@ -188,8 +188,29 @@ class ParamsParser:
rf_ringdown_time: float | None = None
adc_dead_time: float | None = None

def __post_init__(self): # noqa

# rounding
if self.psd_rf_wait is not None:
self.psd_rf_wait *= 1e-6
self.psd_rf_wait = round(self.psd_rf_wait * 1e6) / 1e6
if self.psd_grd_wait is not None:
self.psd_grd_wait *= 1e-6
self.psd_grd_wait = round(self.psd_grd_wait * 1e6) / 1e6
if self.raster is not None:
self.raster = round(self.raster * 1e6) / 1e6
if self.dwell is not None:
# self.dwell = round(self.dwell * 1e6) / 1e6
self.dwell = 4e-6
if self.rf_dead_time is not None:
self.rf_dead_time = round(self.rf_dead_time * 1e6) / 1e6
if self.rf_ringdown_time is not None:
self.rf_ringdown_time = round(self.rf_ringdown_time * 1e6) / 1e6
if self.adc_dead_time is not None:
self.adc_dead_time = round(self.adc_dead_time * 1e6) / 1e6

@classmethod
def from_file(cls, filename: str) -> "ParamsParser":
def from_file(cls, filename: str) -> "ParamsParser": # noqa
with open(filename, "rb") as file:
return ParamsParser.from_bytes(file.read())

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ def __init__(
Nslices: int | None = None,
slice_thickness: float | None = None,
slice_spacing: float | None = 0.0,
Rplane: float | None = 1,
PFplane: float | None = 1.0,
R: float | None = 1,
PF: float | None = 1.0,
TE: float | None = 0.0,
TR: float | None = 0.0,
flip: float | None = None,
Expand Down Expand Up @@ -73,12 +73,12 @@ def __init__(
self.flip_angle = flip

# TE / TR
self.TE = TE
self.TR = TR
self.TE = TE * 1e-3
self.TR = TR * 1e-3

# Accelerations
self.R = Rplane
self.PF = PFplane
self.R = R
self.PF = PF

# Build opts
super().__init__(
Expand Down Expand Up @@ -111,9 +111,11 @@ def __init__(
Ny: int | None = None,
Nslices: int | None = None,
slice_thickness: float | None = None,
R: float | None = 1,
Rplane: float | None = 1,
Rplane2: float | None = 1,
PFslice: float | None = 1.0,
Rslice: float | None = 1,
Rshift: float | None = 0,
PF: float | None = 1.0,
TE: float | None = 0.0,
TR: float | None = 0.0,
flip: float | None = None,
Expand Down Expand Up @@ -159,13 +161,16 @@ def __init__(
self.flip_angle = flip

# TE / TR
self.TE = TE
self.TR = TR
self.TE = TE * 1e-3
self.TR = TR * 1e-3

# Accelerations
self.Rpi = Rplane
self.Rcs = Rplane2
self.PF = PFslice
self.R = R
self.Rplane = Rplane
self.Rplane = Rplane
self.Rslice = Rslice
self.Rshift = Rshift
self.PF = PF

# Build opts
super().__init__(
Expand Down
2 changes: 1 addition & 1 deletion tests/_server/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from unittest.mock import MagicMock
from unittest.mock import patch

from pulserver._parsing import ParamsParser
from pulserver.parsing import ParamsParser
from pulserver._server._server import load_plugins
from pulserver._server._server import parse_request
from pulserver._server._server import setup_function_logger
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Test SequenceParams structure."""

from pulserver._parsing import ParamsParser
from pulserver.parsing import ParamsParser


# Test case to verify correct creation and attribute assignment in ParamsParser
Expand Down

0 comments on commit aa46bcb

Please sign in to comment.