Exemplo n.º 1
0
def check_version(cluster):
    """Check the gluster version, exit if less than 3.12"""
    if version(cluster.glusterfs_version) < version(supported_version):
        print("gstatus: GlusterFS %s is not supported, use GlusterFS %s "
              "or above." % (glusterfs_version, supported_version),
              file=sys.stderr)
        exit(1)
Exemplo n.º 2
0
    def __init__(self, ppm=0, osr=4, fc=940e6, samp_rate_in=1e6):
        grgsm.hier_block.__init__(
            self,
            "GSM input adaptor",
            gr.io_signature(1, 1, gr.sizeof_gr_complex * 1),
            gr.io_signature(1, 1, gr.sizeof_gr_complex * 1),
        )

        ##################################################
        # Parameters
        ##################################################
        self.ppm = ppm
        self.osr = osr
        self.fc = fc
        self.samp_rate_in = samp_rate_in

        ##################################################
        # Variables
        ##################################################
        self.samp_rate_out = samp_rate_out = 1625000.0 / 6.0 * osr

        ##################################################
        # Blocks
        ##################################################
        if version(gr.version()) >= version('3.7.9'):
            self.message_port_register_hier_in("ppm_in")
        else:
            self.message_port_register_hier_out("ppm_in")

        self.low_pass_filter_0_0 = filter.fir_filter_ccf(
            1,
            firdes.low_pass(1, samp_rate_out, 125e3, 5e3, firdes.WIN_HAMMING,
                            6.76))
        self.gsm_clock_offset_corrector_0 = grgsm.clock_offset_corrector(
            fc=fc,
            ppm=ppm,
            samp_rate_in=samp_rate_in,
        )
        self.fractional_resampler_xx_0 = filter.fractional_resampler_cc(
            0, samp_rate_in / samp_rate_out)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.low_pass_filter_0_0, 0), (self, 0))
        self.connect((self.fractional_resampler_xx_0, 0),
                     (self.low_pass_filter_0_0, 0))
        self.connect((self.gsm_clock_offset_corrector_0, 0),
                     (self.fractional_resampler_xx_0, 0))
        self.connect((self, 0), (self.gsm_clock_offset_corrector_0, 0))

        ##################################################
        # Asynch Message Connections
        ##################################################
        self.msg_connect(self, "ppm_in", self.gsm_clock_offset_corrector_0,
                         "ppm_in")
Exemplo n.º 3
0
def version_check():
    if version(URLLIB3_VERSION) >= version(URLLIB3_MIN_REQUIRED_VERSION):
        return

    err = '{0} version: {1}, minimum required version: {2}, please upgrade'.format(
        URLLIB3,
        URLLIB3_VERSION,
        URLLIB3_MIN_REQUIRED_VERSION,
    )
    raise Exception(err)
Exemplo n.º 4
0
class DeltaDiracModel(Model):
    r"""A function that is zero everywhere except for the x-value closest
    to the center parameter.

    At value-closest-to-center, the model evaluates to the amplitude
    parameter divided by the x-spacing. This last division is
    necessary to preserve normalization with integrating the function
    over the X-axis

    Fitting parameters:
        - integrated intensity ``amplitude`` :math:`A`
        - position of the peak ``center`` :math:`E_0`
    """
    def __init__(self,
                 independent_vars=['x'],
                 prefix='',
                 missing=None,
                 name=None,
                 **kwargs):
        kwargs.update({
            'prefix': prefix,
            'missing': missing,
            'independent_vars': independent_vars
        })
        super(DeltaDiracModel, self).__init__(delta_dirac, **kwargs)

    if version(lmfit.__version__) > version('0.9.5'):
        __init__.__doc__ = lmfit.models.COMMON_INIT_DOC

    def guess(self, y, x=None, **kwargs):
        r"""Guess starting values for the parameters of a model.

        Parameters
        ----------
        y : :class:`~numpy:numpy.ndarray`
            Intensities
        x : :class:`~numpy:numpy.ndarray`
            energy values
        kwargs : dict
            additional optional arguments, passed to model function.

        Returns
        -------
        :class:`~lmfit.parameter.Parameters`
            parameters with guessed values
        """
        amplitude = max(y)
        center = 0.0
        if x is not None:
            center = x[index_of(y, max(y))]
            dx = (x[-1] - x[0]) / (len(x) - 1)  # x-spacing
            amplitude /= dx
        return self.make_params(amplitude=amplitude, center=center)
Exemplo n.º 5
0
def get_from_api(uri):
    """
        Get an object from the api
    """
    headers = {'Accept': 'application/json'}
    r = requests.get(APIURI+uri+"?limit="+APILIMIT,headers=headers)
    if r.status_code != 200:
        print ("Could not get "+APIURI+uri)
        r.raise_for_status()
    if version(requests.__version__) >= version("2.0.0"):
        return r.json()
    else:
        return r.json
Exemplo n.º 6
0
def get_from_api(uri):
    """
        Get an object from the api
    """
    headers = {'Accept': 'application/json'}
    r = requests.get(APIURI + uri + "?limit=" + APILIMIT, headers=headers)
    if r.status_code != 200:
        print("Could not get " + APIURI + uri)
        r.raise_for_status()
    if version(requests.__version__) >= version("2.0.0"):
        return r.json()
    else:
        return r.json
Exemplo n.º 7
0
 def load(self):
     self.base.conf.read()
     self.base.conf.cacheonly = True
     self.base.read_all_repos()
     self.packages = hawkey.Query(hawkey.Sack())
     if version(dnf.VERSION) >= version("4.7.0"):
         try:
             # do not use standard self.base.fill_sack() it does not respect cacheonly
             self.base.fill_sack_from_repos_in_cache(load_system_repo=True)
             self.packages = self.base.sack.query()
         except dnf.exceptions.RepoError:
             # RepoError is raised when cache is empty
             pass
     self.repos = self.base.repos
