Skip to content

Commit

Permalink
Merge branch 'SCECcode:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
bayonato89 authored Sep 12, 2023
2 parents e3d71b5 + efde281 commit 9a71bfe
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-sphinx.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
generate-run-shell: true
environment-file: requirements.yml
create-args: >-
python=3.10
python=3.9
pillow
sphinx
sphinx-gallery
Expand Down
12 changes: 6 additions & 6 deletions .github/workflows/publish-pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ jobs:

steps:
- uses: actions/checkout@v2
- uses: conda-incubator/setup-miniconda@v2
- uses: mamba-org/setup-micromamba@v1
with:
activate-environment: csep-dev
python-version: '3.10'
channels: conda-forge
generate-run-shell: true
environment-file: requirements.yml
create-args: >-
python=3.10
- name: Install dependencies
- name: Check dependencies
run: |
conda env update --file requirements.yml
conda info -a
conda list
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ Software support for pyCSEP is provided by that Southern California Earthquake C
This group supports several research software distributions including UCVM. Users can report issues and feature requests
using the pyCSEP github-based issue tracking link below. Developers will also respond to emails sent to the SCEC software contact listed below.
1. [pyCSEP Issues](https://github.com/SCECcode/pycsep/issues)
2. Email Contact: software [at] scec [dot] usc [dot] edu
2. Email Contact: software [at] scec [dot] org

# Contributing:
We welcome contributions to the pyCSEP Toolkit. If you would like to contribute to this package, including software, tests, and documentation,
Expand Down
2 changes: 1 addition & 1 deletion csep/core/catalogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ def write_ascii(self, filename, write_header=True, write_empty=True, append=Fals
write_string = 'a'
else:
write_string = 'w'
with open(filename, write_string) as outfile:
with open(filename, write_string, newline='') as outfile:
writer = csv.DictWriter(outfile, fieldnames=header, delimiter=',')
if write_header:
writer.writeheader()
Expand Down
20 changes: 19 additions & 1 deletion csep/utils/time_utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import calendar
import datetime
import re
import os
import warnings
from csep.utils.constants import SECONDS_PER_ASTRONOMICAL_YEAR, SECONDS_PER_DAY

Expand All @@ -17,8 +18,25 @@ def epoch_time_to_utc_datetime(epoch_time_milli):
"""
if epoch_time_milli is None:
return epoch_time_milli

epoch_time = epoch_time_milli / 1000
dt = datetime.datetime.fromtimestamp(epoch_time, datetime.timezone.utc)

if os.name == "nt" and epoch_time < 0:

if isinstance(epoch_time, int):
sec = epoch_time
milli_sec = 0
else:
whole, frac = str(epoch_time).split(".")
sec = int(whole)
milli_sec = int(frac) * -1
dt = datetime.datetime(1970, 1, 1) + datetime.timedelta(
seconds=sec,
milliseconds=milli_sec
)
else:
dt = datetime.datetime.fromtimestamp(epoch_time, datetime.timezone.utc)

return dt

def datetime_to_utc_epoch(dt):
Expand Down
7 changes: 5 additions & 2 deletions tests/test_time_utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,8 @@ def test_decimal_year_epoch(self):
test_year = decimal_year(epoch_time_to_utc_datetime(epoch))
self.assertAlmostEqual(year, test_year)



def test_negative_epoch(self):
year = 1969.12315213421321321
epoch = decimal_year_to_utc_epoch(year)
test_year = decimal_year(epoch_time_to_utc_datetime(epoch))
self.assertAlmostEqual(year, test_year)

0 comments on commit 9a71bfe

Please sign in to comment.