Skip to content

Commit a3def9a

Browse files
authored
Merge branch 'master' into curvilinear-index-search
2 parents 41a04a0 + 6c83aa0 commit a3def9a

6 files changed

Lines changed: 21 additions & 8 deletions

File tree

environment_py3_osx.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ dependencies:
2525
- six>=1.10.0
2626
- xarray>=0.10.8
2727
- dask>=2.0
28-
- cftime
28+
- cftime>=1.3.1
2929
- pytest
3030
- nbval
3131
- scikit-learn

environment_py3_win.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ dependencies:
2222
- six>=1.10.0
2323
- xarray>=0.5.1
2424
- dask>=2.0
25-
- cftime
25+
- cftime>=1.3.1
2626
- ipykernel<5.0
2727
- pytest
2828
- nbval

environment_py3p6_linux.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ dependencies:
2424
- scipy>=0.16.0
2525
- six >=1.10.0
2626
- xarray>=0.10.8
27-
- cftime
27+
- cftime>=1.3.1
2828
- dask>=2.0
2929
- pytest
3030
- nbval

parcels/kernel.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -388,16 +388,15 @@ def remove_deleted_soa(self, pset, output_file, endtime):
388388
This deletion function is targetted to index-addressable, random-access array-collections.
389389
"""
390390
# Indices marked for deletion.
391-
bool_indices = np.array([p.state == OperationCode.Delete for p in pset])
391+
bool_indices = pset.collection.state == OperationCode.Delete
392392
indices = np.where(bool_indices)[0]
393393
if len(indices) > 0 and output_file is not None:
394394
output_file.write(pset, endtime, deleted_only=bool_indices)
395395
pset.remove_indices(indices)
396396

397397
def execute(self, pset, endtime, dt, recovery=None, output_file=None, execute_once=False):
398398
"""Execute this Kernel over a ParticleSet for several timesteps"""
399-
for p in pset:
400-
p.set_state(StateCode.Evaluate)
399+
pset.collection.state[:] = StateCode.Evaluate
401400

402401
if abs(dt) < 1e-6 and not execute_once:
403402
logger.warning_once("'dt' is too small, causing numerical accuracy limit problems. Please chose a higher 'dt' and rather scale the 'time' axis of the field accordingly. (related issue #762)")

parcels/particlesets/baseparticleset.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from datetime import timedelta as delta
66
from os import path
77
import time as time_module
8+
import cftime
89

910
import progressbar
1011

@@ -350,6 +351,8 @@ def execute(self, pyfunc=AdvectionRK4, endtime=None, runtime=None, dt=1.,
350351
raise RuntimeError('endtime must be either a datetime or a double')
351352
if isinstance(endtime, datetime):
352353
endtime = np.datetime64(endtime)
354+
elif isinstance(endtime, cftime.datetime):
355+
endtime = self.time_origin.reltime(endtime)
353356
if isinstance(endtime, np.datetime64):
354357
if self.time_origin.calendar is None:
355358
raise NotImplementedError('If fieldset.time_origin is not a date, execution endtime must be a double')

parcels/tools/converters.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# flake8: noqa: E999
12
import inspect
23
from datetime import timedelta as delta
34
from math import cos
@@ -53,9 +54,19 @@ def reltime(self, time):
5354
return (time - self.time_origin) / np.timedelta64(1, 's')
5455
elif self.calendar in _get_cftime_calendars():
5556
if isinstance(time, (list, np.ndarray)):
56-
return np.array([(t - self.time_origin).total_seconds() for t in time])
57+
try:
58+
return np.array([(t - self.time_origin).total_seconds() for t in time])
59+
except ValueError:
60+
raise ValueError("Cannot subtract 'time' (a %s object) from a %s calendar.\n"
61+
"Provide 'time' as a %s object?"
62+
% (type(time), self.calendar, type(self.time_origin)))
5763
else:
58-
return (time - self.time_origin).total_seconds()
64+
try:
65+
return (time - self.time_origin).total_seconds()
66+
except ValueError:
67+
raise ValueError("Cannot subtract 'time' (a %s object) from a %s calendar.\n"
68+
"Provide 'time' as a %s object?"
69+
% (type(time), self.calendar, type(self.time_origin)))
5970
elif self.calendar is None:
6071
return time - self.time_origin
6172
else:

0 commit comments

Comments
 (0)