def calc_using_eval_module(
    y_clean: ndarray, y_est: ndarray, T_ys: Sequence[int] = (0, )) -> ODict:
    """ calculate metric using EvalModule. y can be a batch.

    :param y_clean:
    :param y_est:
    :param T_ys:
    :return:
    """

    if y_clean.ndim == 1:
        y_clean = y_clean[np.newaxis, ...]
        y_est = y_est[np.newaxis, ...]
    if T_ys == (0, ):
        T_ys = (y_clean.shape[1], ) * y_clean.shape[0]

    keys = None
    sum_result = None
    for T, item_clean, item_est in zip(T_ys, y_clean, y_est):
        # noinspection PyArgumentList,PyTypeChecker
        temp: ODict = EvalModule(item_clean[:T], item_est[:T], hp.fs)
        result = np.array(list(temp.values()))
        if not keys:
            keys = temp.keys()
            sum_result = result
        else:
            sum_result += result

    return ODict(zip(keys, sum_result.tolist()))
Ejemplo n.º 2
0
def getRecsTree(srcDir):
    depths, dataFolders = getDataFolders(srcDir)
    recsTree = ODict()
    for depth, dataFoldersAtDepth in zip(depths, dataFolders):
        recs = []
        if not depth in recsTree.keys():
            recsTree[depth] = {}
        for folder in dataFoldersAtDepth:
            try:
                recs.append(Recording(folder))
            except RuntimeError as err:  # Could not create instance
                print(
                    "Warning: could not create recording for folder {}, skipping; {}"
                    .format(folder, err))
        numberedRecs = setRecNbs(recs)
        if numberedRecs:  # Skip if nothing of type 'rec'
            try:
                angle = list(numberedRecs.keys())[0]
                numberedRecsDict = list(numberedRecs.values())[0]
            except IndexError:
                print("Depth: {}".format(depth))
                print("\tRecordings: {}".format(numberedRecs))
                raise
            recsTree[depth][angle] = numberedRecsDict
    return recsTree
Ejemplo n.º 3
0
    def on_post(self, req, rep, userId):
        """
        Handles POST requests
        """
        try:
            raw_json = req.stream.read()
        except Exception:
            raise falcon.HTTPError(falcon.HTTP_748, 'Read Error',
                                   'Could not read the request body.')

        try:
            data = json.loads(raw_json, 'utf-8')
        except ValueError:
            raise falcon.HTTPError(
                falcon.HTTP_753, 'Malformed JSON',
                'Could not decode the request body. The '
                'JSON was incorrect.')

        #console.terse("Received JSON Data: \n{}\n".format(data))

        result = ODict(userId=userId, data=data)

        #rep.status = falcon.HTTP_201
        #rep.location = '/example/%s' % (userId)  # location header redirect

        rep.status = falcon.HTTP_200  # This is the default status
        rep.body = json.dumps(result)
Ejemplo n.º 4
0
def loadAllKeyRoles(dirpath, prefix="key", role=""):
    """
    Load and Return the keys dict indexed by role for all key data files with
    prefix in  directory at dirpath  both .json and .msgpack file extensions
    are supported

    If role is not empty then loads last keyfile that matches both prefix and role

    key files names of form:
    prefix.role.json
    prefix.role.msgpack

    (when prefix is the default "key" )
    key.server.json
    key.server.msgpack

    key fields in keyfiles should be in:
    ('seed', 'sigkey', 'verkey', 'prikey', 'pubkey')

    values are bytes of binary key value

    """
    roles = ODict()
    for filename in os.listdir(dirpath):  # filenames without directory
        filepath = os.path.join(dirpath, filename)  # need full path for isfile
        if not os.path.isfile(filepath):
            continue
        root, ext = os.path.splitext(filename)
        if ext not in ['.json', '.msgpack']:
            continue
        pre, sep, rol = root.partition('.')
        if not rol or pre != prefix or (role and rol != role):
            continue
        roles[rol] = loadKeys(filepath)
    return roles
