def test_get_dataset(self, mocked_dataset): """Test reading datasets.""" from satpy.readers.olci_nc import NCOLCI2 from satpy import DatasetID import numpy as np import xarray as xr mocked_dataset.return_value = xr.Dataset( { 'mask': (['rows', 'columns'], np.array([1 << x for x in range(30) ]).reshape(5, 6)) }, coords={ 'rows': np.arange(5), 'columns': np.arange(6) }) ds_id = DatasetID(name='mask') filename_info = { 'mission_id': 'S3A', 'dataset_name': 'mask', 'start_time': 0, 'end_time': 0 } test = NCOLCI2('somedir/somefile.nc', filename_info, 'c') res = test.get_dataset(ds_id, {'nc_key': 'mask'}) self.assertEqual(res.dtype, np.dtype('bool'))
def test_instantiate(self, mocked_dataset): """Test initialization of file handlers.""" from satpy.readers.olci_nc import (NCOLCIBase, NCOLCICal, NCOLCIGeo, NCOLCIChannelBase, NCOLCI1B, NCOLCI2) from satpy import DatasetID import xarray as xr cal_data = xr.Dataset( { 'solar_flux': (('bands'), [0, 1, 2]), 'detector_index': (('bands'), [0, 1, 2]), }, { 'bands': [0, 1, 2], }, ) ds_id = DatasetID(name='Oa01', calibration='reflectance') ds_id2 = DatasetID(name='wsqf', calibration='reflectance') filename_info = { 'mission_id': 'S3A', 'dataset_name': 'Oa01', 'start_time': 0, 'end_time': 0 } test = NCOLCIBase('somedir/somefile.nc', filename_info, 'c') test.get_dataset(ds_id, filename_info) mocked_dataset.assert_called() mocked_dataset.reset_mock() test = NCOLCICal('somedir/somefile.nc', filename_info, 'c') test.get_dataset(ds_id, filename_info) mocked_dataset.assert_called() mocked_dataset.reset_mock() test = NCOLCIGeo('somedir/somefile.nc', filename_info, 'c') test.get_dataset(ds_id, filename_info) mocked_dataset.assert_called() mocked_dataset.reset_mock() test = NCOLCIChannelBase('somedir/somefile.nc', filename_info, 'c') test.get_dataset(ds_id, filename_info) mocked_dataset.assert_called() mocked_dataset.reset_mock() cal = mock.Mock() cal.nc = cal_data test = NCOLCI1B('somedir/somefile.nc', filename_info, 'c', cal) test.get_dataset(ds_id, filename_info) mocked_dataset.assert_called() mocked_dataset.reset_mock() test = NCOLCI2('somedir/somefile.nc', filename_info, 'c') test.get_dataset(ds_id, {'nc_key': 'the_key'}) test.get_dataset(ds_id2, {'nc_key': 'the_key'}) mocked_dataset.assert_called() mocked_dataset.reset_mock()
def test_instantiate(self, mocked_dataset): """Test initialization of file handlers.""" from satpy.readers.olci_nc import (NCOLCIBase, NCOLCICal, NCOLCIGeo, NCOLCIChannelBase, NCOLCI1B, NCOLCI2) from satpy import DatasetID ds_id = DatasetID(name='foo') filename_info = { 'mission_id': 'S3A', 'dataset_name': 'foo', 'start_time': 0, 'end_time': 0 } test = NCOLCIBase('somedir/somefile.nc', filename_info, 'c') test.get_dataset(ds_id, filename_info) mocked_dataset.assert_called() mocked_dataset.reset_mock() test = NCOLCICal('somedir/somefile.nc', filename_info, 'c') test.get_dataset(ds_id, filename_info) mocked_dataset.assert_called() mocked_dataset.reset_mock() test = NCOLCIGeo('somedir/somefile.nc', filename_info, 'c') test.get_dataset(ds_id, filename_info) mocked_dataset.assert_called() mocked_dataset.reset_mock() test = NCOLCIChannelBase('somedir/somefile.nc', filename_info, 'c') test.get_dataset(ds_id, filename_info) mocked_dataset.assert_called() mocked_dataset.reset_mock() test = NCOLCI1B('somedir/somefile.nc', filename_info, 'c', mock.Mock()) test.get_dataset(ds_id, filename_info) mocked_dataset.assert_called() mocked_dataset.reset_mock() test = NCOLCI2('somedir/somefile.nc', filename_info, 'c') test.get_dataset(ds_id, {'nc_key': 'the_key'}) mocked_dataset.assert_called() mocked_dataset.reset_mock()