Exemplo n.º 8
0
    def __init__(self, ppm=0, osr=4, fc=940e6, samp_rate_in=1e6):
        gr.hier_block2.__init__(
            self, "GSM input adaptor",
            gr.io_signature(1, 1, gr.sizeof_gr_complex*1),
            gr.io_signature(1, 1, gr.sizeof_gr_complex*1),
        )

        ##################################################
        # Parameters
        ##################################################
        self.ppm = ppm
        self.osr = osr
        self.fc = fc
        self.samp_rate_in = samp_rate_in

        ##################################################
        # Variables
        ##################################################
        self.samp_rate_out = samp_rate_out = 1625000.0/6.0*osr

        ##################################################
        # Blocks
        ##################################################
        if version(gr.version()) >= version('3.7.9'):
            self.message_port_register_hier_in("ppm_in")
        else:
            self.message_port_register_hier_out("ppm_in")

        self.low_pass_filter_0_0 = filter.fir_filter_ccf(1, firdes.low_pass(
        	1, samp_rate_out, 125e3, 5e3, firdes.WIN_HAMMING, 6.76))
        self.gsm_clock_offset_corrector_0 = grgsm.clock_offset_corrector(
            fc=fc,
            ppm=ppm,
            samp_rate_in=samp_rate_in,
        )
        self.fractional_resampler_xx_0 = filter.fractional_resampler_cc(0, samp_rate_in/samp_rate_out)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.low_pass_filter_0_0, 0), (self, 0))
        self.connect((self.fractional_resampler_xx_0, 0), (self.low_pass_filter_0_0, 0))
        self.connect((self.gsm_clock_offset_corrector_0, 0), (self.fractional_resampler_xx_0, 0))
        self.connect((self, 0), (self.gsm_clock_offset_corrector_0, 0))

        ##################################################
        # Asynch Message Connections
        ##################################################
        self.msg_connect(self, "ppm_in", self.gsm_clock_offset_corrector_0, "ppm_in")
    def __init__(self, fc=936.6e6, ppm=0, samp_rate_in=1625000.0/6.0*4.0):
        gr.hier_block2.__init__(
            self, "Clock offset corrector",
            gr.io_signature(1, 1, gr.sizeof_gr_complex*1),
            gr.io_signature(1, 1, gr.sizeof_gr_complex*1),
        )
        if version(gr.version()) >= version('3.7.9'):
            self.message_port_register_hier_in("ppm_in")
        else:
            self.message_port_register_hier_out("ppm_in")

        ##################################################
        # Parameters
        ##################################################
        self.fc = fc
        self.ppm = ppm
        self.samp_rate_in = samp_rate_in

        ##################################################
        # Variables
        ##################################################
        self.samp_rate_out = samp_rate_out = samp_rate_in

        ##################################################
        # Blocks
        ##################################################
        self.gsm_controlled_rotator_cc_0 = grgsm.controlled_rotator_cc(0,samp_rate_out)
        self.gsm_controlled_const_source_f_0 = grgsm.controlled_const_source_f(ppm)
        self.fractional_resampler_xx_0 = filter.fractional_resampler_cc(0, samp_rate_in/samp_rate_out)
        self.blocks_multiply_const_vxx_0_0 = blocks.multiply_const_vff((1.0e-6*samp_rate_in/samp_rate_out, ))
        self.blocks_multiply_const_vxx_0 = blocks.multiply_const_vff((fc/samp_rate_out*(2*math.pi)/1e6, ))
        self.blocks_add_const_vxx_0 = blocks.add_const_vff((samp_rate_in/samp_rate_out, ))

        ##################################################
        # Connections
        ##################################################
        self.connect((self, 0), (self.fractional_resampler_xx_0, 0))
        self.connect((self.fractional_resampler_xx_0, 0), (self.gsm_controlled_rotator_cc_0, 0))
        self.connect((self.blocks_add_const_vxx_0, 0), (self.fractional_resampler_xx_0, 1))
        self.connect((self.blocks_multiply_const_vxx_0_0, 0), (self.blocks_add_const_vxx_0, 0))
        self.connect((self.blocks_multiply_const_vxx_0, 0), (self.gsm_controlled_rotator_cc_0, 1))
        self.connect((self.gsm_controlled_rotator_cc_0, 0), (self, 0))
        self.connect((self.gsm_controlled_const_source_f_0, 0), (self.blocks_multiply_const_vxx_0_0, 0))
        self.connect((self.gsm_controlled_const_source_f_0, 0), (self.blocks_multiply_const_vxx_0, 0))

        ##################################################
        # Asynch Message Connections
        ##################################################
        self.msg_connect(self, "ppm_in", self.gsm_controlled_const_source_f_0, "constant_msg")
Exemplo n.º 10
0
def label_particles_edge(im, sigma=2, closing_size=0, **extra_args):
    """ label_particles_edge(image, sigma=3, closing_size=3)
        Returns the labels for an image.
        Segments using Canny edge-finding filter.

        keyword arguments:
        image        -- The image in which to find particles
        sigma        -- The size of the Canny filter
        closing_size -- The size of the closing filter
    """
    from skimage.morphology import square, binary_closing, skeletonize
    if skversion < version('0.11'):
        from skimage.filter import canny
    else:
        from skimage.filters import canny
    edges = canny(im, sigma=sigma)
    if closing_size > 0:
        edges = binary_closing(edges, square(closing_size))
    edges = skeletonize(edges)
    labels = sklabel(edges)
    print "found {} segments".format(labels.max())
    labels = np.ma.array(
        labels,
        mask=edges == 0)  # in ma.array mask, False is True, and vice versa
    return labels
