(self, metadata, keys: List[str] = None)
| 954 | return f"{self.metadata_id_map[key]} v0={bin_idx}" |
| 955 | |
| 956 | def metadata_to_string(self, metadata, keys: List[str] = None): |
| 957 | keys = list(metadata.keys()) if keys is None else keys |
| 958 | |
| 959 | if self.shuffle: |
| 960 | # Randomly shuffle |
| 961 | random.shuffle(keys) |
| 962 | if self.random_trunc: |
| 963 | # Randomly truncate |
| 964 | keys = keys[:random.randint(1,len(keys))] |
| 965 | |
| 966 | metadata_strings = [] |
| 967 | |
| 968 | for key in keys: |
| 969 | if key in self.image_dim_modalities: |
| 970 | # Image dimension modalities |
| 971 | metadata_str = self.image_dim_to_string(metadata, key, bin_size=self.image_dim_bin_size) |
| 972 | elif key in self.metadata_int_modalities: |
| 973 | # Integer modalities that don't undergo any scaling |
| 974 | metadata_str = self.int_metadata_to_string(metadata, key) |
| 975 | elif key in self.metadata_manual_bins: |
| 976 | # Metadata modalities for which bin boundaries are manually defined |
| 977 | metadata_str = self.manual_bin_metadata_to_string(metadata, key) |
| 978 | else: |
| 979 | # All other modalities |
| 980 | vmin, vmax, bins = self.metadata_min_max_bins[key] |
| 981 | metadata_str = self.float_metadata_to_string(metadata, key, vmin, vmax, bins) |
| 982 | |
| 983 | metadata_strings.append(metadata_str) |
| 984 | |
| 985 | if self.return_chunks: |
| 986 | return metadata_strings |
| 987 | else: |
| 988 | return ' '.join(metadata_strings) |
| 989 | |
| 990 | def load(self, path): |
| 991 | with open(path, 'r') as f: |
no test coverage detected