Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add recipe for mseedlib #29360

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions recipes/mseedlib/meta.yaml
Original file line number Diff line number Diff line change
@@ -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
49 changes: 49 additions & 0 deletions recipes/mseedlib/run_test.py
Original file line number Diff line number Diff line change
@@ -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'
Loading