Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
0fbcc59
Added QTiledWidget.py to PyMca5/PyMcaGui/io. This has the TiledBrowse…
Jul 8, 2024
1dd5774
Added bluesky icon to IconDict0, which will then add it to IconDict f…
Jul 8, 2024
1cd65a8
Added a tiledButton to the source selector that will have the bluesky…
Jul 8, 2024
995142b
Added key value pairs to both source_types and source_widgets dicts. …
Jul 8, 2024
02760b6
Changed relative reference of QDataSource in the imports to reference…
Jul 8, 2024
e6781dc
Created a file for QDataSource in order to create a Tab for Tiled dat…
Jul 8, 2024
bec9a91
Removed debugging code from QSourceSelector.py and PyMca_Icons.py
Jul 12, 2024
11b1664
Connected bluesky pushbutton to the Tiled Tab so that when the icon i…
Jul 18, 2024
659713b
Added shells of TiledDataSource.py and TiledFile.py. TiledDataSource.…
Jul 18, 2024
3ff42ea
Replaced all Nexus references with Tiled in TiledDataSource.py.
Jul 18, 2024
5866fe5
Changed relative imports to absolute imports and fixed way McaWindow …
Jul 25, 2024
7985524
Created Data Channel Table for Tiled Browser.
Jul 29, 2024
6426a70
Formatted Data Channel Table and set it up so the data channels are c…
Jul 30, 2024
4711c8e
Connect 'ADD', 'REPLACE', and 'REMOVE' buttons in Tiled Browser to me…
Jul 30, 2024
dda425c
Cleaned up Data Channel Table. Added Search By Widgets to Tiled Brows…
Aug 2, 2024
56aa0a9
Cleanned up files per comments on last PR.
Aug 2, 2024
b6f3be9
Added search by functionality to Tiled Browser.
Aug 5, 2024
48d437f
Added search entry functionality to Tiled Browser.
Aug 6, 2024
e9f67cc
Can select items in Catalog Table that have text that is not uid now.
Aug 6, 2024
f70e200
Search bar filters results for entire Catalog table now.
Aug 7, 2024
8c7d9aa
Different scans can be selected, search by can be changed, and search…
Aug 8, 2024
c1e3861
Can change rows per page after scan is selected now.
Aug 8, 2024
970a204
Recent changes to Tiled Browser, TiledDataSource, and QDataSource. Ti…
Aug 16, 2024
f900427
WIP using TiledDataSource
AbbyGi Aug 30, 2024
dbc295d
Rename TiledDataSource to QTiledDataSource
AbbyGi Sep 3, 2024
fe433b8
Plotting not working but no errors
AbbyGi Sep 5, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
158 changes: 158 additions & 0 deletions PyMca5/PyMcaCore/QTiledDataSource.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
import numpy as np
import time
import sys

from PyMca5.PyMcaCore import DataObject
from PyMca5.PyMcaGui.io.TiledDataChannelTable import TiledDataChannelTable
from PyMca5.PyMcaGui.io.QTiledWidget import TiledBrowser
from PyMca5.PyMcaGui.pymca import QSource


SOURCE_TYPE = 'Tiled'

class QTiledDataSource(QSource.QSource):
"""
Creates instance of a Tiled Data Source class. This is neccesary
to create a Tiled Tab in the QDispatcher, which houses the Tiled
Browser.

This is largely based on the NexusDataSource class, but all Data
Source tabs (Spec, EDF, SPS) have an analogous class.

See QDataSource.py
"""

def __init__(self, nameInput):
print("-------- QTiledDataSource init")
super().__init__()
if isinstance(nameInput, list):
nameList = nameInput
else:
nameList = [nameInput]
self.sourceName = nameList
self.sourceType = SOURCE_TYPE
self.__sourceNameList = self.sourceName
self.refresh()

def refresh(self):
pass

def getDataObject(self, key_list, selection=None, poll=False):
if type(key_list) not in [type([])]:
nolist = True
key_list = [key_list]
else:
output = []
nolist = False
data = self.get_data_object(key_list, selection=selection)

return data

def _set_key(self, selection=None):
"""Sets key once a scan has been selected in Tiled Browser."""

key = {
"scan": selection.metadata['start']['uid'],
"scan_id": selection.metadata['start']['scan_id'],
"streams": list(selection),
"selection": selection,
}

return key

def _set_data_channel_selection(self):
"""Retrieve Data Channel Selections from Tiled Data Channel Table."""
print("-------- QTiledDataSource _set_data_channel_selection")
channel_sel = TiledDataChannelTable.getChannelSelection()
self.chan_sel = {
'x': channel_sel['x'],
'y': channel_sel['y'],
'm': channel_sel['m'],
'Channel List': channel_sel['Data Channel List'],
}

def _get_key_info(self, selection):
"""Retrives key info."""

key = self._set_key(selection=selection)
key_info = {
"SourceType": SOURCE_TYPE,
"selection": selection,
"key": key,
}

return key_info

def get_data_object(self, key, selection=None):
"""Generate a dataObject that will be used to plot scan data."""
print("-------- QTiledDataSource get_data_object")
dataObject = DataObject.DataObject()
dataObject.info = self._get_key_info(selection)
dataObject.data = key['selection']

