Skip to content

Commit

Permalink
Update metadata structure for non-uniform values, update frame select…
Browse files Browse the repository at this point in the history
…or component and tests
  • Loading branch information
annehaley committed Oct 16, 2024
1 parent fbc3f93 commit b3fde84
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 46 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
<script>
import Vue from 'vue';
import {restRequest} from '@girder/core/rest';
import {getChannelColor, OTHER_COLORS} from '../utils/colors';
import CompositeLayers from './CompositeLayers.vue';
Expand All @@ -23,8 +21,7 @@ export default Vue.extend({
indexInfo: {},
style: {},
modesShown: {1: true},
histogramParamStyles: {},
internalMetadata: undefined
histogramParamStyles: {}
};
},
computed: {
Expand All @@ -43,30 +40,22 @@ export default Vue.extend({
sliderLabels() {
const labels = {};
labels.IndexC = this.imageMetadata.channels;
if (
this.internalMetadata &&
this.internalMetadata.zarr &&
this.internalMetadata.zarr.main &&
this.internalMetadata.zarr.main.multiscales &&
this.internalMetadata.zarr.main.multiscales[0] &&
this.internalMetadata.zarr.main.multiscales[0].axes
) {
this.internalMetadata.zarr.main.multiscales[0].axes.forEach((axis) => {
if (axis.values) {
const key = 'Index' + axis.name.toUpperCase();
const expectedLength = this.indexInfo[key].range + 1;
if (axis.values.length === expectedLength) {
// uniform values have same length as axis
labels[key] = axis.values;
} else if (axis.values.length === this.maxFrame + 1) {
Object.entries(this.metadata).forEach(([key, info]) => {
if (key.includes("Value")) {
const labelKey = key.replace('Value', 'Index')
if (info.values) {
if (info.uniform) {
labels[labelKey] = info.values
} else {
// non-uniform values have a value for every frame
// labels will change with currentFrame, so only populate current label
labels[key] = new Array(expectedLength).fill('');
labels[key][this.indexInfo[key].current] = axis.values[this.currentFrame];
labels[labelKey] = new Array(this.indexInfo[labelKey].range + 1).fill('');
labels[labelKey][this.indexInfo[labelKey].current] = info.values[this.currentFrame];
}
}
});
}
}
})
return labels;
}
},
Expand All @@ -79,22 +68,12 @@ export default Vue.extend({
mounted() {
this.metadata = Object.assign({}, this.imageMetadata);
this.fillMetadata();
this.fetchInternalMetadata();
this.maxFrame = this.metadata.frames.length - 1;
this.populateIndices();
this.populateModes();
this.loaded = true;
},
methods: {
fetchInternalMetadata() {
restRequest({
type: 'GET',
url: 'item/' + this.itemId + '/tiles/internal_metadata/'
}).then((internal) => {
this.internalMetadata = internal;
return undefined;
});
},
setCurrentMode(mode) {
this.currentModeId = mode.id;
},
Expand Down
21 changes: 12 additions & 9 deletions large_image/tilesource/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1334,24 +1334,27 @@ def _getFrameValueInformation(self, frames: List[Dict]):
if hasattr(self, 'frameUnits') and self.frameUnits is not None:
units = self.frameUnits.get(axis_name)
uniform = all(len(set(value_list)) <= 1 for value_list in value_mapping.values())
# after evaluating uniform, continue with only
# the first value for each index along this axis
first_values = [
value_list[0] for value_list in value_mapping.values() if len(value_list)
]
if uniform:
# for uniform values, only record values at each axis index
values = [
value_list[0] for value_list in value_mapping.values() if len(value_list)
]
else:
# for non-uniform axes, record values at every frame
values = [frame.get(key) for frame in frames]
try:
min_val = min(first_values)
max_val = max(first_values)
min_val = min(values)
max_val = max(values)
except TypeError:
min_val = None
max_val = None
frame_value_info[key] = dict(
values=first_values,
values=values,
uniform=uniform,
units=units,
min=min_val,
max=max_val,
datatype=np.array(first_values).dtype.name,
datatype=np.array(values).dtype.name,
)
return frame_value_info

Expand Down
20 changes: 17 additions & 3 deletions test/test_sink.py
Original file line number Diff line number Diff line change
Expand Up @@ -560,11 +560,11 @@ def get_expected_metadata(axis_spec, frame_shape):
},
**{
f'Value{k.upper()}': dict(
values=v['values'],
values=v.get('all_values', v['values']),
units=v['units'],
uniform=v['uniform'],
min=min(v['values']),
max=max(v['values']),
min=min(v.get('all_values', v['values'])),
max=max(v.get('all_values', v['values'])),
datatype=v['dtype'],
) for k, v in axis_spec.items()
},
Expand Down Expand Up @@ -656,6 +656,20 @@ def testFrameValues(use_add_tile_args, tmp_path):
),
t=dict(
values=[10.0, 20.0, 30.0],
all_values=(
[10.00] * 3 +
[10.01] * 3 +
[10.02] * 3 +
[10.03] * 3 +
[20.00] * 3 +
[20.01] * 3 +
[20.02] * 3 +
[20.03] * 3 +
[30.00] * 3 +
[30.01] * 3 +
[30.02] * 3 +
[30.03] * 3
),
uniform=False,
units='millisecond',
stride=3,
Expand Down

0 comments on commit b3fde84

Please sign in to comment.