Skip to content

Commit

Permalink
Load & display pixelsType, use pixel_range for max Z proj
Browse files Browse the repository at this point in the history
  • Loading branch information
will-moore committed Apr 11, 2024
1 parent 054222a commit a21caec
Show file tree
Hide file tree
Showing 9 changed files with 83 additions and 2 deletions.
3 changes: 3 additions & 0 deletions omero_figure/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@
# Use query ?image=1&image=2
re_path(r'^timestamps/$', views.timestamps, name='figure_timestamps'),

# Get pixelsType for images. Use query ?image=1&image=2
re_path(r'^pixels_type/$', views.pixels_type, name='figure_pixels_type'),

# Get Z scale for images
# Use query ?image=1&image=2
re_path(r'^z_scale/$', views.z_scale, name='figure_z_scale'),
Expand Down
20 changes: 20 additions & 0 deletions omero_figure/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,26 @@ def timestamps(request, conn=None, **kwargs):
return JsonResponse(data)


@login_required()
def pixels_type(request, conn=None, **kwargs):

iids = request.GET.getlist('image')
data = {}
for iid in iids:
try:
iid = int(iid)
except ValueError:
pass
else:
image = conn.getObject('Image', iid)
if image is not None:
data[image.id] = {
"pixelsType": image.getPixelsType(),
"pixel_range": image.getPixelRange()
}
return JsonResponse(data)


@login_required()
def z_scale(request, conn=None, **kwargs):

Expand Down
29 changes: 28 additions & 1 deletion src/js/models/figure_model.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

// Version of the json file we're saving.
// This only needs to increment when we make breaking changes (not linked to release versions.)
var VERSION = 7;
var VERSION = 8;


// ------------------------- Figure Model -----------------------------------
Expand Down Expand Up @@ -280,6 +280,31 @@
}
});
}

if (v < 8) {
console.log("Transforming to VERSION 8");
// need to load pixelsType.
var iids = json.panels.map(p => p.imageId);
console.log('Load pixelsType for images', iids);
if (iids.length > 0) {
var ptUrl = BASE_WEBFIGURE_URL + 'pixels_type/';
ptUrl += '?image=' + iids.join('&image=');
getJson(ptUrl).then(data => {
// Update all panels
// NB: By the time that this callback runs, the panels will have been created
self.panels.forEach(function(p){
var iid = p.get('imageId');
if (data[iid]) {
p.set({
'pixelsType': data[iid].pixelsType,
'pixel_range': data[iid].pixel_range
});
}
});
});
}
}

return json;
},

Expand Down Expand Up @@ -573,6 +598,8 @@
'pixel_size_x_unit': data.pixel_size.unitX,
'pixel_size_z_unit': data.pixel_size.unitZ,
'deltaT': data.deltaT,
'pixelsType': data.meta.pixelsType,
'pixels_range': data.pixels_range,
};
if (baseUrl) {
n.baseUrl = baseUrl;
Expand Down
17 changes: 17 additions & 0 deletions src/js/models/panel_model.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@
// we replace these attributes...
var newData = {'imageId': data.imageId,
'name': data.name,
'pixelsType': data.pixelsType,
'pixel_range': data.pixel_range,
'sizeZ': data.sizeZ,
'sizeT': data.sizeT,
'orig_width': data.orig_width,
Expand Down Expand Up @@ -559,6 +561,21 @@
}
},

getMaxZprojPlanes: function() {
const MAX_BYTES = 1024 * 1024 * 256;
let bytes_per_pixel = 4;
if (this.get("pixel_range")) {
bytes_per_pixel = Math.ceil(Math.log2(this.get("pixel_range")[1]) / 8.0);
}
console.log('pixel_range', this.get("pixel_range"), 'bytes_per_pixel', bytes_per_pixel);
let active_channels = this.get("channels").reduce((prev, channel) => channel.active ? prev + 1 : prev, 0);
console.log('active_channels', active_channels);
let max_planes = MAX_BYTES / bytes_per_pixel / (this.get('orig_width') * this.get('orig_height'));
max_planes = Math.floor(max_planes / active_channels);
console.log("max_planes", max_planes);
return max_planes;
},

// When a multi-select rectangle is drawn around several Panels
// a resize of the rectangle x1, y1, w1, h1 => x2, y2, w2, h2
// will resize the Panels within it in proportion.
Expand Down
3 changes: 2 additions & 1 deletion src/js/views/info_panel_view.js
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,8 @@ var InfoPanelView = Backbone.View.extend({
} else {
json.name = title;
// compare json summary so far with this Panel
var attrs = ["imageId", "orig_width", "orig_height", "sizeT", "sizeZ", "x", "y", "width", "height", "dpi", "min_export_dpi", "max_export_dpi"];
var attrs = ["imageId", "orig_width", "orig_height", "sizeT", "sizeZ", "x", "y",
"width", "height", "dpi", "min_export_dpi", "max_export_dpi", "pixelsType"];
_.each(attrs, function(a){
if (json[a] != this_json[a]) {
if (a === 'x' || a === 'y' || a === 'width' || a === 'height') {
Expand Down
2 changes: 2 additions & 0 deletions src/js/views/modal_views.js
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,8 @@ import { hideModal } from "./util";
var newImg = {
'imageId': data.id,
'name': data.meta.imageName,
'pixelsType': data.meta.pixelsType,
'pixel_range': data.pixel_range,
// 'width': data.size.width,
// 'height': data.size.height,
'sizeZ': data.size.z,
Expand Down
3 changes: 3 additions & 0 deletions src/js/views/right_panel_view.js
Original file line number Diff line number Diff line change
Expand Up @@ -1091,9 +1091,11 @@
sum_sizeZ = 0,
rotation,
z_projection,
max_z_proj_planes = Infinity,
zp;
if (this.models) {
this.models.forEach(function(m, i){
max_z_proj_planes = Math.min(max_z_proj_planes, m.getMaxZprojPlanes());
rotation = m.get('rotation');
max_rotation = Math.max(max_rotation, rotation);
sum_rotation += rotation;
Expand Down Expand Up @@ -1123,6 +1125,7 @@
const z_projection_disabled = ((sum_sizeZ === this.models.length) || anyBig);

html = this.template({
zrange_max: max_z_proj_planes,
projectionIconUrl,
'z_projection_disabled': z_projection_disabled,
'rotation': rotation,
Expand Down
6 changes: 6 additions & 0 deletions src/templates/image_display_options.template.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,9 @@
<img src="<%= projectionIconUrl %>" />
</button>
</div>

<div style="font-size: 80%; line-height: 1.3;">
<button class="btn btn-sm btn-link" style="padding: 0; margin: 0; font-size: 0.8rem; text-align: left;;">
Z-range max: <%= zrange_max %>
</button>
</div>
2 changes: 2 additions & 0 deletions src/templates/info_panel.template.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
print(_.escape(c)); print((i < channels.length-1) ? ", " : "");
}); %>
</small></div>
<div class="col-sm-5"><small><strong>Pixels Type</strong>:</small></div>
<div class="col-sm-7"><small><%= pixelsType %></small></div>
</td></tr>
</tbody>
</table>

0 comments on commit a21caec

Please sign in to comment.