Skip to content

Commit

Permalink
Cleanup various warnings encountered when running Satpy tests
Browse files Browse the repository at this point in the history
  • Loading branch information
djhoese committed Mar 3, 2021
1 parent e344613 commit 605bc63
Show file tree
Hide file tree
Showing 24 changed files with 63 additions and 85 deletions.
2 changes: 1 addition & 1 deletion satpy/composites/crefl_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ def run_crefl(refl, coeffs,
# Get digital elevation map data for our granule, set ocean fill value to 0
if avg_elevation is None:
LOG.debug("No average elevation information provided in CREFL")
# height = np.zeros(lon.shape, dtype=np.float)
# height = np.zeros(lon.shape, dtype=np.float64)
height = 0.
else:
LOG.debug("Using average elevation information provided to CREFL")
Expand Down
2 changes: 1 addition & 1 deletion satpy/composites/viirs.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def __call__(self, datasets, optional_datasets, **info):
nc = NCDataset(self.dem_file, "r")
# average elevation is stored as a 16-bit signed integer but with
# scale factor 1 and offset 0, convert it to float here
avg_elevation = nc.variables[self.dem_sds][:].astype(np.float)
avg_elevation = nc.variables[self.dem_sds][:].astype(np.float64)
if isinstance(avg_elevation, np.ma.MaskedArray):
avg_elevation = avg_elevation.filled(np.nan)
else:
Expand Down
4 changes: 2 additions & 2 deletions satpy/readers/aapp_l1b.py
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ def _vis_calibrate(data,
if calib_type == 'counts':
return channel

channel = channel.astype(np.float)
channel = channel.astype(np.float64)

if calib_type == 'radiance':
logger.info("Radiances are not yet supported for " +
Expand Down Expand Up @@ -556,7 +556,7 @@ def _ir_calibrate(header, data, irchn, calib_type, mask=True):

# Mask unnaturally low values
mask &= count != 0
count = count.astype(np.float)
count = count.astype(np.float64)

k1_ = da.from_array(data['calir'][:, irchn, 0, 0], chunks=LINE_CHUNK) / 1.0e9
k2_ = da.from_array(data['calir'][:, irchn, 0, 1], chunks=LINE_CHUNK) / 1.0e6
Expand Down
2 changes: 1 addition & 1 deletion satpy/readers/ghrsst_l3c_sst.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def get_dataset(self, dataset_id, ds_info, out=None):

if out is None:
out = np.ma.empty(shape, dtype=dtype)
out.mask = np.zeros(shape, dtype=np.bool)
out.mask = np.zeros(shape, dtype=bool)

out.data[:] = np.require(self[var_path][0][::-1], dtype=dtype)
valid_min = self[var_path + '/attr/valid_min']
Expand Down
2 changes: 1 addition & 1 deletion satpy/readers/hrpt.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ def calibrate_thermal_channel(self, data, key):
from pygac.calibration import calibrate_thermal
line_numbers = (
np.round((self.times - self.times[-1]) /
np.timedelta64(166666667, 'ns'))).astype(np.int)
np.timedelta64(166666667, 'ns'))).astype(int)
line_numbers -= line_numbers[0]
prt, ict, space = self.telemetry
index = _get_channel_index(key)
Expand Down
4 changes: 2 additions & 2 deletions satpy/readers/msi_safe.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,15 +187,15 @@ def _get_coarse_dataset(self, key, info):
if key['name'] in ['solar_zenith_angle', 'solar_azimuth_angle']:
elts = angles.findall(info['xml_tag'] + '/Values_List/VALUES')
return np.array([[val for val in elt.text.split()] for elt in elts],
dtype=np.float)
dtype=np.float64)

elif key['name'] in ['satellite_zenith_angle', 'satellite_azimuth_angle']:
arrays = []
elts = angles.findall(info['xml_tag'] + '[@bandId="1"]')
for elt in elts:
items = elt.findall(info['xml_item'] + '/Values_List/VALUES')
arrays.append(np.array([[val for val in item.text.split()] for item in items],
dtype=np.float))
dtype=np.float64))
return np.nanmean(np.dstack(arrays), -1)
return None

Expand Down
4 changes: 2 additions & 2 deletions satpy/readers/olci_nc.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,12 @@ def __getitem__(self, item):
data = self._value
if isinstance(data, xr.DataArray):
data = data.data
res = ((data >> pos) % 2).astype(np.bool)
res = ((data >> pos) % 2).astype(bool)
res = xr.DataArray(res, coords=self._value.coords,
attrs=self._value.attrs,
dims=self._value.dims)
else:
res = ((data >> pos) % 2).astype(np.bool)
res = ((data >> pos) % 2).astype(bool)
return res


Expand Down
8 changes: 4 additions & 4 deletions satpy/readers/seviri_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -384,9 +384,9 @@ def get(self):
record = [
('MPEF_File_Id', np.int16),
('MPEF_Header_Version', np.uint8),
('ManualDissAuthRequest', np.bool),
('ManualDisseminationAuth', np.bool),
('DisseminationAuth', np.bool),
('ManualDissAuthRequest', bool),
('ManualDisseminationAuth', bool),
('DisseminationAuth', bool),
('NominalTime', time_cds_short),
('ProductQuality', np.uint8),
('ProductCompleteness', np.uint8),
Expand Down Expand Up @@ -417,7 +417,7 @@ def images_used(self):
record = [
('Padding1', 'S2'),
('ExpectedImage', time_cds_short),
('ImageReceived', np.bool),
('ImageReceived', bool),
('Padding2', 'S1'),
('UsedImageStart_Day', np.uint16),
('UsedImageStart_Millsec', np.uint32),
Expand Down
8 changes: 5 additions & 3 deletions satpy/readers/seviri_l1b_hrit.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,10 +276,12 @@ def get_satpos(self):
x, y, z = self._get_satpos_cart()

# Transform to geodetic coordinates
geocent = pyproj.Proj(proj='geocent')
a, b = self.get_earth_radii()
latlong = pyproj.Proj(proj='latlong', a=a, b=b, units='m')
lon, lat, alt = pyproj.transform(geocent, latlong, x, y, z)
geocent_crs = pyproj.CRS.from_string('+proj=geocent')
latlong_crs = pyproj.CRS.from_string(
'+proj=latlong +a={} +b={} +units=m'.format(a, b))
transformer = pyproj.Transformer.from_crs(geocent_crs, latlong_crs)
lon, lat, alt = transformer.transform(x, y, z)
except NoValidOrbitParams as err:
logger.warning(err)
lon = lat = alt = None
Expand Down
26 changes: 13 additions & 13 deletions satpy/readers/seviri_l1b_native_hdr.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class GSDTRecords(object):
# 16 bytes
gp_pk_sh1 = [
('SubHeaderVersionNo', np.uint8),
('ChecksumFlag', np.bool),
('ChecksumFlag', bool),
('Acknowledgement', (np.uint8, 4)),
('ServiceType', gp_svce_type),
('ServiceSubtype', np.uint8),
Expand Down Expand Up @@ -220,11 +220,11 @@ def satellite_status(self):

# 28 bytes
satellite_operations = [
('LastManoeuvreFlag', np.bool),
('LastManoeuvreFlag', bool),
('LastManoeuvreStartTime', time_cds_short),
('LastManoeuvreEndTime', time_cds_short),
('LastManoeuvreType', np.uint8),
('NextManoeuvreFlag', np.bool),
('NextManoeuvreFlag', bool),
('NextManoeuvreStartTime', time_cds_short),
('NextManoeuvreEndTime', time_cds_short),
('NextManoeuvreType', np.uint8)]
Expand Down Expand Up @@ -325,23 +325,23 @@ def image_acquisition(self):
('RefocusingLines', np.uint16),
('RefocusingDirection', np.uint8),
('RefocusingPosition', np.uint16),
('ScanRefPosFlag', np.bool),
('ScanRefPosFlag', bool),
('ScanRefPosNumber', np.uint16),
('ScanRefPosVal', np.float32),
('ScanFirstLine', np.uint16),
('ScanLastLine', np.uint16),
('RetraceStartLine', np.uint16)]

decontamination = [
('DecontaminationNow', np.bool),
('DecontaminationNow', bool),
('DecontaminationStart', time_cds_short),
('DecontaminationEnd', time_cds_short)]

radiometer_operations = [
('LastGainChangeFlag', np.bool),
('LastGainChangeFlag', bool),
('LastGainChangeTime', time_cds_short),
('Decontamination', decontamination),
('BBCalScheduled', np.bool),
('BBCalScheduled', bool),
('BBCalibrationType', np.uint8),
('BBFirstLine', np.uint16),
('BBLastLine', np.uint16),
Expand Down Expand Up @@ -445,12 +445,12 @@ def image_description(self):
def radiometric_processing(self):
"""Get radiometric processing data."""
rp_summary = [
('RadianceLinearization', (np.bool, 12)),
('DetectorEqualization', (np.bool, 12)),
('OnboardCalibrationResult', (np.bool, 12)),
('MPEFCalFeedback', (np.bool, 12)),
('MTFAdaptation', (np.bool, 12)),
('StrayLightCorrection', (np.bool, 12))]
('RadianceLinearization', (bool, 12)),
('DetectorEqualization', (bool, 12)),
('OnboardCalibrationResult', (bool, 12)),
('MPEFCalFeedback', (bool, 12)),
('MTFAdaptation', (bool, 12)),
('StrayLightCorrection', (bool, 12))]

level_15_image_calibration = [
('CalSlope', np.float64),
Expand Down
2 changes: 1 addition & 1 deletion satpy/readers/viirs_l1b.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ def get_dataset(self, dataset_id, ds_info):
lut_var_path = ds_info.get('lut', var_path + '_brightness_temperature_lut')
data = self[var_path]
# we get the BT values from a look up table using the scaled radiance integers
index_arr = data.data.astype(np.int)
index_arr = data.data.astype(int)
coords = data.coords
data.data = self[lut_var_path].data[index_arr.ravel()].reshape(data.shape)
data = data.assign_coords(**coords)
Expand Down
2 changes: 1 addition & 1 deletion satpy/readers/xmlformat.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def process_field(elt, ascii=False):
except ValueError:
scale = (10 / np.array(
elt.get("scaling-factor").replace("^", "e").split(","),
dtype=np.float))
dtype=np.float64))

return ((elt.get("name"), current_type, scale))

Expand Down
2 changes: 1 addition & 1 deletion satpy/resample.py
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,7 @@ def load_neighbour_info(self, cache_dir, mask=None, **kwargs):
cache = np.array(fid[idx_name])
if idx_name == 'valid_input_index':
# valid input index array needs to be boolean
cache = cache.astype(np.bool)
cache = cache.astype(bool)
except ValueError:
raise IOError
cache = self._apply_cached_index(cache, idx_name)
Expand Down
4 changes: 2 additions & 2 deletions satpy/tests/reader_tests/test_fci_l2_nc.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def setUp(self):
two_layers_dataset[0, :, :] = np.ones((100, 10))
two_layers_dataset[1, :, :] = 2 * np.ones((100, 10))

mtg_geos_projection = nc.createVariable('mtg_geos_projection', np.int, dimensions=())
mtg_geos_projection = nc.createVariable('mtg_geos_projection', int, dimensions=())
mtg_geos_projection.longitude_of_projection_origin = 10.0
mtg_geos_projection.semi_major_axis = 6378137.
mtg_geos_projection.semi_minor_axis = 6356752.
Expand Down Expand Up @@ -403,7 +403,7 @@ def setUp(self):
x.standard_name = 'projection_y_coordinate'
y[:] = np.arange(1)

mtg_geos_projection = nc_byte.createVariable('mtg_geos_projection', np.int, dimensions=())
mtg_geos_projection = nc_byte.createVariable('mtg_geos_projection', int, dimensions=())
mtg_geos_projection.longitude_of_projection_origin = 10.0
mtg_geos_projection.semi_major_axis = 6378137.
mtg_geos_projection.semi_minor_axis = 6356752.
Expand Down
2 changes: 1 addition & 1 deletion satpy/tests/reader_tests/test_iasi_l2_so2_bufr.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
1007, 1031, 25060, 2019, 2020, 4001, 4002, 4003, 4004, 4005,
4006, 5040, 201133, 5041, 201000, 5001, 6001, 5043, 7024, 5021,
7025, 5022, 7007, 40068, 7002, 15045, 12080, 102000, 31001, 7007,
15045], dtype=np.int),
15045], dtype=int),
'#1#satelliteIdentifier': 4,
'#1#centre': 254,
'#1#softwareIdentification': 605,
Expand Down
4 changes: 2 additions & 2 deletions satpy/tests/reader_tests/test_seviri_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def test_pad_data_vertically():
def test_get_padding_area_float():
"""Test padding area generator for floats."""
shape = (10, 10)
dtype = np.float
dtype = np.float64
res = get_padding_area(shape, dtype)
expected = da.full(shape, np.nan, dtype=dtype, chunks=CHUNK_SIZE)
np.testing.assert_array_equal(res, expected)
Expand All @@ -131,7 +131,7 @@ def test_get_padding_area_float():
def test_get_padding_area_int():
"""Test padding area generator for integers."""
shape = (10, 10)
dtype = np.int
dtype = np.int64
res = get_padding_area(shape, dtype)
expected = da.full(shape, 0, dtype=dtype, chunks=CHUNK_SIZE)
np.testing.assert_array_equal(res, expected)
2 changes: 1 addition & 1 deletion satpy/tests/reader_tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ def test_geostationary_mask(self):
(-6498000.088960204, -6498000.088960204,
6502000.089024927, 6502000.089024927))