Ejemplo n.º 5
0
 def __init__(self, namestr):
     self.name    = namestr
     self.parent  = None
     self.parentJ = None
     self.children= list()
     self.inertia = dict()
     self.frames  = ODict()
     self.rcg_R_urdf = np.identity(3)
Ejemplo n.º 6
0
def delegator():
    """
    example generator that yields empty bytes before returning data
    """
    for i in range(10):
        yield bytes()
        time.sleep(0.1)
    return ODict(name="John Smith", country="United States")
Ejemplo n.º 7
0
    def __call__(self, clean: ndarray, noisy: ndarray, fs: int) -> ODict:
        import matlab
        clean = matlab.double(clean.tolist())
        noisy = matlab.double(noisy.tolist())
        fs = matlab.double([fs])
        results = self.eng.se_eval(clean, noisy, fs, nargout=3, stdout=self.strio)

        return ODict([(m, r) for m, r in zip(Evaluation.metrics, results)])
Ejemplo n.º 8
0
    def __init__(self, obj, defaultflags=None):
        """
        :param obj, (int, dict):
            either the decimal form of the bitwise array, or
            a dictionary (complete or otherwise) of the form
            {flag : bool, flag : bool, ...}
        :param defaultflags, dict:
            a dictionary representing the default for
            one or more flags.  Only applicable
            when a dictionary is passed to obj.  It's
            ignored when obj is an integer.
        """

        # calculate an msb-like number, which is actually
        # the msb * 2 to get one more digit than
        # the number of flags

        self.msb = 2 ** (len(BitFlag.flags) + 1)

        # if an integer was passed...
        # convert it to a boolean array
        if isinstance(obj, int):
            self.val = obj % self.msb
            tmp = self.val + self.msb

            self.bools = []
            while tmp != 0:
                self.bools.append(tmp % 2 == 1)
                tmp >>= 1
            self.bools = self.bools[:-1]

            for i, key in enumerate(BitFlag.flags):
                setattr(self, key, self.bools[i])

        # a dict of the form {flags : bool, } was passed...
        # convert it to the boolean array just the same.
        elif isinstance(obj, (dict, list)):
            if isinstance(obj, list):
                obj = dict(zip(obj, [True] * len(obj)))
            # if there are defaultflags, use them, otherwise assume all flags
            # are unset
            if defaultflags:
                defaults = defaultflags
            else:
                defaults = zip(BitFlag.flags, [False] * len(BitFlag.flags))
                defaults = ODict(defaults)

            self.bools = []
            self.val = 0
            for i, key in enumerate(BitFlag.flags):
                if key in obj:
                    val = obj[key]
                else:
                    val = defaults[key]
                setattr(self, key, val)
                self.bools.append(val)
                if val:
                    self.val += 2 ** i
Ejemplo n.º 9
0
class IVR(Module):
    description = "IVRs"
    item_name = "IVR"
    repr_format = "{name}"
    dest_regex = "ivr-([0-9]+)"

    db_table = "ivr_details"
    pk_field = "id"
    render_template = "list.tpl"
    config_param = staticmethod(lambda s: {
        "display": "ivr",
        "action": "edit",
        "id": s["id"]
    })

    fields = ODict([
        ("id", IntField()),
        ("name", StringField("IVR name")),
        ("description", StringField("IVR description")),
        ("announcement",
         ForeignKeyField("announcement", "Recording", {0: "None"})),
        ("directdial",
         ForeignKeyField("direct dial", "Directory", {
             "": "Disabled",
             "ext-local": "Extensions"
         })),
        ("timeout_time", IntField("timeout")),
        ("invalid_loops", IntField("invalid loops")),
        ("invalid_retry_recording",
         ForeignKeyField("invalid retry recording", "Recording", {
             "": "None",
             "default": "Default"
         })),
        ("invalid_append_announce",
         BooleanField("append announcement on invalid", (0, 1))),
        ("invalid_recording",
         ForeignKeyField("invalid recording", "Recording", {
             "": "None",
             "default": "Default"
         })),
        ("invalid_destination", DestinationField("invalid destination")),
        ("timeout_loops", IntField("timeout retries")),
        ("timeout_retry_recording",
         ForeignKeyField("timeout retry recording", "Recording", {
             "": "None",
             "default": "Default"
         })),
        ("timeout_append_announce",
         BooleanField("append announcement on timeout", (0, 1))),
        ("timeout_recording",
         ForeignKeyField("timeout recording", "Recording", {
             "": "None",
             "default": "Default"
         })),
        ("timeout_destination", DestinationField("timeout destination")),
        ("retvm", BooleanField("return to IVR after VM", ("", "on"))),
        ("entries", ManyToManyField("IVR entries", "IVREntry", "ivr_id")),
    ])
