Ejemplo n.º 1
0
def load_model(ctx, cfg):
    stmt = db.select_tile(cfg, ctx['tx'], ctx['ty'])

    fn = excepts(
        StopIteration, lambda cfg, statement: bytes.fromhex(
            first(db.execute_statement(cfg, statement)).model))

    model = fn(cfg, stmt)

    if model is None:
        raise Exception("No model found for tx:{tx} and ty:{ty}".format(**ctx))
    else:
        return assoc(ctx, 'model_bytes', model)
Ejemplo n.º 2
0
def create(x, y, chipseq, dateseq, locations, spec_index):
    """Transforms a sequence of chips into a sequence of rods
       filtered by date, deduplicated, sorted, located and identified.

       Args:
           x (int): x projection coordinate of chip
           y (int): y projection coordinate of chip
           chipseq (seq): sequence of chips
           dates (seq): sequence of dates that should be included in the rods
           locations (numpy.Array): 2d numpy array of pixel coordinates
           spec_index (dict): specs indexed by ubid

       Returns:
           dict: {(chip_x, chip_y, x, y): {'k1': [], 'k2': [], 'k3': [], ...}}
    """

    return thread_last(
        chipseq, partial(chips.trim, dates=dateseq), chips.deduplicate,
        chips.rsort, partial(chips.to_numpy, spec_index=spec_index),
        excepts(ValueError, from_chips, lambda _: []),
        excepts(AttributeError, partial(locate, locations=locations),
                lambda _: {}), partial(identify, x=x, y=y))
Ejemplo n.º 3
0
    async def _handle_get_collations(self, peer, msg):
        """Respond with all requested collations that we know about."""
        collation_hashes = set(msg["collation_hashes"])
        self.collation_hashes_at_peer[peer] |= collation_hashes

        get_collation_or_none = excepts(
            (CollationHeaderNotFound, CollationBodyNotFound),
            self.shard.get_collation_by_hash)
        collations = [
            collation for collation in [
                get_collation_or_none(collation_hash)
                for collation_hash in collation_hashes
            ] if collation is not None
        ]
        self.logger.info(
            "Responding to peer %s with %d collations",
            peer.remote,
            len(collations),
        )
        peer.sub_proto.send_collations(msg["request_id"], collations)