Skip to content

Commit 2109cdd

Browse files
authored
Bugfix for shapefile reader (#147)
* 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)
1 parent a05f812 commit 2109cdd

File tree

10 files changed

+320
-1576
lines changed

10 files changed

+320
-1576
lines changed

.github/workflows/tcrm-pylint.yml

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
name: Pylint tests for TCRM
1+
name: Pylint tests for TCRM
22

3-
on:
3+
on:
44
push:
55
branches: [ master, develop ]
66

@@ -12,17 +12,18 @@ jobs:
1212
steps:
1313
- uses: actions/checkout@v2
1414
- name: Set up environment
15-
uses: conda-incubator/setup-miniconda@v2.0.0
16-
with:
17-
python-version: 3.7
18-
mamba-version: "*"
15+
uses: conda-incubator/setup-miniconda@v2
16+
with:
17+
python-version: 3.9
18+
miniforge-variant: Mambaforge
1919
channels: conda-forge,defaults
2020
channel-priority: true
2121
activate-environment: tcrm
2222
environment-file: tcrmenv.yml
2323
auto-activate-base: false
2424
use-only-tar-bz2: true
25-
25+
26+
2627
- name: Install dependencies
2728
run: |
2829
python -m pip install --upgrade pip
@@ -32,7 +33,7 @@ jobs:
3233
pylint --rcfile pylintrc --fail-under=7 `find -regextype egrep -regex '(.*.py)$'` |
3334
tee pylint.txt
3435
- name: Upload pylint.txt as artifact
35-
uses: actions/upload-artifact@v2
36+
uses: actions/upload-artifact@v3
3637
with:
3738
name: pylint report
3839
path: pylint.txt

.github/workflows/tcrm-tests.yml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,21 @@ jobs:
1515
runs-on: ubuntu-latest
1616
strategy:
1717
matrix:
18-
python-version: [3.7, 3.8, 3.9]
18+
python-version: ['3.9', '3.10']
1919
steps:
20-
- uses: actions/checkout@v2
20+
- uses: actions/checkout@v3
2121
- name: Set up environment
22-
uses: conda-incubator/setup-miniconda@v2.0.0
22+
uses: conda-incubator/setup-miniconda@v2
2323
with:
24+
miniforge-variant: MambaForge
2425
python-version: ${{ matrix.python-version }}
25-
mamba-version: "*"
2626
channels: conda-forge,defaults
2727
channel-priority: true
2828
activate-environment: tcrm
2929
environment-file: tcrmenv.yml
3030
auto-activate-base: false
31-
use-only-tar-bz2: true
31+
use-only-tar-bz2: tru
32+
3233

3334
- name: Test with pytest
3435
env:

Evaluate/evaluate.py

Lines changed: 29 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@
3232

3333
from matplotlib import pyplot, cm
3434
from matplotlib.dates import date2num
35-
from mpl_toolkits.basemap import Basemap
35+
from cartopy import crs as ccrs
36+
from cartopy import feature as cfeature
3637
from scipy.stats import scoreatpercentile as percentile
3738
from datetime import datetime
3839

