Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
lat = inputs[11]
lon = inputs[12]
msg_con_quick = image.ImageContainerQuick(ir108.squeeze(), area_def)
area_con_quick = msg_con_quick.resample(euro_areadef)
result_data_quick = area_con_quick.image_data
# Create satpy scene
testscene = Scene(platform_name="msg",
sensor="seviri",
start_time=datetime(2013, 11, 12, 8, 30),
end_time=datetime(2013, 11, 12, 8, 45),
area=area_def)
array_kwargs = {'area': area_def}
testscene['ir108'] = Dataset(ir108.squeeze(), **array_kwargs)
print(testscene['ir108'])
testscene.show('ir108', overlay={'coast_dir': '/home/mastho/data/', 'color': 'gray'})
resampscene = testscene.resample('germ')
print(resampscene.shape)
#resampscene.show('ir108', overlay={'coast_dir': '/home/mastho/data/', 'color': 'gray'})
# Define custom fog colormap
fogcol = Colormap((0., (250 / 255.0, 200 / 255.0, 40 / 255.0)),
(1., (1.0, 1.0, 229 / 255.0)))
maskcol = (250 / 255.0, 200 / 255.0, 40 / 255.0)
# Create image from data
'4': 3,
'5': 4}
index = avhrr_channel_index[key.name]
mask = False
if key.name in ['3a', '3b'] and self._is3b is None:
ch3a = bfield(self._data["id"]["id"], 10)
self._is3b = np.logical_not(ch3a)
if key.name == '3a':
mask = np.tile(self._is3b, (1, 2048))
elif key.name == '3b':
mask = np.tile(np.logical_not(self._is3b), (1, 2048))
data = self._data["image_data"][:, :, index]
if key.calibration == 'counts':
return Dataset(data,
mask=mask,
area=self.get_lonlats(),
units='1')
pg_spacecraft = ''.join(self.platform_name.split()).lower()
jdays = (np.datetime64(self.start_time) - np.datetime64(str(
self.year) + '-01-01T00:00:00Z')) / np.timedelta64(1, 'D')
if index < 2 or key.name == '3a':
data = calibrate_solar(data, index, self.year, jdays,
pg_spacecraft)
units = '%'
if index > 2 or key.name == '3b':
if self.times is None:
self.times = time_seconds(self._data["timecode"], self.year)
def __call__(self, projectables, nonprojectables=None, **info):
if len(projectables) != 2:
raise ValueError("Expected 2 datasets, got %d" %
(len(projectables), ))
info = combine_metadata(*projectables)
info['name'] = self.attrs['name']
return Dataset(projectables[0] - projectables[1], **info)
if len(projectables) != 2:
raise ValueError("Expected 2 datasets, got %d" %
(len(projectables), ))
# TODO: support datasets with palette to delegate this to the image
# writer.
data, palette = projectables
palette = np.asanyarray(palette).squeeze()
colormap = self.build_colormap(palette / 255.0, data.dtype, data.attrs)
r, g, b = colormap.colorize(np.asanyarray(data))
r[data.mask] = palette[-1][0]
g[data.mask] = palette[-1][1]
b[data.mask] = palette[-1][2]
r = Dataset(r, copy=False, mask=data.mask, **data.attrs)
g = Dataset(g, copy=False, mask=data.mask, **data.attrs)
b = Dataset(b, copy=False, mask=data.mask, **data.attrs)
return super(ColorizeCompositor, self).__call__((r, g, b), **data.attrs)
def enhance2dataset(dset):
"""Apply enhancements to dataset *dset* and convert the image data
back to Dataset object."""
img = get_enhanced_image(dset)
data = np.rollaxis(np.dstack(img.channels), axis=2)
mask = dset.mask
if mask.ndim < data.ndim:
mask = np.expand_dims(mask, 0)
mask = np.repeat(mask, 3, 0)
elif mask.ndim > data.ndim:
mask = mask[0, :, :]
data = Dataset(np.ma.masked_array(data, mask=mask),
copy=False,
**dset.info)
return data
def get_dataset(self, key, info):
stdname = info.get('standard_name')
if stdname in ['latitude', 'longitude']:
if self.lons is None or self.lats is None:
self.lons = self.ds['lon'][:]
self.lats = self.ds['lat'][:]
if info['standard_name'] == 'longitude':
return Dataset(self.lons, id=key, **info)
else:
return Dataset(self.lats, id=key, **info)
if stdname in ['wind_speed']:
return Dataset(self.ds['wind_speed'][:], id=key, **info)
if stdname in ['wind_direction']:
return Dataset(self.ds['wind_dir'][:], id=key, **info)
if stdname in ['ice_prob']:
return Dataset(self.ds['ice_prob'][:], id=key, **info)
if stdname in ['ice_age']:
return Dataset(self.ds['ice_age'][:], id=key, **info)
def get_dataset(self, key, info, out=None, xslice=slice(None), yslice=slice(None)):
to_return = out is None
if out is None:
nlines = int(self.data_info['number_of_lines'])
ncols = int(self.data_info['number_of_columns'])
out = Dataset(np.ma.empty((nlines, ncols), dtype=np.float32))
self.read_band(key, info, out, xslice, yslice)
if to_return:
from satpy.yaml_reader import Shuttle
return Shuttle(out.data, out.mask, out.info)
if index > 2 or key.name == '3b':
if self.times is None:
self.times = time_seconds(self._data["timecode"], self.year)
line_numbers = (
np.round((self.times - self.times[-1]) /
np.timedelta64(166666667, 'ns'))).astype(np.int)
line_numbers -= line_numbers[0]
if self.prt is None:
self.prt, self.ict, self.space = self.get_telemetry()
chan = index + 1
data = calibrate_thermal(data, self.prt, self.ict[:, chan - 3],
self.space[:, chan - 3], line_numbers,
chan, pg_spacecraft)
units = 'K'
# TODO: check if entirely masked before returning
return Dataset(data, mask=mask, units=units)
if valid_min is not None and valid_max is not None:
out.mask[:] |= (out.data < valid_min) | (out.data > valid_max)
factors = (scale_factor, scale_offset)
if factors[0] != 1 or factors[1] != 0:
out.data[:] *= factors[0]
out.data[:] += factors[1]
ds_info.update({
"units": ds_info.get("units", file_units),
"platform_name": PLATFORM_NAME.get(self['/attr/platform'], self['/attr/platform']),
"sensor": SENSOR_NAME.get(self['/attr/sensor'], self['/attr/sensor']),
})
ds_info.update(dataset_id.to_dict())
cls = ds_info.pop("container", Dataset)
return cls(out, **ds_info)
if self.lons is None or self.lats is None:
self.lons = h5data['Longitude'][:]*self.longitude_scale
self.lats = h5data['Latitude'][:]*self.latitude_scale
if info['standard_name'] == 'longitude':
return Dataset(self.lons, id=key, **info)
else:
return Dataset(self.lats, id=key, **info)
if stdname in ['wind_speed']:
windspeed = h5data['Wind_speed_selection'][:, :] * self.wind_speed_scale
return Dataset(windspeed, id=key, **info)
if stdname in ['wind_direction']:
wind_direction = h5data['Wind_direction_selection'][:, :] * self.wind_direction_scale
return Dataset(wind_direction, id=key, **info)