FAQ | This is a LIVE service | Changelog

Skip to content
Snippets Groups Projects
Unverified Commit f835dc13 authored by Eduardo Gonzalez Solares's avatar Eduardo Gonzalez Solares
Browse files

Add function to parse mocasic file

parent 323da61a
No related branches found
No related tags found
1 merge request!3Dask
from os import listdir
from pathlib import Path
from typing import Dict
import dask.array as da
import numpy as np
......@@ -111,6 +113,25 @@ def get_mosaic_file(root_dir):
return ''
def parse_mosaic_file(root_dir: Path) -> Dict[str, str]:
"""Return contents of mosaic file as dictionary.
Parameters
----------
root_dir
Directory containing mosaic file
Returns
-------
dictionary of key, values with mosaic file contents
"""
mosaic_file = get_mosaic_file(root_dir)
with open(mosaic_file) as fh:
items = [item.strip().split(':', 1) for item in fh.readlines()]
res = {k[0]: k[1] for k in items}
return res
def get_img_cube(
root_dir,
imgs,
......
......@@ -8,15 +8,17 @@ import zarr
from dask import delayed
from distributed import Client, wait
from scipy.ndimage import geometric_transform
from zarr import blosc
from imaxt_image.image import TiffImage
from stpt_pipeline.utils import get_coords
from .mosaic_functions import get_mosaic_file
from .mosaic_functions import parse_mosaic_file
from .settings import Settings
from .stpt_displacement import defringe, magic_function
log = logging.getLogger('owl.daemon.pipeline')
blosc.use_threads = False # TODO: Check if this makes it quicker or slower
def read_flatfield(flat_file: Path):
......@@ -141,14 +143,11 @@ def preprocess(root_dir: Path, flat_file: Path, output_dir: Path):
z = zarr.group(out, 'w')
dirs = list_directories(root_dir)
for d in dirs:
for d in dirs[:2]:
# TODO: All this should be metadata
section = re.compile(r'\d\d\d\d$').search(d.name).group()
mosaic_file = get_mosaic_file(d)
res = open(d / mosaic_file, 'r').read()
mrows = re.compile(r'mrows:(\d+)\n').search(res).groups()[0]
mcolumns = re.compile(r'mcolumns:(\d+)\n').search(res).groups()[0]
mrows, mcolumns = int(mrows), int(mcolumns)
mosaic = parse_mosaic_file(d)
mrows, mcolumns = int(mosaic['mrows']), int(mosaic['mcolumns'])
fovs = mrows * mcolumns
files = sorted(list(d.glob('*.tif')))
files_ch1 = sorted(list(d.glob('*_01.tif')))
......@@ -168,6 +167,7 @@ def preprocess(root_dir: Path, flat_file: Path, output_dir: Path):
wait(fut)
# Write metadata
# TODO: Write contents of mosaic file here as well
z.attrs['sections'] = len(dirs) # TODO: Read from mosaic file
z.attrs['fovs'] = fovs
z.attrs['mrows'] = mrows
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment