Exemplo n.º 1
0
    def test__get_band_from_subfile__var4d(self, mock_init):
        mock_init.return_value = None
        mm = Mapper()
        mm.input_filename = self.tmp_filename
        fn = 'NETCDF:"' + self.tmp_filename + '":var4d'
        bdict200 = mm._get_band_from_subfile(
            fn,
            netcdf_dim={
                'time': np.datetime64('2019-06-15T18:00'),  # 2nd band
                'pressure': 200
            },
            bands=['x_wind'])
        bdict500 = mm._get_band_from_subfile(
            fn,
            netcdf_dim={
                'time': np.datetime64('2019-06-15T18:00'),  # 2nd band
                'pressure': 500
            },
            bands=['x_wind'])

        self.assertEqual(bdict200['src']['SourceBand'], 8)
        self.assertEqual(bdict200['dst']['NETCDF_DIM_pressure'], '200')
        self.assertEqual(bdict200['dst']['time_iso_8601'],
                         np.datetime64('2019-06-15T18:00:00.000000'))
        self.assertEqual(bdict500['src']['SourceBand'], 12)
        self.assertEqual(bdict500['dst']['NETCDF_DIM_pressure'], '500')
        self.assertEqual(bdict500['dst']['time_iso_8601'],
                         np.datetime64('2019-06-15T18:00:00.000000'))
Exemplo n.º 2
0
 def test_with_xy_dims(self, mock_init):
     mock_init.return_value = None
     mm = Mapper()
     mm.input_filename = self.tmp_filename_xy
     fn = 'NETCDF:"' + self.tmp_filename + '":var3d'
     bdict = mm._get_band_from_subfile(fn, bands=['x_wind'])
     self.assertEqual(bdict['src']['SourceBand'], 1)
Exemplo n.º 3
0
 def test_variable_with_a_dimension_that_is_not_itself_added_as_a_variable(self, mock_init):
     mock_init.return_value = None
     mm = Mapper()
     mm.input_filename = self.tmp_filename
     fn = 'NETCDF:"' + self.tmp_filename + '":rgb_var'
     bdict = mm._get_band_from_subfile(fn)
     self.assertEqual(bdict['src']['SourceBand'], 1)
Exemplo n.º 4
0
    def test_time_count_to_np_datetime64(self, mock_init, mock_units):
        mock_init.return_value = None
        tu = (datetime.datetime(1900, 1, 1, 0, 0), 'days since 1900-1-1 0:0:0 +0')
        mock_units.return_value = tu
        mm = Mapper()
        time_count = '43648.22734953704'

        # TEST DAYS
        tt = mm._time_count_to_np_datetime64(time_count)
        # Assert data type of tt is np.datetime64
        self.assertEqual(type(tt), np.datetime64)

        tt = mm._time_count_to_np_datetime64(time_count, time_reference=tu)
        # Assert data type of tt is np.datetime64
        self.assertEqual(type(tt), np.datetime64)
