Ejemplo n.º 1
0
def main():
    if len(sys.argv) != 1 + 1:
        print("Provide the android PhotoScan file folder as argument.")
        return

    directory = sys.argv[1]

    handler = FileHandler()

    w = FileWatcher(directory, handler.processNewFile)
    w.run()

    try:
        while True:
            seriesName = input("Current series name: ")
            seriesDate = input("Series Date (YYYY:MM) : ")

            handler.setSeriesName(seriesName)
            handler.setSeriesDate(seriesDate)

            print("Running series...")

            # command loop
            command = ""
            while command != "n":
                command = input("[d]elete last image or [n]ext series? ")
                if command == "d":
                    handler.deleteLastFile()

    except KeyboardInterrupt:
        print("")  # force newline in terminal
        w.stop()
        sys.exit()
Ejemplo n.º 2
0
    def initialize_filehandler():

        filehandler = FileHandler()
        filehandler.d_save_info['save_dir'] = OUTPUT_FOLDER_ROOT
        #print("DEBUG1: filehandler {0},  OUTPUT_FOLDER_ROOT {1}, filehandler.get_save_location() {2}".format(filehandler.__repr__(), OUTPUT_FOLDER_ROOT,filehandler.get_save_location()))

        if ic_timestamp_subfolder:
            if IMG_RAW_FILE:
                filehandler.d_save_info['sub_dir_1'] = str(
                    datetime.datetime.now()).replace(":", "_").replace(
                        " ", "_") + "_" + IMG_RAW_FILE[0:-4]
            else:
                filehandler.d_save_info['sub_dir_1'] = str(
                    datetime.datetime.now()).replace(":",
                                                     "_").replace(" ", "_")

        filehandler.set_save_info_root()
        #print("DEBUG2: filehandler {0},  OUTPUT_FOLDER_ROOT {1}, filehandler.get_save_location() {2}".format(filehandler.__repr__(), OUTPUT_FOLDER_ROOT,filehandler.get_save_location()))
        filehandler.d_load_info['load_dir'] = IMG_RAW_DIR
        filehandler.take_snapshot()
        #print("DEBUG3: filehandler {0},  OUTPUT_FOLDER_ROOT {1}, filehandler.get_save_location() {2}".format(filehandler.__repr__(), OUTPUT_FOLDER_ROOT,filehandler.get_save_location()))
        print('SDT_MAIN.py:all info will be written to : ',
              filehandler.get_save_location())

        return filehandler
Ejemplo n.º 3
0
def make_image_sequence(input_file, output_folder, prefix='man_seg_000_'):
    '''
    the fiji 'image sequence' can lead to the error :'Incorrect count for "ColorMap" when using Tiffreader, therefore made my own
    '''
    filehandler = FileHandler()
    filehandler.d_load_info['f_name'] = str(input_file)
    filehandler.d_save_info['save_dir'] = str(output_folder)
    a_img = filehandler.load_tif()
    for ix_z, a_slice in enumerate(a_img):
        suffix = "{:03d}".format(ix_z)
        filehandler.d_save_info['f_name'] = "{0}{1}".format(prefix, suffix)
        filehandler.save_data(a_slice)

    return
Ejemplo n.º 4
0
    def count(self, most_common_words, *args):
        """
        :param dir_path: String - Full path to directory where files reside
        :param most_common_words: Integer - Number of most common words in all files
        :return: Integer - Number of most common words
        """

        _counter = Counter()
        self.most_common_words = most_common_words
        _root_dir = DirectoryHandler()
        for path in map(abspath, args):
            if isfile(path):
                _counter += FileHandler().file_word_count(filename=path)
            else:
                with ThreadPoolExecutor(max_workers=multiprocessing.cpu_count()) as executor:
                    future_file_counts = {executor.submit(FileHandler().file_word_count, _filename):
                                              _filename for _filename in _root_dir.scan_dir(path)}

                    for future in as_completed(future_file_counts):
                        _counter += future.result()

        self.logger.debug("size of counter is {0} MB".format(round(getsizeof(_counter) / 1024 / 1024), 3))
        return _counter.most_common(self.most_common_words)