Exemplo n.º 11
0
def dump_exception_info(exc, pages, cmdhist, objects):
    """Dump exception info to stderr.

    Args:
        exc: An exception tuple (type, value, traceback)
        pages: A list of lists of the open pages (URLs as strings)
        cmdhist: A list with the command history (as strings)
        objects: A list of all QObjects as string.
    """
    print(file=sys.stderr)
    print("\n\n===== Handling exception with --no-err-windows... =====\n\n",
          file=sys.stderr)
    print("\n---- Exceptions ----", file=sys.stderr)
    print(''.join(traceback.format_exception(*exc)), file=sys.stderr)
    print("\n---- Version info ----", file=sys.stderr)
    try:
        print(version.version(), file=sys.stderr)
    except Exception:
        traceback.print_exc()
    print("\n---- Config ----", file=sys.stderr)
    try:
        conf = objreg.get('config')
        print(conf.dump_userconfig(), file=sys.stderr)
    except Exception:
        traceback.print_exc()
    print("\n---- Commandline args ----", file=sys.stderr)
    print(' '.join(sys.argv[1:]), file=sys.stderr)
    print("\n---- Open pages ----", file=sys.stderr)
    print('\n\n'.join('\n'.join(e) for e in pages), file=sys.stderr)
    print("\n---- Command history ----", file=sys.stderr)
    print('\n'.join(cmdhist), file=sys.stderr)
    print("\n---- Objects ----", file=sys.stderr)
    print(objects, file=sys.stderr)
Exemplo n.º 12
0
def filter_segments(labels, max_ecc, min_area, max_area, max_detect=None,
                    circ=None, intensity=None, **extra_args):
    """ filter_segments(labels, max_ecc=0.5, min_area=15, max_area=200) -> [Segment]
        Returns a list of Particles and masks out labels for
        particles not meeting acceptance criteria.
    """
    pts = []
    strengths = []
    centroid = 'Centroid' if intensity is None else 'WeightedCentroid'
    if skversion < version('0.10'):
        rprops = regionprops(labels, ['Area', 'Eccentricity', centroid], intensity)
    else:
        rprops = regionprops(labels, intensity)
    for rprop in rprops:
        area = rprop['area']
        if area < min_area or area > max_area:
            continue
        ecc = rprop['eccentricity']
        if ecc > max_ecc:
            continue
        x, y = rprop[centroid]
        if circ:
            co, ro = circ
            if (x - co[0])**2 + (y - co[1])**2 > ro**2:
                continue
        pts.append(Segment(x, y, rprop.label, ecc, area))
        if max_detect is not None:
            strengths.append(rprop['mean_intensity'])
    if max_detect is not None:
        pts = pts[np.argsort(-strengths)]
    return pts[:max_detect]
Exemplo n.º 13
0
    def run(self):
        # ask or get password from command line
        self.pwd = self.args.password if self.args.password else getpass()

        self.sock = self.connect()

        # get Odoo version:
        odoo_version = self.get_odoo_version()

        if version(odoo_version) >= '6.0' and version(odoo_version) < '7.0':
            self.move_using_document_storage()
        elif version(odoo_version) >= '7.0':
            self.move_using_config_parameter()
        else:
            msg = ("Moving attachments in Odoo version '{}' is not yet "
                   "implemented").format(odoo_version)
            raise Exception(msg)
def compare_version(version_left="", version_right=""):
    """
    get latest version in version_lest and version right, using  "from distutils.version import LooseVersion".
    Refers: https://segmentfault.com/q/1010000000331434

    :param version_left:
    :param version_right:
    :return latest version in version_lest and version right:
    """
    from distutils.version import LooseVersion as version

    res = cmp(version(version_left), version(version_right))
    if res > 0:
        return version_left
    elif res < 0:
        return version_right
    else:
        return version_left
Exemplo n.º 15
0
def compare_version(version_left="", version_right=""):
    """
    get latest version in version_lest and version right, using  "from distutils.version import LooseVersion".
    Refers: https://segmentfault.com/q/1010000000331434

    :param version_left:
    :param version_right:
    :return latest version in version_lest and version right:
    """
    from distutils.version import LooseVersion as version

    res = cmp(version(version_left), version(version_right))
    if res > 0:
        return version_left
    elif res < 0:
        return version_right
    else:
        return version_left
Exemplo n.º 16
0
    def __init__(self, api_client: ApiClient) -> None:
        if client_version < version('0.2.2'):
            sys.exit(
                'Requires carbon3d-client version of at least 0.2.2, ({v} found)'
                .format(v=client_version) +
                '\nUpdate with: pip install --upgrade carbon3d-client')

        self.printed_parts_api = PrintedPartsApi(api_client)
        self.prints_api = PrintsApi(api_client)
Exemplo n.º 17
0
def open_database():
    """Open the database for editing values."""
    sudo_required()
    global conn
    global c

    # Check if Datebase is already open, else open it.
    try:
        conn.execute("")
    except:
        verbose_output("Opening Database...")
    try:
        if not os.path.isfile(tcc_db):
            print("TCC Database has not been found.")
            sys.exit(1)
        conn = sqlite3.connect(tcc_db)
        c = conn.cursor()

        # Do a sanity check that TCC access table has expected structure
        c.execute(
            "SELECT sql FROM sqlite_master WHERE name='access' and type='table'"
        )
        accessTableDigest = ""
        for row in c.fetchall():
            accessTableDigest = hashlib.sha1(row[0]).hexdigest()[0:10]
            break
        # check if table in DB has expected structure:
        if not (accessTableDigest == "8e93d38f7c"  # prior to El Capitan
                or (osx_version >= version(
                    '10.11')  # El Capitan , Sierra, High Sierra
                    and accessTableDigest in ["9b2ea61b30", "1072dc0e4b"]) or
                (osx_version >= version('10.14')  # Mojave and Catalina
                 and accessTableDigest in ["ecc443615f", "80a4bb6912"]) or
                (osx_version >= version('10.16')  # Big Sur and later
                 and accessTableDigest == "3d1c2a0e97")):
            print("TCC Database structure is unknown.")
            sys.exit(1)

        verbose_output("Database opened.\n")
    except:
        print(
            "Error opening Database.  You probably need to disable SIP for this to work."
        )
        sys.exit(1)
Exemplo n.º 18
0
def disable(client):
    """Disable a client in the database."""
    open_database()
    verbose_output("Disabling %s..." % (client,))
    # Setting typically appears in System Preferences
    # right away (without closing the window).
    # Set to 0 to disable the client.
    enable_mode_name = 'auth_value' if osx_version >= version('10.16') else 'allowed'
    c.execute("UPDATE access SET %s='0' WHERE client='%s' AND service IS '%s'" % (enable_mode_name, client, service))
    commit_changes()
