Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issues with mosaic plot #3

Open
serbng opened this issue Oct 17, 2024 · 0 comments
Open

Issues with mosaic plot #3

serbng opened this issue Oct 17, 2024 · 0 comments
Assignees
Labels
bug Something isn't working question Further information is requested

Comments

@serbng
Copy link
Collaborator

serbng commented Oct 17, 2024

Issue with Mosaic tab in lauetoolsenv2

Hello everyone.

I tried generating some mosaic plots with the GUI but failed.

Tried on the notebook with lauetoolsenv2, but I failed.

Details

In the peaksearch board I opened the first image of the dataset

/data/visitor/a321204/bm32/20240919/RAW_DATA/lto_fa2/lto_fa2_test/scan0003

Under Mosaic & Monitor I zoomed on the central LTO peak in the blue square and selected the parameters

image

Starting the mosaic plot yields in the terminal:

counter mosaic selected
current dict of ROIs {'None': (5, 2, 2)}
in buildMosaic() of PEAKSEARCHGUI.py------------------------------------

nbimages_asked 101
nbimages_per_line 101
reminder == 0
nb_lines 1
len(selected2Darray_imageindex) 101
selected2Darray_imageindex [[  0   1   2   3   4   5   6   7   8   9  10  11  12  13  14  15  16  17
   18  19  20  21  22  23  24  25  26  27  28  29  30  31  32  33  34  35
   36  37  38  39  40  41  42  43  44  45  46  47  48  49  50  51  52  53
   54  55  56  57  58  59  60  61  62  63  64  65  66  67  68  69  70  71
   72  73  74  75  76  77  78  79  80  81  82  83  84  85  86  87  88  89
   90  91  92  93  94  95  96  97  98  99 100]]
selected pixel position: xpic, ypic 1462.0 1493.0
len(selected2Darray_imageindex) 1
(nb_lines, nbimages_per_line) (1, 101)
dict_param in buildMosaic3  {'imagesfolder': '/home/esrf/bongiorn/Documents/20240919 - a321204/lto_fa2/lto_fa2_test/scan0003', 'filename_representative': 'img_0001.tif', 'CCDLabel': 'sCMOS', 'nbdigits': 4, 'selected2Darray_imageindex': array([[  0,   1,   2,   3,   4,   5,   6,   7,   8,   9,  10,  11,  12,
         13,  14,  15,  16,  17,  18,  19,  20,  21,  22,  23,  24,  25,
         26,  27,  28,  29,  30,  31,  32,  33,  34,  35,  36,  37,  38,
         39,  40,  41,  42,  43,  44,  45,  46,  47,  48,  49,  50,  51,
         52,  53,  54,  55,  56,  57,  58,  59,  60,  61,  62,  63,  64,
         65,  66,  67,  68,  69,  70,  71,  72,  73,  74,  75,  76,  77,
         78,  79,  80,  81,  82,  83,  84,  85,  86,  87,  88,  89,  90,
         91,  92,  93,  94,  95,  96,  97,  98,  99, 100]]), 'pixelX_center': 1462.0, 'pixelY_center': 1493.0, 'pixelboxsize_X': 15, 'pixelboxsize_Y': 15, 'selectedcounters': ['mosaic'], 'NormalizeWithMonitor': False, 'monitoroffset': 0.0}
filename_representative img_0001.tif
ccdlabel sCMOS
selectedcounters ['mosaic']
nb_lines,nb_col 1 101
selected1Darray_absoluteimageindex [  0   1   2   3   4   5   6   7   8   9  10  11  12  13  14  15  16  17
  18  19  20  21  22  23  24  25  26  27  28  29  30  31  32  33  34  35
  36  37  38  39  40  41  42  43  44  45  46  47  48  49  50  51  52  53
  54  55  56  57  58  59  60  61  62  63  64  65  66  67  68  69  70  71
  72  73  74  75  76  77  78  79  80  81  82  83  84  85  86  87  88  89
  90  91  92  93  94  95  96  97  98  99 100]


Traceback (most recent call last):
  File "/mnt/multipath-shares/data/bm32/inhouse/lauetoolsenv2/lib/python3.8/site-packages/LaueTools/GUI/PeakSearchGUI.py", line 1331, in OnMosaic
    self.mainframe.buildMosaic(parent=self)
  File "/mnt/multipath-shares/data/bm32/inhouse/lauetoolsenv2/lib/python3.8/site-packages/LaueTools/GUI/PeakSearchGUI.py", line 4522, in buildMosaic
    MOS.buildMosaic3(dict_param, outputfolder, parent=parent,
  File "/mnt/multipath-shares/data/bm32/inhouse/lauetoolsenv2/lib/python3.8/site-packages/LaueTools/GUI/mosaic.py", line 2463, in buildMosaic3
    stackimageindex=stackimageindex)
