Ejemplo n.º 1
0
def create_strain_images(folder, fcsv, fimg):
    """
    Creates a strain image with the given image and the given csv-file

    :param folder: Folder where be located the csv-file
    :type folder: string
    :param fcsv: csv-file
    :type fcsv: string
    :param fimg: Name of the result image-file 
    :type fimg: string
    """
    files = get_all_files(folder)
    n = len(files)
    if n > 0:
        progress = ProcessDialog(title="Generate files", max_n=len(files))
        cur_n = convert_number(n)
        fpath = join(folder, fcsv.format(cur_n))
        image = join(images_dir, image_file.format(cur_n, '.JPG'))
        progress.update(1, 'Generate file: {0}'.format(basename(fpath)))
        m = create_max_strain_image(fpath, image, fimg.format(cur_n))
        for i in range(1, n):
            cur_n = convert_number(i)
            fpath = join(folder, fcsv.format(cur_n))
            image = join(images_dir, image_file.format(cur_n, '.JPG'))
            arr = np.loadtxt(fpath, dtype=np.float, delimiter=',')
            img = imread(image)
            progress.update(i, 'Generate file: {0}'.format(basename(fpath)))
            create_strain_image(m, arr, img, fimg.format(cur_n))
        progress.close()
Ejemplo n.º 2
0
 def update_images(self, sensors=None):
     try:
         if sensors != None:
             del self.sensors[:]
             for s in sensors:
                 self.sensors.append(s)
         udisplacements = get_all_files(displacement_u_dir)
         vdisplacements = get_all_files(displacement_v_dir)
         progress = ProcessDialog(max_n=self.max_image_number,
                                  title="Update")
         for i in range(self.max_image_number):
             img_name = self.images[i]
             progress.update(i, msg="Update image: {0}".format(img_name))
             udisp = loadtxt(join(displacement_u_dir, udisplacements[i]),
                             delimiter=',')
             vdisp = loadtxt(join(displacement_v_dir, vdisplacements[i]),
                             delimiter=',')
             img = imread(join(travel_sensor_images_dir, img_name))
             for t in self.sensors:
                 p1, p2 = t.points
                 x1, y1 = p1
                 x2, y2 = p2
                 u1, u2 = udisp[y1, x1], udisp[y2, x2]
                 v1, v2 = vdisp[y1, x1], vdisp[y2, x2]
                 img = self.sensor_draw.draw_travel_sensor(
                     img, t, u1, u2, v1, v2)
             imwrite(join(travel_sensor_draw_images_dir, img_name), img)
         self.ref_image = ImageResource(
             join(travel_sensor_draw_images_dir, self.fname))
     except Exception:
         dialog = ErrorDialogs()
         dialog.open_error("Some files are missing")
     progress.close()
Ejemplo n.º 3
0
 def create_reference_image(self):
     """Takes the reference image and transfer the image to the camera"""
     progress = ProcessDialog(title="Transfer image", max_n=2)
     self.recorder.measuring_card.trigger_all_ports()
     progress.update(1, "Download image")
     self.smrc_model.camera.download_reference_image()
     progress.close()
     return True
Ejemplo n.º 4
0
 def _extract_files(self, fpath):
     self.logger.debug("Extract files")
     archive = ZipFile(fpath, 'r')
     archive.extractall(storage_temp_dir)
     archive.close()
     exp_name = basename(fpath).split('.')[0]
     n = len(ext_pairs)
     progress = ProcessDialog(title="Extract files", max_n=n)
     try:
         for i in range(n):
             d, ext = ext_pairs[i]
             folder = "{0}{1}.zip".format(exp_name, ext)
             progress.update(i, "Extract {0}".format(folder))
             archive = ZipFile(join(storage_temp_dir, folder), 'r')
             archive.extractall(d)
             archive.close()
         progress.close()
     except Exception, e:
         self.logger.error(str(e))
         progress.close()
         return False
Ejemplo n.º 5
0
 def send_project(self, t, serie, project):
     basepath = self.source_path+ ftp_experiments+'/' + \
         t + '/' + serie + '/' + project
     print basepath
     try:
         if self.connect():
             try:
                 self.ftp.mkd(basepath)
                 for d in all_server_folders:
                     dir_path = dirname(d)
                     dir_name = basename(d)
                     self.ftp.cwd(basepath + '/' + dir_path)
                     self.ftp.mkd(dir_name)
             except Exception:
                 w=WarningDialog("The project does alread exists. Do you want overrite the files?")
                 if not w.open():
                     raise ValueError()
             n = len(download_folders)
             progress = ProcessDialog(title="Upload project", max_n=n)
             for i in range(n):
                 d = download_folders[i]
                 source = basepath + '/' + d
                 print source
                 progress.update(i, 'Upload: {0}'.format(basename(source)))
                 self.ftp.cwd(source)
                 exist_files = self.ftp.nlst()
                 files = get_all_files(join(temp_dir, d))
                 for f in files:
                     if not f in exist_files:
                         fpath = join(temp_dir, d, f)
                         self.ftp.storbinary("STOR " + f, open(fpath, 'rb'))
             progress.close()
         else:
             progress.close()
             raise Exception(
                 "The connection with the FTP-Service is interrupt")
     except Exception, e:
         self.logger.error(str(e))
         errordialog = ErrorDialogs()
         errordialog.open_error("The project does already exists")