Exemplo n.º 19
0
def insert_client(client):
  #------------------------
  open_database()
  # Check if it is a command line utility or a bundle ID as the default value to enable it is different.
  cli_util_or_bundle_id(client)
  verbose_output("Inserting \"%s\" into Database..." % (client))
  if osx_version >= version('10.11'): # El Capitan or higher.
    c.execute("INSERT or REPLACE INTO access VALUES('kTCCServiceAccessibility','%s',%s,1,1,NULL,NULL)" % (client, client_type))
  else: # Yosemite or lower.
    c.execute("INSERT or REPLACE INTO access VALUES('kTCCServiceAccessibility','%s',%s,1,1,NULL)" % (client, client_type))
  commit_changes()
Exemplo n.º 20
0
def insert_client(client):
  #------------------------
  open_database()
  # Check if it is a command line utility or a bundle ID as the default value to enable it is different.
  cli_util_or_bundle_id(client)
  verbose_output("Inserting \"%s\" into Database..." % (client))
  if osx_version >= version('10.11'): # El Capitan or higher.
    c.execute("INSERT or REPLACE INTO access VALUES('kTCCServiceAccessibility','%s',%s,1,1,NULL,NULL)" % (client, client_type))
  else: # Yosemite or lower.
    c.execute("INSERT or REPLACE INTO access VALUES('kTCCServiceAccessibility','%s',%s,1,1,NULL)" % (client, client_type))
  commit_changes()
Exemplo n.º 21
0
def insert_client(client):
    """Insert a client into the database."""
    open_database()
    # Check if it is a command line utility or a bundle ID
    # as the default value to enable it is different.
    cli_util_or_bundle_id(client)
    verbose_output("Inserting \"%s\" into Database..." % (client))
    if osx_version >= version('10.15'):  # Catalina and later
        c.execute("INSERT or REPLACE INTO \
access VALUES('kTCCServiceAccessibility','%s',%s,1,1,NULL,NULL,NULL,'UNUSED',NULL,0,NULL)"
                  % (client, client_type))
    elif osx_version >= version('10.11'):  # El Capitan through Mojave
        c.execute("INSERT or REPLACE INTO \
access VALUES('kTCCServiceAccessibility','%s',%s,1,1,NULL,NULL)" %
                  (client, client_type))
    else:  # Yosemite or lower.
        c.execute("INSERT or REPLACE INTO \
access VALUES('kTCCServiceAccessibility','%s',%s,1,1,NULL)" %
                  (client, client_type))
    commit_changes()
Exemplo n.º 22
0
def _check_xen_version(xversion, **kwargs):
    log_str = 'Checking xen version: '

    if xversion in XEN_VERSIONS['Custom']:
        log_str += 'xen version \'{0}\' found in Custom-versions, OK'.format(xversion)
        log.info(log_str)
        return True

    for cversion in XEN_VERSIONS['Main']:
        if version(xversion) >= version(cversion):
            log_str += 'xen version \'{0}\' >= \'{1}\', OK!'.format(xversion, cversion)
            log.info(log_str)
            return True

    msg = (
        '\'{0}\' not found in Xen-custom-versions '
        'and {0} < Xen-Main-versions, FAILED!'
    )
    log_str += msg.format(xversion)
    log.info(log_str)
    return False
Exemplo n.º 23
0
def _check_kernel_version(wversion, distro):
    '''
    Check current kernel version against known good versions
    from distro list and custom kernel names.
    '''
    log_str = 'Checking kernel version: '
    safe_kernels = KERNEL_VERSIONS[distro]
    cust_kernels  = KERNEL_VERSIONS['Custom']

    # Steps:
    # 1. Check excact versions in KERNEL_VERSIONS['distro']
    # 2. Check excact versions in KERNEL_VERSIONS['Custom']
    # 3. Compare version to known safe mainline and LTS versions
    # 4. Fail if none of the above succeeded
    if wversion in safe_kernels:
        log_str += '\'{0}\' found in {0}-kernels, OK'.format(wversion, distro)
        log.info(log_str)
        return True

    elif wversion in cust_kernels:
        log_str += '\'{0}\' found in Custom-kernels, OK'.format(wversion, distro)
        log.info(log_str)
        return True

    else:

        for ml_version in KERNEL_VERSIONS['Mainline']:
            if version(wversion) >= version(ml_version):
                log_str += '\'{0}\' >= \'{1}\' from Mainline/LTS, OK!'.format(wversion, ml_version)
                log.info(log_str)
                return True

        log_str += '\'{0}\' < \'{1}\' and its not in {2}- or Custom-kernel list, FAILED'.format(
           wversion,
           KERNEL_VERSIONS['Mainline'],
           distro
        )
        log.info(log_str)
        return False
Exemplo n.º 24
0
def _check_bios_version(wversion, **kwargs):
    log_str = 'Checking bios version: '

    # create shortcut to platform data
    cdata = BIOS_VERSIONS[kwargs['system_product_name']]

    if not cdata['bios_version']:
       msg = 'Cant check bios, no data for platform {0} available, FAILED!'
       log.error(msg.format(kwargs['system_product_name']))
       return False

    if not wversion:
        log_str += 'Bios version from system \'{0}\' unusable, Failed!'.format(wversion)
        log.info(log_str)
        return False

    if version(wversion) > version(cdata['bios_version']):
        log_str += '\'{0}\' >= \'{1}\', OK!'.format(wversion, cdata['bios_version'])
        log.info(log_str)
        return True
    else:
        log_str += '\'{0}\' < \'{1}\', FAILED!'.format(wversion, cdata['bios_version'])
        log.info(log_str)
        return False
Exemplo n.º 25
0
    def _gather_crash_info(self):
        """Gather crash information to display.

        Args:
            pages: A list of lists of the open pages (URLs as strings)
            cmdhist: A list with the command history (as strings)
            exc: An exception tuple (type, value, traceback)
        """
        try:
            self._crash_info.append(("Version info", version.version()))
        except Exception:
            self._crash_info.append(("Version info", traceback.format_exc()))
        try:
            conf = objreg.get('config')
            self._crash_info.append(("Config", conf.dump_userconfig()))
        except Exception:
            self._crash_info.append(("Config", traceback.format_exc()))
