Skip to content

Commit

Permalink
Merge pull request #62 from leosaffin/merge-master
Browse files Browse the repository at this point in the history
Merge master
  • Loading branch information
leosaffin authored Nov 15, 2024
2 parents 6149cef + 22ac221 commit fc77aed
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 6 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,20 @@

A python package for working with various forms of feature tracking data

## Version 1 coming soon! Subscribe for notification.
We will release version 1 soon (by the end of November 2024). We advice you wait for this version to install the package. To stay updated about it, there are two options:
1. Most specific: Subscribe to [this discussion](https://github.com/Huracan-project/huracanpy/discussions/57), that we will use to communicate with our community of users.
2. Less specific: "Watch" the repo by clicking the button on the top-right of this page. Select "custom" then tick "discussions". You can always go back if there turns out to be too much emails.
(We wish there was a better way for you to subscribe to announcements. If you agree with us, please up [this issue](https://github.com/orgs/community/discussions/3951).)

## Installation
To install the package, you can use `pip`: `pip install huracanpy`.

This can fail with older python versions due to issues with installing cartopy through
pip. If this happens, use conda to install cartopy first
(e.g. `conda install -c conda-forge cartopy`), then install huracanpy as normal


## Usage
The idea of this package is to be a standard way for working with cyclone track data. We
were all working on track data, but in slightly different ways which makes sharing code
Expand Down
12 changes: 9 additions & 3 deletions huracanpy/info/_time.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,15 @@ def season(track_id, lat, time, convention="short"):
# Derive values
hemi = hemisphere(lat)

time = pd.to_datetime(time)
year = time.year
month = time.month
try:
time = pd.to_datetime(time)
year = time.year
month = time.month
except TypeError:
# Fix for cftime
year = np.array([t.year for t in time])
month = np.array([t.month for t in time])

# Store in a dataframe
df = pd.DataFrame(
{"hemi": hemi, "year": year, "month": month, "track_id": track_id}
Expand Down
16 changes: 16 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import datetime
from collections import namedtuple

import cftime
import numpy as np
import xarray as xr

Expand Down Expand Up @@ -32,6 +33,21 @@ def tracks_with_extra_coord(tracks_csv):
)


@pytest.fixture()
def tracks_year():
return huracanpy.load(huracanpy.example_year_file)


@pytest.fixture()
def tracks_year_cftime():
tracks = huracanpy.load(huracanpy.example_year_file)
time = [
cftime.datetime(t.dt.year, t.dt.month, t.dt.day, t.dt.hour) for t in tracks.time
]
tracks["time"] = ("record", time)
return tracks


@pytest.fixture()
def tracks_minus180_plus180():
return xr.Dataset(
Expand Down
9 changes: 6 additions & 3 deletions tests/test_info/test_time.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import pytest
import numpy as np

import huracanpy
Expand Down Expand Up @@ -42,9 +43,11 @@ def test_time_components(tracks_csv):
np.testing.assert_equal(hour, hours)


def test_seasons():
data = huracanpy.load(huracanpy.example_year_file)
season = huracanpy.info.season(data.track_id, data.lat, data.time)
@pytest.mark.parametrize(("tracks",), [("tracks_year",), ("tracks_year_cftime",)])
def test_seasons(tracks, request):
tracks = request.getfixturevalue(tracks)

season = huracanpy.info.season(tracks.track_id, tracks.lat, tracks.time)
assert season.astype(int).min() == 1996
assert season.astype(int).max() == 1997
np.testing.assert_approx_equal(season.astype(int).mean(), 1996.09894459, 1e-6)

0 comments on commit fc77aed

Please sign in to comment.