Exemplo n.º 1
0
def test_wrong_connection():
    from ufo import Read, FlatFieldCorrect, Write

    darks = Read()
    flats = Read()
    radios = Read()
    write = Write()
    ffc = FlatFieldCorrect()

    g = Ufo.TaskGraph()
    g.connect_nodes_full(radios.task, ffc.task, 0)
    g.connect_nodes_full(darks.task, ffc.task, 1)
    g.connect_nodes_full(flats.task, ffc.task, 0)
    g.connect_nodes(ffc.task, write.task)

    sched = Ufo.Scheduler()
    sched.run(g)
Exemplo n.º 2
0
def test_read_single_tiffs_stepped():
    from ufo import Read, Null

    with single_tiff_setup(32) as d:
        read = Read(path=d.root, step=2)
        null = Null()
        null(read()).run().join()
        assert (null.task.props.num_processed == 32 / 2)
Exemplo n.º 3
0
def test_read_multi_tiffs():
    from ufo import Read, Null

    with tempdir() as d:
        n_images = 32
        data = np.ones((512, 512, n_images))
        tifffile.imsave(d.path('foo.tif'), data)

        read = Read(path=d.path('foo.tif'))
        null = Null()

        null(read()).run().join()
        assert (null.task.props.num_processed == n_images)
Exemplo n.º 4
0
def test_memory_out():
    with tempdir() as d:
        from ufo import MemoryOut, Read

        ref = random.astype(np.float32)
        out = np.zeros_like(ref).astype(np.float32)
        tifffile.imsave(d.path('foo.tif'), ref)

        read = Read(path=d.path('foo.tif'))
        write = MemoryOut(pointer=out.__array_interface__['data'][0],
                          max_size=ref.nbytes)

        write(read()).run().join()
        assert (np.all(out == ref))
Exemplo n.º 5
0
def test_core_issue_61_16_bit_tiffs():
    from ufo import Read, Write

    orig = np.random.randint(0, 65535, (512, 512)).astype(np.uint16)

    with tempdir() as d:
        tifffile.imsave(d.path('temp.tif'), orig)

        read = Read(path=d.path('temp.tif'))
        write = Write(filename=d.path('temp-%i.tif'))

        write(read()).run().join()

        produced = tifffile.imread(d.path('temp-0.tif'))
        assert (np.sum(orig - produced) == 0.0)
Exemplo n.º 6
0
    def run(self):
        from ufo import Read, DetectEdge, Rescale, Write
        import math
        import time

        app.logger.debug("Start creation slice thumbs for reco.id={}".format(self.slices_thumbs.reco.id))

        try:
            start_time = time.time()
            self.slices_thumbs.creation_going = True
            db.session.commit()

            if not(os.path.exists(os.path.join(self.slices_thumbs.reco.path_to_dir, 'slice-00000.tif'))):
                raise Exception("Slices do not exists in the path: {}".format(self.slices_thumbs.reco.path_to_dir))
            
            # Read slices
            read = Read(path=self.slices_thumbs.reco.path_to_slices)
            
            rescale = Rescale(factor=1.0)
            # edge = DetectEdge()
            write = Write(filename=self.slices_thumbs.path_to_thumbs, bits=8)
            write(
                rescale(
                    # edge(
                        read()
                    # )
                )
            ).run().join()

            self.slices_thumbs.has_error = False
            self.slices_thumbs.creation_going = False

            self.slices_thumbs.time = time.time() - start_time

            app.logger.debug("Finished slices thumbs creation for reco.id={} in {} s.".format(self.slices_thumbs.reco.id, self.slices_thumbs.time))

        except Exception as e:
            self.slices_thumbs.has_error = True
            app.logger.error("Crashed slices thumbs creation for reco.id={}. Error: {}".format(self.slices_thumbs.reco.id, e))

        finally:
            self.slices_thumbs.done = True
            db.session.commit()
Exemplo n.º 7
0
    def run(self):
        from ufo import Read, MapSlice, Rescale, Write
        from PIL import Image
        import tifffile
        import math
        import time
        
        app.logger.debug("Start creation slice map for reco.id={}".format(self.slice_map.reco.id))

        try:
            start_time = time.time()

            self.slice_map.creation_going = True
            db.session.commit()

            if not(os.path.exists(os.path.join(self.slice_map.reco.path_to_dir, 'slice-00000.tif'))):
                raise Exception("Slices do not exists in the path: {}".format(self.slice_map.reco.path_to_dir))
            
            im = tifffile.imread(os.path.join(self.slice_map.reco.path_to_dir,os.listdir(self.slice_map.reco.path_to_dir)[0]))
            sliceResolution = im.shape
            
            self.slice_map.original_slice_width = sliceResolution[0]
            self.slice_map.original_slice_height = sliceResolution[1]

            self.slice_map.slices_number = len([name for name in os.listdir(self.slice_map.reco.path_to_dir) if os.path.isfile( os.path.join(self.slice_map.reco.path_to_dir, name) )])

            self.slice_map.resize_factor = float(self.slice_map.width/self.slice_map.slices_per_row) / self.slice_map.original_slice_width

            self.slice_map.slice_width = self.slice_map.original_slice_width * self.slice_map.resize_factor
            self.slice_map.slice_height = self.slice_map.original_slice_height * self.slice_map.resize_factor

            self.slice_map.slice_maps_numbers = math.ceil(float(self.slice_map.slices_number) / float(self.slice_map.slices_per_row * self.slice_map.slices_per_col))
            
            # Read slices
            read = Read(path=self.slice_map.reco.path_to_dir, number=self.slice_map.slices_number)
            
            # Rescale slices
            rescale = Rescale(factor=self.slice_map.resize_factor)
            
            slice_map = MapSlice(number=self.slice_map.slices_per_row * self.slice_map.slices_per_col)
            
            # Write slice map
            write = Write(filename=os.path.join(self.slice_map.path_to_dir, self.slice_map.file_name_format), bits=8)
            write(
                slice_map(
                    rescale(
                        read()
                    )
                )
            ).run().join()

            self.slice_map.has_error = False
            self.slice_map.creation_going = False

            self.slice_map.time = time.time() - start_time

            app.logger.debug("Finished slice map creation for reco.id={} in {} s.".format(self.slice_map.reco_id, self.slice_map.time))

        except Exception as e:
            self.slice_map.has_error = True
            app.logger.error("Crashed slice map creation for reco.id={}. Error: {}".format(self.slice_map.reco_id, e))

        finally:
            self.slice_map.done = True
            db.session.commit()