5
5
import pytest
6
6
7
7
import mikeio
8
- from mikeio import EUMType , ItemInfo , EUMUnit , Dataset
8
+ from mikeio import EUMType , ItemInfo , Dataset
9
9
from mikeio .exceptions import OutsideModelDomainError
10
10
11
11
@@ -86,8 +86,6 @@ def test_properties(ds1: Dataset) -> None:
86
86
assert ds1 .geometry .nx == 7
87
87
assert ds1 ._zn is None
88
88
89
- # assert not hasattr(ds1, "keys") # TODO: remove this
90
- # assert not hasattr(ds1, "values") # TODO: remove this
91
89
assert isinstance (ds1 .items [0 ], ItemInfo )
92
90
93
91
@@ -328,7 +326,6 @@ def test_select_multiple_items_by_name() -> None:
328
326
data = [d1 , d2 , d3 ]
329
327
330
328
time = pd .date_range ("2000-1-2" , freq = "h" , periods = nt )
331
- # items = [ItemInfo("Foo"), ItemInfo("Bar"), ItemInfo("Baz")]
332
329
items = [ItemInfo (x ) for x in ["Foo" , "Bar" , "Baz" ]]
333
330
ds = mikeio .Dataset .from_numpy (data = data , time = time , items = items )
334
331
@@ -387,17 +384,15 @@ def test_decribe(ds1: Dataset) -> None:
387
384
assert df .Foo ["max" ] == pytest .approx (0.1 )
388
385
389
386
390
- def test_create_undefined () -> None :
387
+ def test_create_undefined_eum_type () -> None :
391
388
nt = 100
392
389
d1 = np .zeros ([nt ])
393
390
d2 = np .zeros ([nt ])
394
391
395
392
time = pd .date_range ("2000-1-2" , freq = "h" , periods = nt )
396
393
data = {
397
- "Item 1" : mikeio .DataArray (
398
- data = d1 , time = time , item = ItemInfo ("Item 1" )
399
- ), # TODO redundant name
400
- "Item 2" : mikeio .DataArray (data = d2 , time = time , item = ItemInfo ("Item 2" )),
394
+ "Item 1" : mikeio .DataArray (d1 , time = time ),
395
+ "Item 2" : mikeio .DataArray (d2 , time = time ),
401
396
}
402
397
403
398
ds = mikeio .Dataset (data )
@@ -421,7 +416,6 @@ def test_to_dataframe_single_timestep() -> None:
421
416
df = ds .to_dataframe ()
422
417
423
418
assert "Bar" in df .columns
424
- # assert isinstance(df.index, pd.DatetimeIndex)
425
419
426
420
df2 = ds .to_pandas ()
427
421
assert df2 .shape == (1 , 2 )
@@ -467,18 +461,6 @@ def test_multidimensional_to_dataframe_no_supported() -> None:
467
461
ds .to_dataframe ()
468
462
469
463
470
- def test_get_data () -> None :
471
- data = []
472
- nt = 100
473
- d = np .zeros ([nt , 100 , 30 ]) + 1.0
474
- data .append (d )
475
- time = pd .date_range ("2000-1-2" , freq = "h" , periods = nt )
476
- items = [ItemInfo ("Foo" )]
477
- ds = mikeio .Dataset .from_numpy (data = data , time = time , items = items )
478
-
479
- assert ds .shape == (100 , 100 , 30 )
480
-
481
-
482
464
def test_interp_time () -> None :
483
465
nt = 4
484
466
d = np .zeros ([nt , 10 , 3 ])
@@ -508,27 +490,20 @@ def test_interp_time() -> None:
508
490
509
491
510
492
def test_interp_time_to_other_dataset () -> None :
511
- # Arrange
512
- ## mikeio.Dataset 1
513
493
nt = 4
514
494
data = [np .zeros ([nt , 10 , 3 ])]
515
495
time = pd .date_range ("2000-1-1" , freq = "D" , periods = nt )
516
496
items = [ItemInfo ("Foo" )]
517
497
ds1 = mikeio .Dataset .from_numpy (data = data , time = time , items = items )
518
- assert ds1 .shape == (nt , 10 , 3 )
519
498
520
- ## mikeio.Dataset 2
521
499
nt = 12
522
500
data = [np .ones ([nt , 10 , 3 ])]
523
501
time = pd .date_range ("2000-1-1" , freq = "h" , periods = nt )
524
502
items = [ItemInfo ("Foo" )]
525
503
ds2 = mikeio .Dataset .from_numpy (data = data , time = time , items = items )
526
504
527
- # Act
528
- ## interp
529
505
dsi = ds1 .interp_time (dt = ds2 .time )
530
506
531
- # Assert
532
507
assert dsi .time [0 ] == ds2 .time [0 ]
533
508
assert dsi .time [- 1 ] == ds2 .time [- 1 ]
534
509
assert len (dsi .time ) == len (ds2 .time )
@@ -540,8 +515,6 @@ def test_interp_time_to_other_dataset() -> None:
540
515
541
516
542
517
def test_extrapolate () -> None :
543
- # Arrange
544
- ## mikeio.Dataset 1
545
518
nt = 2
546
519
data = [np .zeros ([nt , 10 , 3 ])]
547
520
time = pd .date_range ("2000-1-1" , freq = "D" , periods = nt )
@@ -556,11 +529,8 @@ def test_extrapolate() -> None:
556
529
items = [ItemInfo ("Foo" )]
557
530
ds2 = mikeio .Dataset .from_numpy (data = data , time = time , items = items )
558
531
559
- # Act
560
- ## interp
561
532
dsi = ds1 .interp_time (dt = ds2 .time , fill_value = 1.0 )
562
533
563
- # Assert
564
534
assert dsi .time [0 ] == ds2 .time [0 ]
565
535
assert dsi .time [- 1 ] == ds2 .time [- 1 ]
566
536
assert len (dsi .time ) == len (ds2 .time )
@@ -589,23 +559,9 @@ def test_extrapolate_not_allowed() -> None:
589
559
ds1 .interp_time (dt = ds2 .time , fill_value = 1.0 , extrapolate = False )
590
560
591
561
592
- def test_get_data_2 () -> None :
593
- nt = 100
594
- data = []
595
- d = np .zeros ([nt , 100 , 30 ]) + 1.0
596
- data .append (d )
597
- time = pd .date_range ("2000-1-2" , freq = "h" , periods = nt )
598
- items = [ItemInfo ("Foo" )]
599
- mikeio .Dataset .from_numpy (data = data , time = time , items = items )
600
-
601
- assert data [0 ].shape == (100 , 100 , 30 )
602
-
603
-
604
562
def test_get_data_name () -> None :
605
563
nt = 100
606
- data = []
607
- d = np .zeros ([nt , 100 , 30 ]) + 1.0
608
- data .append (d )
564
+ data = [np .zeros ([nt , 100 , 30 ]) + 1.0 ]
609
565
time = pd .date_range ("2000-1-2" , freq = "h" , periods = nt )
610
566
items = [ItemInfo ("Foo" )]
611
567
ds = mikeio .Dataset .from_numpy (data = data , time = time , items = items )
@@ -629,19 +585,6 @@ def test_modify_selected_variable() -> None:
629
585
assert ds .Foo .to_numpy ()[0 , 0 ] == 1.0 # type: ignore
630
586
631
587
632
- def test_get_bad_name () -> None :
633
- nt = 100
634
- data = []
635
- d = np .zeros ([100 , 100 , 30 ]) + 1.0
636
- data .append (d )
637
- time = pd .date_range ("2000-1-2" , freq = "h" , periods = nt )
638
- items = [ItemInfo ("Foo" )]
639
- ds = mikeio .Dataset .from_numpy (data = data , time = time , items = items )
640
-
641
- with pytest .raises (Exception ):
642
- ds ["BAR" ]
643
-
644
-
645
588
def test_flipud () -> None :
646
589
nt = 2
647
590
d = np .random .random ([nt , 100 , 30 ])
@@ -656,37 +599,16 @@ def test_flipud() -> None:
656
599
assert dsud ["Foo" ].to_numpy ()[0 , 0 , 0 ] == ds ["Foo" ].to_numpy ()[0 , - 1 , 0 ]
657
600
658
601
659
- def test_aggregation_workflows (tmp_path : Path ) -> None :
660
- # TODO move to integration tests
661
- filename = "tests/testdata/HD2D.dfsu"
662
- dfs = mikeio .Dfsu2DH (filename )
663
-
664
- ds = dfs .read (items = ["Surface elevation" , "Current speed" ])
665
- ds2 = ds .max (axis = 1 )
666
-
667
- outfilename = tmp_path / "max.dfs0"
668
- ds2 .to_dfs (outfilename )
669
- assert outfilename .exists ()
670
-
671
- ds3 = ds .min (axis = 1 )
672
-
673
- outfilename = tmp_path / "min.dfs0"
674
- ds3 .to_dfs (outfilename )
675
- assert outfilename .exists ()
676
-
677
-
678
602
def test_aggregation_dataset_no_time () -> None :
679
- filename = "tests/testdata/HD2D.dfsu"
680
- dfs = mikeio .Dfsu2DH (filename )
603
+ dfs = mikeio .Dfsu2DH ("tests/testdata/HD2D.dfsu" )
681
604
ds = dfs .read (time = - 1 , items = ["Surface elevation" , "Current speed" ])
682
605
683
606
ds2 = ds .max ()
684
607
assert ds2 ["Current speed" ].values == pytest .approx (1.6463733 )
685
608
686
609
687
610
def test_aggregations () -> None :
688
- filename = "tests/testdata/gebco_sound.dfs2"
689
- ds = mikeio .read (filename )
611
+ ds = mikeio .read ("tests/testdata/gebco_sound.dfs2" )
690
612
691
613
for axis in [0 , 1 , 2 ]:
692
614
ds .mean (axis = axis )
@@ -718,21 +640,6 @@ def test_to_dfs_extension_validation(tmp_path: Path) -> None:
718
640
assert "dfsu" in str (excinfo .value )
719
641
720
642
721
- def test_weighted_average (tmp_path : Path ) -> None :
722
- # TODO move to integration tests
723
- fp = Path ("tests/testdata/HD2D.dfsu" )
724
- dfs = mikeio .Dfsu2DH (fp )
725
-
726
- ds = dfs .read (items = ["Surface elevation" , "Current speed" ])
727
-
728
- area = dfs .geometry .get_element_area ()
729
- ds2 = ds .average (weights = area , axis = 1 )
730
-
731
- out_path = tmp_path / "average.dfs0"
732
- ds2 .to_dfs (out_path )
733
- assert out_path .exists ()
734
-
735
-
736
643
def test_quantile_axis1 (ds1 : Dataset ) -> None :
737
644
dsq = ds1 .quantile (q = 0.345 , axis = 1 )
738
645
assert dsq [0 ].to_numpy ()[0 ] == 0.1
@@ -867,70 +774,6 @@ def test_dropna() -> None:
867
774
assert ds2 .n_timesteps == 8
868
775
869
776
870
- def test_default_type () -> None :
871
- item = ItemInfo ("Foo" )
872
- assert item .type == EUMType .Undefined
873
- assert repr (item .unit ) == "undefined"
874
-
875
-
876
- def test_int_is_valid_type_info () -> None :
877
- item = ItemInfo ("Foo" , 100123 )
878
- assert item .type == EUMType .Viscosity
879
-
880
- item = ItemInfo ("U" , 100002 )
881
- assert item .type == EUMType .Wind_Velocity
882
-
883
-
884
- def test_int_is_valid_unit_info () -> None :
885
- item = ItemInfo ("U" , 100002 , 2000 )
886
- assert item .type == EUMType .Wind_Velocity
887
- assert item .unit == EUMUnit .meter_per_sec
888
- assert repr (item .unit ) == "meter per sec" # TODO replace _per_ with /
889
-
890
-
891
- def test_default_unit_from_type () -> None :
892
- item = ItemInfo ("Foo" , EUMType .Water_Level )
893
- assert item .type == EUMType .Water_Level
894
- assert item .unit == EUMUnit .meter
895
- assert repr (item .unit ) == "meter"
896
-
897
- item = ItemInfo ("Tp" , EUMType .Wave_period )
898
- assert item .type == EUMType .Wave_period
899
- assert item .unit == EUMUnit .second
900
- assert repr (item .unit ) == "second"
901
-
902
- item = ItemInfo ("Temperature" , EUMType .Temperature )
903
- assert item .type == EUMType .Temperature
904
- assert item .unit == EUMUnit .degree_Celsius
905
- assert repr (item .unit ) == "degree Celsius"
906
-
907
-
908
- def test_default_name_from_type () -> None :
909
- item = ItemInfo (EUMType .Current_Speed )
910
- assert item .name == "Current Speed"
911
- assert item .unit == EUMUnit .meter_per_sec
912
-
913
- item2 = ItemInfo (EUMType .Current_Direction , EUMUnit .degree )
914
- assert item2 .unit == EUMUnit .degree
915
- item3 = ItemInfo (
916
- "Current direction (going to)" , EUMType .Current_Direction , EUMUnit .degree
917
- )
918
- assert item3 .type == EUMType .Current_Direction
919
- assert item3 .unit == EUMUnit .degree
920
-
921
-
922
- def test_iteminfo_string_type_should_fail_with_helpful_message () -> None :
923
- with pytest .raises (ValueError ):
924
- ItemInfo ("Water level" , "Water level" ) # type: ignore
925
-
926
-
927
- def test_item_search () -> None :
928
- res = EUMType .search ("level" )
929
-
930
- assert len (res ) > 0
931
- assert isinstance (res [0 ], EUMType )
932
-
933
-
934
777
def test_dfsu3d_dataset () -> None :
935
778
filename = "tests/testdata/oresund_sigma_z.dfsu"
936
779
0 commit comments