DEV: add power spectra + additional_type info

This commit is contained in:
atravert 2022-09-14 16:28:02 +02:00
parent 1b86527b94
commit ff63b8e02f
5 changed files with 96 additions and 12 deletions

View File

@ -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 = {
4: "ScSm Data Parameter",
8: "IgSm Data Parameter",
12: "PhSm Data Parameter",
56: "PwSm Data Parameter",
132: "ScSm_(1) Data Parameter",
136: "IgSm_(1) Data Parameter"
136: "IgSm_(1) Data Parameter",
}
BLOCK_27 = {4: "ScRf Data Parameter",
8: "IgRf Data Parameter",
132: "ScRf_(1) Data Parameter",
136: "IgRf_(1) Data Parameter"}
# parameters of other reference spectral data
BLOCK_27 = {
4: "ScRf Data Parameter",
8: "IgRf Data Parameter",
56: "PwRf Data Parameter",
132: "ScRf_(1) Data Parameter",
136: "IgRf_(1) Data Parameter",
}
DIFFERENT_BLOCKS = {
31: "AB Data Parameter",
@ -56,12 +64,14 @@ class BlockMeta:
data_type: int,
channel_type: int,
text_type: int,
additional_type: int,
chunk_size: int,
offset: int,
):
self.data_type = data_type
self.channel_type = channel_type
self.text_type = text_type
self.additional_type = additional_type
self.chunk_size = chunk_size
self.offset = offset

View File

@ -6,13 +6,17 @@ from brukeropusreader.constants import (
NULL_BYTE,
ENCODING_LATIN,
ENCODING_UTF,
NULL_STR)
NULL_STR,
)
from brukeropusreader.opus_reader import read_chunk
from struct import unpack, error
import numpy as np
def parse_param(data: bytes, block_meta):
"""parse data blocks of parameters
BLOCK_23, BLOCK_27"""
cursor = 0
chunk = read_chunk(data, block_meta)
params = {}

View File

@ -11,6 +11,7 @@ from brukeropusreader.opus_reader import (
read_data_type,
read_channel_type,
read_text_type,
read_additional_type,
read_chunk_size,
read_offset,
)
@ -25,6 +26,15 @@ def read_file(file_path: str) -> OpusData:
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]
spectra_meta = []
cursor = FIRST_CURSOR_POSITION
@ -35,14 +45,14 @@ def parse_meta(data: bytes) -> List[BlockMeta]:
data_type = read_data_type(header, cursor)
channel_type = read_channel_type(header, cursor)
text_type = read_text_type(header, cursor)
additional_type = read_additional_type(header, cursor)
chunk_size = read_chunk_size(header, cursor)
offset = read_offset(header, cursor)
if offset <= 0:
break
block_meta = BlockMeta(data_type, channel_type,
text_type, chunk_size, offset)
block_meta = BlockMeta(data_type, channel_type, text_type, additional_type, chunk_size, offset)
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:
"""parse the data of the opus file using the file header's informations
parame"""
opus_data = OpusData()
for block_meta in blocks_meta:
try:
@ -61,8 +73,8 @@ def parse_data(data: bytes, blocks_meta: List[BlockMeta]) -> OpusData:
except UnknownBlockType:
continue
parsed_data = parser(data, block_meta)
# in some instances, multiple entries - in particular 'AB' seem to be present
# they are added with a key ending by '_(1)', '_(2)', etc...
# in some instances, multiple entries - in particular 'AB' are
# present. they are added with a key ending by '_(1)', '_(2)', etc...
if name in opus_data.keys():
i = 1
while name + '_(' + str(i) + ')' in opus_data.keys():

View File

@ -21,6 +21,12 @@ def read_text_type(header: bytes, cursor: int) -> int:
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:
p1 = cursor + 4
p2 = cursor + 8

52
recipe/meta.yaml.bak Normal file
View File

@ -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