mask = hf.get_geostationary_mask(area).astype(np.int).compute()
mask = hf.get_geostationary_mask(area).astype(int).compute()

# Check results along a couple of lines
# a) Horizontal
Expand Down
4 changes: 2 additions & 2 deletions satpy/tests/test_composites.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,15 +290,15 @@ def setUp(self):
start_time = datetime(2018, 1, 1, 18, 0, 0)

# RGB
a = np.zeros((3, 2, 2), dtype=np.float)
a = np.zeros((3, 2, 2), dtype=np.float64)
a[:, 0, 0] = 0.1
a[:, 0, 1] = 0.2
a[:, 1, 0] = 0.3
a[:, 1, 1] = 0.4
a = da.from_array(a, a.shape)
self.data_a = xr.DataArray(a, attrs={'test': 'a', 'start_time': start_time},
coords={'bands': bands}, dims=('bands', 'y', 'x'))
b = np.zeros((3, 2, 2), dtype=np.float)
b = np.zeros((3, 2, 2), dtype=np.float64)
b[:, 0, 0] = np.nan
b[:, 0, 1] = 0.25
b[:, 1, 0] = 0.50
Expand Down
20 changes: 9 additions & 11 deletions satpy/tests/test_resample.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,15 +141,14 @@ class TestKDTreeResampler(unittest.TestCase):
def test_kd_resampling(self, xr_resampler, create_filename, zarr_open,
xr_dset, cnc):
"""Test the kd resampler."""
import numpy as np
import dask.array as da
from satpy.resample import KDTreeResampler
data, source_area, swath_data, source_swath, target_area = get_test_data()
mock_dset = mock.MagicMock()
xr_dset.return_value = mock_dset
resampler = KDTreeResampler(source_swath, target_area)
resampler.precompute(
mask=da.arange(5, chunks=5).astype(np.bool), cache_dir='.')
mask=da.arange(5, chunks=5).astype(bool), cache_dir='.')
xr_resampler.assert_called_once()
resampler.resampler.get_neighbour_info.assert_called()
# swath definitions should not be cached
Expand Down Expand Up @@ -300,7 +299,7 @@ def test_2d_ewa(self, get_lonlats, ll2cr, fornav):
self.assertIn('x', new_data.coords)
self.assertIn('crs', new_data.coords)
self.assertIsInstance(new_data.coords['crs'].item(), CRS)
self.assertIn('lcc', new_data.coords['crs'].item().to_proj4())
self.assertIn('lambert', new_data.coords['crs'].item().coordinate_operation.method_name.lower())
self.assertEqual(new_data.coords['y'].attrs['units'], 'meter')
self.assertEqual(new_data.coords['x'].attrs['units'], 'meter')
self.assertEqual(target_area.crs, new_data.coords['crs'].item())
Expand Down Expand Up @@ -350,7 +349,7 @@ def test_3d_ewa(self, get_lonlats, ll2cr, fornav):
self.assertIn('bands', new_data.coords)
self.assertIn('crs', new_data.coords)
self.assertIsInstance(new_data.coords['crs'].item(), CRS)
self.assertIn('lcc', new_data.coords['crs'].item().to_proj4())
self.assertIn('lambert', new_data.coords['crs'].item().coordinate_operation.method_name.lower())
self.assertEqual(new_data.coords['y'].attrs['units'], 'meter')
self.assertEqual(new_data.coords['x'].attrs['units'], 'meter')
np.testing.assert_equal(new_data.coords['bands'].values,
Expand Down Expand Up @@ -400,7 +399,7 @@ def test_expand_dims(self):
self.assertIn('x', new_data.coords)
self.assertIn('crs', new_data.coords)
self.assertIsInstance(new_data.coords['crs'].item(), CRS)
self.assertIn('lcc', new_data.coords['crs'].item().to_proj4())
self.assertIn('lambert', new_data.coords['crs'].item().coordinate_operation.method_name.lower())
self.assertEqual(new_data.coords['y'].attrs['units'], 'meter')
self.assertEqual(new_data.coords['x'].attrs['units'], 'meter')
self.assertEqual(target_area.crs, new_data.coords['crs'].item())
Expand All @@ -424,7 +423,7 @@ def test_expand_dims_3d(self):
['R', 'G', 'B'])
self.assertIn('crs', new_data.coords)
self.assertIsInstance(new_data.coords['crs'].item(), CRS)
self.assertIn('lcc', new_data.coords['crs'].item().to_proj4())
self.assertIn('lambert', new_data.coords['crs'].item().coordinate_operation.method_name.lower())
self.assertEqual(new_data.coords['y'].attrs['units'], 'meter')
self.assertEqual(new_data.coords['x'].attrs['units'], 'meter')
self.assertEqual(target_area.crs, new_data.coords['crs'].item())
Expand All @@ -442,7 +441,7 @@ def test_expand_without_dims(self):
self.assertTrue(np.all(new_data == new_data2))
self.assertIn('crs', new_data.coords)
self.assertIsInstance(new_data.coords['crs'].item(), CRS)
self.assertIn('lcc', new_data.coords['crs'].item().to_proj4())
self.assertIn('lambert', new_data.coords['crs'].item().coordinate_operation.method_name.lower())
self.assertEqual(target_area.crs, new_data.coords['crs'].item())

def test_expand_without_dims_4D(self):
Expand All @@ -464,7 +463,6 @@ class TestBilinearResampler(unittest.TestCase):
def test_bil_resampling(self, xr_resampler, create_filename,
move_existing_caches):
"""Test the bilinear resampler."""
import numpy as np
import dask.array as da
import xarray as xr
from satpy.resample import BilinearResampler
Expand All @@ -473,7 +471,7 @@ def test_bil_resampling(self, xr_resampler, create_filename,
# Test that bilinear resampling info calculation is called
resampler = BilinearResampler(source_swath, target_area)
resampler.precompute(
mask=da.arange(5, chunks=5).astype(np.bool))
mask=da.arange(5, chunks=5).astype(bool))
resampler.resampler.load_resampling_info.assert_not_called()
resampler.resampler.get_bil_info.assert_called_once()
resampler.resampler.reset_mock()
Expand All @@ -489,7 +487,7 @@ def test_bil_resampling(self, xr_resampler, create_filename,
self.assertIn('x', new_data.coords)
self.assertIn('crs', new_data.coords)
self.assertIsInstance(new_data.coords['crs'].item(), CRS)
self.assertIn('lcc', new_data.coords['crs'].item().to_proj4())
self.assertIn('lambert', new_data.coords['crs'].item().coordinate_operation.method_name.lower())
self.assertEqual(new_data.coords['y'].attrs['units'], 'meter')
self.assertEqual(new_data.coords['x'].attrs['units'], 'meter')
self.assertEqual(target_area.crs, new_data.coords['crs'].item())
Expand Down Expand Up @@ -670,7 +668,7 @@ def test_swath_def_coordinates(self):
self.assertIn('crs', new_data_arr.coords)
crs = new_data_arr.coords['crs'].item()
self.assertIsInstance(crs, CRS)
self.assertIn('longlat', crs.to_proj4())
assert crs.is_geographic
self.assertIsInstance(new_data_arr.coords['crs'].item(), CRS)


Expand Down
Loading

0 comments on commit 605bc63

Please sign in to comment.