chan_sel = self.chan_sel

# What data.info attributes to add?
dataObject.info['selection'] = selection

# data = [key['selection']][datachannel][data]
# If data channel selected in x axis go to data and time
dataObject.data.x = dataObject.data.chan_sel['x']['data']['time']
# If data channel selected in y axis plot everything
dataObject.data.y = dataObject.data.chan_sel['y']['data']
# If data selected in m divide y by m and plot
dataObject.data.m = dataObject.data.chan_sel['m']['data']

return dataObject

def isUpdated(self,key):
pass


def _is_Tiled_Source(filename):
try:
if hasattr(filename, self.node_path):
return True
except Exception:
return False

source_types = {SOURCE_TYPE: QTiledDataSource}

def DataSource(name="", source_type=SOURCE_TYPE):
try:
sourceClass = source_types[source_type]
except KeyError:
#ERROR invalid source type
raise TypeError("Invalid Source Type, source type should be one of %s" %\
source_types.keys())
return sourceClass(name)


if __name__ == "__main__":
try:
sourcename = sys.argv[1]
key = sys.argv[2]
except Exception:
print("Usage: QTiledDataSource <file> <key>")
sys.exit()
#one can use this:
obj = QTiledDataSource(sourcename)
#or this:
obj = DataSource(sourcename)
#data = obj.getData(key,selection={'pos':(10,10),'size':(40,40)})
#data = obj.getDataObject(key,selection={'pos':None,'size':None})
t0 = time.time()
data = obj.getDataObject(key,selection=None)
print("elapsed = ",time.time() - t0)
print("info = ",data.info)
if data.data is not None:
print("data shape = ",data.data.shape)
print(np.ravel(data.data)[0:10])
else:
print(data.y[0].shape)
print(np.ravel(data.y[0])[0:10])
data = obj.getDataObject('1.1',selection=None)
r = int(key.split('.')[-1])
print(" data[%d,0:10] = " % (r-1),data.data[r-1 ,0:10])
print(" data[0:10,%d] = " % (r-1),data.data[0:10, r-1])

20 changes: 20 additions & 0 deletions PyMca5/PyMcaGui/io/QSourceSelector.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ def __init__(self, parent=None, filetypelist=None, pluginsIcon=False):
self.specIcon = qt.QIcon(qt.QPixmap(icons.IconDict["bliss"]))
else:
self.specIcon = qt.QIcon(qt.QPixmap(icons.IconDict["spec"]))
self.tiledIcon = qt.QIcon(qt.QPixmap(icons.IconDict["bluesky"]))

openButton.setIcon(self.openIcon)
openButton.setSizePolicy(qt.QSizePolicy(qt.QSizePolicy.Fixed, qt.QSizePolicy.Minimum))
Expand All @@ -106,8 +107,13 @@ def __init__(self, parent=None, filetypelist=None, pluginsIcon=False):
else:
specButton.setToolTip("Open new shared memory source")

tiledButton = qt.QPushButton(self.fileWidget)
tiledButton.setIcon(self.tiledIcon)
tiledButton.setToolTip("Open tiled data source")

closeButton.setSizePolicy(qt.QSizePolicy(qt.QSizePolicy.Fixed, qt.QSizePolicy.Minimum))
specButton.setSizePolicy(qt.QSizePolicy(qt.QSizePolicy.Fixed, qt.QSizePolicy.Minimum))
tiledButton.setSizePolicy(qt.QSizePolicy(qt.QSizePolicy.Fixed, qt.QSizePolicy.Minimum))
refreshButton.setSizePolicy(qt.QSizePolicy(qt.QSizePolicy.Fixed, qt.QSizePolicy.Minimum))

openButton.clicked.connect(self._openFileSlot)
Expand All @@ -121,10 +127,13 @@ def __init__(self, parent=None, filetypelist=None, pluginsIcon=False):
_logger.debug("Using deprecated signal")
self.fileCombo.activated[str].connect(self._fileSelection)

tiledButton.clicked.connect(self.tiledConnection)

fileWidgetLayout.addWidget(self.fileCombo)
fileWidgetLayout.addWidget(openButton)
fileWidgetLayout.addWidget(closeButton)
fileWidgetLayout.addWidget(specButton)
fileWidgetLayout.addWidget(tiledButton)
if sys.platform == "win32":specButton.hide()
fileWidgetLayout.addWidget(refreshButton)
self.specButton = specButton
Expand Down Expand Up @@ -331,6 +340,17 @@ def openSpec(self):
lambda i=spec:self.openFile(i, specsession=True))
menu.exec(self.cursor().pos())

def tiledConnection(self):
"""When 'bluesky' icon clicked it opens the TiledBrowser in the Tiled Tab"""
# ddict = {"event": "Open Tiled Tab"}
url = "https://tiled-demo.blueskyproject.io/api"
ddict = {
"event": "NewSourceSelected",
"sourcelist": url,
}
self.sigSourceSelectorSignal.emit(ddict)

# Potentially add a authorization window when clicked

def _fileSelection(self, qstring):
_logger.debug("file selected %s", qstring)
Expand Down
Loading