Skip to content

Commit

Permalink
Merge pull request #734 from bp/prop_selection_with_em
Browse files Browse the repository at this point in the history
extra metadata option for selective version of property collection
  • Loading branch information
andy-beer committed Jun 27, 2023
2 parents 01ab596 + 7c77ced commit 64faed0
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 5 deletions.
9 changes: 8 additions & 1 deletion resqpy/property/_collection_add_part.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
def _add_selected_part_from_other_dict(collection, part, other, realization, support_uuid, uuid, continuous,
categorical, count, points, indexable, property_kind, facet_type, facet,
citation_title, citation_title_match_mode, time_series_uuid, time_index,
string_lookup_uuid, related_uuid, const_value, ignore_clashes):
string_lookup_uuid, related_uuid, const_value, extra, ignore_clashes):
if _check_not_none_and_not_equals(realization, other.realization_for_part, part):
return
if _check_not_none_and_not_uuid_match(support_uuid, other.support_uuid_for_part, part):
Expand Down Expand Up @@ -55,6 +55,13 @@ def _add_selected_part_from_other_dict(collection, part, other, realization, sup
assert other.model is not None
if other.model.part(parts_list = [part], related_uuid = related_uuid) is None:
return
if extra is not None and len(extra):
em = other.extra_metadata_for_part(part)
if em is None or len(em) < len(extra):
return
for key, value in extra.items():
if em.get(key) != value:
return
if part in collection.dict.keys():
if ignore_clashes:
return
Expand Down
3 changes: 2 additions & 1 deletion resqpy/property/property_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,7 @@ def inherit_parts_selectively_from_other_collection(
categorical = None,
related_uuid = None,
const_value = None,
extra = None,
ignore_clashes = False):
"""Adds those parts from the other PropertyCollection which match all arguments that are not None.
Expand Down Expand Up @@ -485,7 +486,7 @@ def inherit_parts_selectively_from_other_collection(
pcap._add_selected_part_from_other_dict(self, part, other, realization, support_uuid, uuid, continuous,
categorical, count, points, indexable, property_kind, facet_type,
facet, citation_title, citation_title_match_mode, time_series_uuid,
time_index, string_lookup_uuid, related_uuid, const_value,
time_index, string_lookup_uuid, related_uuid, const_value, extra,
ignore_clashes)

def inherit_similar_parts_for_time_series_from_other_collection(self,
Expand Down
7 changes: 5 additions & 2 deletions resqpy/property/property_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,8 @@ def selective_version_of_collection(collection,
title = None,
title_mode = None,
related_uuid = None,
const_value = None):
const_value = None,
extra = None):
"""Returns a new PropertyCollection with those parts which match all arguments that are not None.
arguments:
Expand All @@ -549,6 +550,7 @@ def selective_version_of_collection(collection,
if not specified and title or citation_title argument is present
related_uuid (UUID or str, optional): only properties with direct relationship to this uuid are selected
const_value (float or int, optional): only properties flagged as constant, with given value, are selected
extra (dict, optional): only properties where the extra metadata includes all the items of this dict are selected
returns:
a new PropertyCollection containing those properties which match the filter parameters that are not None
Expand Down Expand Up @@ -594,7 +596,8 @@ def selective_version_of_collection(collection,
string_lookup_uuid = string_lookup_uuid,
categorical = categorical,
related_uuid = related_uuid,
const_value = const_value)
const_value = const_value,
extra = extra)
return view


Expand Down
8 changes: 7 additions & 1 deletion tests/unit_tests/property/test_property.py
Original file line number Diff line number Diff line change
Expand Up @@ -2131,14 +2131,20 @@ def test_facet_array_ref(example_model_with_properties):
facet_type = 'what',
facet = facet)
pc.write_hdf5_for_imported_list()
pc.create_xml_for_imported_list_and_add_parts_to_model()
pc.create_xml_for_imported_list_and_add_parts_to_model(extra_metadata = {'test': 'new sat'})

# Act
empty_a = rqp.selective_version_of_collection(pc, extra = {'test': 'old sat'})
empty_b = rqp.selective_version_of_collection(pc, extra = {'testing': 'new sat'})
satpc_em = rqp.selective_version_of_collection(pc, extra = {'test': 'new sat'})
satpc = rqp.PropertyCollection()
satpc.set_support(support = model.grid())
satpc.inherit_parts_selectively_from_other_collection(pc, property_kind = 'saturation')

# Assert
assert empty_a is None or empty_a.number_of_parts() == 0
assert empty_b is None or empty_b.number_of_parts() == 0
assert satpc_em.number_of_parts() == 3
assert len(satpc.parts()) == 3 # added 3 parts
farray = satpc.facets_array_ref()
assert farray.shape == (3, 3, 5, 5)
Expand Down

0 comments on commit 64faed0

Please sign in to comment.