UnboundLocalError: local variable 'stackimageindex' referenced before assignment

Backtracking the source code of the mosaic plot in GUI/PeakSearchGUI.py and GUI/mosaic.py, I created a jupyter notebook (/data/bm32/inhouse/STAFF/SERGIOB/build_mosaic.ipynb) that should achieve the same thing. When executed with lauetoolsenv2, the error message reads

---------------------------------------------------------------------------
UnboundLocalError                         Traceback (most recent call last)
Cell In[9], line 1
----> 1 CountersData = MOS.buildMosaic3(dict_param, os.getcwd(), parent = None, verbose =0)

File /mnt/multipath-shares/data/bm32/inhouse/lauetoolsenv2/lib/python3.8/site-packages/LaueTools/GUI/mosaic.py:2463, in buildMosaic3(dict_param, outputfolder, ccdlabel, plot, parent, dictfittingparameters, verbose)
   2454         print("imin, imax, jmin, jmax", imin, imax, jmin, jmax)
   2455     # new fast way to read specific area in file directly
   2456     datacrop = IOimage.readrectangle_in_image(filename,
   2457                                             xpic,
   2458                                             ypic,
   2459                                             halfboxsizes[0],
   2460                                             halfboxsizes[1],
   2461                                             dirname=None,
   2462                                             CCDLabel=ccdlabel,
-> 2463                                             stackimageindex=stackimageindex)
   2464     #print('datacrop max --> ', np.amax(datacrop))
   2465 else:  # ends with("tif.gz")
   2467     framedim = framedimraw

UnboundLocalError: local variable 'stackimageindex' referenced before assignment

However, in the current version of LaueTools on GitHub there is no input variable named stackimageindex!
Not only that, but in the docstring (the types are specified whereas in the repo they are not)

Notebook with laueenv

For reference, I report the minimal working example that I wrote.

import os
import numpy as np
from LaueTools.GUI import mosaic as MOS
import LaueTools.generaltools as GT

dict_param = {"imagesfolder": '/data/visitor/a321204/bm32/20240919/RAW_DATA/lto_fa2/lto_fa2_test/scan0003',
              "filename_representative": "img_0000.tif",
              "CCDLabel": "sCMOS",
              "nbdigits": 4,
              "pixelX_center": 1460,
              "pixelY_center": 1491,
              "pixelboxsize_X": 20,
              "pixelboxsize_Y": 20,
              "NormalizeWithMonitor": False,
            # ------------------------------------- 
              "startind": 0,
              "endind": 99,
              "stepind": 1,
              "nb_lines": 1,
              "nb_images_per_line": 100,
              "xpic": 1460,
              "ypic": 1491,
              "boxsize_col": 20,
              "boxsize_line": 20,
              "selectedcounters": ["mosaic"], # NEEDS TO BE A LIST!!
              "monitoroffset": None
}
absoluteimageindexarray2D = (dict_param["startind"] + np.arange(dict_param["endind"] - dict_param["startind"] + 1)).reshape((dict_param["nb_lines"], dict_param["nb_images_per_line"]))

dict_param["selected2Darray_imageindex"] = absoluteimageindexarray2D

CountersData = MOS.buildMosaic3(dict_param, os.getcwd(), parent = None, verbose =0)

import matplotlib.pyplot as plt
fig, ax = plt.subplots()
fig.set_size_inches(25,3)
ax.imshow(np.loadtxt("MOSAIC_image_Plot_date_20241017_155412"), vmin = 1000, vmax = 8000, cmap = 'OrRd')

image

The plot will be generated and saved in a file, but buildMosaic3 doesn't manage to show it. In the jupyter slurm it's understandable since it tries to open a window but fails, returning:

import wx
wx.App(False)

SystemExit: Unable to access the X Display, is $DISPLAY set properly?

Nevertheless, even executing the same notebook in vscode directly on the esrf computer doesn't seem to work.

@serbng serbng added bug Something isn't working question Further information is requested labels Oct 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working question Further information is requested
Projects
None yet
Development

No branches or pull requests

4 participants