Skip to content

Commit

Permalink
import tif
Browse files Browse the repository at this point in the history
  • Loading branch information
cudmore committed Jul 22, 2024
1 parent b8a7c08 commit e019ef1
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 39 deletions.
7 changes: 4 additions & 3 deletions pymapmanager/interface2/pyMapManagerApp2.py
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ def loadMapWidget(self, path):
# self.stackWidgetFromStack(aStack)

# abj
def loadTifFile(self, path : str):
def _old_loadTifFile(self, path : str):
"""Load a stack from tif from a path.
Only happens on first load/ drag and drop
Create stackwidget/ mmap from tif file
Expand Down Expand Up @@ -567,12 +567,13 @@ def stackWidgetFromStack(self, newStack : "pymapmanager.stack"):
self._stackWidgetDict[stackTitle] = _stackWidget

def loadStackWidget(self, path : str):
"""Load a stack from a zarr path.
"""Load a stack from a path.
Path can be from (.mmap, .tif)
Parameters
----------
path : str
Full path to zarr file
Full path to (zarr, tif) file
"""
if path in self._stackWidgetDict.keys():
logger.info('showing already create stack widget')
Expand Down
3 changes: 2 additions & 1 deletion pymapmanager/interface2/runInterfaceBob.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ def run():

# a single timepoint tif file
path = mapmanagercore.data.getTiffChannel_1()
app.loadTifFile2(path) # simulate user drag/drop a tiff image
# app.loadTifFile2(path) # simulate user drag/drop a tiff image
app.loadStackWidget(path)

sys.exit(app.exec_())

Expand Down
2 changes: 1 addition & 1 deletion pymapmanager/interface2/stackWidgets/stackWidget2.py
Original file line number Diff line number Diff line change
Expand Up @@ -709,7 +709,7 @@ def _afterEdit(self, event):
stateEvent = pmmEvent(pmmEventType.stateChange, self)
stateEvent.setType(pmmEventType.stateChange)
stateEvent.setStateChange(pmmStates.edit)
self.slot_pmmEvent(selectionEvent)
self.slot_pmmEvent(stateEvent)

# select the point annotation
_spines = event.getSpines()
Expand Down
61 changes: 30 additions & 31 deletions pymapmanager/stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,14 @@ def __init__(self, path : str = None,
# load the map
_startSec = time.time()

# load from file
# TODO: in the future we will load from more file types
if path is not None:
_ext = os.path.splitext(path)[1]
if _ext == '.mmap'
if _ext == '.mmap':
self._load_zarr()
elif _ext == '.tif':
self._load_tiff()
self._import_tiff()

# elif zarrMap is not None:
# # load from in memory map
Expand All @@ -74,38 +76,47 @@ def __init__(self, path : str = None,
_stopSec = time.time()
logger.info(f'loaded stack in {round(_stopSec-_startSec,3)} sec')

logger.info('loaded core metedata is')
print(self.getMetadata())

# TODO: cludge, remove
if os.path.splitext(self.path)[1] == '.tif':
self.header['numChannels'] = 1

def _load_zarr(self):
"""Load from mmap file.
"""
path = self._zarrPath
path = self.path
logger.info(f'loading zarr path: {path}')
self._filename = os.path.split(path)[1]
self._fullMap : MapAnnotations = MapAnnotations.load(path)

# Reduce full core map to a single session id.
# self._sessionMap = self._fullMap.getTimePoint(self.sessionID)

def _load_tiff(self):
def _import_tiff(self):
"""Load from tif file.
"""
path = self._zarrPath
path = self.path

loader = MultiImageLoader()
loader.read(path, channel=0)

map = MapAnnotations(loader.build(),
lineSegments=pd.DataFrame(),
points=pd.DataFrame())


self._fullMap : MapAnnotations = map

logger.info(f'map from tif file is {map}')

# TODO: need to actually check the number of image channels
self.header['numChannels'] = 1

# self.header['numChannels'] = 1
def getMetadata(self) -> Metadata:
"""Get metadata from the core map.
"""
return self._fullMap.metadata()
return self.sessionMap.metadata()

def _buildSessionMap(self):
"""Reduce full core map to a single session id.
Expand Down Expand Up @@ -190,11 +201,12 @@ def getFileName(self) -> str:
# return os.path.split(self._zarrPath)[1]

def getPath(self):
return self._zarrPath
return self.path

@property
def sessionMap(self) -> MapAnnotations:
"""Get backend core map manager map.
One timepoint (Session)
"""
return self._sessionMap

Expand Down Expand Up @@ -236,22 +248,6 @@ def loadLines(self) -> None:
defaultColums = self._fullMap.segments[:].columns
self._lines = LineAnnotationsCore(self.sessionMap, defaultColums=defaultColums)

def _old_getImageChannel(self,
channel : int = 1
) -> Optional[np.ndarray]:
"""Get the full image volume for one color channel.
"""

# if channel is None:
# channel = 1

channelIdx = channel - 1
try:
return self._images[channelIdx]
except (IndexError):
logger.warning(f'Max channel is {self.numChannels}, got channelIdx:{channelIdx}')
return None

def getAutoContrast(self, channel):
channelIdx = channel - 1
_min, _max = self.sessionMap.getAutoContrast_qt(channel=channelIdx)
Expand Down Expand Up @@ -413,14 +409,17 @@ def redo(self):
# print(f'_ret:{_ret}')

self.getPointAnnotations()._buildDataFrame()

#abj
def save(self, path):
def save(self):
""" Stack saves changes to its Zarr file
"""
logger.info(f"Entering Stack save")
self._fullMap.save(path)

if os.path.splitext(self.path)[1] == '.mmap':
self._fullMap.save(self.path)
else:
# TO: save as zarr (prompt user for an mmap file path/name)
pass

# def saveAs(self, path):
# """ Stack saves changes to to a new zarr file path
# """
Expand Down
5 changes: 2 additions & 3 deletions tests/test_core_segments.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,8 @@ def test_segment():
print('tp.segments[:]')
print(tp.segments[:])

# s = gpd.GeoSeries.from_wkt(tp.segments[:]['segment'])
print('segment length:', tp.segments[:]['segment'].loc[0].length)
print('rough tracing length:', tp.segments[:]['roughTracing'].loc[0].length)
# when there is just one segment, we get a LineString, not a df of linestring?
print('rough tracing length:', tp.segments[:]['roughTracing'].length)

def test_qt_segments():
"""Load zarr, test core segment
Expand Down

0 comments on commit e019ef1

Please sign in to comment.