Exemplo n.º 26
0
    def _gather_crash_info(self):
        """Gather crash information to display.

        Args:
            pages: A list of lists of the open pages (URLs as strings)
            cmdhist: A list with the command history (as strings)
            exc: An exception tuple (type, value, traceback)
        """
        try:
            self._crash_info.append(("Version info", version.version()))
        except Exception:
            self._crash_info.append(("Version info", traceback.format_exc()))
        try:
            conf = objreg.get('config')
            self._crash_info.append(("Config", conf.dump_userconfig()))
        except Exception:
            self._crash_info.append(("Config", traceback.format_exc()))
Exemplo n.º 27
0
def filter_segments(labels,
                    max_ecc,
                    min_area,
                    max_area,
                    max_detect=None,
                    circ=None,
                    intensity=None,
                    **extra_args):
    """ filter_segments(labels, max_ecc=0.5, min_area=15, max_area=200) -> [Segment]
        Returns a list of Particles and masks out labels for
        particles not meeting acceptance criteria.
    """
    pts = []
    strengths = []
    centroid = 'Centroid' if intensity is None else 'WeightedCentroid'
    if skversion < version('0.10'):
        rprops = regionprops(labels, ['Area', 'Eccentricity', centroid],
                             intensity)
    else:
        rprops = regionprops(labels, intensity)
    for rprop in rprops:
        area = rprop['area']
        ecc = rprop['eccentricity']
        if area < min_area:
            #print 'too small:', area
            continue
        elif area > max_area:
            #print 'too big:', area
            continue
        elif ecc > max_ecc:
            #print 'too eccentric:', ecc
            #labels[labels==rprop.label] = np.ma.masked
            continue
        x, y = rprop[centroid]
        if circ:
            co, ro = circ
            if (x - co[0])**2 + (y - co[1])**2 > ro**2:
                continue
        pts.append(Segment(x, y, rprop.label, ecc, area))
        if max_detect is not None:
            strengths.append(rprop['mean_intensity'])
    if max_detect is not None:
        pts = pts[np.argsort(-strengths)]
    return pts[:max_detect]
Exemplo n.º 28
0
def open_database():
    #------------------------
    sudo_required()
    global conn
    global c

    # Check if Datebase is already open, else open it.
    try:
        conn.execute("")
    except:
        verbose_output("Opening Database...")
        try:
            if not os.path.isfile(tcc_db):
                print "TCC Database has not been found."
                sys.exit(1)
            conn = sqlite3.connect(tcc_db)
            c = conn.cursor()

            # Do a sanity check that TCC access table has expected structure
            c.execute(
                "SELECT sql FROM sqlite_master WHERE name='access' and type='table'"
            )
            accessTableDigest = ""
            for row in c.fetchall():
                accessTableDigest = hashlib.sha1(row[0]).hexdigest()[0:10]
                break
            # check if table in DB has expected structure:
            if not (accessTableDigest == "8e93d38f7c"  #prior to El Capitan
                    or
                    (osx_version >= version('10.11')
                     and accessTableDigest in ["9b2ea61b30", "1072dc0e4b"])):
                print "TCC Database structure is unknown."
                sys.exit(1)

            verbose_output("Database opened.\n")
        except:
            print "Error opening Database."
            sys.exit(1)
Exemplo n.º 29
0
def label_particles_edge(im, sigma=2, closing_size=0, **extra_args):
    """ label_particles_edge(image, sigma=3, closing_size=3)
        Returns the labels for an image.
        Segments using Canny edge-finding filter.

        keyword arguments:
        image        -- The image in which to find particles
        sigma        -- The size of the Canny filter
        closing_size -- The size of the closing filter
    """
    from skimage.morphology import square, binary_closing, skeletonize
    if skversion < version('0.11'):
        from skimage.filter import canny
    else:
        from skimage.filters import canny
    edges = canny(im, sigma=sigma)
    if closing_size > 0:
        edges = binary_closing(edges, square(closing_size))
    edges = skeletonize(edges)
    labels = sklabel(edges)
    print "found {} segments".format(labels.max())
    labels = np.ma.array(labels, mask=edges==0) # in ma.array mask, False is True, and vice versa
    return labels
Exemplo n.º 30
0
def open_database():
  #------------------------
  sudo_required()
  global conn
  global c

  # Check if Datebase is already open, else open it.
  try: conn.execute("")
  except:
    verbose_output("Opening Database...")
    try:
      if not os.path.isfile(tcc_db):
        print "TCC Database has not been found."
        sys.exit(1)
      conn = sqlite3.connect(tcc_db)
      c = conn.cursor()

      # Do a sanity check that TCC access table has expected structure
      c.execute("SELECT sql FROM sqlite_master WHERE name='access' and type='table'")
      accessTableDigest=""
      for row in c.fetchall():
        accessTableDigest=hashlib.sha1(row[0]).hexdigest()[0:10]
        break;
      # check if table in DB has expected structure:
      if not (
        accessTableDigest == "8e93d38f7c" #prior to El Capitan
        or
        (osx_version >= version('10.11') and accessTableDigest in ["9b2ea61b30", "1072dc0e4b"])
      ):
        print "TCC Database structure is unknown."
        sys.exit(1)

      verbose_output("Database opened.\n")
    except:
      print "Error opening Database."
      sys.exit(1)
Exemplo n.º 31
0
def filter_segments(labels, max_ecc, min_area, max_area, max_detect=None, circ=None, intensity=None, **extra_args):
    """ filter_segments(labels, max_ecc=0.5, min_area=15, max_area=200) -> [Segment]
        Returns a list of Particles and masks out labels for
        particles not meeting acceptance criteria.
    """
    pts = []
    strengths = []
    centroid = "Centroid" if intensity is None else "WeightedCentroid"
    if skversion < version("0.10"):
        rprops = regionprops(labels, ["Area", "Eccentricity", centroid], intensity)
    else:
        rprops = regionprops(labels, intensity)
    for rprop in rprops:
        area = rprop["area"]
        ecc = rprop["eccentricity"]
        if area < min_area:
            # print 'too small:', area
            continue
        elif area > max_area:
            # print 'too big:', area
            continue
        elif ecc > max_ecc:
            # print 'too eccentric:', ecc
            # labels[labels==rprop.label] = np.ma.masked
            continue
        x, y = rprop[centroid]
        if circ:
            co, ro = circ
            if (x - co[0]) ** 2 + (y - co[1]) ** 2 > ro ** 2:
                continue
        pts.append(Segment(x, y, rprop.label, ecc, area))
        if max_detect is not None:
            strengths.append(rprop["mean_intensity"])
    if max_detect is not None:
        pts = pts[np.argsort(-strengths)]
    return pts[:max_detect]
Exemplo n.º 32
0
 def message_port_register_hier_out(self, port_id):
     if version(gr.version()) >= version('3.7.9'):
         super(hier_block, self).message_port_register_hier_out(port_id)
     else:
         super(hier_block, self).message_port_register_hier_in(port_id)
Exemplo n.º 33
0
#!/usr/bin/env python

from socket import gethostname

hostname = gethostname()

from distutils.version import StrictVersion as version
import skimage

skversion = version(skimage.__version__)

import numpy as np
from scipy.ndimage import gaussian_filter, median_filter, binary_erosion, convolve, center_of_mass, imread
from skimage import segmentation

if skversion < version("0.10"):
    from skimage.morphology import label as sklabel
    from skimage.measure import regionprops
else:
    from skimage.measure import regionprops, label as sklabel
from skimage.morphology import disk as _disk
from collections import namedtuple


def label_particles_edge(im, sigma=2, closing_size=0, **extra_args):
    """ label_particles_edge(image, sigma=3, closing_size=3)
        Returns the labels for an image.
        Segments using Canny edge-finding filter.

        keyword arguments:
        image        -- The image in which to find particles
Exemplo n.º 34
0
import sqlite3
import sys
import getopt
import os
from platform import mac_ver
from distutils.version import StrictVersion as version


##############################
######## VARIABLES ###########

# Utility Name
util_name = os.path.basename(sys.argv[0])

# Current OS X version
osx_version = version(mac_ver()[0])

# Database Path
tcc_db = '/Library/Application Support/com.apple.TCC/TCC.db'

# Set "sudo" to True if called with admin-privileges.
sudo = True if os.getuid() == 0 else False

# Default Verbosity
verbose = False


##############################
######## FUNCTIONS ###########

def usage(error_code=None):
Exemplo n.º 35
0
#!/usr/bin/env python

from socket import gethostname
hostname = gethostname()

from distutils.version import StrictVersion as version
import skimage
skversion = version(skimage.__version__)

import numpy as np
from scipy.ndimage import gaussian_filter, median_filter, binary_erosion, convolve, center_of_mass, imread
from skimage import segmentation
if skversion < version('0.10'):
    from skimage.morphology import label as sklabel
    from skimage.measure import regionprops
else:
    from skimage.measure import regionprops, label as sklabel
from skimage.morphology import disk as _disk
from collections import namedtuple

def label_particles_edge(im, sigma=2, closing_size=0, **extra_args):
    """ label_particles_edge(image, sigma=3, closing_size=3)
        Returns the labels for an image.
        Segments using Canny edge-finding filter.

        keyword arguments:
        image        -- The image in which to find particles
        sigma        -- The size of the Canny filter
        closing_size -- The size of the closing filter
    """
    from skimage.morphology import square, binary_closing, skeletonize
Exemplo n.º 36
0
import argparse
import sqlite3
import sys
import os
import hashlib
from platform import mac_ver
from distutils.version import StrictVersion as version

# Utility Name
util_name = os.path.basename(sys.argv[0])

# Utility Version
util_version = '1.2.10'

# Current OS X version
osx_version = version(mac_ver()[0]) # mac_ver() returns 10.16 for Big Sur instead 11.+

# Database Path
tcc_db = '/Library/Application Support/com.apple.TCC/TCC.db'

# Set "sudo" to True if called with Admin-Privileges.
sudo = True if os.getuid() == 0 else False

# Default Verbosity
verbose = False

# TCC Service
service = "kTCCServiceAccessibility"


parser = argparse.ArgumentParser(description='Modify Accesibility Preferences')
Exemplo n.º 37
0
 def message_port_register_hier_in(self, port_id):
     if version(gr.version()) >= version('3.7.9'):
         super(hier_block, self).message_port_register_hier_in(port_id)
     else:
         super(hier_block, self).message_port_register_hier_out(port_id)
Exemplo n.º 38
0
import argparse
import sqlite3
import sys
import os
import hashlib
from platform import mac_ver
from distutils.version import StrictVersion as version

# Utility Name
util_name = os.path.basename(sys.argv[0])

# Utility Version
util_version = '1.2.5'

# Current OS X version
osx_version = version(mac_ver()[0])

# Database Path
tcc_db = '/Library/Application Support/com.apple.TCC/TCC.db'

# Set "sudo" to True if called with Admin-Privileges.
sudo = True if os.getuid() == 0 else False

# Default Verbosity
verbose = False

parser = argparse.ArgumentParser(description='Modify Accesibility Preferences')
parser.add_argument(
    'action',
    metavar='ACTION',
    type=str,
Exemplo n.º 39
0
#!/usr/bin/env python

from socket import gethostname
hostname = gethostname()

from distutils.version import StrictVersion as version
import skimage
skversion = version(skimage.__version__)

import numpy as np
from scipy.ndimage import gaussian_filter, median_filter, binary_erosion, convolve, center_of_mass, imread
from skimage import segmentation
if skversion < version('0.10'):
    from skimage.morphology import label as sklabel
    from skimage.measure import regionprops
else:
    from skimage.measure import regionprops, label as sklabel
from skimage.morphology import disk as _disk
from collections import namedtuple


def label_particles_edge(im, sigma=2, closing_size=0, **extra_args):
    """ label_particles_edge(image, sigma=3, closing_size=3)
        Returns the labels for an image.
        Segments using Canny edge-finding filter.

        keyword arguments:
        image        -- The image in which to find particles
        sigma        -- The size of the Canny filter
        closing_size -- The size of the closing filter
    """
Exemplo n.º 40
0
class StretchedExponentialFTModel(Model):
    r"""Fourier transform of the symmetrized stretched exponential

    .. math::

        S(E) = A \int_{-\infty}^{\infty} dt/h e^{-i2\pi(E-E_0)t/h} e^{|\frac{x}{\tau}|^\beta}

    Normalization and maximum at :math:`E=E_0`:

    .. math::

        \int_{-\infty}^{\infty} dE S(E) = A
        max(S) = A \frac{\tau}{\beta} \Gamma(\beta^{-1})

    Uses scipy.fftpack.fft for the Fourier transform

    Fitting parameters:
        - integrated intensity ``amplitude`` :math:`A`
        - position of the peak ``center`` :math:`E_0`
        - nominal relaxation time ``tau``` :math:`\tau`
        - stretching exponent ``beta`` :math:`\beta`

    If the time unit is picoseconds, then the reciprocal energy unit is mili-eV
    """  # noqa: E501

    def __init__(self,
                 independent_vars=['x'],
                 prefix='',
                 missing=None,
                 name=None,
                 **kwargs):
        kwargs.update({
            'prefix': prefix,
            'missing': missing,
            'independent_vars': independent_vars
        })
        super(StretchedExponentialFTModel, self).__init__(strexpft, **kwargs)
        self.set_param_hint('amplitude', min=0)
        self.set_param_hint('tau', min=0)
        self.set_param_hint('beta', min=0)

    if version(lmfit.__version__) > version('0.9.5'):
        __init__.__doc__ = lmfit.models.COMMON_INIT_DOC

    def guess(self, y, x=None, **kwargs):
        r"""Guess starting values for the parameters of a model.

        Parameters
        ----------
        y : :class:`~numpy:numpy.ndarray`
            Intensities
        x : :class:`~numpy:numpy.ndarray`
            energy values
        kwargs : dict
            additional optional arguments, passed to model function.

        Returns
        -------
        :class:`~lmfit.parameter.Parameters`
            parameters with guessed values
        """
        amplitude = 1.0
        center = 0.0
        tau = 10.0
        beta = 1.0
        if x is not None:
            center = x[index_of(y, max(y))]  # assumed peak within domain x
            # Assumptions:
            #   1. large dynamic range, function decays fast in domain x
            #   2. x-values are equispaced
            amplitude = sum(y) * (max(x) - min(x)) / len(x)
            tau = max(y) / amplitude  # assumed beta==1.0
        return self.make_params(amplitude=amplitude,
                                center=center,
                                tau=tau,
                                beta=beta)
Exemplo n.º 41
0
    def __init__(self, fc=936.6e6, ppm=0, samp_rate_in=1625000.0 / 6.0 * 4.0):
        gr.hier_block2.__init__(
            self,
            "Clock offset corrector",
            gr.io_signature(1, 1, gr.sizeof_gr_complex * 1),
            gr.io_signature(1, 1, gr.sizeof_gr_complex * 1),
        )
        if version(gr.version()) >= version('3.7.9'):
            self.message_port_register_hier_in("ppm_in")
        else:
            self.message_port_register_hier_out("ppm_in")

        ##################################################
        # Parameters
        ##################################################
        self.fc = fc
        self.ppm = ppm
        self.samp_rate_in = samp_rate_in

        ##################################################
        # Variables
        ##################################################
        self.samp_rate_out = samp_rate_out = samp_rate_in

        ##################################################
        # Blocks
        ##################################################
        self.gsm_controlled_rotator_cc_0 = grgsm.controlled_rotator_cc(
            0, samp_rate_out)
        self.gsm_controlled_const_source_f_0 = grgsm.controlled_const_source_f(
            ppm)
        self.fractional_resampler_xx_0 = filter.fractional_resampler_cc(
            0, samp_rate_in / samp_rate_out)
        self.blocks_multiply_const_vxx_0_0 = blocks.multiply_const_vff(
            (1.0e-6 * samp_rate_in / samp_rate_out, ))
        self.blocks_multiply_const_vxx_0 = blocks.multiply_const_vff(
            (fc / samp_rate_out * (2 * math.pi) / 1e6, ))
        self.blocks_add_const_vxx_0 = blocks.add_const_vff(
            (samp_rate_in / samp_rate_out, ))

        ##################################################
        # Connections
        ##################################################
        self.connect((self, 0), (self.fractional_resampler_xx_0, 0))
        self.connect((self.fractional_resampler_xx_0, 0),
                     (self.gsm_controlled_rotator_cc_0, 0))
        self.connect((self.blocks_add_const_vxx_0, 0),
                     (self.fractional_resampler_xx_0, 1))
        self.connect((self.blocks_multiply_const_vxx_0_0, 0),
                     (self.blocks_add_const_vxx_0, 0))
        self.connect((self.blocks_multiply_const_vxx_0, 0),
                     (self.gsm_controlled_rotator_cc_0, 1))
        self.connect((self.gsm_controlled_rotator_cc_0, 0), (self, 0))
        self.connect((self.gsm_controlled_const_source_f_0, 0),
                     (self.blocks_multiply_const_vxx_0_0, 0))
        self.connect((self.gsm_controlled_const_source_f_0, 0),
                     (self.blocks_multiply_const_vxx_0, 0))

        ##################################################
        # Asynch Message Connections
        ##################################################
        self.msg_connect(self, "ppm_in", self.gsm_controlled_const_source_f_0,
                         "constant_msg")
Exemplo n.º 42
0
class TeixeiraWaterModel(Model):
    r"""This fitting function models the dynamic structure factor
    for a particle undergoing jump diffusion.

    J. Teixeira, M.-C. Bellissent-Funel, S. H. Chen, and A. J. Dianoux. `Phys. Rev. A, 31:1913-1917 <http://dx.doi.org/10.1103/PhysRevA.31.1913>`__

    .. math::
        S(Q,E) = \frac{A}{\pi} \cdot \frac{\Gamma}{\Gamma^2+(E-E_0)^2}
    .. math::
        \Gamma = \frac{\hbar\cdot D\cdot Q^2}{1+D\cdot Q^2\cdot \tau}

    :math:`\Gamma` is the HWHM of the lorentzian curve.

    At 298K and 1atm, water has :math:`D=2.30 10^{-5} cm^2/s` and
    :math:`\tau=1.25 ps`.

    A jump length :math:`l` can be associated: :math:`l^2=2N\cdot D\cdot \tau`,
    where :math:`N` is the dimensionality of the diffusion problem
    (:math:`N=3` for diffusion in a volume).

    Fitting parameters:
        - integrated intensity ``amplitude`` :math:`A`
        - position of the peak ``center`` :math:`E_0`
        - residence time ``center`` :math:`\tau`
        - diffusion coefficient ``dcf`` :math:`D`

    Attributes:
        - Momentum transfer ``q``
    """  # noqa: E501

    def __init__(self,
                 independent_vars=['x'],
                 q=0.0,
                 prefix='',
                 missing=None,
                 name=None,
                 **kwargs):
        kwargs.update({
            'prefix': prefix,
            'missing': missing,
            'name': name,
            'independent_vars': independent_vars
        })
        self.q = q

        def txr(x, amplitude=1.0, center=1.0, tau=1.0, dcf=1.0):
            r"""Teixeira intensities with a particular Q-value

            Not implemented as partial(teixeira_water, q=q) because
            inspect.getargspec faults with partial objects in python 2.7"""
            return teixeira_water(x,
                                  amplitude=amplitude,
                                  center=center,
                                  tau=tau,
                                  dcf=dcf,
                                  q=q)

        super(TeixeiraWaterModel, self).__init__(txr, **kwargs)
        [
            self.set_param_hint(name, min=MIN_POS_DBL)
            for name in ('amplitude', 'tau', 'dcf')
        ]
        self.set_param_hint('fwhm', expr=self.fwhm_expr)
        self.set_param_hint('height', expr=self.height_expr)

    if version(lmfit.__version__) > version('0.9.5'):
        __init__.__doc__ = lmfit.models.COMMON_INIT_DOC

    @property
    @prefix_params
    def fwhm_expr(self):
        """Constraint expression for FWHM"""
        dq2 = 'dcf*{q2}'.format(q2=self.q * self.q)
        fmt = '2*{hbar}*{dq2}/(1+tau*{dq2})'
        return fmt.format(hbar=hbar, dq2=dq2)

    @property
    @prefix_params
    def height_expr(self):
        """Constraint expression for maximum peak height."""
        fmt = "2.0/{pi}*amplitude/fwhm"
        return fmt.format(pi=np.pi, prefix=self.prefix)

    def guess(self, y, x=None, **kwargs):
        r"""Guess starting values for the parameters of a model.

        Parameters
        ----------
        y : :class:`~numpy:numpy.ndarray`
            Intensities
        x : :class:`~numpy:numpy.ndarray`
            energy values
        kwargs : dict
            additional optional arguments, passed to model function.

        Returns
        -------
        :class:`~lmfit.parameter.Parameters`
            parameters with guessed values
        """
        amplitude = 1.0
        center = 0.0
        tau = 1.0
        dcf = 1.0
        if x is not None:
            # Use guess method from the Lorentzian model
            p = LorentzianModel().guess(y, x)
            center = p['center']
            # Assume diff*q*q and tau^(-1) same value
            tau = hbar / (2 * p['sigma'])
            dcf = 1.0 / (self.q * self.q * tau)
        return self.make_params(amplitude=amplitude,
                                center=center,
                                tau=tau,
                                dcf=dcf)
Exemplo n.º 43
0
"""
Created on Thu Jan 14 11:51:09 2016

