Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • ghsc/geomag/geomag-algorithms
1 result
Show changes
Commits on Source (10)
# Code of Conduct
All contributions to- and interactions surrounding- this project will abide by
the [USGS Code of Scientific Conduct][1].
[1]: https://www.usgs.gov/about/organization/science-support/science-quality-and-integrity/code-scientific-conduct
\ No newline at end of file
# Contributing
Contributions are welcome from the community. Questions can be asked on the
[issues page][1]. Before creating a new issue, please take a moment to search
and make sure a similar issue does not already exist. If one does exist, you
can comment (most simply even with just a `:+1:`) to show your support for that
issue.
If you have direct contributions you would like considered for incorporation
into the project you can [fork this repository][2] and
[submit a merge request][3] for review.
[1]: https://code.usgs.gov/ghsc/geomag/geomag-algorithms/issues
[2]: https://docs.gitlab.com/ee/workflow/forking_workflow.html#creating-a-fork
[3]: https://docs.gitlab.com/ee/gitlab-basics/add-merge-request.html
# Disclaimer
This software is preliminary or provisional and is subject to revision. It is
being provided to meet the need for timely best science. The software has not
received final approval by the U.S. Geological Survey (USGS). No warranty,
expressed or implied, is made by the USGS or the U.S. Government as to the
functionality of the software and related material nor shall the fact of release
constitute any such warranty. The software is provided on the condition that
neither the USGS nor the U.S. Government shall be held liable for any damages
resulting from the authorized or unauthorized use of the software.
Unless otherwise noted, This software is in the public domain because it
contains materials that originally came from the United States Geological
Survey, an agency of the United States Department of Interior. For more
information, see the official USGS copyright policy at
http://www.usgs.gov/visual-id/credit_usgs.html#copyright
Disclaimers
-----------
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
Information provided by this software may be preliminary or provisional and is
subject to revision. It is being provided to meet the need for timely best
science. The information has not received final approval by the U.S. Geological
Survey (USGS) and is provided on the condition that neither the USGS nor the
U.S. Government shall be held liable for any damages resulting from the
authorized or unauthorized use of the information.
# License
Unless otherwise noted, This project is in the public domain in the United
States because it contains materials that originally came from the United
States Geological Survey, an agency of the United States Department of
Interior. For more information, see the official USGS copyright policy at
https://www.usgs.gov/information-policies-and-instructions/copyrights-and-credits
Additionally, we waive copyright and related rights in the work
worldwide through the CC0 1.0 Universal public domain dedication.
## CC0 1.0 Universal Summary
This is a human-readable summary of the
[Legal Code (read the full text)][1].
### No Copyright
The person who associated a work with this deed has dedicated the work to
the public domain by waiving all of his or her rights to the work worldwide
under copyright law, including all related and neighboring rights, to the
extent allowed by law.
You can copy, modify, distribute and perform the work, even for commercial
purposes, all without asking permission.
### Other Information
In no way are the patent or trademark rights of any person affected by CC0,
nor are the rights that other persons may have in the work or in how the
work is used, such as publicity or privacy rights.
Unless expressly stated otherwise, the person who associated a work with
this deed makes no warranties about the work, and disclaims liability for
all uses of the work, to the fullest extent permitted by applicable law.
When using or citing the work, you should not imply endorsement by the
author or the affirmer.
[1]: https://creativecommons.org/publicdomain/zero/1.0/legalcode
[
{
"name": "geomag-algorithms",
"organization": "U.S. Geological Survey",
"description": "Library for processing Geomagnetic timeseries data.",
"version": "1.2.1",
"status": "Development",
"permissions": {
"usageType": "openSource",
"licenses": [
{
"name": "Public Domain, CC0-1.0",
"URL": "https://code.usgs.gov/ghsc/geomag/geomag-algorithms/raw/master/LICENSE.md"
}
]
},
"homepageURL": "https://code.usgs.gov/ghsc/geomag/geomag-algorithms",
"downloadURL": "https://code.usgs.gov/ghsc/geomag/geomag-algorithms/-/archive/master/geomag-algorithms-master.zip",
"disclaimerURL": "https://code.usgs.gov/ghsc/geomag/geomag-algorithms/raw/master/DISCLAIMER.md",
"repositoryURL": "https://code.usgs.gov/ghsc/geomag/geomag-algorithms.git",
"vcs": "git",
"laborHours": 0,
"tags": ["usgs", "geomagnetism", "timeseries", "processing"],
"languages": ["Shell", "Python"],
"contact": {
"name": "HazDev Team",
"email": "gs-haz_dev_team_group@usgs.gov"
},
"date": {
"metadataLastUpdated": "2020-10-07"
}
}
]
\ No newline at end of file
......@@ -535,3 +535,28 @@ def pad_and_trim_trace(trace, starttime, endtime):
trace.data = numpy.concatenate(
[trace.data, numpy.full(cnt, numpy.nan, dtype=numpy.float64)]
)
def round_usecs(time):
"""Rounds residual microseconds to milliseconds.
Parameters
----------
time: UTCDateTime
time containing microsecond values
Returns
----------
time: UTCDateTime
time containing rounded(or non-rounded) microsecond values
"""
usecs = time.microsecond
# round microseconds to nearest millisecond
rounded_usecs = int(round(usecs / 1000, 0)) * 1000
# reset microseconds to 0 at top of second, add second to input time
if rounded_usecs > 999000:
rounded_usecs = 0
time += 1
if rounded_usecs != usecs:
time = time.replace(microsecond=rounded_usecs)
return time
......@@ -6,6 +6,8 @@ import struct
import sys
from datetime import datetime
from ..TimeseriesFactoryException import TimeseriesFactoryException
from ..TimeseriesUtility import round_usecs
import logging
from obspy.core import UTCDateTime
from time import sleep
......@@ -414,7 +416,7 @@ class RawInputClient:
"""
PARAMETERS
----------
time: UTCDateTime
input_time: UTCDateTime
time of the first sample
RETURNS
......@@ -425,11 +427,20 @@ class RawInputClient:
secs: int
usecs: int
"""
# check for presence of residual microseconds
if (time.microsecond / 1000).is_integer() == False:
# create warning message when rounding is necessary
logging.warning(
"residual microsecond values encountered, rounding to nearest millisecond"
)
# round residual microsecond values
time = round_usecs(time)
yr = time.year
doy = time.datetime.timetuple().tm_yday
secs = time.hour * 3600 + time.minute * 60 + time.second
usecs = time.microsecond
return (yr, doy, secs, usecs)
def _open_socket(self):
......
{
"name": "geomag-algorithms",
"version": "1.2.0",
"homepage": "http://geomag.usgs.gov/",
"repository": "https://github.com/usgs/geomag-algorithms.git",
"description": "Geomagnetism algorithms.",
"author": {
"name": "Jeremy Fee",
"email": "jmfee@usgs.gov"
},
"contributors": [
{
"name": "Abram Claycomb",
"email": "aclaycomb@usgs.gov"
}
],
"keywords": [
"usgs",
"geomag",
"hazdev"
],
"scripts": {
"clean": "rimraf '**/*.pyc'",
"coverage": "pytest --cov=geomagio --cov-report xml",
"lint": "flake8 && echo \"No linting errors found\"",
"test": "pytest test",
"watch": "npm-watch"
},
"watch": {
"lint": {
"extensions": "py",
"patterns": [
"bin",
"geomagio",
"test"
]
},
"test": {
"extensions": "py",
"patterns": [
"bin",
"geomagio",
"test"
]
}
},
"license": "Public Domain",
"dependencies": {},
"devDependencies": {
"npm-watch": "^0.3.0",
"rimraf": "^2.6.2"
},
"engines": {
"node": ">=4"
}
}
......@@ -9,7 +9,7 @@ if ssl_cert_file:
setuptools.setup(
name="geomag-algorithms",
version="1.2.0",
version="1.2.1",
description="USGS Geomag Algorithms Library",
url="https://github.com/usgs/geomag-algorithms",
packages=setuptools.find_packages(exclude=["test*"]),
......
......@@ -449,6 +449,22 @@ def test_pad_and_trim_trace_fixfloat():
)
def test_round_usecs():
"""TimeseriesUtility_test.test_round_usecs()
This tests whether microsecond values are rounded or
not depending on residual microsecond values
"""
# test case with no residual microseconds
time = TimeseriesUtility.round_usecs(UTCDateTime("2020-10-07T00:00:00Z"))
assert_equal(time, UTCDateTime("2020-10-07T00:00:00Z"))
# test case with residual microseconds
time = TimeseriesUtility.round_usecs(UTCDateTime("2020-10-07T00:00:00.995600Z"))
assert_equal(time, UTCDateTime("2020-10-07T00:00:00.996000Z"))
# test case with rounding to next second
time = TimeseriesUtility.round_usecs(UTCDateTime("2020-10-07T00:00:00.9995Z"))
assert_equal(time, UTCDateTime("2020-10-07T00:00:01.000Z"))
def _create_trace(data, channel, starttime, delta=60.0):
stats = Stats()
stats.channel = channel
......
"""Tests for RawInputClient.py"""
import numpy
from datetime import datetime
import logging
from obspy.core import Stats, Trace, UTCDateTime
from geomagio.edge import EdgeFactory, RawInputClient
from numpy.testing import assert_equal
......@@ -56,7 +58,7 @@ def test_raw_input_client():
def test__get_tag():
"""edge_test.RawInputClient_test.test_raw_input_client()"""
"""edge_test.RawInputClient_test.test__get_tag()"""
network = "NT"
station = "BOU"
channel = "MVH"
......@@ -72,3 +74,63 @@ def test__get_tag():
)
tag_send = client._get_tag()
assert_equal(tag_send is not None, True)
def test__get_time_values(caplog):
"""edge_test.RawInputClient_test.test__get_time_values()"""
network = "NT"
station = "BOU"
channel = "MVH"
location = "R0"
client = MockRawInputClient(
tag="tag",
host="host",
port="port",
station=station,
channel=channel,
location=location,
network=network,
)
# test rounding up of microsecond value
time = UTCDateTime("2020-10-07T00:00:15.196855Z")
yr, doy, secs, usecs = client._get_time_values(time)
assert_equal(yr, 2020)
assert_equal(doy, 281)
assert_equal(secs, 15)
assert_equal(usecs, 197000)
# test rounding down of microsecond value
time = UTCDateTime("2020-10-07T00:00:15.196455Z")
yr, doy, secs, usecs = client._get_time_values(time)
assert_equal(yr, 2020)
assert_equal(doy, 281)
assert_equal(secs, 15)
assert_equal(usecs, 196000)
# test top of second adjustment
time = UTCDateTime("2020-10-07T00:00:00.999999Z")
yr, doy, secs, usecs = client._get_time_values(time)
assert_equal(yr, 2020)
assert_equal(doy, 281)
assert_equal(secs, 1)
assert_equal(usecs, 0)
# test top of day adjustment
time = UTCDateTime("2020-10-07T23:59:59.999999Z")
yr, doy, secs, usecs = client._get_time_values(time)
assert_equal(yr, 2020)
assert_equal(doy, 282)
assert_equal(secs, 0)
assert_equal(usecs, 0)
# assert if previous 4 tests generate 4 warning messages
assert_equal(len(caplog.messages), 4)
# clear warnings from log
caplog.clear()
# test ideal case
time = UTCDateTime("2020-10-07T00:00:00.232000Z")
yr, doy, secs, usecs = client._get_time_values(time)
assert_equal(yr, 2020)
assert_equal(doy, 281)
assert_equal(secs, 0)
assert_equal(usecs, 232000)
# assert if previous test does not generate a warning message
assert_equal(len(caplog.messages), 0)