예제 #1
0
파일: sensor.py 프로젝트: simvisage/imbex
 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()
예제 #2
0
 def _set_length_btn_fired(self):
     # make it possible to define a new line
     f = get_all_files(resized_images_dir)[0]
     ref_image = join(images_dir, f)
     self.draw(ref_image)
     self.length_in_pixel = self.get_length()
     self.length_per_pixel = self.length_of_line / self.length_in_pixel
예제 #3
0
 def _sensor_fired(self):
     files = get_all_files(travel_sensor_sensors_dir)
     sensors = []
     for f in files:
         if ".npy" in f:
             sensor = Sensor.load(join(travel_sensor_sensors_dir, f))
             sensors.append(sensor)
     self.sensor_graph.update_sensors(sensors)
     self.sensor_graph.plot(0)
예제 #4
0
 def update_camera_models(self):
     """Updates the camera models in the Combobox."""
     self.camera_models.reset()
     files = get_all_files(cameras_dir)
     for f in files:
         if self.type_extension in f:
             fpath = join(cameras_dir, f)
             data = self.load(fpath)
             self.camera_models.add_item(data["name"], fpath)
예제 #5
0
파일: sensor.py 프로젝트: simvisage/imbex
 def set_images(self):
     displacement = get_all_files(displacement_u_dir)[0]
     w, h = loadtxt(join(displacement_u_dir, displacement),
                    delimiter=',').shape[:2]
     image_shape = (h, w)
     for img_name in self.images:
         img = imread(join(images_dir, img_name))
         img = resize(img, image_shape)
         imwrite(join(travel_sensor_images_dir, img_name), img)
         imwrite(join(travel_sensor_draw_images_dir, img_name), img)
예제 #6
0
 def _add_btn_fired(self):
     points = self.roi_selector.define_roi()
     if len(points) > 1:
         self.points.append(deepcopy(points))
         fpath = join(corr_properties_dir, roi_file)
         img_name = join(images_dir, basename(self.fname))
         roi = self.roi_selector.create_roi(imread(img_name), self.points)
         imwrite(fpath, roi)
         imwrite(join(resized_images_dir, roi_file),
                 resize(roi, (300, 225)))
         files = get_all_files(images_dir)
         for f in files:
             resize_image(join(images_dir, f), True)
         self.ref_image = ImageResource(self.fname)
예제 #7
0
 def load(self, input_ports):
     """Loads the correlation properties"""
     self.logger.debug("Load properties [CorrelationProperties]")
     f = get_all_files(resized_images_dir)[0]
     self.experiment.recorder.update_reference(f)
     self.loaded_reference = True
     try:
         with open(self.path, 'r') as f:
             data = load(f)
         self.unit_converter.length_of_line = data["length_of_line"]
         self.subset_size = data["subset_size"]
         self.roi_selector.points = data["roi_points"]
         self.unit_converter.length_per_pixel = data["length_per_pixel"]
     except Exception:
         self.logger.debug("Correlation properties do not exist")
예제 #8
0
 def upload_all_images(self, project):
     self.logger.debug("Upload all images")
     basepath = self.source_path + '/' + ftp_experiments + '/' + project
     try:
         if self.connect():
             self.ftp.cwd(basepath + '/' + images_folder)
             for img_name in get_all_files(images_dir):
                 fpath = join(images_dir, img_name)
                 self.ftp.storbinary("STOR " + img_name, open(fpath, 'rb'))
                 self.upload_recordings(basepath)
         else:
             raise Exception(
                 "The connection with the FTP-Service is interrupt")
     except Exception, e:
         self.logger.error(str(e))
예제 #9
0
 def upload_references_image(self, project):
     """Upload the reference image"""
     try:
         if self.connect():
             files = get_all_files(images_dir)
             basepath = self.source_path + '/' + project
             self.ftp.cwd(basepath + '/' + images_folder)
             for f in files:
                 fpath = join(images_dir, f)
                 self.ftp.storbinary("STOR " + f, open(fpath, 'rb'))
         else:
             raise Exception(
                 "The connection with the FTP-Service is interrupt")
     except Exception, e:
         self.logger.error(str(e))
예제 #10
0
 def upload_correlation_properties(self, project):
     """Upload the experiment properties"""
     try:
         if self.connect():
             files = get_all_files(corr_properties_dir)
             basepath = self.source_path + '/' + project
             self.ftp.cwd(basepath + '/' + properties_folder)
             for f in files:
                 fpath = join(corr_properties_dir, f)
                 self.ftp.storbinary("STOR " + f, open(fpath, 'rb'))
         else:
             raise Exception(
                 "The connection with the FTP-Service is interrupt")
     except Exception, e:
         self.logger.debug(str(e))
예제 #11
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()
예제 #12
0
    def _update_record_information(self, index):
        """Update the record information by the given index

        :param index: Index of the values which should show
        :type index: int
        """
        self.index = index
        del self.record_information[:]
        for i in range(self.n):
            rec, val = self.container[i][index]
            label = '{0}: {1:.3f}'.format(self.input_ports[i].name, val)
            self.record_information.append(label)
        self.record_information.append('Time: {0}'.format(rec))
        if not self.show_reference:
            files = get_all_files(images_dir)
            self.update_reference(files[0])
        self.plotview.update_focus_point(index)
        self.result_viewer.update_image(index)
예제 #13
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")
예제 #14
0
 def import_dic_results(self, info):
     try:
         f = get_all_files(images_dir)[0]
         imread(join(images_dir, f)).shape[:2]
         files = [("u-displacements", displacement_u_dir, udisplacement_file),
                  ("v-displacements", displacement_v_dir,
                   vdisplacement_file),
                  ("strain-exx", strain_exx_dir, strain_exx_file),
                  ("strain-exy", strain_exy_dir, strain_exy_file),
                  ("strain-eyy", strain_eyy_dir, strain_eyy_file)]
         for f in files:
             if not self.copy_files(*f):
                 return
         create_strain_images(strain_exx_dir, strain_exx_file,
                              strain_exx_img_file)
         create_strain_images(strain_exy_dir, strain_exy_file,
                              strain_exy_img_file)
         create_strain_images(strain_eyy_dir, strain_eyy_file,
                              strain_eyy_img_file)
         resize_strain_images()
     except Exception, e:
         self.logger.error(str(e))
         self.application_dialogs.open_error(msg="Can not find images")
         return
예제 #15
0
파일: sensor.py 프로젝트: simvisage/imbex
 def update_storage_properties(self):
     self.images = get_all_files(images_dir)
     self.max_image_number = len(self.images)
     n = len(get_all_files(travel_sensor_draw_images_dir))
     if not n == self.max_image_number:
         self.set_images()
예제 #16
0
 def _edit_roi_btn_fired(self):
     self.roi_selector.open_dialog()
     f = get_all_files(resized_images_dir)[0]
     self.experiment.recorder.update_reference(f)
예제 #17
0
 def send_image(self):
     """Sends the last recorded image to the server"""
     img_file = get_all_files(images_dir)[-1]
     t, s = self.type.get_type_serie()
     project = t + '/' + s + '/' + self.type.generate_file_name()
     self.smrc_model.send_image(img_file, project)
예제 #18
0
class CorrelationProperties(HasTraits):
    """Defines the properties for the correlation"""

    #=========================================================================
    # Important components to interact
    #=========================================================================

    unit_converter = Instance(UnitConverter, ())

    roi_selector = Instance(ROISelector, ())

    correlation_method = Instance(MethodSelector, ())

    error_dialog = ErrorDialogs()

    #=========================================================================
    # Properties of the correlation
    #=========================================================================

    subset_size = Int(30)

    record_mode = Bool()

    logger = getLogger("Application")

    def __init__(self, experiment):
        self.logger.debug("Initialize CorrelationProperties")
        self.experiment = experiment
        self.record_mode = experiment.record_mode
        self.roi_selector.set_parent(self)
        self.unit_converter.set_parent(self)
        self.path = join(corr_properties_dir, correlation_properties_file)

    def is_valid(self):
        self.roi_selector.is_valid()
        self.unit_converter.is_valid()

    #=========================================================================
    # Methods to save and load the correlation properties
    #=========================================================================

    def get_properties(self):
        return {
            "subset_size": self.subset_size,
            "length_per_pixel": self.unit_converter.length_per_pixel,
            "length_of_line": self.unit_converter.length_of_line,
            "roi_points": self.roi_selector.points
        }

    def save(self):
        """Save the properties in the temp-folder"""
        self.logger.debug("Save properties [CorrelationProperties]")
        with open(self.path, 'w') as f:
            dump(self.get_properties(), f, indent=2)

    def load(self, input_ports):
        """Loads the correlation properties"""
        self.logger.debug("Load properties [CorrelationProperties]")
        f = get_all_files(resized_images_dir)[0]
        self.experiment.recorder.update_reference(f)
        self.loaded_reference = True
        try:
            with open(self.path, 'r') as f:
                data = load(f)
            self.unit_converter.length_of_line = data["length_of_line"]
            self.subset_size = data["subset_size"]
            self.roi_selector.points = data["roi_points"]
            self.unit_converter.length_per_pixel = data["length_per_pixel"]
        except Exception:
            self.logger.debug("Correlation properties do not exist")

    #=========================================================================
    # Traitsview + Traitsevents
    #=========================================================================

    loaded_reference = Bool(False)

    reference_btn = Button("Edit")

    edit_roi_btn = Button("Edit")

    correlate_btn = Button("Correlate")

    def _reference_btn_fired(self):
        try:
            self.experiment.measuring_card_is_valid()
        except ValueError, e:
            self.error_dialog.open_error(str(e))
            return
        self.experiment.create_reference_image()
        f = get_all_files(resized_images_dir)[0]
        self.experiment.recorder.update_reference(f)
        self.loaded_reference = True
예제 #19
0
 def _reset_btn_fired(self):
     del self.points[:]
     files = get_all_files(images_dir)
     for f in files:
         resize_image(f)
     self.ref_image = ImageResource(self.fname)
예제 #20
0
 def define_roi(self):
     # make it possible to define a new region of interest
     f = get_all_files(images_dir)[0]
     ref_image = join(images_dir, f)
     self.draw(ref_image)
     return self.points
예제 #21
0
 def open_dialog(self):
     f = get_all_files(resized_images_dir)[0]
     ref_image = join(resized_images_dir, f)
     self.dialog.open_dialog(ref_image)