Given the key, sync up between metatensor `data_dict[key]` and meta_dict `data_dict[key_transforms/meta_dict]`. t=True: the one with more applied_operations in metatensor vs meta_dict is the output, False: less is the output.
(key, data_dict, t: bool = True)
| 2152 | |
| 2153 | |
| 2154 | def sync_meta_info(key, data_dict, t: bool = True): |
| 2155 | """ |
| 2156 | Given the key, sync up between metatensor `data_dict[key]` and meta_dict `data_dict[key_transforms/meta_dict]`. |
| 2157 | t=True: the one with more applied_operations in metatensor vs meta_dict is the output, False: less is the output. |
| 2158 | """ |
| 2159 | if not isinstance(data_dict, Mapping): |
| 2160 | return data_dict |
| 2161 | d = dict(data_dict) |
| 2162 | |
| 2163 | # update meta dicts |
| 2164 | meta_dict_key = PostFix.meta(key) |
| 2165 | if meta_dict_key not in d: |
| 2166 | d[meta_dict_key] = monai.data.MetaTensor.get_default_meta() |
| 2167 | if not isinstance(d[key], monai.data.MetaTensor): |
| 2168 | d[key] = monai.data.MetaTensor(data_dict[key]) |
| 2169 | d[key].meta = d[meta_dict_key] |
| 2170 | d[meta_dict_key].update(d[key].meta) # prefer metatensor's data |
| 2171 | |
| 2172 | # update xform info |
| 2173 | xform_key = monai.transforms.TraceableTransform.trace_key(key) |
| 2174 | if xform_key not in d: |
| 2175 | d[xform_key] = monai.data.MetaTensor.get_default_applied_operations() |
| 2176 | from_meta, from_dict = d[key].applied_operations, d[xform_key] |
| 2177 | if not from_meta: # avoid [] |
| 2178 | d[key].applied_operations = d[xform_key] = from_dict |
| 2179 | return d |
| 2180 | if not from_dict: |
| 2181 | d[key].applied_operations = d[xform_key] = from_meta |
| 2182 | return d |
| 2183 | if t: # larger transform info stack is used as the result |
| 2184 | ref = from_meta if len(from_meta) > len(from_dict) else from_dict |
| 2185 | else: # smaller transform info stack is used as the result |
| 2186 | ref = from_dict if len(from_meta) > len(from_dict) else from_meta |
| 2187 | d[key].applied_operations = d[xform_key] = ref |
| 2188 | return d |
| 2189 | |
| 2190 | |
| 2191 | def check_boundaries(boundaries) -> None: |
nothing calls this directly
no test coverage detected
searching dependent graphs…