Skip to content

Commit

Permalink
???
Browse files Browse the repository at this point in the history
  • Loading branch information
cudmore committed Mar 5, 2025
1 parent 9eec932 commit 267419e
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 52 deletions.
8 changes: 6 additions & 2 deletions src/pymapmanager/interface2/runInterfaceBob.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,13 @@ def run():
path = '/Users/cudmore/Sites/MapManagerCore-Data/data/Animal_145_Slice_1_Right.mmap.zip'
path = '/Users/cudmore/Desktop/Animal_145_Slice_1_Right.mmap.zip'

from mapmanagercore.data import getNd2Channel_1, getSingleTimepointMap_nd2
from mapmanagercore.data import getNd2Channel_1, getSingleTimepointMap_nd2, getTiffChannel_1
path = getNd2Channel_1()
path = getSingleTimepointMap_nd2()
# path = getSingleTimepointMap_nd2()

path = '/Users/cudmore/Desktop/Animal_145_Slice_1_Right.mmap.zip'

# path = getTiffChannel_1()

app = PyMapManagerApp(sys.argv)
# mw will be map widget if path has multiple timepoints, otherwise mw is a stackwidget2
Expand Down
93 changes: 51 additions & 42 deletions src/pymapmanager/interface2/stackWidgets/stackWidget2.py
Original file line number Diff line number Diff line change
Expand Up @@ -1302,57 +1302,66 @@ def getOpenPluginDict(self):
"""
return self._openPluginDict

def loadInNewChannel(self, path = None, channel = None):
""" self, path: Union[str, np.ndarray], time: int = 0, channel: int = 0):
def loadInNewChannel(self, path:Optional[str] = None, channel = None):
"""Given a file path append channels from file (can be more than one channel).
self, path: Union[str, np.ndarray], time: int = 0, channel: int = 0):
"""
if path is None:
newTifPath = QtWidgets.QFileDialog.getOpenFileName(None, 'New Tif File')[0]
importPath = QtWidgets.QFileDialog.getOpenFileName(None, 'New Tif File')[0]
else:
newTifPath = path

# check to ensure it is a tif file, Note: might need to expand to list of supported files
_path, _ext = os.path.splitext(newTifPath)
if _ext not in IMPORT_FILE_EXTENSIONS:
logger.error(f'import must have extension "{IMPORT_FILE_EXTENSIONS}", got "{_ext}" -->> did not load.')
QtWidgets.QMessageBox.critical(self, "Error: Incorrect Extension", "Please use .tif as the file extension to save")
return
importPath = path

#Check to ensure it is a valid image channel (same size)
from PIL import Image

# with Image.open(newTifPath) as img:
# newImgWidth, newImgHeight = img.size
# # print("Width:", newImgWidth)
# # print("Height:", newImgHeight)
# newImgSlices = img.n_frames # z dimension

# # Get old tif path
stackHeader = self.getStack().header
x = stackHeader["xPixels"]
y = stackHeader["yPixels"]
z = stackHeader["numSlices"]
# if newImgHeight != y or newImgWidth != x or newImgSlices != z:
# logger.error(f'Incorrect shape when loading in new image.')
# QtWidgets.QMessageBox.critical(self, "Error: Incorrect Image Size",
# f"Please upload an image with size x: {x}, y: {y}, z: {z} ")
# return
time = self.getStack().timepoint

time = self._stack.timepoint
useImageImporter = True
if useImageImporter:
self.getTimeSeriesCore().importChannels(importPath, time=time)

isImgValid = self.getTimeSeriesCore().validateNewChannel(newTifPath, time)
else:
# check to ensure it is a tif file, Note: might need to expand to list of supported files
_path, _ext = os.path.splitext(importPath)
if _ext not in IMPORT_FILE_EXTENSIONS:
logger.error(f'import must have extension "{IMPORT_FILE_EXTENSIONS}", got "{_ext}" -->> did not load.')
QtWidgets.QMessageBox.critical(self, "Error: Incorrect Extension", "Please use .tif as the file extension to save")
return