Ejemplo n.º 10
0
def makeSignedAgentReg(vk, sk, changed=None, **kwa):
    """
    Return duple of (signature,registration) of minimal self-signing
    agent registration record for keypair vk, sk

    registration is json encoded unicode string of registration record
    signature is base64 url-file safe unicode string signature generated
    by signing bytes version of registration

    Parameters:
        vk is bytes that is the public verification key
        sk is bytes that is the private signing key
        changed is ISO8601 date time stamp string if not provided then uses current datetime
        **kwa are optional fields to be added to data resource. Each keyword is
           the associated field name and the argument parameter is the value of
           that field in the data resource.  Keywords in ("did", "signer", "changed",
            "keys") will be overidden. Common use case is "issuants".


    """
    reg = ODict(did="", signer="", changed="",
                keys=None)  # create registration record as dict
    if kwa:
        reg.update(kwa.items())

    if not changed:
        changed = timing.iso8601(aware=True)

    did = makeDid(vk)  # create the did
    index = 0
    signer = "{}#{}".format(did, index)  # signer field value key at index
    key64u = keyToKey64u(vk)  # make key index field value
    kind = "EdDSA"

    reg["did"] = did
    reg["signer"] = signer
    reg["changed"] = changed
    reg["keys"] = [ODict(key=key64u, kind=kind)]

    registration = json.dumps(reg, indent=2)
    sig = libnacl.crypto_sign(registration.encode("utf-8"),
                              sk)[:libnacl.crypto_sign_BYTES]
    signature = keyToKey64u(sig)

    return (signature, registration)
Ejemplo n.º 11
0
    def on_get(self, req, rep, userId):
        """
        Handles GET requests
        """
        message = "\nHello World from {}\n\n".format(userId)
        result = ODict(user=userId, msg=message)

        rep.status = falcon.HTTP_200  # This is the default status
        rep.body = json.dumps(result)
Ejemplo n.º 12
0
def jsonGenerator():
    """
    example generator that yields empty before yielding json and returning
    """
    for i in range(10):
        yield bytes()
        time.sleep(0.1)
    yield bytes(json.dumps(ODict(name="John Smith", country="United States")),
                "ascii")
Ejemplo n.º 13
0
def parseSignatureHeader(signature):
    """
    Returns ODict of fields and values parsed from signature
    which is the value portion of a Signature header

    Signature header has format:

        Signature: headervalue

    Headervalue:
        tag = "signature"

    or

        tag = "signature"; tag = "signature"  ...

    where tag is the name of a field in the body of the request whose value
    is a DID from which the public key for the signature can be obtained
    If the same tag appears multiple times then only the last occurrence is returned

    each signature value is a doubly quoted string that contains the actual signature
    in Base64 url safe format. By default the signatures are EdDSA (Ed25519)
    which are 88 characters long (with two trailing pad bytes) that represent
    64 byte EdDSA signatures

    An option tag name = "kind" with values "EdDSA"  "Ed25519" may be present
    that specifies the type of signature. All signatures within the header
    must be of the same kind.

    The two tag fields currently supported are "did" and "signer"


    """
    sigs = ODict()
    if signature:
        clauses = signature.split(";")
        for clause in clauses:
            clause = clause.strip()
            if not clause:
                continue
            try:
                tag, value = clause.split("=", maxsplit=1)
            except ValueError as ex:
                continue
            tag = tag.strip()
            if not tag:
                continue
            value = value.strip()
            if not value.startswith('"') or not value.endswith(
                    '"') or len(value) < 3:
                continue
            value = value[1:-1]
            value = value.strip()
            sigs[tag] = value

    return sigs
