Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _unit_format_func(layer, units):
units = unit_symbol(units)
if layer[Info.STANDARD_NAME] in ('toa_brightness_temperature', 'brightness_temperature'):
# BT data limits, Kelvin to degC
def _format_unit(val, numeric=True, include_units=True):
return '{:.02f}{units}'.format(val, units=units if include_units else "")
elif "flag_values" in layer:
# flag values don't have units
if "flag_meanings" in layer:
flag_masks = layer["flag_masks"] if "flag_masks" in layer else [-1] * len(layer["flag_values"])
flag_info = tuple(zip(layer["flag_meanings"], layer["flag_values"], flag_masks))
def _format_unit(val, numeric=True, include_units=True, flag_info=flag_info):
val = int(val)
if numeric:
return '{:d}'.format(val)
meanings = []
for fmean, fval, fmask in flag_info:
short_name = self._default_short_name()
name = self._default_display_name(short_name=short_name, display_time=display_time)
ds_info = {
Info.DATASET_NAME: short_name,
Info.SHORT_NAME: short_name,
Info.DISPLAY_NAME: name,
Info.DISPLAY_TIME: display_time,
Info.SCHED_TIME: self.sched_time,
Info.BAND: self.band,
Info.CENTRAL_WAVELENGTH: self.central_wavelength,
Info.INSTRUMENT: self.instrument,
Info.PLATFORM: self.platform,
Info.SCENE: self.scene,
Info.UNIT_CONVERSION: self._get_units_conversion(),
Info.UNITS: None,
Info.VALID_RANGE: [d[Info.VALID_RANGE] if d else (None, None) for d in dep_info],
}
if self.r is None and self.g is None and self.b is None:
ds_info.update({
Info.ORIGIN_X: None,
Info.ORIGIN_Y: None,
Info.CELL_WIDTH: None,
Info.CELL_HEIGHT: None,
Info.PROJ: None,
Info.CLIM: ((None, None), (None, None), (None, None)),
})
# defer initialization until we have upstream layers
else:
highest_res_dep = min([x for x in dep_info if x is not None], key=lambda x: x[Info.CELL_WIDTH])
ds_info.update({
Info.ORIGIN_X: highest_res_dep[Info.ORIGIN_X],
sorted(self._families.items(), key=lambda x: x[1][Info.DISPLAY_FAMILY])):
# Qt can't handle tuples as
# otherwise display information on the selected layer(s)
# figure out the info shared between all the layers currently selected
presentation_info = self.document.current_layer_set
for layer_uuid in selected_uuid_list:
layer_info = self.document.get_info(uuid=layer_uuid)
this_prez = None
for prez_tuple in presentation_info:
if prez_tuple.uuid == layer_uuid:
this_prez = prez_tuple
break
# compare our various values
self._update_if_different(shared_info, layer_info, Info.DISPLAY_NAME)
self._update_if_different(shared_info, layer_info, Info.DISPLAY_TIME)
self._update_if_different(shared_info, layer_info, Info.INSTRUMENT)
self._update_if_different(shared_info, this_prez, attr='colormap')
self._get_shared_color_limits(shared_info, layer_info, this_prez)
self._get_code_block(shared_info, layer_uuid)
# wavelength
wl = layer_info.get(Info.CENTRAL_WAVELENGTH)
fmt = "{:0.2f} µm"
if isinstance(wl, (tuple, list)):
wl = [fmt.format(x) if x is not None else '---' for x in wl]
wl = "(" + ", ".join(wl) + ")"
else:
wl = fmt.format(wl) if wl is not None else '---'
if Info.CENTRAL_WAVELENGTH not in shared_info:
shared_info[Info.CENTRAL_WAVELENGTH] = wl
else:
def _create_layer_affine(self, dsi_or_uuid):
info = self.get_info(dsi_or_uuid)
affine = Affine(
info[Info.CELL_WIDTH],
0.0,
info[Info.ORIGIN_X],
0.0,
info[Info.CELL_HEIGHT],
info[Info.ORIGIN_Y],
)
return affine
def collect_product_metadata_for_paths(self, paths):
LOG.debug("import metadata for files: {}".format(repr(paths)))
for path in paths:
yield 1, {Info.PATHNAME: path}
def menu(self, pos: QPoint, *args):
lbox = self.current_set_listbox
selected_uuids = list(self.current_selected_uuids(lbox))
LOG.debug("selected UUID set is {0!r:s}".format(selected_uuids))
menu = QMenu()
actions = {}
if len(selected_uuids) == 1:
if self.doc[selected_uuids[0]][Info.KIND] in [Kind.IMAGE, Kind.COMPOSITE, Kind.CONTOUR]:
actions.update(self.change_layer_colormap_menu(menu, lbox, selected_uuids, *args))
if self.doc[selected_uuids[0]][Info.KIND] in [Kind.CONTOUR]:
actions.update(self.change_layer_image_kind_menu(menu, lbox, selected_uuids, *args))
if 0 < len(selected_uuids) <= 3:
if all(self.doc[u][Info.KIND] in [Kind.IMAGE, Kind.COMPOSITE]
for u in selected_uuids):
actions.update(self.composite_layer_menu(
menu, lbox, selected_uuids, *args))
if not actions:
action = menu.addAction("No actions available for this layer")
action.setEnabled(False)
sel = menu.exec_(lbox.mapToGlobal(pos))
if sel is None:
return
elif sel in actions:
return actions[sel](sel)
extents = tuple(int(np.round(x / 100.0) * 100.0) for x in extents)
proj_str = area.proj4_string
ds.attrs[Info.SCENE] = "{}-{}".format(str(extents), proj_str)
if ds.attrs.get(Info.CENTRAL_WAVELENGTH) is None:
cw = ""
else:
cw = ":{:5.2f}µm".format(ds.attrs[Info.CENTRAL_WAVELENGTH])
ds.attrs[Info.FAMILY] = '{}:{}:{}{}'.format(
ds.attrs[Info.KIND].name, ds.attrs[Info.STANDARD_NAME],
ds.attrs[Info.SHORT_NAME], cw)
ds.attrs[Info.CATEGORY] = 'SatPy:{}:{}:{}'.format(
ds.attrs[Info.PLATFORM].name, ds.attrs[Info.INSTRUMENT].name,
ds.attrs[Info.SCENE]) # system:platform:instrument:target
# TODO: Include level or something else in addition to time?
start_str = ds.attrs['start_time'].isoformat()
ds.attrs[Info.SERIAL] = start_str if model_time is None else model_time + ":" + start_str
ds.attrs.setdefault('reader', self.reader)
return self.scn
plat = Platform('Himawari-{}'.format(int(plat)))
band = int(bb)
#
# # workaround to make old files work with new information
# from uwsift.model.guidebook import AHI_HSF_Guidebook
# if band in AHI_HSF_Guidebook.REFL_BANDS:
# standard_name = "toa_bidirectional_reflectance"
# else:
# standard_name = "toa_brightness_temperature"
meta.update({
Info.PLATFORM: plat,
Info.BAND: band,
Info.INSTRUMENT: Instrument.AHI,
Info.SCHED_TIME: when,
Info.OBS_TIME: when,
Info.OBS_DURATION: DEFAULT_GTIFF_OBS_DURATION,
Info.SCENE: scene,
})
return meta