Exemplo n.º 5
0
    def test_time_count_to_np_datetime64(self, mock_init, mock_units):
        mock_init.return_value = None
        tu = (datetime.datetime(1900, 1, 1, 0, 0), 'days since 1900-1-1 0:0:0 +0')
        mock_units.return_value = tu
        mm = Mapper()
        time_count = '43648.22734953704'

        # TEST DAYS
        tt = mm._time_count_to_np_datetime64(time_count)
        # Assert data type of tt is np.datetime64
        self.assertEqual(type(tt), np.datetime64)

        tt = mm._time_count_to_np_datetime64(time_count, time_reference=tu)
        # Assert data type of tt is np.datetime64
        self.assertEqual(type(tt), np.datetime64)

        time_count = '43648'
        tt = mm._time_count_to_np_datetime64(time_count)
        # Assert data type of tt is np.datetime64
        self.assertEqual(type(tt), np.datetime64)
        self.assertEqual(tt, np.datetime64('2019-07-04'))

        # TEST HOURS
        tu = (datetime.datetime(1900, 1, 1, 0, 0), 'hours since 1900-1-1 0:0:0 +0')
        tt = mm._time_count_to_np_datetime64(time_count, time_reference=tu)
        # Assert data type of tt is np.datetime64
        self.assertEqual(type(tt), np.datetime64)
        self.assertEqual(tt, np.datetime64('1904-12-24T16:00:00.000000'))

        time_count = '43648.22734953704'
        tt = mm._time_count_to_np_datetime64(time_count, time_reference=tu)
        # Assert data type of tt is np.datetime64
        self.assertEqual(type(tt), np.datetime64)
        self.assertEqual(tt, np.datetime64('1904-12-24T16:13:38.458333'))

        # TEST MINUTES
        tu = (datetime.datetime(1900, 1, 1, 0, 0), 'minutes since 1900-1-1 0:0:0 +0')
        tt = mm._time_count_to_np_datetime64(time_count, time_reference=tu)
        # Assert data type of tt is np.datetime64
        self.assertEqual(type(tt), np.datetime64)
        self.assertEqual(tt, np.datetime64('1900-01-31T07:28:13.640972'))

        # TEST SECONDS
        tu = (datetime.datetime(1900, 1, 1, 0, 0), 'seconds since 1900-1-1 0:0:0 +0')
        tt = mm._time_count_to_np_datetime64(time_count, time_reference=tu)
        # Assert data type of tt is np.datetime64
        self.assertEqual(type(tt), np.datetime64)
        self.assertEqual(tt, np.datetime64('1900-01-01T12:07:28.227350'))
Exemplo n.º 6
0
    def test_buggy_var(self, mock_init):
        """ The last band dimensions should be latitude and longitude - otherwise gdal will fail in
        reading the data correctly.
        
        This is to confirm that this understanding is correct..

        The shape of buggy_var is ('time', 'latitude', 'longitude', 'pressure')
        """
        mock_init.return_value = None
        mm = Mapper()
        mm.input_filename = self.tmp_filename
        fn = 'NETCDF:"' + self.tmp_filename + '":buggy_var'
        bdict = mm._get_band_from_subfile(fn, bands=['x_wind'])
        self.assertEqual(bdict['src']['SourceBand'], 1)
        self.assertEqual(bdict['dst']['NETCDF_DIM_latitude'], '0')
        self.assertEqual(bdict['dst']['time_iso_8601'],
                         np.datetime64('2019-06-15T15:00:00.000000'))
        subds = gdal.Open(fn)
        self.assertEqual(subds.RasterXSize, 7)  # size of pressure dimension
        self.assertEqual(subds.RasterYSize, 20)  # size of longitude dimension