Ejemplo n.º 14
0
def _select_preset():
    """Have the user select a preset."""

    values = [(preset.name, preset) for preset in o.PRESETS]
    option = OptionODict('PRESET',
                         PRESET_DEFAULT,
                         'Which preset',
                         odict=ODict(values))

    _load_options([option], PRESET_OPTIONS)
Ejemplo n.º 15
0
    def __init__(self, qcalc_exec, calcdirs, pdb_file, en_list_fn,
                 lambdas_A, lambdas_B, resid_first, resid_last,
                 scale_ionized, nthreads, qmask=None):

        self._en_list_fn = en_list_fn
        self._qcalc_exec = qcalc_exec
        try:
            self._pdb_qstruct = QStruct(pdb_file, "pdb")
        except QStructError as error_msg:
            raise QGroupContribError("Can't parse PDB file '{}': {}"
                                     "".format(pdb_file, error_msg))

        self._calcdirs = [os.path.relpath(cd) for cd in calcdirs]
        self._nthreads = nthreads
        self._lambdas_A = lambdas_A
        self._lambdas_B = lambdas_B
        self._resid_first = resid_first
        self._resid_last = resid_last
        self._scale_ionized = scale_ionized
        self._qmask = qmask


        self._qcalc_io = ODict()
        self.gcs = ODict()
        self.failed = ODict()
        self.qcalc_version = None

        self.kill_event = threading.Event()

        lambda1_st1, lambda2_st1 = lambdas_A[0], lambdas_B[0]
        sci = self._scale_ionized
        colnames = ["Residue id",
                    "Residue name",
                    "N",
                    "VdW(l={:5.4f}->l={:5.4f})_mean"
                    "".format(lambda1_st1, lambda2_st1),
                    "VdW(l={:5.4f}->l={:5.4f})_stdev"
                    "".format(lambda1_st1, lambda2_st1),
                    "El(l={:5.4f}->l={:5.4f})_(scale={})_mean"
                    "".format(lambda1_st1, lambda2_st1, sci),
                    "El(l={:5.4f}->l={:5.4f})_(scale={})_stdev"
                    "".format(lambda1_st1, lambda2_st1, sci)]
        self.gcs_stats = DataContainer(colnames)
Ejemplo n.º 16
0
 def __repr__(self):
     """Pretty print class as: ClassName(arg1=val1, arg2=val2)"""
     # Shorten NumPy array output:
     np.set_printoptions(precision=3, threshold=7, edgeitems=3)
     # Line width:
     lwidth = 60
     # Sort list of parameters alphabetically:
     sorted_params = ODict(sorted(self._pprint_params().items()))
     # Start string with class name, followed by all arguments:
     str_params = self.__class__.__name__ + '('
     # New line indent (align with class name on first line):
     lindent = len(str_params)
     # Keep track of number of chars on current line:
     lc = len(str_params)
     for key, val in sorted_params.items():
         # Attribute string:
         if isinstance(val, str):
             # Need extra '' around strings for repr:
             sparam = key + '=\'' + str(val) + '\', '
         else:
             if isinstance(val, np.ndarray):
                 # Print NumPy arrays without line breaks:
                 strobj = np.array2string(val).replace('\n', ',')
                 # If still too long, show shape:
                 if len(strobj) > lwidth - lindent:
                     strobj = '<%s np.ndarray>' % str(val.shape)
             else:
                 strobj = str(val)
                 is_type = isinstance(val, type)
                 if len(strobj) > lwidth - lindent:
                     # Too long, just show the type:
                     strobj = str(type(val))
                     is_type = True
                 if is_type:
                     # of the form <class 'X'>, only retain X:
                     strobj = strobj.replace("<class '", "")
                     strobj = strobj.replace("'>", "")
                     # For X.Y.Z, only retain Z:
                     strobj = strobj.split('.')[-1]
             sparam = key + '=' + strobj + ', '
         # If adding `sparam` puts line over `lwidth`, start a new line:
         if lc + len(sparam) > lwidth:
             # But only do so if this is not the first param to be added
             # (check last character of previously written string):
             if str_params[-1] != '(':
                 str_params += '\n' + ' ' * lindent
                 lc = lindent
         str_params += sparam
         lc += len(sparam)
     if len(sorted_params) > 0:
         # Delete last comma:
         str_params = str_params[:-2]
     # Add ')':
     str_params += ')'
     return str_params
Ejemplo n.º 17
0
 def __init__(self, title, plot_type="line", xlabel=None, ylabel=None):
     self.title = title
     PLOT_TYPES = ["line", "bar"]
     if plot_type not in PLOT_TYPES:
         raise ValueError(
             "'plot_type' %s not supported. Try one of these instead: %s" %
             (plot_type, ",".join(PLOT_TYPES)))
     self.plot_type = plot_type
     self.xlabel = xlabel
     self.ylabel = ylabel
     self.subplots = ODict()
Ejemplo n.º 18
0
 def dumpKeys(self):
     """
     Dump Keeper keys to file in .baseDirpath
     key values stored in unicode hex format
     """
     keys = ODict()
     for field in self.fields:
         if hasattr(self, field):
             keys[field] = binascii.hexlify(getattr(self,
                                                    field)).decode('utf-8')
     self.dump(keys, self.filePath)
Ejemplo n.º 19
0
    def __init__(self, qfep_exec, mapdirs, en_list_fn, hij, alpha, temperature,
                 gas_const, points_skip, gap_bins, minpts_bin, nthreads):

        self._en_list_fn = en_list_fn
        self._qfep = QFep(qfep_exec)
        self._mapdirs = [os.path.relpath(m) for m in mapdirs]
        self._nthreads = nthreads

        self.parms = {"hij": hij,
                      "alpha": alpha,
                      "temperature": temperature,
                      "gas_const": gas_const,
                      "points_skip": points_skip,
                      "gap_bins": gap_bins,
                      "minpts_bin": minpts_bin}

        self.mapped = ODict()
        self.failed = ODict()

        self.kill_event = threading.Event()
Ejemplo n.º 20
0
 def decode_plotdata(self, d):
     d = ODict(d)
     if "__type__" not in d:
         return d
     t = d["__type__"]
     if t == "PlotData":
         pd = PlotData(d["title"], d["plot_type"], d["xlabel"], d["ylabel"])
         pd.subplots = d["subplots"]
         return pd
     else:
         return d
Ejemplo n.º 21
0
    def backendGenerator(self, skin, req=None, rep=None):
        """
        example generator that yields empty before returning json
        """
        path = req.get_param("path")
        if not path:
            path = "/example"
        port = 8101
        berep = yield from backendRequest(method='GET',
                                          port=port,
                                          path=path,
                                          store=self.store,
                                          timeout=0.5)

        if berep is None:  # timed out waiting for authorization server
            raise httping.HTTPError(
                httping.SERVICE_UNAVAILABLE,
                title='Timeout Validation Error',
                detail='Timeout backend validation request.')

        if berep['status'] != 200:
            if berep['errored']:
                emsg = berep['error']
            else:
                emsg = "unknown"
            raise httping.HTTPError(
                berep['status'],
                title="Backend Validation Error",
                detail="Error backend validation. {}".format(emsg))

        yield b''
        skin._status = falcon.HTTP_200  # This is the default status
        headers = ODict()
        headers["Content-Type"] = "application/json"
        skin._headers = headers

        result = ODict(approved=True, body=berep['body'].decode())
        body = json.dumps(result, indent=2)
        bodyb = body.encode()

        return bodyb
Ejemplo n.º 22
0
    def _Y_describePop(self):
        ''' Return nested dictionary with necessary object NETPYNE descriptors

            Used for NETPYNE popParams() functionality
            INPUTS:

            Example parameter dictionary for run file:
            >> from netpyne import specs
            >> netParams = specs.NetParams()
            >> netParams.popParams['L23_RS_PYR'] = {'cellType': 'PYR', 'numCells': 36,
            >>                                     'yRange': [  81.6,  587.1],
            >>                                     'vInit': [ -70, 20]
            >>                                     'cellModel': 'suppyrRS_mod'}

            Keyargs are stored in 'Y_populationParams'

            See http://neurosimlab.org/netpyne/index.html for more details
        '''

        # Populaton dictionary for NETPYNE instantiation
        Y_populationParams = ODict()  # Maintain order for plotting later

        # Construct full cell ids for nesting
        self.Y_pop_ids = [[], [], [], []]
        for i, (layers, ptypes, etypes, _, _) in enumerate(self.Y_ziplist):
            for layer, ptype, etype in zip(layers, ptypes, etypes):
                self.Y_pop_ids[i].append(layer + '_' + etype + '_' + ptype)

        # Calculate population depths
        self.depths = self._calcDepths()

        # Update ziplist
        self.Y_ziplist = zip(self.Y_pop_ids, self.depths, self.layers,
                             self.p_types, self.e_types, self.N_Y,
                             self.templatenames)

        # Create data structure
        for i, (pops, depths, layers, ptypes, _, sizes,
                temps) in enumerate(self.Y_ziplist):
            for pop, depth, ptype, size, temp in zip(pops, depths, ptypes,
                                                     sizes, temps):
                Y_populationParams.update({
                    pop: {
                        'cellType': ptype,
                        'numCells': size,
                        'yRange':
                        depth.tolist(),  # NETPYNE accepts yRange as a list
                        'vInit': self.v_range,
                        'cellModel': temp + '_mod',
                    }
                })

        return Y_populationParams
Ejemplo n.º 23
0
 def __init__(self):
     self.options = ODict()
     self.atom_types = ODict()
     self.bonds = ODict()
     self.angles = ODict()
     self.torsions = ODict()
     self.impropers = ODict()
Ejemplo n.º 24
0
def test_getEntities():
    """
    Test get all entities Agents and Things in db

    getEntities(dbn='core', env=None)
    """
    print("Testing getEntities in DB Env")

    priming.setupTest()
    dbEnv = dbing.gDbEnv
    keeper = keeping.gKeeper
    kdid = keeper.did

    agents, things = dbing.setupTestDbAgentsThings()
    agents['sam'] = (kdid, keeper.verkey, keeper.sigkey)  # sam the server

    entities = dbing.getEntities()
    assert len(entities) == 6
    assert entities == [
        ODict([('did', 'did:igo:3syVH2woCpOvPF0SD9Z0bu_OxNe2ZgxKjTQ961LlMnA='),
               ('kind', 'agent')]),
        ODict([('did', 'did:igo:4JCM8dJWw_O57vM4kAtTt0yWqSgBuwiHpVgd55BioCM='),
               ('kind', 'thing')]),
        ODict([('did', 'did:igo:QBRKvLW1CnVDIgznfet3rpad-wZBL4qGASVpGRsE2uU='),
               ('kind', 'agent')]),
        ODict([('did', 'did:igo:Qt27fThWoNZsa88VrTkep6H-4HA8tr54sHON1vWl6FE='),
               ('kind', 'agent')]),
        ODict([('did', 'did:igo:Xq5YqaL6L48pf0fu7IUhL0JRaU2_RxFP0AL43wYn148='),
               ('kind', 'agent')]),
        ODict([('did', 'did:igo:dZ74MLZXD-1QHoa73w9pQ9GroAvxqFi2RTZWlkC0raY='),
               ('kind', 'agent')])
    ]

    cleanupTmpBaseDir(dbEnv.path())
    print("Done Test")
