|
53 | 53 |
|
54 | 54 | from parcels.fieldset import FieldSet |
55 | 55 |
|
56 | | -__all__ = ["Field", "NestedField", "VectorField"] |
| 56 | +__all__ = ["Field", "VectorField"] |
57 | 57 |
|
58 | 58 |
|
59 | 59 | def _isParticle(key): |
@@ -140,11 +140,6 @@ class Field: |
140 | 140 | Write the Field in NetCDF format at the same frequency as the ParticleFile outputdt, |
141 | 141 | using a filenaming scheme based on the ParticleFile name |
142 | 142 |
|
143 | | - Examples |
144 | | - -------- |
145 | | - For usage examples see the following tutorials: |
146 | | -
|
147 | | - * `Nested Fields <../examples/tutorial_NestedFields.ipynb>`__ |
148 | 143 | """ |
149 | 144 |
|
150 | 145 | allow_time_extrapolation: bool |
@@ -1352,75 +1347,3 @@ def __getitem__(self, key): |
1352 | 1347 | return self.eval(*key) |
1353 | 1348 | except tuple(AllParcelsErrorCodes.keys()) as error: |
1354 | 1349 | return _deal_with_errors(error, key, vector_type=self.vector_type) |
1355 | | - |
1356 | | - |
1357 | | -class NestedField(list): |
1358 | | - """NestedField is a class that allows for interpolation of fields on different grids of potentially varying resolution. |
1359 | | -
|
1360 | | - The NestedField class is a list of Fields where the first Field that contains the particle within the domain is then used for interpolation. |
1361 | | - This induces that the order of the fields in the list matters. |
1362 | | - Each one it its turn, a field is interpolated: if the interpolation succeeds or if an error other |
1363 | | - than `ErrorOutOfBounds` is thrown, the function is stopped. Otherwise, next field is interpolated. |
1364 | | - NestedField returns an `ErrorOutOfBounds` only if last field is as well out of boundaries. |
1365 | | - NestedField is composed of either Fields or VectorFields. |
1366 | | -
|
1367 | | - Parameters |
1368 | | - ---------- |
1369 | | - name : str |
1370 | | - Name of the NestedField |
1371 | | - F : list of Field |
1372 | | - List of fields (order matters). F can be a scalar Field, a VectorField, or the zonal component (U) of the VectorField |
1373 | | - V : list of Field |
1374 | | - List of fields defining the meridional component of a VectorField, if F is the zonal component. (default: None) |
1375 | | - W : list of Field |
1376 | | - List of fields defining the vertical component of a VectorField, if F and V are the zonal and meridional components (default: None) |
1377 | | -
|
1378 | | -
|
1379 | | - Examples |
1380 | | - -------- |
1381 | | - See `here <../examples/tutorial_NestedFields.ipynb>`__ |
1382 | | - for a detailed tutorial |
1383 | | -
|
1384 | | - """ |
1385 | | - |
1386 | | - def __init__(self, name: str, F, V=None, W=None): |
1387 | | - if V is None: |
1388 | | - if isinstance(F[0], VectorField): |
1389 | | - vector_type = F[0].vector_type |
1390 | | - for Fi in F: |
1391 | | - assert isinstance(Fi, Field) or ( |
1392 | | - isinstance(Fi, VectorField) and Fi.vector_type == vector_type |
1393 | | - ), "Components of a NestedField must be Field or VectorField" |
1394 | | - self.append(Fi) |
1395 | | - elif W is None: |
1396 | | - for i, Fi, Vi in zip(range(len(F)), F, V, strict=True): |
1397 | | - assert isinstance(Fi, Field) and isinstance( |
1398 | | - Vi, Field |
1399 | | - ), "F, and V components of a NestedField must be Field" |
1400 | | - self.append(VectorField(f"{name}_{i}", Fi, Vi)) |
1401 | | - else: |
1402 | | - for i, Fi, Vi, Wi in zip(range(len(F)), F, V, W, strict=True): |
1403 | | - assert ( |
1404 | | - isinstance(Fi, Field) and isinstance(Vi, Field) and isinstance(Wi, Field) |
1405 | | - ), "F, V and W components of a NestedField must be Field" |
1406 | | - self.append(VectorField(f"{name}_{i}", Fi, Vi, Wi)) |
1407 | | - self.name = name |
1408 | | - |
1409 | | - def __getitem__(self, key): |
1410 | | - if isinstance(key, int): |
1411 | | - return list.__getitem__(self, key) |
1412 | | - else: |
1413 | | - for iField in range(len(self)): |
1414 | | - try: |
1415 | | - if _isParticle(key): |
1416 | | - val = list.__getitem__(self, iField).eval(key.time, key.depth, key.lat, key.lon, particle=None) |
1417 | | - else: |
1418 | | - val = list.__getitem__(self, iField).eval(*key) |
1419 | | - break |
1420 | | - except tuple(AllParcelsErrorCodes.keys()) as error: |
1421 | | - if iField == len(self) - 1: |
1422 | | - vector_type = self[iField].vector_type if isinstance(self[iField], VectorField) else None |
1423 | | - return _deal_with_errors(error, key, vector_type=vector_type) |
1424 | | - else: |
1425 | | - pass |
1426 | | - return val |
0 commit comments