|
7 | 7 | import pandas as pd |
8 | 8 | import pytest |
9 | 9 |
|
10 | | -from parcels import Field, ParticleFile, ParticleSet, XGrid, convert |
| 10 | +import parcels.tutorial |
| 11 | +from parcels import Field, ParticleFile, ParticleSet, XGrid, convert, open_raw_zarr |
11 | 12 | from parcels._core.fieldset import FieldSet, _datetime_to_msg |
12 | 13 | from parcels._core.model import _default_vector_field_components |
13 | 14 | from parcels._datasets.structured.generic import datasets as datasets_structured |
@@ -398,21 +399,94 @@ def test_fieldset_describe(fieldset_two_models: FieldSet): |
398 | 399 | fieldset = fieldset_two_models |
399 | 400 | io = StringIO() |
400 | 401 | expected = """\ |
401 | | -| Name | Type | Grid number | Interp method / value | |
402 | | -|:---------------|:------------|:--------------|:------------------------| |
403 | | -| my_list | Context | - | [1, 2, 'hello'] | |
404 | | -| my_value | Context | - | 2.0 | |
405 | | -| U | Field | 0 | XLinear(...) | |
406 | | -| V | Field | 0 | XLinear(...) | |
407 | | -| UV | VectorField | 0 | XLinear_Velocity(...) | |
408 | | -| U_wind | Field | 1 | XLinear(...) | |
409 | | -| V_wind | Field | 1 | XLinear(...) | |
410 | | -| UV_wind | VectorField | 1 | XLinear_Velocity(...) | |
411 | | -| constant_field | Field | 2 | XConstantField(...) | |
| 402 | +| Name | Type | Grid number | Interp method / value | Backend | |
| 403 | +| Name | Type | Grid number | Interp method / value | Parcels backend | |
| 404 | +|:---------------|:------------|:--------------|:------------------------|:------------------| |
| 405 | +| my_list | Context | - | [1, 2, 'hello'] | - | |
| 406 | +| my_value | Context | - | 2.0 | - | |
| 407 | +| U | Field | 0 | XLinear(...) | NumPy | |
| 408 | +| V | Field | 0 | XLinear(...) | NumPy | |
| 409 | +| UV | VectorField | 0 | XLinear_Velocity(...) | - | |
| 410 | +| U_wind | Field | 1 | XLinear(...) | NumPy | |
| 411 | +| V_wind | Field | 1 | XLinear(...) | NumPy | |
| 412 | +| UV_wind | VectorField | 1 | XLinear_Velocity(...) | - | |
| 413 | +| constant_field | Field | 2 | XConstantField(...) | NumPy | |
412 | 414 |
|
413 | 415 | mesh: flat |
414 | 416 | time interval: (np.datetime64('2000-01-01T00:00:00.000000000'), np.datetime64('2001-01-01T00:00:00.000000000')) |
415 | 417 | """ |
416 | 418 | fieldset.describe(io) |
417 | 419 | actual = io.getvalue() |
418 | 420 | assert actual == expected |
| 421 | + |
| 422 | + |
| 423 | +def test_fieldset_describe_backends(tmp_path): |
| 424 | + ds_u = parcels.tutorial.open_dataset("NemoNorthSeaORCA025-N006_data/U") |
| 425 | + ds_v = parcels.tutorial.open_dataset("NemoNorthSeaORCA025-N006_data/V") |
| 426 | + ds_w = parcels.tutorial.open_dataset("NemoNorthSeaORCA025-N006_data/W") |
| 427 | + ds_coords = parcels.tutorial.open_dataset("NemoNorthSeaORCA025-N006_data/mesh_mask")[["glamf", "gphif"]] |
| 428 | + |
| 429 | + ds_fset = convert.nemo_to_sgrid( |
| 430 | + fields={"U": ds_u["uo"], "V": ds_v["vo"], "W": ds_w["wo"]}, |
| 431 | + coords=ds_coords, |
| 432 | + ) |
| 433 | + fieldset = FieldSet.from_sgrid_conventions(ds_fset) |
| 434 | + |
| 435 | + io = StringIO() |
| 436 | + expected = """\ |
| 437 | +| Name | Type | Grid number | Interp method / value | Parcels backend | |
| 438 | +|:-------|:------------|--------------:|:------------------------|:------------------| |
| 439 | +| U | Field | 0 | XLinear(...) | Dask | |
| 440 | +| V | Field | 0 | XLinear(...) | Dask | |
| 441 | +| W | Field | 0 | XLinear(...) | Dask | |
| 442 | +| UV | VectorField | 0 | CGrid_Velocity(...) | - | |
| 443 | +| UVW | VectorField | 0 | CGrid_Velocity(...) | - | |
| 444 | +
|
| 445 | +mesh: spherical |
| 446 | +time interval: (np.datetime64('2000-01-02T12:00:00.000000000'), np.datetime64('2000-01-12T12:00:00.000000000')) |
| 447 | +""" |
| 448 | + fieldset.describe(io) |
| 449 | + actual = io.getvalue() |
| 450 | + assert actual == expected |
| 451 | + |
| 452 | + # Also run with WindowedArray backend |
| 453 | + fieldset = fieldset.to_windowed_arrays() |
| 454 | + |
| 455 | + io = StringIO() |
| 456 | + expected = """\ |
| 457 | +| Name | Type | Grid number | Interp method / value | Parcels backend | |
| 458 | +|:-------|:------------|--------------:|:------------------------|:------------------| |
| 459 | +| U | Field | 0 | XLinear(...) | WindowedArray | |
| 460 | +| V | Field | 0 | XLinear(...) | WindowedArray | |
| 461 | +| W | Field | 0 | XLinear(...) | WindowedArray | |
| 462 | +| UV | VectorField | 0 | CGrid_Velocity(...) | - | |
| 463 | +| UVW | VectorField | 0 | CGrid_Velocity(...) | - | |
| 464 | +
|
| 465 | +mesh: spherical |
| 466 | +time interval: (np.datetime64('2000-01-02T12:00:00.000000000'), np.datetime64('2000-01-12T12:00:00.000000000')) |
| 467 | +""" |
| 468 | + fieldset.describe(io) |
| 469 | + actual = io.getvalue() |
| 470 | + assert actual == expected |
| 471 | + |
| 472 | + path = tmp_path / "ds.zarr" |
| 473 | + ds_fset.to_zarr(path) |
| 474 | + ds_zarr = open_raw_zarr(path) |
| 475 | + fieldset = FieldSet.from_sgrid_conventions(ds_zarr) |
| 476 | + |
| 477 | + io = StringIO() |
| 478 | + expected = """\ |
| 479 | +| Name | Type | Grid number | Interp method / value | Parcels backend | |
| 480 | +|:-------|:------------|--------------:|:------------------------|:------------------| |
| 481 | +| U | Field | 0 | XLinear(...) | Zarr | |
| 482 | +| V | Field | 0 | XLinear(...) | Zarr | |
| 483 | +| W | Field | 0 | XLinear(...) | Zarr | |
| 484 | +| UV | VectorField | 0 | CGrid_Velocity(...) | - | |
| 485 | +| UVW | VectorField | 0 | CGrid_Velocity(...) | - | |
| 486 | +
|
| 487 | +mesh: spherical |
| 488 | +time interval: (np.datetime64('2000-01-02T12:00:00.000000000'), np.datetime64('2000-01-12T12:00:00.000000000')) |
| 489 | +""" |
| 490 | + fieldset.describe(io) |
| 491 | + actual = io.getvalue() |
| 492 | + assert actual == expected |
0 commit comments