Ejemplo n.º 25
0
def testValidateDataIncompleteMajority():
    consense = consensing.CompositeConsense()

    response1 = builder.DideryResponseBuilder(
        builder.CompositeHistoryBuilder().withRotations()).withPort(8000)
    response2 = builder.DideryResponseBuilder(
        builder.CompositeHistoryBuilder().withRotations().withRotations())
    response3 = builder.DideryResponseBuilder(builder.CompositeHistoryBuilder(
    ).withRotations().withRotations()).withPort(8081)
    response4 = builder.DideryResponseBuilder(
        builder.CompositeHistoryBuilder().withRotations()).withPort(8001)

    data = {
        'http://localhost:8000/event/': response1.build(),
        'http://localhost:8080/event/': response2.build(),
        'http://localhost:8081/event/': response3.build(),
        'http://localhost:8001/event/': response4.build()
    }

    consense.validateData(data)

    exp_data = response1.historyBuilder.build()
    sha = sha256(str(ODict(exp_data)).encode()).hexdigest()
    bad_exp_data = response2.historyBuilder.build()
    bad_sha = sha256(str(ODict(bad_exp_data)).encode()).hexdigest()

    assert len(consense.valid_data) == 2

    assert sha in consense.valid_data
    assert consense.valid_data[sha]['0'] == exp_data['0'].data
    assert consense.valid_data[sha]['1'] == exp_data['1'].data
    assert sha in consense.valid_match_counts
    assert consense.valid_match_counts[sha] == 2

    assert bad_sha in consense.valid_data
    assert consense.valid_data[bad_sha]['0'] == bad_exp_data['0'].data
    assert consense.valid_data[bad_sha]['1'] == bad_exp_data['1'].data
    assert consense.valid_data[bad_sha]['2'] == bad_exp_data['2'].data
    assert bad_sha in consense.valid_match_counts
    assert consense.valid_match_counts[bad_sha] == 2
Ejemplo n.º 26
0
    def __init__(self, parent, plotdata, plotdata_files):
        self.parent = parent
        self.plots = plotdata
        # self.plots looks like this:
        #
        # { "dgde" : { 0 : PlotData_instance (from file 1),
        #              1 : PlotData_instance (from file 2), ... },
        #   "egap_l" : { 0 : PlotData_instance (from file 1),
        #                1 : PlotData_instance (from file 2), ... },
        #  ... }
        # where 0,1,... are indices of the filenames in plotdata_files
        #
        self.plotdata_files = plotdata_files  #  [ "/home/.../pro/qa.PlotData.pickle", "/home/.../wat/qa.PlotData.pickle" ]
        self.nrows = 1
        self.ncols = 1
        self.blocked_draw = False
        self.subplot_lines = {}
        self.legend_font = FontProperties(size="xx-small")

        self.lb1_entries = ODict()
        for plot_key, plot in six.iteritems(self.plots):
            self.lb1_entries[list(plot.values())[0].title] = plot_key

        self.lb1 = Tk.Listbox(self.parent,
                              selectmode=Tk.EXTENDED,
                              exportselection=0)

        for plot_title in self.lb1_entries.keys():
            self.lb1.insert(Tk.END, plot_title)

        self.lb1.pack(fill=Tk.Y, side=Tk.LEFT)
        self.lb2 = Tk.Listbox(self.parent,
                              selectmode=Tk.EXTENDED,
                              exportselection=0)
        self.lb2.pack(fill=Tk.Y, side=Tk.LEFT)

        self.figure = Figure(figsize=(5, 4), dpi=100)

        self.canvas = FigureCanvasTkAgg(self.figure, master=self.parent)
        self.canvas.get_tk_widget().pack()
        self.canvas._tkcanvas.pack(fill=Tk.BOTH, expand=1)

        if int(matplotlib.__version__[0]) > 2:
            self.toolbar = NavigationToolbar2Tk(self.canvas, self.parent)
        else:
            self.toolbar = NavigationToolbar2TkAgg(self.canvas, self.parent)
        self.toolbar.update()
        self.canvas._tkcanvas.pack(side=Tk.TOP, fill=Tk.BOTH, expand=1)

        self.lb1.bind("<<ListboxSelect>>", self.on_select_lb1)
        self.lb2.bind("<<ListboxSelect>>", self.on_select_lb2)
        self.parent.bind("<Configure>", self.on_resize)
