Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix true colors generation for AHI HSD data and refactor the dep tree code #1313

Merged
merged 12 commits into from
Sep 1, 2020
64 changes: 54 additions & 10 deletions satpy/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,15 +376,16 @@ def __hash__(self):
'type': WavelengthRange,
},
'resolution': {
'transitive': True,
'transitive': False,
},
'calibration': {
'enum': [
'reflectance',
'brightness_temperature',
'radiance',
'counts'
]
],
'transitive': True,
},
'modifiers': {
'default': ModifierTuple(),
Expand Down Expand Up @@ -509,7 +510,7 @@ def id_keys(self):
"""Get the id_keys."""
return deepcopy(self._id_keys)

def create_dep_filter(self, query):
def create_filter_query_without_required_fields(self, query):
"""Remove the required fields from *query*."""
try:
new_query = query.to_dict()
Expand Down Expand Up @@ -618,6 +619,26 @@ def __lt__(self, other):
update = _immutable
setdefault = _immutable

def _find_modifiers_key(self):
for key, val in self.items():
if isinstance(val, ModifierTuple):
return key
raise KeyError

def create_less_modified_query(self):
"""Create a query with one less modifier."""
new_dict = self.to_dict()
new_dict['modifiers'] = tuple(new_dict['modifiers'][:-1])
return DataQuery.from_dict(new_dict)

def is_modified(self):
"""Check if this is modified."""
try:
key = self._find_modifiers_key()
except KeyError:
return False
return bool(self[key])


class DataQuery:
"""The data query object.
Expand Down Expand Up @@ -678,8 +699,12 @@ def from_dict(cls, the_dict):
"""Convert a dict to an ID."""
return cls(**the_dict)

def items(self):
"""Get the items of this query."""
return self._dict.items()

def _asdict(self):
return dict(zip(self._fields, self._values))
return self._dict.copy()

def to_dict(self, trim=True):
"""Convert the ID to a dict."""
Expand Down Expand Up @@ -804,6 +829,16 @@ def sort_dataids(self, dataids):
distances, dataids = zip(*sorted(zip(distances, sorted_dataids)))
return dataids, distances

def create_less_modified_query(self):
"""Create a query with one less modifier."""
new_dict = self.to_dict()
new_dict['modifiers'] = tuple(new_dict['modifiers'][:-1])
return DataQuery.from_dict(new_dict)

def is_modified(self):
"""Check if this is modified."""
return bool(self._dict.get('modifiers'))


class DatasetID:
"""Deprecated datasetid."""
Expand All @@ -824,6 +859,20 @@ def create_filtered_query(dataset_key, filter_query):
has priority.

"""
ds_dict = _create_id_dict_from_any_key(dataset_key)
_update_dict_with_filter_query(ds_dict, filter_query)

return DataQuery.from_dict(ds_dict)


def _update_dict_with_filter_query(ds_dict, filter_query):
if filter_query is not None:
for key, value in filter_query.items():
if value != '*':
ds_dict.setdefault(key, value)


def _create_id_dict_from_any_key(dataset_key):
try:
ds_dict = dataset_key.to_dict()
except AttributeError:
Expand All @@ -833,12 +882,7 @@ def create_filtered_query(dataset_key, filter_query):
ds_dict = {'wavelength': dataset_key}
else:
raise TypeError("Don't know how to interpret a dataset_key of type {}".format(type(dataset_key)))
if filter_query is not None:
for key, value in filter_query._dict.items():
if value != '*':
ds_dict.setdefault(key, value)

return DataQuery.from_dict(ds_dict)
return ds_dict


def dataset_walker(datasets):
Expand Down