Ejemplo n.º 6
0
 def copy_images(self, files):
     values = []
     ref_time = getmtime(files[0])
     progress = ProcessDialog(title="Copy image", max_n=len(files))
     for i in range(len(files)):
         f = files[i]
         progress.update(i, msg="Copy file: {0}".format(basename(f)))
         ext = "." + f.split('.')[-1]
         dst_file = image_file.format(convert_number(i), ext)
         dst = join(images_dir, dst_file)
         copy(f, dst)
         values.append((dst_file, getmtime(f) - ref_time))
     progress.close()
     return values
Ejemplo n.º 7
0
    def save_project(self, fpath):
        """Save the project

        :param fpath: Path to the file
        :type fpath: string
        :returns: True, if the experiment was saved, False otherwise
        :rtype: bool
        """
        n = len(ext_pairs)
        exp_name = self.experiment.save_all_components()
        progress = ProcessDialog(title="Save project", max_n=n)
        try:
            for i in range(n):
                d, ext = ext_pairs[i]
                progress.update(i, "Save: {0}".format(d))
                self.zip_files(d, storage_temp_dir, exp_name + ext, "zip")
            self.zip_files(storage_temp_dir, fpath, exp_name, project_ext)
            progress.close()
        except Exception, e:
            progress.close()
            self.logger.error(str(e))
            return False
Ejemplo n.º 8
0
 def copy_files(self, fnames, dst_path, fname):
     fdlg = FileDialog(wildcard="*.csv*", title="Select {0}".format(fnames),
                       action='open files')
     if fdlg.open() == OK:
         files = sorted(fdlg.paths)
         progress = ProcessDialog(title="Copy file", max_n=len(files))
         for i in range(1, len(files)):
             f = files[i]
             progress.update(i, msg="Copy file: {0}".format(basename(f)))
             dst_file = fname.format(convert_number(i))
             dst = join(dst_path, dst_file)
             copy(f, dst)
         progress.close()
         return True
     return False
Ejemplo n.º 9
0
 def load_project_from_server(self, project):
     self.logger.debug("Download project from server")
     self.server.download_project(project)
     files = get_all_files(images_dir)
     n = len(files)
     progress = ProcessDialog(title="Resize images", max_n=n)
     for i in range(n):
         f = files[i]
         self.logger.debug("Resize image: {0}".format(f))
         progress.update(i, "Resize image: {0}".format(f))
         try:
             resize_image(join(images_dir, f), True, True)
         except Exception:
             resize_image(join(images_dir, f))
     progress.close()
     self.create_strain_files()
Ejemplo n.º 10
0
def resize_strain_images():
    """Resizes all strain-images in the folder: /evaluation/results/normal"""
    files = get_all_files(result_normal_dir)
    n = len(files)
    if n > 0:
        progress = ProcessDialog(title="Resize strain_images",
                                 max_n=len(files))
        for i in range(len(files)):
            f = files[i]
            progress.update(n=i, msg="Resize image: {0}".format(f))
            src = join(result_normal_dir, f)
            dst = join(result_resized_dir, f)
            img = imread(src)
            img = resize(img, (300, 225))
            imwrite(dst, img)
        progress.close()
Ejemplo n.º 11
0
 def download_project(self, project):
     """Creates all folders on the server"""
     self.logger.debug("Download project: {0}".format(project))
     try:
         basepath = project
         n = len(download_folders)
         progress = ProcessDialog(title="Download project", max_n=n)
         for i in range(n):
             d = download_folders[i]
             source = basepath + '/' + d
             progress.update(i, 'Download: {0}'.format(basename(source)))
             self.ftp.cwd(source)
             files = self.ftp.nlst()
             for fname in files:
                 fpath = join(temp_dir, d, fname)
                 self.logger.debug("Download file : {0}".format(fname))
                 with open(fpath, 'wb') as f:
                     self.ftp.retrbinary('RETR ' + fname, f.write)
     except Exception, e:
         self.logger.error(e)
         progress.close()
         return False