Commit 1783de23 authored by Julia Garriga Ferrer's avatar Julia Garriga Ferrer Committed by Julia Garriga Ferrer
Browse files

[gui][grainplot] Modify maps dictionary to have parameters for later replot of...

[gui][grainplot] Modify maps dictionary to have parameters for later replot of orientation distribution map
parent 77c4738a
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
__authors__ = ["J. Garriga"] __authors__ = ["J. Garriga"]
__license__ = "MIT" __license__ = "MIT"
__date__ = "05/08/2021" __date__ = "10/08/2021"
from matplotlib.colors import hsv_to_rgb from matplotlib.colors import hsv_to_rgb
import numpy import numpy
...@@ -62,7 +62,7 @@ class GrainPlotWidget(qt.QMainWindow): ...@@ -62,7 +62,7 @@ class GrainPlotWidget(qt.QMainWindow):
sigComputed = qt.Signal() sigComputed = qt.Signal()
def __init__(self, parent=None): def __init__(self, parent=None):
qt.QWidget.__init__(self, parent) qt.QMainWindow.__init__(self, parent)
self._methodCB = qt.QComboBox() self._methodCB = qt.QComboBox()
self._methodCB.addItems(Method.values()) self._methodCB.addItems(Method.values())
...@@ -200,7 +200,7 @@ class GrainPlotWidget(qt.QMainWindow): ...@@ -200,7 +200,7 @@ class GrainPlotWidget(qt.QMainWindow):
colors = self._curvesColormap.applyToData(levels) colors = self._curvesColormap.applyToData(levels)
xdim = self.dataset.dims.get(1) xdim = self.dataset.dims.get(1)
ydim = self.dataset.dims.get(0) ydim = self.dataset.dims.get(0)
self._curves = [] self._curves = {}
for ipolygon, polygon in enumerate(polygons): for ipolygon, polygon in enumerate(polygons):
# iso contours # iso contours
for icontour, contour in enumerate(polygon): for icontour, contour in enumerate(polygon):
...@@ -209,16 +209,20 @@ class GrainPlotWidget(qt.QMainWindow): ...@@ -209,16 +209,20 @@ class GrainPlotWidget(qt.QMainWindow):
# isClosed = numpy.allclose(contour[0], contour[-1]) # isClosed = numpy.allclose(contour[0], contour[-1])
x = contour[:, 1] x = contour[:, 1]
y = contour[:, 0] y = contour[:, 0]
x *= (xdim.unique_values[-1] - xdim.unique_values[0]) / (xdim.size - 1) rescale_x = (xdim.unique_values[-1] - xdim.unique_values[0]) / (xdim.size - 1)
y *= (ydim.unique_values[-1] - ydim.unique_values[0]) / (ydim.size - 1) rescale_y = (ydim.unique_values[-1] - ydim.unique_values[0]) / (ydim.size - 1)
x *= rescale_x
y *= rescale_y
if self._centerDataCheckbox.isChecked(): if self._centerDataCheckbox.isChecked():
xcenter = (xdim.unique_values[-1] - xdim.unique_values[0]) / 2 xcenter = (xdim.unique_values[-1] - xdim.unique_values[0]) / 2
x -= xcenter x -= xcenter
ycenter = (ydim.unique_values[-1] - ydim.unique_values[0]) / 2 ycenter = (ydim.unique_values[-1] - ydim.unique_values[0]) / 2
y -= ycenter y -= ycenter
self._curves.append((x, y, colors[ipolygon])) legend = "poly{}.{}".format(icontour, ipolygon)
legend = "custom-polygon-%d" % icontour * (ipolygon + 1) self._curves[legend] = {
"points": (x.copy(), y.copy()),
"color": colors[ipolygon]
}
self._contoursPlot.addCurve(x=x, y=y, linestyle="-", linewidth=2.0, self._contoursPlot.addCurve(x=x, y=y, linestyle="-", linewidth=2.0,
legend=legend, resetzoom=False, legend=legend, resetzoom=False,
color=colors[ipolygon]) color=colors[ipolygon])
...@@ -284,21 +288,29 @@ class GrainPlotWidget(qt.QMainWindow): ...@@ -284,21 +288,29 @@ class GrainPlotWidget(qt.QMainWindow):
""" """
Loads the file from a FileDialog. Loads the file from a FileDialog.
""" """
if self.dataset and self.dataset.dims.ndim > 1: if self.dataset and self.dataset.dims.ndim > 1:
nx = { nx = {
"entry": { "entry": {
"data": { "MOSAICITY": {
">" + Method.MOSAICITY.name: "../maps/" + Method.MOSAICITY.name, ">" + Method.MOSAICITY.name: "../maps/" + Method.MOSAICITY.name,
"@signal": Method.MOSAICITY.name, "@signal": Method.MOSAICITY.name,
"@NX_class": "NXdata" "@NX_class": "NXdata"
}, },
"maps": { "maps": {
Method.ORI_DIST.name: self.ori_dist,
Method.MOSAICITY.name: hsv_to_rgb(self._computeMosaicity()), Method.MOSAICITY.name: hsv_to_rgb(self._computeMosaicity()),
Method.MOSAICITY.name + "@interpretation": "rgba-image", Method.MOSAICITY.name + "@interpretation": "rgba-image",
"@NX_class": "NXcollection" "@NX_class": "NXcollection"
}, },
Method.ORI_DIST.name: {
"key": {
"image": hsv_to_rgb(self.hsv_key),
"scale": self._contoursPlot.getImage().getScale(),
"xlabel": self._contoursPlot.getImage().getXLabel(),
"ylabel": self._contoursPlot.getImage().getYLabel(),
"image@interpretation": "rgba-image",
},
"curves": self._curves
},
"@NX_class": "NXentry", "@NX_class": "NXentry",
"@default": "data", "@default": "data",
}, },
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment