Example #1
0
    def load_blank(self, blank_fn):
        results = jwslib.read_file(blank_fn)
        error = True
        if results[0] == jwslib.JWS_ERROR_SUCCESS:
            blank_header = results[1]
            blank_channels = results[2]
            if len(blank_channels) < 1:
                self.error(_("Error: Blank has no channel data.\n"))
            else:
                error = False
        elif results[0] == jwslib.JWS_ERROR_COULD_NOT_READ_FILE:
            self.error( _("Error reading blank file %(#)s:\n%(##)s\n") % \
                        {'#':blank_fn, '##':results[1] } )

        elif results[0] == jwslib.JWS_ERROR_INVALID_FILE:
            self.error(
                _("Invalid blank file %(#)s:\n%(##)s\n") % {
                    '#': blank_fn,
                    '##': results[1]
                })
        else:
            self.error(_("Unknown error loading blank\n"))
        if error:
            return None
        else:
            return (blank_header, blank_channels)
Example #2
0
def test2():
  import jwslib
  import sys
  results = jwslib.read_file("spc.jws")
  if results[0] == jwslib.JWS_ERROR_SUCCESS:
    header = results[1]
    channels = results[2]
  else:
    sys.exit(-1)
  channels[0] = mean_movement(channels[0], 25)
  jwslib.dump_channel_data('feo3.txt', header, channels)
def test2():
    import jwslib
    import sys
    results = jwslib.read_file("spc.jws")
    if results[0] == jwslib.JWS_ERROR_SUCCESS:
        header = results[1]
        channels = results[2]
    else:
        sys.exit(-1)
    channels[0] = mean_movement(channels[0], 25)
    jwslib.dump_channel_data('feo3.txt', header, channels)
def test3():
    import jwslib
    import sys
    results = jwslib.read_file("spc.jws")
    if results[0] == jwslib.JWS_ERROR_SUCCESS:
        header = results[1]
        channels = results[2]
    else:
        sys.exit(-1)
    original = channels[0]
    for i in range(5, 25, 2):
        channels[0] = sgolayfilt(original, 1, i)
        jwslib.dump_channel_data('spc_sg_1_%d.txt' % i, header, channels)
Example #5
0
def test3():
  import jwslib
  import sys
  results = jwslib.read_file("spc.jws")
  if results[0] == jwslib.JWS_ERROR_SUCCESS:
    header = results[1]
    channels = results[2]
  else:
    sys.exit(-1)
  original = channels[0]
  for i in range(5,25,2):
    channels[0] = sgolayfilt(original, 1, i)
    jwslib.dump_channel_data('spc_sg_1_%d.txt'%i, header, channels)
 def show_spectrum_file(self, input_fn, options=None):
     results = jwslib.read_file(input_fn)
     error = True
     if results[0] == jwslib.JWS_ERROR_SUCCESS:
         header = results[1]                
         channels = results[2]
         if len(channels) > 0:
             error = False
     if error:
         return False
     else:
         if options is not None:
             self.options = options
         self.show_spectrum(header, channels)
         return True
 def __init__(self, input_fn, options=ProcessOptions(), parent=None):
     results = jwslib.read_file(input_fn)
     error = True
     if results[0] == jwslib.JWS_ERROR_SUCCESS:
         header = results[1]                
         channels = results[2]
         if len(channels) > 0:
             error = False
     if error:
         raise Exception, "File %s could not be loaded" % input_fn
     (head, tail) = os.path.split(input_fn) # head=path; tail=nombre arch.
     title = _("Showing %s") % tail
     SmoothingSelectionDialog.__init__(self, header, channels, options, 
                                       parent, title, 
                                       (gtk.STOCK_CLOSE, gtk.RESPONSE_OK))
Example #8
0
    def __init__(self, path):
        self.path = path
        from jwslib import read_file
        t = read_file(self.path)
        self.header = t[1]

        if t[0] != 0:
            print t[1]
            raise Exception("Invalid file")

        if len(t[2]) == 1:
            self.y_data = np.array(t[2][0])
            self.y_data_norm = (self.y_data - self.y_data.min()) / (self.y_data.max() - self.y_data.min())
        else:
            raise Exception("Multiple channels")

        self.x_data = np.linspace(self.header.x_for_first_point, self.header.x_for_last_point, num=self.header.point_number)
 def _update_preview_cb(self, widget):
     input_fn = self.get_preview_filename()
     error = True
     if input_fn is not None:
         results = jwslib.read_file(input_fn)
         if results[0] == jwslib.JWS_ERROR_SUCCESS:
             header = results[1]
             channels = results[2]
             if len(channels) > 0:
                 error = False
         if not error:
             xdata = arange(
                 header.x_for_first_point,  #start
                 header.x_for_last_point + header.x_increment,  #end+incr.
                 header.x_increment)  #increment
             ellipticity = array(channels[0], float32)
             self.figure.clear()
             p = self.figure.add_subplot(111)
             p.plot(xdata, ellipticity)
             self.canvas.draw()
     self.set_preview_widget_active(not error)
Example #10
0
    def load_blank(self, blank_fn):        
        results = jwslib.read_file(blank_fn)
        error = True
        if results[0] == jwslib.JWS_ERROR_SUCCESS:
            blank_header = results[1]                
            blank_channels = results[2]
            if len(blank_channels) < 1:
                self.error(_("Error: Blank has no channel data.\n"))
            else:
                error = False
        elif results[0] == jwslib.JWS_ERROR_COULD_NOT_READ_FILE:
            self.error( _("Error reading blank file %(#)s:\n%(##)s\n") % \
                        {'#':blank_fn, '##':results[1] } )

        elif results[0] == jwslib.JWS_ERROR_INVALID_FILE:
            self.error(_("Invalid blank file %(#)s:\n%(##)s\n") % {'#':blank_fn, '##':results[1]})
        else:
            self.error(_("Unknown error loading blank\n"))
        if error:
            return None
        else:            
            return (blank_header, blank_channels)
 def _update_preview_cb(self, widget):
     input_fn = self.get_preview_filename()
     error = True
     if input_fn is not None:
         results = jwslib.read_file(input_fn)
         if results[0] == jwslib.JWS_ERROR_SUCCESS:
             header = results[1]
             channels = results[2]
             if len(channels) > 0:
                 error = False
         if not error:
             xdata = arange(
                 header.x_for_first_point,  # start
                 header.x_for_last_point + header.x_increment,  # end+incr.
                 header.x_increment,
             )  # increment
             ellipticity = array(channels[0], float32)
             self.figure.clear()
             p = self.figure.add_subplot(111)
             p.plot(xdata, ellipticity)
             self.canvas.draw()
     self.set_preview_widget_active(not error)
