Skip to content

Commit

Permalink
Update to Github actions
Browse files Browse the repository at this point in the history
Also fix datetime issues in track.ncReadTrackData
  • Loading branch information
wcarthur committed Apr 22, 2021
1 parent 41580d9 commit 73c2049
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 10 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/tcrm-tests.yml
@@ -0,0 +1,29 @@
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions

name: Unit tests for TCRM

on:
push:
branches: [ master, develop ]
pull_request:
branches: [ master, develop ]

jobs:
Hazimp:
name: Test HazImp
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up environment
uses: conda-incubator/setup-miniconda@v2.0.0
with:
activate-environment: tcrm
environment-file: tcrmenv.yml
python-version: 3.7
auto-activate-base: false

- name: Test with nose
shell: bash -l {0}
run: |
python tests/run.py
4 changes: 2 additions & 2 deletions Evaluate/interpolateTracks.py
Expand Up @@ -84,7 +84,7 @@ def interpolate(track, delta, interpolation_type=None):
else:
raise
dt_ = 24.0 * np.diff(time_)
dt = np.empty(len(track.data), dtype=float)
dt = np.zeros(len(track.data), dtype=float)
dt[1:] = dt_

# Convert all times to a time after initial observation:
Expand All @@ -93,13 +93,13 @@ def interpolate(track, delta, interpolation_type=None):
newtime = np.arange(timestep[0], timestep[-1] + .01, delta)
newtime[-1] = timestep[-1]
_newtime = (newtime / 24.) + time_[0]

newdates = num2date(_newtime)
newdates = np.array([n.replace(tzinfo=None) for n in newdates])

if not hasattr(track, 'Speed'):
idx = np.zeros(len(track.data))
idx[0] = 1
# TODO: Possibly could change `np.mean(dt)` to `dt`?
track.WindSpeed = maxWindSpeed(idx, np.mean(dt), track.Longitude,
track.Latitude, track.CentralPressure,
track.EnvPressure)
Expand Down
12 changes: 6 additions & 6 deletions README.rst
Expand Up @@ -65,18 +65,18 @@ TCRM requires:
Status
======

.. image:: https://travis-ci.org/GeoscienceAustralia/tcrm.svg?branch=develop
:target: https://travis-ci.org/GeoscienceAustralia/tcrm
.. image:: https://github.com/GeoscienceAustralia/tcrm/actions/workflows/tcrm-tests.yml/badge.svg?branch=master
:target: https://github.com/GeoscienceAustralia/tcrm/actions/workflows/tcrm-tests.yml
:alt: Build status


.. image:: https://coveralls.io/repos/GeoscienceAustralia/tcrm/badge.svg?branch=develop
:target: https://coveralls.io/r/GeoscienceAustralia/tcrm?branch=develop
.. image:: https://coveralls.io/repos/GeoscienceAustralia/tcrm/badge.svg?branch=master
:target: https://coveralls.io/r/GeoscienceAustralia/tcrm?branch=master
:alt: Test coverage


.. image:: https://landscape.io/github/GeoscienceAustralia/tcrm/develop/landscape.svg?style=flat
:target: https://landscape.io/github/GeoscienceAustralia/tcrm/develop
.. image:: https://landscape.io/github/GeoscienceAustralia/tcrm/master/landscape.svg?style=flat
:target: https://landscape.io/github/GeoscienceAustralia/tcrm/master
:alt: Code Health

.. image:: https://zenodo.org/badge/DOI/10.5281/zenodo.4070660.svg
Expand Down
8 changes: 6 additions & 2 deletions Utilities/track.py
Expand Up @@ -25,6 +25,7 @@
from Utilities.maputils import bearing2theta

from netCDF4 import Dataset, date2num, num2date
from cftime import num2pydate

try:
from exceptions import WindowsError
Expand Down Expand Up @@ -206,11 +207,13 @@ def ncReadTrackData(trackfile):
units = ncobj.getncattr('time_units')
calendar = ncobj.getncattr('calendar')
dtt = num2date(dt[:], units, calendar)
# Convert to true python datetimes
dtconversion = [datetime.strptime(d.strftime(), "%Y-%m-%d %H:%M:%S") for d in dtt]
newtd = np.zeros(len(dtt), dtype=track_dtype)
for f in ncobj.variables.keys():
if f != 'Datetime' and f in track_dtype.names:
newtd[f] = ncobj.variables[f][:]
newtd['Datetime'] = dtt
newtd['Datetime'] = dtconversion
track = Track(newtd)
track.trackfile = trackfile
track.trackId = eval(ncobj.trackId)
Expand All @@ -237,7 +240,8 @@ def ncReadTrackData(trackfile):
for f in track_data.dtype.names:
if f != 'Datetime' and f in track_dtype.names:
newtd[f] = track_data[f]
newtd['Datetime'] = dt
dtconversion = [datetime.strptime(d.strftime(), "%Y-%m-%d %H:%M:%S") for d in dt]
newtd['Datetime'] = dtconversion

track = Track(newtd)
track.trackfile = trackfile
Expand Down

0 comments on commit 73c2049

Please sign in to comment.