Ejemplo n.º 27
0
    def get_spiking_freq_lists_per_trial(self):
        """
        Non stacked rasters (list of spiking frequencies) per trial

        :return:
        """
        bsl_rasters, rasters, rasters_starts = self.get_rasters()
        bsl_freqs = []
        clock_wise_freqs = []
        c_clock_wise_freqs = []
        first_quarter_freqs = []
        second_quarter_freqs = []
        third_quarter_freqs = []
        fourth_quarter_freqs = []

        # Using bsl_plot_segment_duration since bsl_rasters split  to compare with clockwise/counterclock
        # BASELINE
        for r in bsl_rasters:
            bsl_freqs.append(r.size / self.bsl_plot_segment_duration)

        # CW CCW
        mid = self.half_segment_duration
        for s, raster in zip(rasters_starts, rasters):
            r = raster - s  # tODO: check if needs np.array
            n_spikes_clock_wise = r[r < mid].size
            clock_wise_freqs.append(n_spikes_clock_wise / mid)
            n_spikes_c_clock_wise = r[r >= mid].size
            c_clock_wise_freqs.append(n_spikes_c_clock_wise / mid)

        # CONTRA IPSI
        quarter_duration = mid / 2
        for s, raster in zip(rasters_starts, rasters):
            r = raster - s  # tODO: check if needs np.array
            first_quarter_freqs.append(r[r < quarter_duration].size / quarter_duration)

            fourth_quarter_freqs.append(r[r >= (quarter_duration*3)].size /quarter_duration)

            second_quarter_n_spikes = r[np.logical_and(r >= quarter_duration, r < mid)].size
            second_quarter_freqs.append(second_quarter_n_spikes / quarter_duration)

            third_quarter_n_spikes = r[np.logical_and(r >= mid, r < (quarter_duration*3))].size
            third_quarter_freqs.append(third_quarter_n_spikes / quarter_duration)

        table = ODict()
        table['bsl'] = bsl_freqs
        table['clockWise'] = clock_wise_freqs
        table['cClockWise'] = c_clock_wise_freqs
        table['cw_contra'] = first_quarter_freqs
        table['ccw_contra'] = fourth_quarter_freqs
        table['cw_ipsi'] = second_quarter_freqs
        table['ccw_ipsi'] = third_quarter_freqs
        return table
Ejemplo n.º 28
0
def clean_spider(obj):
    """Removes incomplete data from the spider"""
    if 'init_requests' in obj:
        required_fields = ('type', 'loginurl', 'username', 'password')
        obj['init_requests'] = [
            req for req in obj['init_requests']
            if all(f in req for f in required_fields)
        ]
    if 'start_urls' in obj:
        obj['start_urls'] = list(ODict([(x, 1) for x in obj['start_urls']]))
    # XXX: Need id to keep track of renames for deploy and export
    if 'id' not in obj:
        obj['id'] = short_guid()
Ejemplo n.º 29
0
def parameter_lookup_dict(dct):
    """ Make a dict to lookup where a given parameter is stored. """
    lt = ODict()
    for group in dct:
        for key in dct[group]:
            if key in lt:
                lt[key].append(group)
            else:
                lt[key] = [group]
    # Finally add the key itself at the end
    for key in lt:
        lt[key].append(key)
    return lt
Ejemplo n.º 30
0
    def __init__(self, log_entry: Bracket = None):
        self.hash: Dict[str, BlockGroup] = ODict()
        self.block = None

        if log_entry is not None:
            assert log_entry.is_left()
            self.block = Block(log_entry)
            self._hash(self.block)

        self.root = self.block

        self.sparse_checkpoints: List[int] = []
        self.iterations_count = 0