@author: ibackus
"""

import scipy
from scipy.interpolate import InterpolatedUnivariateSpline as spline
from warnings import warn
import numpy as np

from distutils.version import LooseVersion as version

# InterpolatedUnivariateSpline in older versions of scipy don't handle regions
# outside the bbox and don't have the argument ext=0
if version(scipy.__version__) < '0.16.0':
    warn('WARNING: Deprecated version of scipy.  Please upgrade to at least 0.16.0')
    
    spl = spline
    
    # OVERRIDE spline if scipy is outdated
    def spline(x, y, w=None, bbox=[None]*2, k=3, ext=0, check_finite=False):
        
        splobj = spl(x, y, w, bbox, k)
        bbox = list(splobj._data[3:5])
        
        if ext == 'zeros':
            
            ext = 0
        
        def splfcn(xpts):
Exemplo n.º 44
0
#! /usr/bin/env python3
import sys
import subprocess
from distutils.version import LooseVersion as version

assert len(sys.argv) == 3
inreq_path, outreq_path = sys.argv[1:]


def libv(s):
    s = str(s).strip()
    return s.split('==') if '==' in s else s.split('>=')


txt = subprocess.check_output(['pip3', 'list', '--format=freeze'])
txt = txt.decode('ascii', 'ignore')
installed = {}
for line in txt.split():
    lib, v = libv(line)
    installed[lib] = version(v)
with open(inreq_path) as fin, \
     open(outreq_path, 'w') as fout:
    for line in fin:
        rlib, rv = libv(line)
        if (rlib not in installed or version(rv) > installed[rlib]):
            fout.write(line)
Exemplo n.º 45
0
"""
Created on Thu Jan 14 11:51:09 2016

@author: ibackus
"""

import scipy
from scipy.interpolate import InterpolatedUnivariateSpline as spline
from warnings import warn
import numpy as np

from distutils.version import LooseVersion as version

# InterpolatedUnivariateSpline in older versions of scipy don't handle regions
# outside the bbox and don't have the argument ext=0
if version(scipy.__version__) < '0.16.0':
    warn(
        'WARNING: Deprecated version of scipy.  Please upgrade to at least 0.16.0'
    )

    spl = spline

    # OVERRIDE spline if scipy is outdated
    def spline(x, y, w=None, bbox=[None] * 2, k=3, ext=0, check_finite=False):

        splobj = spl(x, y, w, bbox, k)
        bbox = list(splobj._data[3:5])

        if ext == 'zeros':

            ext = 0