DEV: add power spectra + additional_type info
This commit is contained in:
parent
1b86527b94
commit
ff63b8e02f
|
@ -19,22 +19,30 @@ BLOCK_0 = defaultdict(
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
BLOCK_7 = {4: "ScSm", 8: "IgSm", 12: "PhSm", 132: "ScSm_(1)", 136: "IgSm_(1)"}
|
# other sample spectral data (single channel, interferogram, power spectrum, ...)
|
||||||
|
BLOCK_7 = {4: "ScSm", 8: "IgSm", 12: "PhSm", 56: "PwSm", 132: "ScSm_(1)", 136: "IgSm_(1)"}
|
||||||
|
|
||||||
BLOCK_11 = {4: "ScRf", 8: "IgRf", 132: "ScRf_(1)", 136: "IgRf_(1)" }
|
# other reference spectral data (single channel, interferogram, power spectrum, ...)
|
||||||
|
BLOCK_11 = {4: "ScRf", 8: "IgRf", 56: "PwRf", 132: "ScRf_(1)", 136: "IgRf_(1)"}
|
||||||
|
|
||||||
|
# parameters of other sample spectral data
|
||||||
BLOCK_23 = {
|
BLOCK_23 = {
|
||||||
4: "ScSm Data Parameter",
|
4: "ScSm Data Parameter",
|
||||||
8: "IgSm Data Parameter",
|
8: "IgSm Data Parameter",
|
||||||
12: "PhSm Data Parameter",
|
12: "PhSm Data Parameter",
|
||||||
|
56: "PwSm Data Parameter",
|
||||||
132: "ScSm_(1) Data Parameter",
|
132: "ScSm_(1) Data Parameter",
|
||||||
136: "IgSm_(1) Data Parameter"
|
136: "IgSm_(1) Data Parameter",
|
||||||
}
|
}
|
||||||
|
|
||||||
BLOCK_27 = {4: "ScRf Data Parameter",
|
# parameters of other reference spectral data
|
||||||
|
BLOCK_27 = {
|
||||||
|
4: "ScRf Data Parameter",
|
||||||
8: "IgRf Data Parameter",
|
8: "IgRf Data Parameter",
|
||||||
|
56: "PwRf Data Parameter",
|
||||||
132: "ScRf_(1) Data Parameter",
|
132: "ScRf_(1) Data Parameter",
|
||||||
136: "IgRf_(1) Data Parameter"}
|
136: "IgRf_(1) Data Parameter",
|
||||||
|
}
|
||||||
|
|
||||||
DIFFERENT_BLOCKS = {
|
DIFFERENT_BLOCKS = {
|
||||||
31: "AB Data Parameter",
|
31: "AB Data Parameter",
|
||||||
|
@ -56,12 +64,14 @@ class BlockMeta:
|
||||||
data_type: int,
|
data_type: int,
|
||||||
channel_type: int,
|
channel_type: int,
|
||||||
text_type: int,
|
text_type: int,
|
||||||
|
additional_type: int,
|
||||||
chunk_size: int,
|
chunk_size: int,
|
||||||
offset: int,
|
offset: int,
|
||||||
):
|
):
|
||||||
self.data_type = data_type
|
self.data_type = data_type
|
||||||
self.channel_type = channel_type
|
self.channel_type = channel_type
|
||||||
self.text_type = text_type
|
self.text_type = text_type
|
||||||
|
self.additional_type = additional_type
|
||||||
self.chunk_size = chunk_size
|
self.chunk_size = chunk_size
|
||||||
self.offset = offset
|
self.offset = offset
|
||||||
|
|
||||||
|
|
|
@ -6,13 +6,17 @@ from brukeropusreader.constants import (
|
||||||
NULL_BYTE,
|
NULL_BYTE,
|
||||||
ENCODING_LATIN,
|
ENCODING_LATIN,
|
||||||
ENCODING_UTF,
|
ENCODING_UTF,
|
||||||
NULL_STR)
|
NULL_STR,
|
||||||
|
)
|
||||||
from brukeropusreader.opus_reader import read_chunk
|
from brukeropusreader.opus_reader import read_chunk
|
||||||
from struct import unpack, error
|
from struct import unpack, error
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
|
||||||
|
|
||||||
def parse_param(data: bytes, block_meta):
|
def parse_param(data: bytes, block_meta):
|
||||||
|
"""parse data blocks of parameters
|
||||||
|
|
||||||
|
BLOCK_23, BLOCK_27"""
|
||||||
cursor = 0
|
cursor = 0
|
||||||
chunk = read_chunk(data, block_meta)
|
chunk = read_chunk(data, block_meta)
|
||||||
params = {}
|
params = {}
|
||||||
|
|
|
@ -11,6 +11,7 @@ from brukeropusreader.opus_reader import (
|
||||||
read_data_type,
|
read_data_type,
|
||||||
read_channel_type,
|
read_channel_type,
|
||||||
read_text_type,
|
read_text_type,
|
||||||
|
read_additional_type,
|
||||||
read_chunk_size,
|
read_chunk_size,
|
||||||
read_offset,
|
read_offset,
|
||||||
)
|
)
|
||||||
|
@ -25,6 +26,15 @@ def read_file(file_path: str) -> OpusData:
|
||||||
|
|
||||||
|
|
||||||
def parse_meta(data: bytes) -> List[BlockMeta]:
|
def parse_meta(data: bytes) -> List[BlockMeta]:
|
||||||
|
"""Parse the header of the opus file.
|
||||||
|
|
||||||
|
Returns a list of metadata (BlockMeta) for each block to be read,
|
||||||
|
|
||||||
|
:parameter:
|
||||||
|
data: bytes content of the opus file
|
||||||
|
:returns:
|
||||||
|
parse_meta: list of BlockMeta
|
||||||
|
"""
|
||||||
header = data[:HEADER_LEN]
|
header = data[:HEADER_LEN]
|
||||||
spectra_meta = []
|
spectra_meta = []
|
||||||
cursor = FIRST_CURSOR_POSITION
|
cursor = FIRST_CURSOR_POSITION
|
||||||
|
@ -35,14 +45,14 @@ def parse_meta(data: bytes) -> List[BlockMeta]:
|
||||||
data_type = read_data_type(header, cursor)
|
data_type = read_data_type(header, cursor)
|
||||||
channel_type = read_channel_type(header, cursor)
|
channel_type = read_channel_type(header, cursor)
|
||||||
text_type = read_text_type(header, cursor)
|
text_type = read_text_type(header, cursor)
|
||||||
|
additional_type = read_additional_type(header, cursor)
|
||||||
chunk_size = read_chunk_size(header, cursor)
|
chunk_size = read_chunk_size(header, cursor)
|
||||||
offset = read_offset(header, cursor)
|
offset = read_offset(header, cursor)
|
||||||
|
|
||||||
if offset <= 0:
|
if offset <= 0:
|
||||||
break
|
break
|
||||||
|
|
||||||
block_meta = BlockMeta(data_type, channel_type,
|
block_meta = BlockMeta(data_type, channel_type, text_type, additional_type, chunk_size, offset)
|
||||||
text_type, chunk_size, offset)
|
|
||||||
|
|
||||||
spectra_meta.append(block_meta)
|
spectra_meta.append(block_meta)
|
||||||
|
|
||||||
|
@ -54,6 +64,8 @@ def parse_meta(data: bytes) -> List[BlockMeta]:
|
||||||
|
|
||||||
|
|
||||||
def parse_data(data: bytes, blocks_meta: List[BlockMeta]) -> OpusData:
|
def parse_data(data: bytes, blocks_meta: List[BlockMeta]) -> OpusData:
|
||||||
|
"""parse the data of the opus file using the file header's informations
|
||||||
|
parame"""
|
||||||
opus_data = OpusData()
|
opus_data = OpusData()
|
||||||
for block_meta in blocks_meta:
|
for block_meta in blocks_meta:
|
||||||
try:
|
try:
|
||||||
|
@ -61,8 +73,8 @@ def parse_data(data: bytes, blocks_meta: List[BlockMeta]) -> OpusData:
|
||||||
except UnknownBlockType:
|
except UnknownBlockType:
|
||||||
continue
|
continue
|
||||||
parsed_data = parser(data, block_meta)
|
parsed_data = parser(data, block_meta)
|
||||||
# in some instances, multiple entries - in particular 'AB' seem to be present
|
# in some instances, multiple entries - in particular 'AB' are
|
||||||
# they are added with a key ending by '_(1)', '_(2)', etc...
|
# present. they are added with a key ending by '_(1)', '_(2)', etc...
|
||||||
if name in opus_data.keys():
|
if name in opus_data.keys():
|
||||||
i = 1
|
i = 1
|
||||||
while name + '_(' + str(i) + ')' in opus_data.keys():
|
while name + '_(' + str(i) + ')' in opus_data.keys():
|
||||||
|
|
|
@ -21,6 +21,12 @@ def read_text_type(header: bytes, cursor: int) -> int:
|
||||||
return unpack(UNSIGNED_CHAR, header[p1:p2])[0]
|
return unpack(UNSIGNED_CHAR, header[p1:p2])[0]
|
||||||
|
|
||||||
|
|
||||||
|
def read_additional_type(header: bytes, cursor: int) -> int:
|
||||||
|
p1 = cursor + 3
|
||||||
|
p2 = cursor + 4
|
||||||
|
return unpack(UNSIGNED_CHAR, header[p1:p2])[0]
|
||||||
|
|
||||||
|
|
||||||
def read_chunk_size(header: bytes, cursor: int) -> int:
|
def read_chunk_size(header: bytes, cursor: int) -> int:
|
||||||
p1 = cursor + 4
|
p1 = cursor + 4
|
||||||
p2 = cursor + 8
|
p2 = cursor + 8
|
||||||
|
|
|
@ -0,0 +1,52 @@
|
||||||
|
{% set name = "brukeropusreader" %}
|
||||||
|
{% set version = environ['VERSION'] %}
|
||||||
|
|
||||||
|
package:
|
||||||
|
name: "{{ name|lower }}"
|
||||||
|
version: "{{ version }}"
|
||||||
|
|
||||||
|
source:
|
||||||
|
path: ../
|
||||||
|
|
||||||
|
build:
|
||||||
|
script_env:
|
||||||
|
- VERSION
|
||||||
|
- CONDA_BLD_PATH
|
||||||
|
string: {{ environ['DEVSTRING'] }}
|
||||||
|
noarch: python
|
||||||
|
script: "{{ PYTHON }} -m pip install . -vv"
|
||||||
|
|
||||||
|
requirements:
|
||||||
|
build:
|
||||||
|
- python
|
||||||
|
host:
|
||||||
|
- python
|
||||||
|
- numpy
|
||||||
|
- pip
|
||||||
|
- scipy
|
||||||
|
run:
|
||||||
|
- python
|
||||||
|
- numpy
|
||||||
|
- scipy
|
||||||
|
test:
|
||||||
|
- python {{ python }}
|
||||||
|
- pytest
|
||||||
|
|
||||||
|
test:
|
||||||
|
script_env:
|
||||||
|
- VERSION
|
||||||
|
- CONDA_BLD_PATH
|
||||||
|
imports:
|
||||||
|
- brukeropusreader
|
||||||
|
|
||||||
|
about:
|
||||||
|
home: "https://github.com/spectrochempy/brukeropusreader"
|
||||||
|
license: GPLv3
|
||||||
|
license_family: GPL3
|
||||||
|
summary: "Bruker OPUS File Reader"
|
||||||
|
doc_url: "https://github.com/spectrochempy/brukeropusreader"
|
||||||
|
dev_url: "https://github.com/spectrochempy/brukeropusreader"
|
||||||
|
|
||||||
|
extra:
|
||||||
|
recipe-maintainers:
|
||||||
|
- fernandezc
|
Loading…
Reference in New Issue