Ejemplo n.º 5
0
class Chatbot:
    fh = FileHandler('newconversa.txt')

    def __init__(self, nome):
        self.nome = nome
        resp = self.intro()
        if resp.upper() == 'S':
            while self.conversar().lower() != '.sair':
                self.conversar()
        else:
            self.tchau()

    def intro(self):
        print("{}: Olá meu nome é {}".format(self.nome, self.nome))
        print("{}: Eu sou uma I.A. que irá aprender com você".format(
            self.nome))
        resp = input("{}: Vamos começar? (S/N): ".format(self.nome))
        return resp

    def conversar(self):
        r = input("Você: ")

        if r == '.sair':
            return r

        if self.fh.comunica(r) != 0:
            print(self.nome + ": " + self.fh.comunica(r))
        else:
            self.aprender(r)

        return r

    def aprender(self, p):
        print(self.nome + ": Não sei responder!")
        r = input(self.nome + ": Qual seria a resposta para essa pergunta? ")
        self.fh.gravarArquivo(p, r)

    def tchau(self):
        print("{}: Tchau".format(self.nome))
Ejemplo n.º 6
0
def calculate_CTC_SEG_slice_detail(a_gt,
                                   a_res,
                                   output_folder,
                                   ix_z="",
                                   verbose=False,
                                   output=sys.stdout,
                                   d_d_gt_res_overlap={}):
    '''
	calculate SEG score for 2 slices, with subcalculations
	'''
    if output_folder:
        # f_name =  output_folder / "CTC_SEG_detail_calculations.txt"
        # f_output = open( f_name  ,"w" )
        fh = FileHandler()
        fh.d_save_info['save_dir'] = str(output_folder)

    a_gt_labels = np.unique(a_gt)
    a_gt_labels = np.delete(a_gt_labels, [0])
    if verbose: print('ground truth labels are ', a_gt_labels, file=output)

    SEG_counter = 0
    SEG_sum = 0
    jaccard_sum = 0

    for gt_label in a_gt_labels:
        a_bool_gt = a_gt == gt_label
        nb_gt_label_pix = np.sum(a_bool_gt)
        a_res_overlap = np.where(a_bool_gt, a_res, 0)
        a_bincount_overlap = np.bincount(a_res_overlap.flatten())
        a_bincount_overlap[0] = 0
        a_res_labels_overlap = np.unique(a_res_overlap)
        a_res_labels_overlap = np.delete(a_res_labels_overlap, [0])
        if verbose:
            print('  ground truth label {0} overlaps with res labels {1} '.
                  format(gt_label, a_res_labels_overlap),
                  file=output)

        max_overlap_label = 0
        max_overlap_ratio = 0
        max_jaccard = 0

        d_GT_volumes = d_d_gt_res_overlap.setdefault(
            "GT_volumes", {}
        )  #d_d_gt_res_overlap :  key = gt-label, value = dict (key = RES label, value = nb of overlapping pixels with gt-label)
        nb_pixel_self = d_GT_volumes.setdefault(gt_label, 0)
        d_GT_volumes[gt_label] = nb_pixel_self + np.sum(a_bool_gt)

        d_res_overlap = d_d_gt_res_overlap.setdefault(gt_label, {})
        for res_label in a_res_labels_overlap:
            nb_res_label_pix = np.sum(a_res == res_label)
            nb_overlap_pix = a_bincount_overlap[res_label]
            jaccard = (nb_overlap_pix) / (nb_gt_label_pix + nb_res_label_pix -
                                          nb_overlap_pix)
            overlap_ratio = nb_overlap_pix / nb_gt_label_pix
            if overlap_ratio > max_overlap_ratio:
                max_overlap_label = res_label
                max_overlap_ratio = overlap_ratio
                max_jaccard = jaccard

            rec = "    GT_label {0} ({4} pixels)  overlaps with RES_label {1}({5} pixels) with {6} pixels overlap.  \n    Jaccard = {3} with ratio (nb pix overlap/nb pix GT) = {2}\n".format(
                gt_label, res_label, (nb_overlap_pix / nb_gt_label_pix),
                jaccard, nb_gt_label_pix, nb_res_label_pix, nb_overlap_pix)

            nb_pixel_overlap = d_res_overlap.setdefault(res_label, 0)
            d_res_overlap[res_label] += nb_overlap_pix

            if verbose: print(rec, file=output)

        SEG_score = 0

        if max_overlap_ratio < 0.5:
            SEG_score = 0
            rec = "  SEG_score = 0 because max_overlap_ratio < 0.5 !"
        else:
            SEG_score = max_jaccard
            rec = "  SEG_score = {0} for gt_label {1} overlapping res_label {2} ".format(
                SEG_score, gt_label, max_overlap_label)

        SEG_counter += 1
        SEG_sum += SEG_score
        jaccard_sum += max_jaccard

        if verbose: print(rec, file=output)

        #write visual
        if output_folder:
            # f_output.write(rec)
            fh.d_save_info[
                'f_name'] = "GT_{0}(z{5})_vs_RES_{1}_SEG={2}|jac={3}|overlap={4}".format(
                    gt_label, max_overlap_label, round(SEG_score, 2),
                    round(max_jaccard, 2), round(max_overlap_ratio, 2),
                    str(ix_z).zfill(3))

            a_output = np.zeros_like(a_gt)
            # a_output [a_gt == gt_label] = gt_label
            # a_output [a_res == max_overlap_label] = max_overlap_label
            # a_output [(a_gt == gt_label) & (a_res == max_overlap_label)] = np.round(SEG_score*100)
            a_output[a_gt == gt_label] = 1
            a_output[a_res == max_overlap_label] = 2
            a_output[(a_gt == gt_label) & (a_res == max_overlap_label)] = 3
            fh.save_data(a_output, verbose=verbose)

    # if output_folder:f_output.close()
    a_res_labels = np.unique(a_res)
    a_res_labels = np.delete(a_res_labels, [0])

    if list(a_gt_labels):  # a slice with no GT is skipped (=SEG score rules)
        for res_label in a_res_labels:
            d_RES_volumes = d_d_gt_res_overlap.setdefault(
                "RES_volumes", {}
            )  #d_d_gt_res_overlap :  key = gt-label, value = dict (key = RES label, value = nb of overlapping pixels with gt-label)
            nb_pixel_self = d_RES_volumes.setdefault(res_label, 0)
            d_RES_volumes[res_label] = nb_pixel_self + np.sum(
                a_res == res_label)
            if res_label == 2:
                print(np.sum(a_res == res_label), 'for a total of ',
                      d_RES_volumes[res_label])

    return SEG_sum, jaccard_sum, SEG_counter, d_d_gt_res_overlap
Ejemplo n.º 7
0
from watchdog.observers import Observer

import os
import json
import time

from fileHandler import FileHandler

tracked_folder = input('Type the path to the folder to be tracked: \n')
destination_folder = input('Type the path to the destination folder: \n')

event_handler = FileHandler(tracked_folder, destination_folder)
observer = Observer()
observer.schedule(event_handler, tracked_folder, recursive=True)
observer.start()

try:
    while True:
        time.sleep(10)
except KeyboardInterrupt:
    observer.stop()

observer.join()
Ejemplo n.º 8
0
 def __init__(self):
     self.soupHandler = SoupHandler(SystemInfo.initUri)
     self.downloader = Downloader()
     self.fileHandler = FileHandler()
     self.path = SystemInfo.path
     self.name = SystemInfo.name
Ejemplo n.º 9
0
 def __init__(self):
     self.path = SystemInfo.path
     self.name = SystemInfo.name
     self.videoUriFormat = SystemInfo.videoUriFormat
     self.fileHandler = FileHandler()
     self.strParser = StrParser()