@@ -76,7 +77,7 @@
7677
[ProcessMultipliers]
7778
MaxWorkingThreads = 4
7879
ProcessMultiVersion = 2
79-
ProcessingSegmentSize = 256
80+
ProcessingSegmentSize = 256
8081
WarpMemoryLimit = 500
8182
8283
[Logging]
@@ -169,57 +170,49 @@ def plotDensity(x, y, data, llLon=None, llLat=None, urLon=None, urLat=None,
169170
else:
170171
urcrnrlat = y.max()
171172

172-
meridians = np.arange(dl * np.floor(llcrnrlon / dl),
173-
dl * np.ceil(urcrnrlon / dl), dl)
174-
parallels = np.arange(dl * np.floor(llcrnrlat / dl),
175-
dl * np.ceil(urcrnrlat / dl), dl)
176-
177-
m = Basemap(projection='cyl',
178-
resolution=res,
179-
llcrnrlon=llcrnrlon,
180-
urcrnrlon=urcrnrlon,
181-
llcrnrlat=llcrnrlat,
182-
urcrnrlat=urcrnrlat)
183173

184174
# Set the colour map:
185175
if hasattr(cm, cmap):
186176
cmap = getattr(cm, cmap)
187177
else:
188178
cmap = colours.colourMap(cmap, 'stretched')
189179

190-
if maskocean:
191-
try:
192-
from mpl_toolkits.basemap import maskoceans
193-
except ImportError:
194-
log.debug("Maskoceans module unavailable, skipping this command")
195-
else:
196-
datam = maskoceans(xx, yy, data, inlands=False)
197-
m.pcolormesh(xx, yy, datam, edgecolors='None',
198-
vmin=datarange[0], vmax=datarange[1],
199-
cmap=cmap)
200-
else:
201-
m.pcolormesh(xx, yy, data, edgecolors='None',
202-
vmin=datarange[0], vmax=datarange[1],
203-
cmap=cmap)
180+
ax = pyplot.axes(projection=ccrs.PlateCarree())
181+
pyplot.pcolormesh(xx, yy, data, edgecolors='None',
182+
vmin=datarange[0], vmax=datarange[1],
183+
cmap=cmap, transfom=ccrs.PlateCarree())
204184

205-
m.drawcoastlines(linewidth=0.5)
206185
if maskland:
207-
m.fillcontinents(color='white')
186+
ax.add_feature(cfeature.LAND, zorder=100, edgecolor='k')
187+
188+
if maskocean:
189+
ax.add_feature(cfeature.OCEAN, zorder=100, edgecolor='k')
190+
191+
ax.coastlines(linewidth=0.5)
192+
gl = ax.gridlines(draw_labels=True, crs=ccrs.PlateCarree(), linewidth=0.2)
193+
gl.top_labels = False
194+
gl.right_labels = False
195+
196+
ax.set_extent([llcrnrlon, urcrnrlon,
197+
llcrnrlat, urcrnrlat])
198+
199+
cb = pyplot.colorbar(shrink=0.5, aspect=30,
200+
orientation='horizontal',
201+
extend='max', pad=0.1)
202+
203+
if cb.orientation == 'horizontal':
204+
for t in cb.ax.get_xticklabels():
205+
t.set_fontsize(8)
208206

209-
m.drawparallels(parallels, labels=[1, 0, 0, 0],
210-
fontsize=7.5, linewidth=0.2)
211-
m.drawmeridians(meridians, labels=[0, 0, 0, 1],
212-
fontsize=7.5, linewidth=0.2)
207+
if clabel:
208+
cb.set_label(clabel)
213209
if ylab:
214210
pyplot.ylabel(ylab, fontsize=7.5)
215211
if xlab:
216212
pyplot.xlabel(xlab, fontsize=7.5)
217213
if title:
218214
pyplot.title(title)
219215

220-
pyplot.grid(True)
221-
pyplot.tick_params(direction='out', right='off', top='off')
222-
223216
cb = pyplot.colorbar(shrink=0.5, aspect=30,
224217
orientation='horizontal',
225218
extend='max', pad=0.1)

Evaluate/interpolateTracks.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def interpolate(track, delta, interpolation_type=None):
7373
track.Minute)]
7474
else:
7575
day_ = track.Datetime
76-
76+
7777
timestep = timedelta(delta/24.)
7878
try:
7979
time_ = np.array([d.toordinal() + (d.hour + d.minute/60.)/24.0
@@ -104,7 +104,7 @@ def interpolate(track, delta, interpolation_type=None):
104104
idx[0] = 1
105105
# TODO: Possibly could change `np.mean(dt)` to `dt`?
106106
track.WindSpeed = maxWindSpeed(idx, np.mean(dt), track.Longitude,
107-
track.Latitude, track.CentralPressure,
107+
track.Latitude, track.CentralPressure,
108108
track.EnvPressure)
109109
# Find the indices of valid pressure observations:
110110
validIdx = np.where(track.CentralPressure < sys.maxsize)[0]
@@ -182,7 +182,7 @@ def interpolate(track, delta, interpolation_type=None):
182182
kind='linear')(newtime[firsttime:lasttime])
183183

184184
_nwSpd = interp1d(timestep[validIdx],
185-
track.Speed[validIdx],
185+
track.WindSpeed[validIdx],
186186
kind='linear')(newtime[firsttime:lasttime])
187187

188188
npCentre[firsttime:lasttime] = _npCentre

0 commit comments

Comments
 (0)