Commit 760f1d7c authored by Julia Garriga Ferrer's avatar Julia Garriga Ferrer
Browse files

[gui][grainplot] Use dicttonx to save data into nexus file

parent 2b0c0c4f
Pipeline #52153 passed with stage
in 6 minutes and 9 seconds
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
__authors__ = ["J. Garriga"] __authors__ = ["J. Garriga"]
__license__ = "MIT" __license__ = "MIT"
__date__ = "07/06/2021" __date__ = "05/08/2021"
from matplotlib.colors import hsv_to_rgb from matplotlib.colors import hsv_to_rgb
import numpy import numpy
...@@ -37,10 +37,10 @@ from silx.gui.plot import Plot2D ...@@ -37,10 +37,10 @@ from silx.gui.plot import Plot2D
from silx.image.marchingsquares import find_contours from silx.image.marchingsquares import find_contours
from silx.math.medianfilter import medfilt2d from silx.math.medianfilter import medfilt2d
from silx.utils.enum import Enum as _Enum from silx.utils.enum import Enum as _Enum
from silx.io.dictdump import dicttonx
import darfix import darfix
from .operationThread import OperationThread from .operationThread import OperationThread
from darfix.io.utils import write_maps
class Method(_Enum): class Method(_Enum):
...@@ -200,6 +200,7 @@ class GrainPlotWidget(qt.QMainWindow): ...@@ -200,6 +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 = []
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):
...@@ -216,6 +217,7 @@ class GrainPlotWidget(qt.QMainWindow): ...@@ -216,6 +217,7 @@ class GrainPlotWidget(qt.QMainWindow):
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 = "custom-polygon-%d" % icontour * (ipolygon + 1) legend = "custom-polygon-%d" % icontour * (ipolygon + 1)
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,
...@@ -282,16 +284,37 @@ class GrainPlotWidget(qt.QMainWindow): ...@@ -282,16 +284,37 @@ class GrainPlotWidget(qt.QMainWindow):
""" """
Loads the file from a FileDialog. Loads the file from a FileDialog.
""" """
list_of_maps = {}
if self.dataset.dims.ndim > 1:
nx = {
"entry": {
"data": {
">" + Method.MOSAICITY.name: "../maps/" + Method.MOSAICITY.name,
"@signal": Method.MOSAICITY.name,
"@NX_class": "NXdata"
},
"maps": {
Method.ORI_DIST.name: self.ori_dist,
Method.MOSAICITY.name: hsv_to_rgb(self._computeMosaicity()),
Method.MOSAICITY.name + "@interpretation": "rgba-image",
"@NX_class": "NXcollection"
},
"@NX_class": "NXentry",
"@default": "data",
},
"@NX_class": "NXroot",
"@default": "entry"
}
for axis, dim in self.dataset.dims: for axis, dim in self.dataset.dims:
list_of_maps[dim.name] = { nx["entry"]["maps"].update(
{
Method.COM.name: self._moments[axis][0], Method.COM.name: self._moments[axis][0],
Method.FWHM.name: self._moments[axis][1], Method.FWHM.name: self._moments[axis][1],
Method.SKEWNESS.name: self._moments[axis][2], Method.SKEWNESS.name: self._moments[axis][2],
Method.KURTOSIS.name: self._moments[axis][3] Method.KURTOSIS.name: self._moments[axis][3]
} }
)
list_of_maps[Method.MOSAICITY.name] = hsv_to_rgb(self._computeMosaicity())
fileDialog = qt.QFileDialog() fileDialog = qt.QFileDialog()
...@@ -300,4 +323,4 @@ class GrainPlotWidget(qt.QMainWindow): ...@@ -300,4 +323,4 @@ class GrainPlotWidget(qt.QMainWindow):
fileDialog.setOption(fileDialog.DontUseNativeDialog) fileDialog.setOption(fileDialog.DontUseNativeDialog)
fileDialog.setDefaultSuffix(".h5") fileDialog.setDefaultSuffix(".h5")
if fileDialog.exec_(): if fileDialog.exec_():
write_maps(fileDialog.selectedFiles()[0], list_of_maps, Method.MOSAICITY.name, 'entry', 1) dicttonx(nx, fileDialog.selectedFiles()[0])
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