Example #12
0
    def process_file(self, input_fn, dilution_factor, blank_header,
                     blank_channels, options):
        # Read input file
        error = True
        results = jwslib.read_file(input_fn)
        if results[0] == jwslib.JWS_ERROR_SUCCESS:
            error = False
        elif results[0] == jwslib.JWS_ERROR_COULD_NOT_READ_FILE:
            self.error(
                _("Error reading jws file %(#)s:\n%(##)s\n") % {
                    '#': input_fn,
                    '##': results[1]
                })
        elif results[0] == jwslib.JWS_ERROR_INVALID_FILE:
            self.error(
                _("Invalid file %(#)s:\n%(##)s\n") % {
                    '#': input_fn,
                    '##': results[1]
                })
        else:
            self.error(_("Unknown error loading %s\n") % input_fn)
        if error:
            return None

        header = results[1]
        channels = results[2]
        n_channels = len(channels)

        # Print information about the file
        self.print_header_info(header, input_fn)
        self.info(_("Read data for %d channels\n") % n_channels)
        # Exit if we don't have channel data to process
        if n_channels < 1:
            self.error(_("Error: This file has no channel data\n"))
            return None
        ellipticity = array(channels[0], float32)

        # Subtract blank
        if options.subtract_blank:
            error = True
            if blank_header.point_number < header.point_number:
                self.error(
                    _("Error: Blank has not enough data to be subtracted to input.\n"
                      ))
            elif blank_header.x_for_first_point != header.x_for_first_point:
                self.error(
                    _("Error: Blank has no data in the wavelength range of input.\n"
                      ))
            else:
                error = False
            if error:
                return None
            blank = array(blank_channels[0][:len(channels[0])], float32)
            subtract(ellipticity, blank, ellipticity)

        # Make ellipticity at 260nm 0
        if options.subtract260 and options.subtract_blank:
            if header.x_for_first_point == 260.0:
                self.info(_("Making ellipticity at 260nm 0...\n"))
                subtract(ellipticity, ellipticity[0], ellipticity)

        # Apply smoothing
        if options.smoothing:
            self.info(_("Applying smoothing...\n"))
            m = options.get_clamped_m()
            if options.smoothing_type == "mm":
                ellipticity = pysmoothing.mean_movement(ellipticity, m)
            elif options.smoothing_type == "sg":
                p = options.get_clamped_p()
                ellipticity = pysmoothing.sgolayfilt(ellipticity, p, m)
            ellipticity = array(ellipticity, float32)

        # Apply correction factor:
        if options.correct:
            multiply(ellipticity, options.correction_factor, ellipticity)

        if options.correct_dilution:
            multiply(ellipticity, dilution_factor, ellipticity)

        channels[0] = list(ellipticity)
        return (header, channels)
Example #13
0
    def process_file(self, input_fn, dilution_factor, blank_header, blank_channels, options):
        # Read input file
        error = True
        results = jwslib.read_file(input_fn)
        if results[0] == jwslib.JWS_ERROR_SUCCESS:                                    
            error = False
        elif results[0] == jwslib.JWS_ERROR_COULD_NOT_READ_FILE:
            self.error(_("Error reading jws file %(#)s:\n%(##)s\n") % {'#':input_fn, '##':results[1]} )
        elif results[0] == jwslib.JWS_ERROR_INVALID_FILE:
            self.error(_("Invalid file %(#)s:\n%(##)s\n") % {'#':input_fn, '##':results[1]})
        else:
            self.error(_("Unknown error loading %s\n") % input_fn)
        if error:
            return None

        header = results[1]
        channels = results[2]
        n_channels = len(channels)

        # Print information about the file
        self.print_header_info(header, input_fn)
        self.info(_("Read data for %d channels\n") % n_channels)
        # Exit if we don't have channel data to process
        if n_channels < 1:
            self.error(_("Error: This file has no channel data\n"))
            return None
        ellipticity = array(channels[0], float32)

        # Subtract blank
        if options.subtract_blank:
            error = True
            if blank_header.point_number < header.point_number:
                self.error(_("Error: Blank has not enough data to be subtracted to input.\n"))
            elif blank_header.x_for_first_point != header.x_for_first_point:
                self.error(_("Error: Blank has no data in the wavelength range of input.\n"))
            else:
                error = False
            if error: 
                return None
            blank = array(blank_channels[0][:len(channels[0])], float32)
            subtract(ellipticity, blank, ellipticity)

        # Make ellipticity at 260nm 0
        if options.subtract260 and options.subtract_blank:
            if header.x_for_first_point == 260.0:
                self.info(_("Making ellipticity at 260nm 0...\n"))
                subtract(ellipticity, ellipticity[0], ellipticity)

        # Apply smoothing
        if options.smoothing:
            self.info(_("Applying smoothing...\n"))
            m = options.get_clamped_m()
            if options.smoothing_type == "mm":
                ellipticity = pysmoothing.mean_movement(ellipticity, m)
            elif options.smoothing_type == "sg":
                p = options.get_clamped_p()
                ellipticity = pysmoothing.sgolayfilt(ellipticity, p, m)
            ellipticity = array(ellipticity, float32)
            
        # Apply correction factor:
        if options.correct:
            multiply(ellipticity, options.correction_factor, ellipticity)

        if options.correct_dilution:
            multiply(ellipticity, dilution_factor, ellipticity)
            
        channels[0] = list(ellipticity)
        return (header, channels)