Exemplo n.º 7
0
    def test__get_band_from_subfile__var5d(self, mock_init):
        mock_init.return_value = None
        mm = Mapper()
        mm.input_filename = self.tmp_filename
        fn = 'NETCDF:"' + self.tmp_filename + '":var5d'
        # should give 1 band when time, pressure and height is in netcdf_dim
        bdict1 = mm._get_band_from_subfile(
            fn,
            netcdf_dim={
                'time': np.datetime64('2019-06-15T18:00'),
                'pressure': 200,
                'height': 20
            },
            bands=['x_wind'])
        self.assertEqual(bdict1['dst']['NETCDF_DIM_height'], '20')
        self.assertEqual(bdict1['dst']['NETCDF_DIM_pressure'], '200')
        self.assertEqual(bdict1['dst']['time_iso_8601'],
                         np.datetime64('2019-06-15T18:00:00.000000'))
        self.assertEqual(bdict1['src']['SourceBand'], 72)
        # should give first height_sz band when only time and pressure is in netcdf_dim
        bdict1 = mm._get_band_from_subfile(
            fn,
            netcdf_dim={
                'time': np.datetime64('2019-06-15T18:00'),
                'pressure': 200
            },
            bands=['x_wind'])
        self.assertEqual(bdict1['dst']['NETCDF_DIM_height'], '10')
        self.assertEqual(bdict1['dst']['NETCDF_DIM_pressure'], '200')
        self.assertEqual(bdict1['dst']['time_iso_8601'],
                         np.datetime64('2019-06-15T18:00:00.000000'))
        self.assertEqual(bdict1['src']['SourceBand'], 71)
        # should give first height_sz and pressure bands when only time is in netcdf_dim
        bdict1 = mm._get_band_from_subfile(
            fn,
            netcdf_dim={
                'time': np.datetime64('2019-06-15T18:00'),
            },
            bands=['x_wind'])
        self.assertEqual(bdict1['dst']['NETCDF_DIM_height'], '10')
        self.assertEqual(bdict1['dst']['NETCDF_DIM_pressure'], '200')
        self.assertEqual(bdict1['dst']['time_iso_8601'],
                         np.datetime64('2019-06-15T18:00:00.000000'))
        self.assertEqual(bdict1['src']['SourceBand'], 71)

        bdict1 = mm._get_band_from_subfile(
            fn,
            netcdf_dim={
                'pressure': 300,  # 3rd band
            },
            bands=['x_wind'])
        self.assertEqual(bdict1['dst']['NETCDF_DIM_height'], '10')
        self.assertEqual(bdict1['dst']['NETCDF_DIM_pressure'], '300')
        self.assertEqual(bdict1['dst']['time_iso_8601'],
                         np.datetime64('2019-06-15T15:00:00.000000'))
        self.assertEqual(bdict1['src']['SourceBand'], 21)

        bdict1 = mm._get_band_from_subfile(
            fn,
            netcdf_dim={
                'height': 30,  # 3rd band
            },
            bands=['x_wind'])
        self.assertEqual(bdict1['dst']['NETCDF_DIM_height'], '30')
        self.assertEqual(bdict1['dst']['NETCDF_DIM_pressure'], '200')
        self.assertEqual(bdict1['dst']['time_iso_8601'],
                         np.datetime64('2019-06-15T15:00:00.000000'))
        self.assertEqual(bdict1['src']['SourceBand'], 3)

        bdict1 = mm._get_band_from_subfile(
            fn,
            netcdf_dim={
                'time': np.datetime64('2019-06-15T15:00'),
            },
            bands=['x_wind'])
        self.assertEqual(bdict1['dst']['NETCDF_DIM_height'], '10')
        self.assertEqual(bdict1['dst']['NETCDF_DIM_pressure'], '200')
        self.assertEqual(bdict1['dst']['time_iso_8601'],
                         np.datetime64('2019-06-15T15:00:00.000000'))
        self.assertEqual(bdict1['src']['SourceBand'], 1)

        # should give first band when netcdf_dim is empty
        bdict1 = mm._get_band_from_subfile(fn, bands=['x_wind'])
        self.assertEqual(bdict1['dst']['NETCDF_DIM_height'], '10')
        self.assertEqual(bdict1['dst']['NETCDF_DIM_pressure'], '200')
        self.assertEqual(bdict1['dst']['time_iso_8601'],
                         np.datetime64('2019-06-15T15:00:00.000000'))
        self.assertEqual(bdict1['src']['SourceBand'], 1)
Exemplo n.º 8
0
    def test__timevarname(self, mock_init):
        mock_init.return_value = None
        mm = Mapper()
        mm.input_filename = self.tmp_filename_no_time_var
        timevar_name = mm._timevarname()
        self.assertEqual(timevar_name, '')

        mm = Mapper()
        mm.input_filename = self.tmp_filename_xy
        timevar_name = mm._timevarname()
        self.assertEqual(timevar_name, 'some_times')

        mm = Mapper()
        mm.input_filename = self.tmp_filename
        timevar_name = mm._timevarname()
        self.assertEqual(timevar_name, 'time')
Exemplo n.º 9
0
 def __init__(self, filename, gdal_dataset, gdal_metadata, *args, **kwargs):
     NetCDF_CF_Mapper.__init__(self, filename, gdal_dataset, gdal_metadata,
                               *args, **kwargs)
     Sentinel1.__init__(self, filename)
     self.add_calibrated_nrcs()
     self.add_nrcs_VV_from_HH()