diff --git a/recipes/mseedlib/meta.yaml b/recipes/mseedlib/meta.yaml new file mode 100644 index 0000000000000..36a81c5304a9e --- /dev/null +++ b/recipes/mseedlib/meta.yaml @@ -0,0 +1,56 @@ +{% set name = "mseedlib" %} +{% set version = "0.0.6" %} +{% set sha256 = "ceea0ea9fee075f5c3222837d23f2c196f7dd6012bdd96f3c54fc72ef0d1c540" %} + +package: + name: {{ name|lower }} + version: {{ version }} + +source: + url: https://pypi.org/packages/source/{{ name[0] }}/{{ name }}/mseedlib-{{ version }}.tar.gz + sha256: {{ sha256 }} + +build: + noarch: python + script: {{ PYTHON }} -m pip install . -vv --no-deps --no-build-isolation + number: 0 + +requirements: + build: + - {{ compiler('c') }} + - {{ stdlib('c') }} + - make + host: + - python >=3.9 + - hatchling >=1.21.0 + - pip + run: + - python >=3.9 + +test: + imports: + - mseedlib + commands: + - pip check + requires: + - pip + +about: + home: https://github.com/EarthScope/mseedlib + summary: 'A Python package for reading and writing miniSEED formatted data' + description: | + The mseedlib package allows for reading and writing of miniSEED + (https://docs.fdsn.org/projects/miniseed3) formatted data, which is + commonly used for seismological and other geophysical time series data. + The module leverages the C-language libmseed + (https://earthscope.github.io/libmseed) for most of the heavy + data format and manipulation work. + license: Apache-2.0 + license_file: + - LICENSE + - src/mseedlib/libmseed/LICENSE + +extra: + recipe-maintainers: + - megies + - chad-earthscope diff --git a/recipes/mseedlib/run_test.py b/recipes/mseedlib/run_test.py new file mode 100644 index 0000000000000..6994958767ee7 --- /dev/null +++ b/recipes/mseedlib/run_test.py @@ -0,0 +1,49 @@ +import math +import tempfile +from mseedlib import MSTraceList, timestr2nstime + +# Generate synthetic sinusoid data, starting at 0, 45, and 90 degrees +data0 = list(map(lambda x: int(math.sin(math.radians(x)) * 500), range(0, 500))) +data1 = list(map(lambda x: int(math.sin(math.radians(x)) * 500), range(45, 500 + 45))) +data2 = list(map(lambda x: int(math.sin(math.radians(x)) * 500), range(90, 500 + 90))) + +mstl = MSTraceList() + +sample_rate = 40.0 +start_time = timestr2nstime("2024-01-01T15:13:55.123456789Z") +format_version = 2 +record_length = 512 + +# Add synthetic data to the trace list +mstl.add_data(sourceid="FDSN:XX_TEST__B_S_0", + data_samples=data0, sample_type='i', + sample_rate=sample_rate, start_time=start_time) + +mstl.add_data(sourceid="FDSN:XX_TEST__B_S_0", + data_samples=data1, sample_type='i', + sample_rate=sample_rate, start_time=start_time) + +mstl.add_data(sourceid="FDSN:XX_TEST__B_S_0", + data_samples=data2, sample_type='i', + sample_rate=sample_rate, start_time=start_time) + +# Record handler called for each generated record +def record_handler(record, handler_data): + handler_data['fh'].write(record) + +with tempfile.TemporaryFile() as file_handle: + # Generate miniSEED records + mstl.pack(record_handler, + {'fh': file_handle}, + flush_data=True) + # file pointer should have been moved + assert file_handle.tell() > 0 + # magic numbers at start of file, see + # https://docs.fdsn.org/projects/miniseed3/en/latest/definition.html + file_handle.seek(0) + assert file_handle.read(2) == b'MS' + # next should be an uint8 value of 3 for MiniSEED version 3 + assert file_handle.read(1) == b'\x03' + # later on we can look for the source id and we should be ok + file_handle.seek(40) + assert file_handle.read(19) == b'FDSN:XX_TEST__B_S_0'