mseedlib


Namemseedlib JSON
Version 0.0.2 PyPI version JSON
download
home_page
SummaryA Python package for reading and writing miniSEED formatted data
upload_time2024-01-28 21:48:58
maintainer
docs_urlNone
author
requires_python>=3.8
licenseApache-2.0
keywords data miniseed mseed seismic seismology waveform
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # mseedlib - a Python package to read and write miniSEED formatted data

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.

## Installation

The [releases](https://pypi.org/project/mseedlib/) should be installed
directly from PyPI with, for example, `pip install mseedlib`.
The package does not depend on anything other than the Python standard library.

## Example usage

Working programs for a variety of use cases ca be found in the
[examples](https://github.com/EarthScope/mseedlib/tree/main/examples) directory of the repository.

Read a file and print details from each record:
```Python
from mseedlib import MS3RecordReader,TimeFormat

with MS3RecordReader('testdata-3channel-signal.mseed3') as msreader:
    for msr in msreader:
        # Print values directly
        print(f'   SourceID: {msr.sourceid}, record length {msr.reclen}')
        print(f' Start Time: {msr.starttime_str(timeformat=TimeFormat.ISOMONTHDAY_SPACE_Z)}')
        print(f'    Samples: {msr.samplecnt}')

        # Alternatively, use the library print function
        msr.print()
```

Read a file into a trace list and print the list:
```Python
from mseedlib import MSTraceList

mstl = MSTraceList('testdata-3channel-signal.mseed3')

# Print the trace list using the library print function
mstl.print(details=1, gaps=True)

# Alternatively, traverse the data structures and print each trace ID and segment
for traceid in mstl.traceids():
    print(traceid)

    for segment in traceid.segments():
        print('  ', segment)
```

Writing miniSEED requires specifying a "record handler" function that is
a callback to consume, and do whatever you want, with generated records.

Simple example of writing multiple channels of data:
```Python
import math
from mseedlib import MSTraceList, timestr2nstime

# Generate synthetic sinusoid data, starting at 9, 45, and 90 degrees
data0 = list(map(lambda x: int(math.sin(math.radians(0)) * 500), range(0, 500)))
data1 = list(map(lambda x: int(math.sin(math.radians(45)) * 500), range(45, 500 + 45)))
data2 = list(map(lambda x: int(math.sin(math.radians(90)) * 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)

file_handle = open('output.mseed', 'wb')

# Generate miniSEED records
mstl.pack(record_handler,
          {'fh':file_handle},
          flush_data=True)
```

## Package design rationale

The package functionality and exposed API are designed to support the most
common use cases of reading and writing miniSEED data using `libmseed`.
Extensions of data handling beyond the functionality of the library are
out-of-scope for this package.  Furthermore, the naming of functions,
classes, arguments, etc. follows the naming used in the library in order
to reference their fundamentals at the C level if needed; even though this
leaves some names distinctly non-Pythonic.

In a nutshell, the goal of this package is to provide just enough of a Python
layer to `libmseed` to handle the most common cases of miniSEED data without
needing to know any of the C-level details.

## License

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

[http://www.apache.org/licenses/LICENSE-2.0](http://www.apache.org/licenses/LICENSE-2.0)

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Copyright (C) 2023 Chad Trabant, EarthScope Data Services

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "mseedlib",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": "",
    "keywords": "data,miniseed,mseed,seismic,seismology,waveform",
    "author": "",
    "author_email": "EarthScope Data Services <software@earthscope.org>",
    "download_url": "https://files.pythonhosted.org/packages/fd/f8/1eee621c22590733b04c5bfab5585fd7e595dfc5ede36e4c4318dd2a7277/mseedlib-0.0.2.tar.gz",
    "platform": null,
    "description": "# mseedlib - a Python package to read and write miniSEED formatted data\n\nThe mseedlib package allows for reading and writing of [miniSEED](https://docs.fdsn.org/projects/miniseed3)\nformatted data, which is commonly used for seismological and other geophysical\ntime series data.\n\nThe module leverages the C-language [libmseed](https://earthscope.github.io/libmseed)\nfor most of the heavy data format and manipulation work.\n\n## Installation\n\nThe [releases](https://pypi.org/project/mseedlib/) should be installed\ndirectly from PyPI with, for example, `pip install mseedlib`.\nThe package does not depend on anything other than the Python standard library.\n\n## Example usage\n\nWorking programs for a variety of use cases ca be found in the\n[examples](https://github.com/EarthScope/mseedlib/tree/main/examples) directory of the repository.\n\nRead a file and print details from each record:\n```Python\nfrom mseedlib import MS3RecordReader,TimeFormat\n\nwith MS3RecordReader('testdata-3channel-signal.mseed3') as msreader:\n    for msr in msreader:\n        # Print values directly\n        print(f'   SourceID: {msr.sourceid}, record length {msr.reclen}')\n        print(f' Start Time: {msr.starttime_str(timeformat=TimeFormat.ISOMONTHDAY_SPACE_Z)}')\n        print(f'    Samples: {msr.samplecnt}')\n\n        # Alternatively, use the library print function\n        msr.print()\n```\n\nRead a file into a trace list and print the list:\n```Python\nfrom mseedlib import MSTraceList\n\nmstl = MSTraceList('testdata-3channel-signal.mseed3')\n\n# Print the trace list using the library print function\nmstl.print(details=1, gaps=True)\n\n# Alternatively, traverse the data structures and print each trace ID and segment\nfor traceid in mstl.traceids():\n    print(traceid)\n\n    for segment in traceid.segments():\n        print('  ', segment)\n```\n\nWriting miniSEED requires specifying a \"record handler\" function that is\na callback to consume, and do whatever you want, with generated records.\n\nSimple example of writing multiple channels of data:\n```Python\nimport math\nfrom mseedlib import MSTraceList, timestr2nstime\n\n# Generate synthetic sinusoid data, starting at 9, 45, and 90 degrees\ndata0 = list(map(lambda x: int(math.sin(math.radians(0)) * 500), range(0, 500)))\ndata1 = list(map(lambda x: int(math.sin(math.radians(45)) * 500), range(45, 500 + 45)))\ndata2 = list(map(lambda x: int(math.sin(math.radians(90)) * 500), range(90, 500 + 90)))\n\nmstl = MSTraceList()\n\nsample_rate = 40.0\nstart_time = timestr2nstime(\"2024-01-01T15:13:55.123456789Z\")\nformat_version = 2\nrecord_length = 512\n\n# Add synthetic data to the trace list\nmstl.add_data(sourceid=\"FDSN:XX_TEST__B_S_0\",\n              data_samples=data0, sample_type='i',\n              sample_rate=sample_rate, start_time=start_time)\n\nmstl.add_data(sourceid=\"FDSN:XX_TEST__B_S_0\",\n              data_samples=data1, sample_type='i',\n              sample_rate=sample_rate, start_time=start_time)\n\nmstl.add_data(sourceid=\"FDSN:XX_TEST__B_S_0\",\n              data_samples=data2, sample_type='i',\n              sample_rate=sample_rate, start_time=start_time)\n\n# Record handler called for each generated record\ndef record_handler(record, handler_data):\n    handler_data['fh'].write(record)\n\nfile_handle = open('output.mseed', 'wb')\n\n# Generate miniSEED records\nmstl.pack(record_handler,\n          {'fh':file_handle},\n          flush_data=True)\n```\n\n## Package design rationale\n\nThe package functionality and exposed API are designed to support the most\ncommon use cases of reading and writing miniSEED data using `libmseed`.\nExtensions of data handling beyond the functionality of the library are\nout-of-scope for this package.  Furthermore, the naming of functions,\nclasses, arguments, etc. follows the naming used in the library in order\nto reference their fundamentals at the C level if needed; even though this\nleaves some names distinctly non-Pythonic.\n\nIn a nutshell, the goal of this package is to provide just enough of a Python\nlayer to `libmseed` to handle the most common cases of miniSEED data without\nneeding to know any of the C-level details.\n\n## License\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n[http://www.apache.org/licenses/LICENSE-2.0](http://www.apache.org/licenses/LICENSE-2.0)\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n\nCopyright (C) 2023 Chad Trabant, EarthScope Data Services\n",
    "bugtrack_url": null,
    "license": "Apache-2.0",
    "summary": "A Python package for reading and writing miniSEED formatted data",
    "version": "0.0.2",
    "project_urls": {
        "Homepage": "https://github.com/EarthScope/mseedlib",
        "Issues": "https://github.com/EarthScope/mseedlib/issues"
    },
    "split_keywords": [
        "data",
        "miniseed",
        "mseed",
        "seismic",
        "seismology",
        "waveform"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "654f791f20a1b4c9d82b28b6c0c964097e60c3d9b2fc140c14b974669cf5a973",
                "md5": "49f527a8bc06fd53d2f0a478852b2001",
                "sha256": "28102e3592b4a78be97f84bf92d172fd6d76f5f7d1bed5295802d155c43329da"
            },
            "downloads": -1,
            "filename": "mseedlib-0.0.2-py3-none-macosx_14_0_x86_64.whl",
            "has_sig": false,
            "md5_digest": "49f527a8bc06fd53d2f0a478852b2001",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 227052,
            "upload_time": "2024-01-28T21:48:55",
            "upload_time_iso_8601": "2024-01-28T21:48:55.151110Z",
            "url": "https://files.pythonhosted.org/packages/65/4f/791f20a1b4c9d82b28b6c0c964097e60c3d9b2fc140c14b974669cf5a973/mseedlib-0.0.2-py3-none-macosx_14_0_x86_64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "fdf81eee621c22590733b04c5bfab5585fd7e595dfc5ede36e4c4318dd2a7277",
                "md5": "1e21f3e345cc5a9e1aa784201bfb1cbe",
                "sha256": "a30625b35619a892def158d53208257b2aae31d93ec2e70cdedc103905cae264"
            },
            "downloads": -1,
            "filename": "mseedlib-0.0.2.tar.gz",
            "has_sig": false,
            "md5_digest": "1e21f3e345cc5a9e1aa784201bfb1cbe",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 1274828,
            "upload_time": "2024-01-28T21:48:58",
            "upload_time_iso_8601": "2024-01-28T21:48:58.641254Z",
            "url": "https://files.pythonhosted.org/packages/fd/f8/1eee621c22590733b04c5bfab5585fd7e595dfc5ede36e4c4318dd2a7277/mseedlib-0.0.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-01-28 21:48:58",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "EarthScope",
    "github_project": "mseedlib",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "mseedlib"
}
        
Elapsed time: 0.17507s