@@ -71,9 +71,13 @@ def setUpClass(cls):
71
71
cls .data1 = np .ones ((in_shape [0 ], in_shape [1 ]))
72
72
cls .data2 = 2. * cls .data1
73
73
cls .data3 = cls .data1 + 9.5
74
+ cls .data3_1d = np .ravel (cls .data3 )
75
+
74
76
lons , lats = np .meshgrid (np .linspace (- 25. , 40. , num = in_shape [0 ]),
75
77
np .linspace (45. , 75. , num = in_shape [1 ]))
76
78
cls .source_def = geometry .SwathDefinition (lons = lons , lats = lats )
79
+ cls .source_def_1d = geometry .SwathDefinition (lons = np .ravel (lons ),
80
+ lats = np .ravel (lats ))
77
81
78
82
cls .radius = 50e3
79
83
cls ._neighbours = 32
@@ -331,6 +335,22 @@ def test_get_sample_from_bil_info(self):
331
335
input_idxs , idx_arr )
332
336
assert not hasattr (res , 'mask' )
333
337
338
+ def test_get_sample_from_bil_info_1d (self ):
339
+ """Test resampling using resampling indices for 1D data."""
340
+ from pyresample .bilinear import get_bil_info , get_sample_from_bil_info
341
+
342
+ t__ , s__ , input_idxs , idx_arr = get_bil_info (self .source_def_1d ,
343
+ self .target_def ,
344
+ 50e5 , neighbours = 32 ,
345
+ nprocs = 1 )
346
+ # Sample from 1D data
347
+ res = get_sample_from_bil_info (self .data3_1d , t__ , s__ ,
348
+ input_idxs , idx_arr )
349
+ self .assertAlmostEqual (np .nanmin (res ), 10.5 )
350
+ self .assertAlmostEqual (np .nanmax (res ), 10.5 )
351
+ # Four pixels are outside of the data
352
+ self .assertEqual (np .isnan (res ).sum (), 4 )
353
+
334
354
def test_resample_bilinear (self ):
335
355
"""Test whole bilinear resampling."""
336
356
from pyresample .bilinear import resample_bilinear
@@ -467,9 +487,12 @@ def setUp(self):
467
487
self .data1 = DataArray (da .ones ((in_shape [0 ], in_shape [1 ])), dims = ('y' , 'x' ))
468
488
self .data2 = 2. * self .data1
469
489
self .data3 = self .data1 + 9.5
490
+
470
491
lons , lats = np .meshgrid (np .linspace (- 25. , 40. , num = in_shape [0 ]),
471
492
np .linspace (45. , 75. , num = in_shape [1 ]))
472
493
self .source_def = geometry .SwathDefinition (lons = lons , lats = lats )
494
+ self .source_def_1d = geometry .SwathDefinition (lons = np .ravel (lons ),
495
+ lats = np .ravel (lats ))
473
496
474
497
self .radius = 50e3
475
498
self ._neighbours = 32
@@ -714,6 +737,45 @@ def test_slice_data(self):
714
737
self .assertTrue (np .all (np .isnan (p_1 )) and np .all (np .isnan (p_2 )) and
715
738
np .all (np .isnan (p_3 )) and np .all (np .isnan (p_4 )))
716
739
740
+ def test_slice_data_1d (self ):
741
+ """Test slicing 1D data."""
742
+ import dask .array as da
743
+ from xarray import DataArray
744
+
745
+ from pyresample .bilinear import XArrayBilinearResampler
746
+
747
+ resampler = XArrayBilinearResampler (self .source_def_1d , self .target_def ,
748
+ self .radius )
749
+ resampler .get_bil_info ()
750
+
751
+ # 1D data
752
+ data = DataArray (da .ones (self .source_def_1d .shape ))
753
+ p_1 , p_2 , p_3 , p_4 = resampler ._slice_data (data , np .nan )
754
+ self .assertEqual (p_1 .shape , resampler .bilinear_s .shape )
755
+ self .assertTrue (p_1 .shape == p_2 .shape == p_3 .shape == p_4 .shape )
756
+ self .assertTrue (np .all (p_1 == 1.0 ) and np .all (p_2 == 1.0 ) and
757
+ np .all (p_3 == 1.0 ) and np .all (p_4 == 1.0 ))
758
+
759
+ def test_get_sample_from_bil_info_1d (self ):
760
+ """Test resampling using resampling indices for 1D data."""
761
+ import dask .array as da
762
+ from xarray import DataArray
763
+
764
+ from pyresample .bilinear import XArrayBilinearResampler
765
+
766
+ resampler = XArrayBilinearResampler (self .source_def_1d , self .target_def ,
767
+ 50e5 )
768
+ resampler .get_bil_info ()
769
+
770
+ # Sample from 1D data
771
+ data = DataArray (da .ones (self .source_def_1d .shape ), dims = ('y' ))
772
+ res = resampler .get_sample_from_bil_info (data ) # noqa
773
+ assert 'x' in res .dims
774
+ assert 'y' in res .dims
775
+
776
+ # Four pixels are outside of the data
777
+ self .assertEqual (np .isnan (res ).sum ().compute (), 4 )
778
+
717
779
@mock .patch ('pyresample.bilinear.xarr.np.meshgrid' )
718
780
def test_get_slices (self , meshgrid ):
719
781
"""Test slice array creation."""
0 commit comments