Skip to content

Commit

Permalink
Bugfix for shapefile reader (#147)
Browse files Browse the repository at this point in the history
* Change `Speed` to `WindSpeed` in track interpolation
* Remove deprecated Basemap references
* Update conda environment file
* Update actions/checkout to v3, setup-miniconda to v2.2
* Remove deprecated Basemap references
* #145 replace shapefile with pyshp module (#146)
  • Loading branch information
wcarthur committed Feb 14, 2024
1 parent a05f812 commit 2109cdd
Show file tree
Hide file tree
Showing 10 changed files with 320 additions and 1,576 deletions.
17 changes: 9 additions & 8 deletions .github/workflows/tcrm-pylint.yml
@@ -1,6 +1,6 @@
name: Pylint tests for TCRM
name: Pylint tests for TCRM

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

Expand All @@ -12,17 +12,18 @@ jobs:
steps:
- uses: actions/checkout@v2
- name: Set up environment
uses: conda-incubator/setup-miniconda@v2.0.0
with:
python-version: 3.7
mamba-version: "*"
uses: conda-incubator/setup-miniconda@v2
with:
python-version: 3.9
miniforge-variant: Mambaforge
channels: conda-forge,defaults
channel-priority: true
activate-environment: tcrm
environment-file: tcrmenv.yml
auto-activate-base: false
use-only-tar-bz2: true



- name: Install dependencies
run: |
python -m pip install --upgrade pip
Expand All @@ -32,7 +33,7 @@ jobs:
pylint --rcfile pylintrc --fail-under=7 `find -regextype egrep -regex '(.*.py)$'` |
tee pylint.txt
- name: Upload pylint.txt as artifact
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v3
with:
name: pylint report
path: pylint.txt
11 changes: 6 additions & 5 deletions .github/workflows/tcrm-tests.yml
Expand Up @@ -15,20 +15,21 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.7, 3.8, 3.9]
python-version: ['3.9', '3.10']
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Set up environment
uses: conda-incubator/setup-miniconda@v2.0.0
uses: conda-incubator/setup-miniconda@v2
with:
miniforge-variant: MambaForge
python-version: ${{ matrix.python-version }}
mamba-version: "*"
channels: conda-forge,defaults
channel-priority: true
activate-environment: tcrm
environment-file: tcrmenv.yml
auto-activate-base: false
use-only-tar-bz2: true
use-only-tar-bz2: tru


- name: Test with pytest
env:
Expand Down
65 changes: 29 additions & 36 deletions Evaluate/evaluate.py
Expand Up @@ -32,7 +32,8 @@

from matplotlib import pyplot, cm
from matplotlib.dates import date2num
from mpl_toolkits.basemap import Basemap
from cartopy import crs as ccrs
from cartopy import feature as cfeature
from scipy.stats import scoreatpercentile as percentile
from datetime import datetime

Expand Down Expand Up @@ -76,7 +77,7 @@
[ProcessMultipliers]
MaxWorkingThreads = 4
ProcessMultiVersion = 2
ProcessingSegmentSize = 256
ProcessingSegmentSize = 256
WarpMemoryLimit = 500
[Logging]
Expand Down Expand Up @@ -169,57 +170,49 @@ def plotDensity(x, y, data, llLon=None, llLat=None, urLon=None, urLat=None,
else:
urcrnrlat = y.max()

meridians = np.arange(dl * np.floor(llcrnrlon / dl),
dl * np.ceil(urcrnrlon / dl), dl)
parallels = np.arange(dl * np.floor(llcrnrlat / dl),
dl * np.ceil(urcrnrlat / dl), dl)

m = Basemap(projection='cyl',
resolution=res,
llcrnrlon=llcrnrlon,
urcrnrlon=urcrnrlon,
llcrnrlat=llcrnrlat,
urcrnrlat=urcrnrlat)

# Set the colour map:
if hasattr(cm, cmap):
cmap = getattr(cm, cmap)
else:
cmap = colours.colourMap(cmap, 'stretched')

if maskocean:
try:
from mpl_toolkits.basemap import maskoceans
except ImportError:
log.debug("Maskoceans module unavailable, skipping this command")
else:
datam = maskoceans(xx, yy, data, inlands=False)
m.pcolormesh(xx, yy, datam, edgecolors='None',
vmin=datarange[0], vmax=datarange[1],
cmap=cmap)
else:
m.pcolormesh(xx, yy, data, edgecolors='None',
vmin=datarange[0], vmax=datarange[1],
cmap=cmap)
ax = pyplot.axes(projection=ccrs.PlateCarree())
pyplot.pcolormesh(xx, yy, data, edgecolors='None',
vmin=datarange[0], vmax=datarange[1],
cmap=cmap, transfom=ccrs.PlateCarree())

m.drawcoastlines(linewidth=0.5)
if maskland:
m.fillcontinents(color='white')
ax.add_feature(cfeature.LAND, zorder=100, edgecolor='k')

if maskocean:
ax.add_feature(cfeature.OCEAN, zorder=100, edgecolor='k')

ax.coastlines(linewidth=0.5)
gl = ax.gridlines(draw_labels=True, crs=ccrs.PlateCarree(), linewidth=0.2)
gl.top_labels = False
gl.right_labels = False

ax.set_extent([llcrnrlon, urcrnrlon,
llcrnrlat, urcrnrlat])

cb = pyplot.colorbar(shrink=0.5, aspect=30,
orientation='horizontal',
extend='max', pad=0.1)

if cb.orientation == 'horizontal':
for t in cb.ax.get_xticklabels():
t.set_fontsize(8)

m.drawparallels(parallels, labels=[1, 0, 0, 0],
fontsize=7.5, linewidth=0.2)
m.drawmeridians(meridians, labels=[0, 0, 0, 1],
fontsize=7.5, linewidth=0.2)
if clabel:
cb.set_label(clabel)
if ylab:
pyplot.ylabel(ylab, fontsize=7.5)
if xlab:
pyplot.xlabel(xlab, fontsize=7.5)
if title:
pyplot.title(title)

pyplot.grid(True)
pyplot.tick_params(direction='out', right='off', top='off')

cb = pyplot.colorbar(shrink=0.5, aspect=30,
orientation='horizontal',
extend='max', pad=0.1)
Expand Down
6 changes: 3 additions & 3 deletions Evaluate/interpolateTracks.py
Expand Up @@ -73,7 +73,7 @@ def interpolate(track, delta, interpolation_type=None):
track.Minute)]
else:
day_ = track.Datetime

timestep = timedelta(delta/24.)
try:
time_ = np.array([d.toordinal() + (d.hour + d.minute/60.)/24.0
Expand Down Expand Up @@ -104,7 +104,7 @@ def interpolate(track, delta, interpolation_type=None):
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.Latitude, track.CentralPressure,
track.EnvPressure)
# Find the indices of valid pressure observations:
validIdx = np.where(track.CentralPressure < sys.maxsize)[0]
Expand Down Expand Up @@ -182,7 +182,7 @@ def interpolate(track, delta, interpolation_type=None):
kind='linear')(newtime[firsttime:lasttime])

_nwSpd = interp1d(timestep[validIdx],
track.Speed[validIdx],
track.WindSpeed[validIdx],
kind='linear')(newtime[firsttime:lasttime])

npCentre[firsttime:lasttime] = _npCentre
Expand Down

0 comments on commit 2109cdd

Please sign in to comment.