if not isImgValid:
logger.error(f'Incorrect shape when loading in new image.')
QtWidgets.QMessageBox.critical(self, "Error: Incorrect Image Size",
f"Please upload an image with size x: {x}, y: {y}, z: {z} ")
return
#Check to ensure it is a valid image channel (same size)
# from PIL import Image

# with Image.open(newTifPath) as img:
# newImgWidth, newImgHeight = img.size
# # print("Width:", newImgWidth)
# # print("Height:", newImgHeight)
# newImgSlices = img.n_frames # z dimension

# # Get old tif path
stackHeader = self.getStack().header
x = stackHeader["xPixels"]
y = stackHeader["yPixels"]
z = stackHeader["numSlices"]
# if newImgHeight != y or newImgWidth != x or newImgSlices != z:
# logger.error(f'Incorrect shape when loading in new image.')
# QtWidgets.QMessageBox.critical(self, "Error: Incorrect Image Size",
# f"Please upload an image with size x: {x}, y: {y}, z: {z} ")
# return

isImgValid = self.getTimeSeriesCore().validateNewChannel(importPath, time)

if not isImgValid:
logger.error(f'Incorrect shape when loading in new image.')
QtWidgets.QMessageBox.critical(self, "Error: Incorrect Image Size",
f"Please upload an image with size x: {x}, y: {y}, z: {z} ")
return

if channel is None:
channel = self._stack.getTimeSeriesTotalChannels() # len of total channels = new channel, since it is 0 based

logger.info(f"channel num {channel}")
self.getTimeSeriesCore().loadInNewChannel(newTifPath, time=time, channel=channel)
if channel is None:
channel = self._stack.getTimeSeriesTotalChannels() # len of total channels = new channel, since it is 0 based
logger.info(f"channel num {channel}")
self.getTimeSeriesCore().loadInNewChannel(importPath, time=time, channel=channel)

# abb TODO make a signalChannelUpdate for add/remove/edit (channel name)

# reset stackToolBar
self._topToolbar._setStack(theStack=self._stack)

Expand Down
21 changes: 13 additions & 8 deletions src/pymapmanager/timeseriesCore.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,13 +336,6 @@ def _import_tiff(self):
points=pd.DataFrame())

self._fullMap : MapAnnotations = map

def _import_ome_zarr(self):
from mapmanagercore.image_importers.image_importer_ome_zarr import ImageImporter_Ome_Zarr
path = self.path
flz = ImageImporter_Ome_Zarr(path)
map = flz.getMapAnnotations()
self._fullMap : MapAnnotations = map

def save(self):
""" Stack saves changes to its .mmap Zarr file that is stored
Expand Down Expand Up @@ -390,6 +383,17 @@ def redo(self):
# self.getPointAnnotations()._buildTimepoint() # rebuild single timepoint
# self.getPointAnnotations()._buildDataFrame()

# abb imageImport can we just always have a zarr loader or a MultiImageLoader (not both)
def importChannels(self, importPath:str, time:int):
# if isinstance(self._fullMap._images, ZarrLoader):
# logger.error('abb NOT IMPLEMENTED for ZarrLoader')
# # self._fullMap._images.read(path, time=time, channel=channel)
# elif isinstance(self._fullMap._images, MultiImageLoader):
# self._fullMap.loader.appendChannels(importPath, time)

logger.warning('abb imageImport')
self._fullMap.loader.appendChannels(importPath, time)

def loadInNewChannel(self, path: Union[str, np.ndarray], time: int = 0, channel: int = 0):
""" Call loadInNewChannel in backend MapManagerCore
Expand Down Expand Up @@ -454,7 +458,8 @@ def swapChannels(self, tp, srcChannel, destChannel):
destTimePoint = tp, destChannel = destChannel)

def updateChannel(self, tp, channelIdx, newChannelName: str):
""""""
"""
"""

# dict uses one based indexing
updateDict = {"name" : newChannelName,
Expand Down

0 comments on commit 267419e

Please sign in to comment.