Skip to content

Commit

Permalink
Add support for SPC multidimentional maps
Browse files Browse the repository at this point in the history
  • Loading branch information
georgievgeorgi committed Nov 18, 2024
1 parent d7a6dd5 commit 25369b6
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/ramanchada2/spectrum/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@
from .creators.from_theoretical_lines import from_theoretical_lines
from .creators.hdr_from_multi_exposure import hdr_from_multi_exposure
from .filters import * # noqa
from .multimap import * # noqa
from .peaks import * # noqa
from .spectrum import Spectrum # noqa
1 change: 1 addition & 0 deletions src/ramanchada2/spectrum/multimap/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .spc import read_map_spc
24 changes: 24 additions & 0 deletions src/ramanchada2/spectrum/multimap/spc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from collections import namedtuple
from typing import Dict, NamedTuple

import spc_io

from ..spectrum import Spectrum

SPCMapCoordinates = namedtuple('SPCMapCoordinates', ['z', 'w'])


def read_map_spc(filename: str) -> Dict[NamedTuple('SPCMapCoordinates',
[('z', float), ('w', float)]),
Spectrum]:
spc = spc_io.SPC.from_bytes_io(open(filename, 'rb'))

ret = dict()

spc_meta = {k.strip(): v.strip() for k, v in spc.log_book.text.items()}
for meas in spc:
spe_meta = {}
spe_meta.update(spc_meta)
spe_meta.update(dict(w=meas.w, z=meas.z))
ret[SPCMapCoordinates(w=meas.w, z=meas.z)] = Spectrum(x=meas.xarray, y=meas.yarray, metadata=spe_meta)
return ret

0 comments on commit 25369b6

Please sign in to comment.