def create_concrete_visitor(base_visitor_name, n_visit_func):
    print('You are creating a concrete visitor class for Visitor pattern.')

    concrete_visitor = meta_class.MetaClass()

    concrete_visitor._add_class_name()

    class_name = concrete_visitor.name

    base_classes = [base_visitor_name]
    commands = generate_commands_add_base(base_classes)
    wrap(concrete_visitor._add_base_names, commands)
    print_class_must_have_base(class_name, base_classes, True)
    concrete_visitor._add_base_names()

    for i in range(n_visit_func):
        curr_func = f'visit_concrete_element_{i}'
        curr_params = [f'concrete_element_{i}']
        curr_decors = []
        commands = generate_commands_add_func(curr_func, curr_params,
                                              curr_decors)
        wrap(concrete_visitor._add_method, commands)
        print_class_must_have_func(class_name, curr_func, curr_params, True)
        concrete_visitor._add_args_to_method(curr_func)
        print_class_must_have_decors(class_name, curr_func, curr_decors, True)
        concrete_visitor._add_method_decorator(curr_func)

    concrete_visitor._add_methods()

    return concrete_visitor
Example #2
0
def evaluate(model, criterion, epoch, eval_losses):
    total = 0
    valid_enum = tqdm(valid_loader, desc='Valid epoch %d' % epoch)

    for txt, feat, spkr in valid_enum:
        input = wrap(txt, volatile=True)
        target = wrap(feat, volatile=True)
        spkr = wrap(spkr, volatile=True)

        output, _ = model([input, spkr], target[0])
        loss = criterion(output, target[0], target[1])

        total += loss.data[0]

        valid_enum.set_description('Valid (loss %.2f) epoch %d' %
                                   (loss.data[0], epoch))

    avg = total / len(valid_loader)
    eval_losses.append(avg)
    if args.visualize:
        vis.line(Y=np.asarray(eval_losses),
                 X=torch.arange(1, 1 + len(eval_losses)),
                 opts=dict(title="Eval"),
                 win='Eval loss ' + args.expName)

    logging.info('====> Test set loss: {:.4f}'.format(avg))
    return avg
def create_base_element():
    print('You are creating a base element class for Visitor pattern.')

    base_element = meta_class.MetaClass()

    base_element._add_class_name()

    class_name = base_element.name

    base_classes = ['ABC']
    commands = generate_commands_add_base(base_classes)
    wrap(base_element._add_base_names, commands)
    print_class_must_have_base(class_name, base_classes, True)
    base_element._add_base_names()

    curr_func = 'accept'
    curr_params = ['visitor']
    curr_decors = ['abstractmethod']
    commands = generate_commands_add_func(curr_func, curr_params, curr_decors)
    wrap(base_element._add_method, commands)
    print_class_must_have_func(class_name, curr_func, curr_params, True)
    base_element._add_args_to_method(curr_func)
    print_class_must_have_decors(class_name, curr_func, curr_decors, True)
    base_element._add_method_decorator(curr_func)

    base_element._add_methods()

    return base_element
def create_base_visitor():
    print('You are creating a base visitor class for Visitor pattern.')

    base_visitor = meta_class.MetaClass()

    base_visitor._add_class_name()

    class_name = base_visitor.name

    base_classes = ['ABC']
    commands = generate_commands_add_base(base_classes)
    wrap(base_visitor._add_base_names, commands)
    print_class_must_have_base(class_name, base_classes, True)
    base_visitor._add_base_names()

    n_visit_func = int(input('How many visitor functions do you want: '))
    for i in range(n_visit_func):
        curr_func = f'visit_concrete_element_{i}'
        curr_params = [f'concrete_element_{i}']
        curr_decors = ['abstractmethod']
        commands = generate_commands_add_func(curr_func, curr_params,
                                              curr_decors)
        wrap(base_visitor._add_method, commands)
        print_class_must_have_func(class_name, curr_func, curr_params, True)
        base_visitor._add_args_to_method(curr_func)
        print_class_must_have_decors(class_name, curr_func, curr_decors, True)
        base_visitor._add_method_decorator(curr_func)

    base_visitor._add_methods()

    return base_visitor, n_visit_func
    def simulate_sensor(self, state, noise=1):

        #states
        xt = state[0, :]
        yt = state[1, :]
        tht = state[2, :]

        #range components w/o sensor noise
        dif1x = self.landmark1[0] - xt
        dif1y = self.landmark1[1] - yt
        dif2x = self.landmark2[0] - xt
        dif2y = self.landmark2[1] - yt
        dif3x = self.landmark3[0] - xt
        dif3y = self.landmark3[1] - yt

        #range and bearing w/o sensor noise/truth
        z_r1_tru = np.sqrt(dif1x**2 + dif1y**2)
        z_r2_tru = np.sqrt(dif2x**2 + dif2y**2)
        z_r3_tru = np.sqrt(dif3x**2 + dif3y**2)
        z_b1_tru = np.arctan2(dif1y, dif1x)
        z_b2_tru = np.arctan2(dif2y, dif2x)
        z_b3_tru = np.arctan2(dif3y, dif3x)

        #add in sensor noise if noise is not specified as 0
        z_r1 = z_r1_tru + noise * np.random.normal(0, self.sig_r)
        z_r2 = z_r2_tru + noise * np.random.normal(0, self.sig_r)
        z_r3 = z_r3_tru + noise * np.random.normal(0, self.sig_r)
        z_b1 = wrap(z_b1_tru - tht + noise * np.random.normal(0, self.sig_phi))
        z_b2 = wrap(z_b2_tru - tht + noise * np.random.normal(0, self.sig_phi))
        z_b3 = wrap(z_b3_tru - tht + noise * np.random.normal(0, self.sig_phi))

        z = np.array([[z_r1], [z_r2], [z_r3], [z_b1], [z_b2], [z_b3]])

        return (z)
    def vel_motion_model(self, ut, state, noise=1):

        #commands and states
        vc = ut[0]
        wc = ut[1]
        xt = state[0, :]
        yt = state[1, :]
        tht = state[2, :]

        size = len(xt)

        #Add noise to commands
        v_hat = vc + noise * np.random.normal(
            0, np.sqrt(self.a1 * vc**2 + self.a2 * wc**2), size)
        w_hat = wc + noise * np.random.normal(
            0, np.sqrt(self.a3 * vc**2 + self.a4 * wc**2), size)
        #include a gamma that accounts for imperfect heading
        gama = noise * np.random.normal(
            0, np.sqrt(self.a5 * vc**2 + self.a6 * wc**2), size)

        #propagate states
        x_new = xt - v_hat / w_hat * np.sin(tht) + v_hat / w_hat * np.sin(
            wrap(tht + w_hat * self.dt))
        y_new = yt + v_hat / w_hat * np.cos(tht) - v_hat / w_hat * np.cos(
            wrap(tht + w_hat * self.dt))
        th_new = wrap(tht + w_hat * self.dt + gama * self.dt)

        states_new = np.array([x_new, y_new, th_new])

        return states_new
Example #7
0
    async def rpg(self, ctx: Context):
        """A rouge-like rpg game you can play with reactions.

        To get the tutorial use the "tutorial" or "rpg tutorial" commands.
        """
        await ctx.send(
            "Welcome to culturebot's rpg game! If this is your first time playing make sure to read the tutorial\n",
            delete_after=10)

        msg = await ctx.send(
            wrap('Please pick a hero:\n'
                 "knight ⚔️ | bleed, steals enemy stamina\n"
                 "rogue  🗡️ | dodge, dodge enemy attack and deal damage back\n"
                 "viking 🪓 | punch, deal high damage"))
        choice = await discord_choice(self.bot, msg, ctx.author,
                                      dict(zip(['⚔️', '🗡️', '🪓'], heroes)))
        if choice is None:
            return
        hero = Hero(**choice)
        await msg.edit(content=wrap(
            'Please pick a difficulty:\n'
            "1: easy   🟩 | enemies move basically at random, gets boring after a while.\n"
            "2: normal 🟨 | enemies use simple AI to attack, recomended for casual players.\n"
            "3: hard   🟥 | super smart AI, hard to beat, a true challenge."))
        difficulty = await discord_choice(
            self.bot, msg, ctx.author, dict(zip(['🟩', '🟨', '🟥'], [1, 2, 3])))
        if difficulty is None:
            return
        await msg.edit(
            content=
            f"Now playing as {hero.name} on {['dev','easy','normal','hard'][difficulty]}"
        )

        await self.gameloop(ctx, hero, difficulty)
Example #8
0
    def toHumanReadable(self, lineLength=72):
        result = u""

        result += "=" * lineLength + "\n"
        result += utils.wrap(self.title, lineLength) + "\n"
        result += "\n"

        notes = [
            note for note in [self.description, self.content, self.hint]
            if note
        ]

        if len(self.schedules) > 0:
            for schedule in self.schedules:
                result += unicode(schedule) + "\n"

            if notes:
                result += "-" * lineLength + "\n"

        result += u"\n".join(
            [utils.wrap(note, lineLength) + "\n" for note in notes])

        if notes:
            result += "=" * lineLength + "\n"

        return result
Example #9
0
    def evaluate_epoch(self, epoch):
        for meter in self.evals_recon:
            meter.reset()
        self.eval_total.reset()

        self.encoder.eval()
        self.decoder.eval()

        n_batches = int(np.ceil(self.args.epoch_len / 10))

        with tqdm(total=n_batches) as valid_enum, \
                torch.no_grad():
            for batch_num in range(n_batches):
                if self.args.short and batch_num == 10:
                    break

                dset_num = batch_num % self.args.n_datasets

                x, x_aug = next(self.data[dset_num].valid_iter)

                x = wrap(x)
                x_aug = wrap(x_aug)
                batch_loss = self.eval_batch(x, x_aug, dset_num)

                valid_enum.set_description(
                    f'Test (loss: {batch_loss:.2f}) epoch {epoch}')
                valid_enum.update()
Example #10
0
    def measurement_model(self, zt, xm, simulate_sensor, sig_r, sig_phi):
        #get range and bearing for each particle without sensor noise
        noise = 0
        zm = simulate_sensor(xm, noise)

        #calculate weights based on probability of each particle's range and bearing given the actual measurement and sensor noise
        dr1 = zt[0] - zm[0]
        dr2 = zt[1] - zm[1]
        dr3 = zt[2] - zm[2]

        db1 = wrap(zt[3] - zm[3])
        db2 = wrap(zt[4] - zm[4])
        db3 = wrap(zt[5] - zm[5])

        # mr = np.mean(dr)
        # mb = np.mean(db)
        wmr1 = self.prob(dr1, sig_r)
        wmr2 = self.prob(dr2, sig_r)
        wmr3 = self.prob(dr3, sig_r)

        wmb1 = self.prob(db1, sig_phi)
        wmb2 = self.prob(db2, sig_phi)
        wmb3 = self.prob(db3, sig_phi)

        wm = wmr1 * wmr2 * wmr3 * wmb1 * wmb2 * wmb3
        # wm = self.prob(dr, sig_phi)*self.prob(db, sig_phi)
        #product of the three probabilties for each landmark is the final probability.  This may not be done in this function?

        return wm
def create_base_strategy():
    print('You are creating a base class for Strategy in Strategy pattern.')

    strategy = meta_class.MetaClass()

    strategy._add_class_name()
    class_name = strategy.name

    base_names = ['ABC']
    commands = generate_commands_add_base(base_names)
    wrap(strategy._add_base_names, commands)
    print_class_must_have_base(class_name, base_names, True)
    strategy._add_base_names()

    curr_func = 'algorithm_interface'
    curr_params = []
    curr_decors = ['abstractmethod']
    commands = generate_commands_add_func(curr_func, curr_params, curr_decors)
    wrap(strategy._add_method, commands)
    print_class_must_have_func(class_name, curr_func, curr_params, True)
    strategy._add_args_to_method(curr_func)
    print_class_must_have_decors(class_name, curr_func, curr_decors, True)
    strategy._add_method_decorator(curr_func)

    strategy._add_methods()

    return strategy
def create_concrete_observer(base_observer_name):
    print(
        'You are creating a concrete class for Observer in Observer pattern.')

    observer = meta_class.MetaClass()

    observer._add_class_name()
    class_name = observer.name

    base_names = [base_observer_name]
    commands = generate_commands_add_base(base_names)
    wrap(observer._add_base_names, commands)
    print_class_must_have_base(class_name, base_names, True)
    observer._add_base_names()

    curr_func = 'update'
    curr_params = ['arg']
    curr_decors = []
    commands = generate_commands_add_func(curr_func, curr_params, curr_decors)
    wrap(observer._add_method, commands)
    print_class_must_have_func(class_name, curr_func, curr_params, True)
    observer._add_args_to_method(curr_func)
    print_class_must_have_decors(class_name, curr_func, curr_decors, True)
    observer._add_method_decorator(curr_func)

    return observer
    def __init__(self,
                 alphas,
                 Q,
                 num_particles=1000,
                 limits=[-5, 5, -5, 5],
                 landmarks=np.empty(0)):
        self.Q = Q.diagonal().reshape((len(Q), 1))
        self.M = num_particles
        self.landmarks = landmarks
        self.g = MotionModel(alphas, noise=True)
        self.h = MeasurementModel()

        self.chi = np.empty((4, num_particles))
        self.chi[0] = np.random.uniform(limits[0], limits[1],
                                        self.chi[0].shape)
        self.chi[1] = np.random.uniform(limits[2], limits[3],
                                        self.chi[1].shape)
        self.chi[2] = np.random.uniform(-np.pi, np.pi, self.chi[2].shape)
        self.chi[3] = 1 / num_particles
        self.mu = wrap(np.mean(self.chi[:3], axis=1, keepdims=True), dim=2)
        mu_diff = wrap(self.chi[:3] - self.mu, dim=2)
        self.sigma = np.cov(mu_diff)
        self.z_nan = 50
        self.z_hat = np.ones((2, len(self.landmarks))) * self.z_nan
        self.z = np.ones((2, len(self.landmarks))) * self.z_nan
        self.n = 3
Example #14
0
    def train_epoch(self, epoch):
        for meter in self.losses_recon:
            meter.reset()
        self.loss_d_right.reset()
        self.loss_total.reset()

        self.encoder.train()
        self.decoder.train()
        self.discriminator.train()

        n_batches = self.args.epoch_len

        with tqdm(total=n_batches,
                  desc='Train epoch %d' % epoch) as train_enum:
            for batch_num in range(n_batches):
                if self.args.short and batch_num == 3:
                    break

                if self.args.distributed:
                    assert self.args.rank < self.args.n_datasets, "No. of workers must be equal to #dataset"
                    # dset_num = (batch_num + self.args.rank) % self.args.n_datasets
                    dset_num = self.args.rank
                else:
                    dset_num = batch_num % self.args.n_datasets

                x, x_aug = next(self.data[dset_num].train_iter)

                x = wrap(x)
                x_aug = wrap(x_aug)
                batch_loss = self.train_batch(x, x_aug, dset_num)

                train_enum.set_description(
                    f'Train (loss: {batch_loss:.2f}) epoch {epoch}')
                train_enum.update()
Example #15
0
    def evaluate_epoch(self, epoch):
        for meter in self.evals_recon:
            meter.reset()
        self.eval_d_right.reset()
        self.eval_total.reset()

        self.encoder.eval()
        self.decoder.eval()
        self.discriminator.eval()

        n_batches = int(np.ceil(self.args.epoch_len / 10))

        with tqdm(total=n_batches) as valid_enum, \
                torch.no_grad():
            for batch_num in range(n_batches):
                if self.args.short and batch_num == 10:
                    break

                if self.args.distributed:
                    assert self.args.rank < self.args.n_datasets, "No. of workers must be equal to #dataset"
                    dset_num = self.args.rank
                else:
                    dset_num = batch_num % self.args.n_datasets

                x, x_aug = next(self.data[dset_num].valid_iter)

                x = wrap(x)
                x_aug = wrap(x_aug)
                batch_loss = self.eval_batch(x, x_aug, dset_num)

                valid_enum.set_description(
                    f'Test (loss: {batch_loss:.2f}) epoch {epoch}')
                valid_enum.update()
Example #16
0
def evp_init(lib):
    wrap(lib.PEM_read_bio_PrivateKey, [c_void_p, c_void_p, c_pass_callback_t, 
                                       c_void_p], c_void_p)
    wrap(lib.EVP_PKEY_free, [c_void_p], None)
    wrap(lib.EVP_sha256, [], c_void_p)
    wrap(lib.EVP_sha384, [], c_void_p)
    wrap(lib.EVP_sha512, [], c_void_p)
def create_concrete_state(base_state_name):
    print('You are creating a concrete class for State in State pattern.')

    state = meta_class.MetaClass()

    state._add_class_name()
    class_name = state.name

    base_names = [base_state_name]
    commands = generate_commands_add_base(base_names)
    wrap(state._add_base_names, commands)
    print_class_must_have_base(class_name, base_names, True)
    state._add_base_names()

    curr_func = 'handle'
    curr_params = []
    curr_decors = []
    commands = generate_commands_add_func(curr_func, curr_params, curr_decors)
    wrap(state._add_method, commands)
    print_class_must_have_func(class_name, curr_func, curr_params, True)
    state._add_args_to_method(curr_func)
    print_class_must_have_decors(class_name, curr_func, curr_decors, True)
    state._add_method_decorator(curr_func)

    state._add_methods()

    return state
Example #18
0
    def train_epoch(self, epoch):
        for meter in self.losses_recon:
            meter.reset()
        self.loss_total.reset()

        self.encoder.eval()
        self.decoder.train()

        n_batches = self.args.epoch_len

        with tqdm(total=n_batches,
                  desc='Train epoch %d' % epoch) as train_enum:
            for batch_num in range(n_batches):
                if self.args.short and batch_num == 3:
                    break

                dset_num = batch_num % self.args.n_datasets

                x, x_aug = next(self.data[dset_num].train_iter)

                x = wrap(x)
                x_aug = wrap(x_aug)
                batch_loss = self.train_batch(x, x_aug, dset_num)

                train_enum.set_description(
                    f'Train (loss: {batch_loss:.2f}) epoch {epoch}')
                train_enum.update()
def create_concrete_class(base_name, n_steps):
    print('You are creating a concrete class for Template method pattern.')

    concrete = meta_class.MetaClass()

    concrete._add_class_name()
    class_name = concrete.name

    base_names = [base_name]
    commands = generate_commands_add_base(base_names)
    wrap(concrete._add_base_names, commands)
    print_class_must_have_base(class_name, base_names, True)
    concrete._add_base_names()

    for i in range(n_steps):
        curr_func = f'_primitive_operation_{i}'
        curr_params = []
        curr_decors = []
        commands = generate_commands_add_func(curr_func, curr_params,
                                              curr_decors)
        wrap(concrete._add_method, commands)
        print_class_must_have_func(class_name, curr_func, curr_params, True)
        concrete._add_args_to_method(curr_func)
        print_class_must_have_decors(class_name, curr_func, curr_decors, True)
        concrete._add_method_decorator(curr_func)

    concrete._add_methods()

    return concrete
    def evaluate(self, loader=None, epoch=1, eval_fold_str='Valid'):
        if not loader:
            loader = self.valid_loader

        total = 0
        valid_enum = tqdm(loader, desc='Eval epoch %d' % epoch)

        total_correct = 0.
        total_samples = 0.

        num_samples = len(loader.dataset)
        all_pred = []
        all_gt = []
        all_correct = []

        self.net.eval()

        for txt, feat, spkr in valid_enum:
            tmp = feat[0]
            tmp = tmp[:self.seq_len, :, :]
            feat = (tmp, feat[1])
            input = wrap(txt, volatile=True)
            target = wrap(feat, volatile=True)
            spkr = wrap(spkr, volatile=True)

            # TODO: run with gradients turned off?
            output = self.net(target[0].transpose(0, 1).unsqueeze(1))
            loss = self.criterion(output, spkr.view(-1))

            # output, _ = model([input, spkr], target[0])
            # loss = criterion(output, target[0], target[1])

            total += loss.data[0]

            valid_enum.set_description('Evaluation %s (loss %.2f) epoch %d' %
                                       (eval_fold_str, loss.data[0], epoch))

            total_samples += len(spkr)

            spkr_gt = spkr.cpu().view(-1).data.numpy()
            spkr_pred = output.cpu().data.numpy().argmax(1)

            correct_pred = spkr_gt == spkr_pred
            num_correct_pred = np.sum(correct_pred)
            total_correct += num_correct_pred

            all_pred.append(spkr_pred)
            all_gt.append(spkr_gt)
            all_correct.append(correct_pred)

        accuracy = total_correct / total_samples

        avg = total / len(loader)

        all_pred = np.concatenate(all_pred)
        all_gt = np.concatenate(all_gt)
        all_correct = np.concatenate(all_correct)

        return avg, accuracy, all_pred, all_gt, all_correct
Example #21
0
def evaluate(model, norm, valid_loader, logging=None):
    total = 0
    total1 = 0
    valid_enum = tqdm(valid_loader, desc='Valid')
    dtw_cost = logSpecDbDist

    cmp_mean = norm[0]
    cmp_std = norm[1]

    for txt, feat, spkr in valid_enum:
        input = wrap(txt, volatile=True)
        target = wrap(feat, volatile=True)
        spkr = wrap(spkr, volatile=True)
        #lan = wrap(lan)
        feat = target[0]

        # model.train()
        #feat = torch.FloatTensor(*target[0].size())
        #feat = Variable(target[0], volatile=True)
        #feat = wrap(feat)

        #with torch.no_grad():
        output, attn = model([input, spkr], feat)

        batch_size = attn.size(1)
        tmp_loss = 0

        ground_truths = target[0].cpu().data.numpy()
        ground_truths = ground_truths * cmp_std + cmp_mean

        synthesised = output.cpu().data.numpy()
        synthesised = synthesised * cmp_std + cmp_mean

        for i in range(batch_size):
            length = target[1][i].cpu().data.numpy()[0]
            ground_truth = ground_truths[:, i]
            ground_truth = ground_truth[:length, :25]

            synth = synthesised[:, i]
            synth = synth[:length, :25]

            unit_loss = dtw(ground_truth, synth, dtw_cost)
            unit_loss /= length
            tmp_loss += unit_loss
        tmp_loss /= batch_size

        total += tmp_loss
        valid_enum.set_description('Valid (MCD %.2f)' %
                                   (tmp_loss))

    avg = total / len(valid_loader)

    if logging:
        logging.info('====> Test set loss: {:.4f}'.format(avg))

    return avg
Example #22
0
class RenderRequest(BaseModel):
    doc_class: str = wrap(template.default_documentclass)
    doc_option: str = wrap(template.default_documentoption)
    preamble: str = wrap(template.default_preamble)
    content: str = wrap(template.example_latex_code)
    engine: str = template.default_engine
    compilepass: int = 3
    target: str = 'svg'

    @property
    def crc32(self):
        return crc32(bytes(self.to_string(), encoding='utf8'))
Example #23
0
    def update(self, t):

        if self.geo.position.z < 1000:
            self.lifespan += t
            if self.lifespan > self.EXPIRES:
                self.reset()
                return
            delta = three.Vector3().copy(self.vector)
            delta.multiplyScalar(self.BULLET_SPEED * t)
            delta.add(self.momentum)
            current_pos = self.geo.position.add(delta)
            self.geo.position.set(current_pos.x, current_pos.y, current_pos.z)
            wrap(self.geo)
Example #24
0
def create_context():
    print('You are creating a context class for State pattern.')

    context = meta_class.MetaClass()

    class_name = 'Context'

    commands = [class_name]
    wrap(context._add_class_name, commands)

    base_classes = []
    commands = generate_commands_add_base(base_classes)
    wrap(context._add_base_names, commands)
    print_class_must_have_base(class_name, base_classes, False)

    curr_func = '__init__'
    curr_params = ['state']
    curr_decors = []
    commands = generate_commands_add_func(curr_func, curr_params, curr_decors)
    wrap(context._add_method, commands)
    print_class_must_have_func(class_name, curr_func, curr_params, False)
    print_class_must_have_decors(class_name, curr_func, curr_decors, False)

    curr_func = 'request'
    curr_params = []
    curr_decors = []
    commands = generate_commands_add_func(curr_func, curr_params, curr_decors)
    wrap(context._add_method, commands)
    print_class_must_have_func(class_name, curr_func, curr_params, False)
    print_class_must_have_decors(class_name, curr_func, curr_decors, False)

    return context
def create_template(n_steps=2):
    print('You are creating a Template class for Template method pattern.')

    template = meta_class.MetaClass()

    class_name = 'TemplateMethod'

    commands = [class_name]
    wrap(template._add_class_name, commands)

    base_classes = ['ABCMeta']
    commands = generate_commands_add_base(base_classes)
    wrap(template._add_base_names, commands)
    print_class_must_have_base(class_name, base_classes, False)

    curr_func = 'template_method'
    curr_params = []
    curr_decors = []
    commands = generate_commands_add_func(curr_func, curr_params, curr_decors)
    wrap(template._add_method, commands)
    print_class_must_have_func(class_name, curr_func, curr_params, False)
    print_class_must_have_decors(class_name, curr_func, curr_decors, False)

    for i in range(n_steps):
        curr_func = f'_primitive_operation_{i}'
        curr_params = []
        curr_decors = ['abstractmethod']
        commands = generate_commands_add_func(curr_func, curr_params,
                                              curr_decors)
        wrap(template._add_method, commands)
        print_class_must_have_func(class_name, curr_func, curr_params, False)
        print_class_must_have_decors(class_name, curr_func, curr_decors, False)

    return template
def create_observer():
    print('You are creating a base class for Observer in Observer pattern.')

    observer = meta_class.MetaClass()

    class_name = 'BaseObserver'

    commands = [class_name]
    wrap(observer._add_class_name, commands)

    base_names = ['ABCMeta']
    commands = generate_commands_add_base(base_names)
    wrap(observer._add_base_names, commands)
    print_class_must_have_base(class_name, base_names, False)

    curr_func = '__init__'
    curr_params = ['_subject', '_observer_state']
    curr_decors = []
    commands = generate_commands_add_func(curr_func, curr_params, curr_decors)
    wrap(observer._add_method, commands)
    print_class_must_have_func(class_name, curr_func, curr_params, False)
    print_class_must_have_decors(class_name, curr_func, curr_decors, False)

    curr_func = 'update'
    curr_params = ['arg']
    curr_decors = ['abstractmethod']
    commands = generate_commands_add_func(curr_func, curr_params, curr_decors)
    wrap(observer._add_method, commands)
    print_class_must_have_func(class_name, curr_func, curr_params, False)
    print_class_must_have_decors(class_name, curr_func, curr_decors, False)

    return observer
Example #27
0
def train(model, criterion, optimizer, epoch, train_losses):
    total = 0  # Reset every plot_every
    model.train()
    train_enum = tqdm(train_loader, desc='Train epoch %d' % epoch)

    for full_txt, full_feat, spkr in train_enum:
        batch_iter = TBPTTIter(full_txt, full_feat, spkr, args.seq_len)
        batch_total = 0

        for txt, feat, spkr, start in batch_iter:
            input = wrap(txt)
            target = wrap(feat)
            spkr = wrap(spkr)

            # Zero gradients
            if start:
                optimizer.zero_grad()

            # Forward
            output, _ = model([input, spkr], target[0], start)
            loss = criterion(output, target[0], target[1])

            # Backward
            loss.backward()
            if check_grad(model.parameters(), args.clip_grad,
                          args.ignore_grad):
                logging.info('Not a finite gradient or too big, ignoring.')
                optimizer.zero_grad()
                continue
            optimizer.step()

            # Keep track of loss
            batch_total += loss.data[0]

        batch_total = batch_total / len(batch_iter)
        total += batch_total
        train_enum.set_description('Train (loss %.2f) epoch %d' %
                                   (batch_total, epoch))

    avg = total / len(train_loader)
    train_losses.append(avg)
    if args.visualize:
        vis.line(Y=np.asarray(train_losses),
                 X=torch.arange(1, 1 + len(train_losses)),
                 opts=dict(title="Train"),
                 win='Train loss ' + args.expName)

    logging.info('====> Train set loss: {:.4f}'.format(avg))

    return avg
Example #28
0
    def initialize():
        # set stdout as non-buffered
        if hasattr(sys.stdout, 'fileno'):
            fileno = sys.stdout.fileno()
            tmp_fd = os.dup(fileno)
            sys.stdout.close()
            os.dup2(tmp_fd, fileno)
            os.close(tmp_fd)
            sys.stdout = os.fdopen(fileno, "w", 0)
        ctx = utils.FormattedDict()
        # Add environment variables
        for key, val in os.environ.iteritems():
            ctx[key] = wrap(val)
        # Convert JSON env variables
        ctx['VCAP_APPLICATION'] = json.loads(
            ctx.get('VCAP_APPLICATION', wrap('{}')))
        ctx['VCAP_SERVICES'] = json.loads(ctx.get('VCAP_SERVICES', wrap('{}')))
        # Build Pack Location
        ctx['BP_DIR'] = os.path.dirname(os.path.dirname(sys.argv[0]))
        # User's Application Files, build droplet here
        ctx['BUILD_DIR'] = sys.argv[1]
        # Cache space for the build pack
        ctx['CACHE_DIR'] = (len(sys.argv) == 3) and sys.argv[2] or None
        # Temp space
        if 'TMPDIR' not in ctx.keys():
            ctx['TMPDIR'] = tempfile.gettempdir()
        # Make sure cache & build directories exist
        if not os.path.exists(ctx['BUILD_DIR']):
            os.makedirs(ctx['BUILD_DIR'])
        if ctx['CACHE_DIR'] and not os.path.exists(ctx['CACHE_DIR']):
            os.makedirs(ctx['CACHE_DIR'])
        # Add place holder for extensions
        ctx['EXTENSIONS'] = []
        # Init Logging
        CloudFoundryUtil.init_logging(ctx)
        _log.info('CloudFoundry Initialized.')
        _log.debug("CloudFoundry Context Setup [%s]", ctx)

        # get default PHP, httpd, and nginx versions from manifest
        manifest_file = os.path.join(ctx['BP_DIR'], 'manifest.yml')
        for dependency in ["php", "nginx", "httpd"]:
            ctx = CloudFoundryUtil.update_default_version(
                dependency, manifest_file, ctx)

        # Git URL, if one exists
        ctx['BP_GIT_URL'] = find_git_url(ctx['BP_DIR'])
        _log.info('Build Pack Version: %s', ctx['BP_GIT_URL'])
        return ctx
Example #29
0
    def getAuthors(self, element):
        log.debug("Getting the authors...")
        authors = self.getOption('author', element, self.author) or 'unknown'
        if not type(authors) == type([]):
            log.debug("Trying to split authors on ','.")
            authors = authors.split(',')
        else:
            log.debug("self.author is already a list, no need to split it.")
        authors = [i.strip() for i in authors]
        log.debug("Found the following authors: %r.", authors)
        log.debug("Getting the email addresses.")
        emails = self.getOption('email', element, self.email) or 'unknown'
        if not type(emails) == type([]):
            # self.email is already a list
            emails = emails.split(',')
        emails = ['<%s>' % i.strip() for i in emails]
        log.debug("Found the following email addresses: %r.", emails)

        authoremail = []
        for author in authors:
            if authors.index(author) < len(emails):
                authoremail.append("%s %s" %
                                   (author, emails[authors.index(author)]))
            else:
                authoremail.append("%s <unknown>" % author)

        authorline = utils.wrap(", ".join(authoremail), 77)

        return authors, emails, authorline
def additional_doc_filters_keep_originals__test():
    with wrap() as wrapper:
        with open("test.sh", 'w') as f:
            f.write(
                trim("""\
                 echo "1 + 1 = {{ 1+1 }}" > hello.txt
                 ls -l"""))

        with open("dexy.yaml", 'w') as f:
            f.write(
                trim("""
            - test.sh|sh:
                - sh: {
                    add-new-files: True,
                    keep-originals: True,
                    additional-doc-filters: "jinja"
                    }
    
            """))

        wrapper.run_from_new()

        assert "doc:hello.txt" in wrapper.nodes

        hello_txt = wrapper.nodes["doc:hello.txt|jinja"]
        assert str(hello_txt.output_data()) == "1 + 1 = 2"
Example #31
0
    def getAuthors(self, element):
        log.debug("Getting the authors...")
        authors = self.getOption('author', element, self.author) or 'unknown'
        if not type(authors) == type([]):
            log.debug("Trying to split authors on ','.")
            authors = authors.split(',')
        else:
            log.debug("self.author is already a list, no need to split it.")
        authors = [i.strip() for i in authors]
        log.debug("Found the following authors: %r.", authors)
        log.debug("Getting the email addresses.")
        emails = self.getOption('email', element, self.email) or 'unknown'
        if not type(emails) == type([]):
            # self.email is already a list
            emails = emails.split(',')
        emails = ['<%s>' % i.strip() for i in emails]
        log.debug("Found the following email addresses: %r.", emails)

        authoremail = []
        for author in authors:
            if authors.index(author) < len(emails):
                authoremail.append("%s %s" % (author, emails[authors.index(author)]))
            else:
                authoremail.append("%s <unknown>" % author)

        authorline = utils.wrap(", ".join(authoremail), 77)

        return authors, emails, authorline
Example #32
0
    def ext_info_filter(self, Ksp, Omp, Ut, Zt):

        #prediction step
        Mup = inv(Omp)@Ksp
        # Mup[2] = utils.wrap(Mup[2]) #could be wrapped, but to match true theta, don't
        thp = Mup[2]
        Gt, Rt= self.propogation_matrices(Ut, thp)
        Omg_bar = inv(Gt@inv(Omp)@Gt.T+Rt)
        g_function = self.dyn_2d(Mup, Ut) #g is needed for both prediction and measurement
        Ks_bar = Omg_bar@g_function

        #measurement step for each marker
        mu_bar = g_function
        no_noise = 0
        h_function = self.model_sensor(mu_bar, no_noise)
        for i in range(len(self.M[0])):
            Ht, Qt = self.measurement_matrices(self.M[:,i], mu_bar)
            #reassign Omg to Omg_bar until all markers are accounted for
            Omg_bar = Omg_bar+Ht.T@inv(Qt)@Ht
            #reassign Ks to Ks_bar until all markers are accounted for
            Ks_bar = Ks_bar+Ht.T@inv(Qt)@(utils.wrap(np.array([Zt[:,i]]).T-np.array([h_function[:,i]]).T)+Ht@mu_bar)
        Ks = Ks_bar
        Omg = Omg_bar

        return Ks, Omg
    def initialize():
        # set stdout as non-buffered
        if hasattr(sys.stdout, 'fileno'):
             fileno = sys.stdout.fileno()
             tmp_fd = os.dup(fileno)
             sys.stdout.close()
             os.dup2(tmp_fd, fileno)
             os.close(tmp_fd)
             sys.stdout = os.fdopen(fileno, "w", 0)
        ctx = utils.FormattedDict()
        # Add environment variables
        for key, val in os.environ.iteritems():
            ctx[key] = wrap(val)
        # Convert JSON env variables
        ctx['VCAP_APPLICATION'] = json.loads(ctx.get('VCAP_APPLICATION',
                                             wrap('{}')))
        ctx['VCAP_SERVICES'] = json.loads(ctx.get('VCAP_SERVICES', wrap('{}')))
        # Build Pack Location
        ctx['BP_DIR'] = os.path.dirname(os.path.dirname(sys.argv[0]))
        # User's Application Files, build droplet here
        ctx['BUILD_DIR'] = sys.argv[1]
        # Cache space for the build pack
        ctx['CACHE_DIR'] = (len(sys.argv) == 3) and sys.argv[2] or None
        # Temp space
        if 'TMPDIR' not in ctx.keys():
            ctx['TMPDIR'] = tempfile.gettempdir()
        # Make sure cache & build directories exist
        if not os.path.exists(ctx['BUILD_DIR']):
            os.makedirs(ctx['BUILD_DIR'])
        if ctx['CACHE_DIR'] and not os.path.exists(ctx['CACHE_DIR']):
            os.makedirs(ctx['CACHE_DIR'])
        # Add place holder for extensions
        ctx['EXTENSIONS'] = []
        # Init Logging
        CloudFoundryUtil.init_logging(ctx)
        _log.info('CloudFoundry Initialized.')
        _log.debug("CloudFoundry Context Setup [%s]", ctx)

        # get default PHP, httpd, and nginx versions from manifest
        manifest_file = os.path.join(ctx['BP_DIR'], 'manifest.yml')
        for dependency in ["php", "nginx", "httpd"]:
            ctx = CloudFoundryUtil.update_default_version(dependency, manifest_file, ctx)

        # Git URL, if one exists
        ctx['BP_GIT_URL'] = find_git_url(ctx['BP_DIR'])
        _log.info('Build Pack Version: %s', ctx['BP_GIT_URL'])
        return ctx
Example #34
0
 def magnetometer_readings_to_tilt_compensated_heading(self, bx, by, bz, phi, theta):
     self.variation = 4.528986*(pi/180)
     Xh = bx * cos(theta) + by * sin(phi) * sin(theta) + bz * cos(phi) * sin(theta)
     Yh = by * cos(phi) - bz * sin(phi)
     heading = wrap((atan2(-Yh, Xh) + self.variation))
     if heading < 0:
         heading += 2*pi
     return heading
def config_txt_single_file_in_subdir__test():
    with wrap() as wrapper:
        write_text_files()
        with open("dexy.yaml", 'w') as f:
            f.write("bar/foo.txt")
        wrapper.run_from_new()

        assert sorted(wrapper.nodes) == ['doc:bar/foo.txt']
Example #36
0
    def add_controls(self):
        """
        Añade los widgets de componen la ventana.
        A saber:
        1 botón de cancelar.
        1 botón de iniciar/cerrar que se pondrá insensitivo una vez se pulse y 
          se activará con el texto "Cerrar" cuando acaben todas las tareas.
        1 barra de progreso global.
        1 VBox que contiene:
            1 HBox por cada tarea que contiene:
                1 Una flecha que se activa cuando la tarea se inicia y se 
                  desactiva después de completarse.
                1 CheckBox que se pone a True cuando la tarea finaliza, a 
                  False si no se completa y en Z si no se ha iniciado aún.
                1 Label con la descripción de la tarea.
        ... y sal al gusto.
        """
        botonera = gtk.HBox(homogeneous = True)
        self.cancel = gtk.Button("Cancelar")
        self.cancel.connect("clicked", self.cancelar)
        botonera.pack_start(self.cancel, False)
        self.startstop = gtk.Button("Iniciar")
        self.startstop.connect("clicked", self.iniciar_o_cerrar)
        botonera.pack_start(self.startstop, False)
        
        self.lista = gtk.VBox()
        self.widgets_tareas = []    # Lista de tuplas con flecha y checkbox.
        for tarea in self.tareas:
            if len(tarea['nombre']) > 140:
                tarea['nombre'] = utils.wrap(tarea['nombre'], 140)
            self.widgets_tareas.append((gtk.Arrow(gtk.ARROW_RIGHT, gtk.SHADOW_NONE), 
                                        gtk.CheckButton(tarea['nombre'], False), 
                                        gtk.CheckButton()))
            tarea['widgets'] = self.widgets_tareas[-1]
            vbox = gtk.HBox()
            vbox.pack_start(tarea['widgets'][0], False)
            vbox.pack_start(tarea['widgets'][1])
            vbox.pack_start(tarea['widgets'][2], False)
            tarea['widgets'][0].set_sensitive(False)
            tarea['widgets'][1].set_inconsistent(True)
            tarea['widgets'][1].set_property("can-focus", False)
            tarea['widgets'][1].connect("clicked", lambda w: w.set_active(w.get_active()))
            tarea['widgets'][2].set_active(True)
            self.lista.pack_start(vbox)

        vbox_out = gtk.VBox()
        vbox_out.pack_start(self.lista, padding = 10)
        self.progreso = gtk.ProgressBar()
        vbox_out.pack_start(self.progreso, False, padding = 10)
        vbox_out.pack_start(botonera, False, padding = 10)
        self.barra_estado = gtk.Statusbar()
        label_statusbar = self.barra_estado.get_children()[0].child
        font = pango.FontDescription("Monospace oblique 7")
        label_statusbar.modify_font(font)
        label_statusbar.modify_fg(gtk.STATE_NORMAL, label_statusbar.get_colormap().alloc_color("darkgray"))
        vbox_out.pack_end(self.barra_estado, False)
        self.window.add(vbox_out)
        self.window.show_all()
def virtual_file_contents__test():
    with wrap() as wrapper:
        with open("dexy.yaml", 'w') as f:
            f.write(trim("""\
            hello.txt|jinja:
                - contents: "1 + 1 = {{ 1+1 }}"
            """))

        wrapper.run_from_new()
        doc = wrapper.nodes['doc:hello.txt|jinja']
        assert str(doc.output_data()) == "1 + 1 = 2"
def config_txt_wildcard__test():
    with wrap() as wrapper:
        write_text_files()
        with open("dexy.yaml", 'w') as f:
            f.write("\"*foo.txt\"")
        wrapper.run_from_new()

        assert sorted(wrapper.nodes) == [
                'doc:bar/baz/foo.txt',
                'doc:bar/foo.txt',
                'doc:foo.txt',
                'pattern:*foo.txt']
Example #39
0
    def search(self, keywords, type='AND'):
        type = type.upper()

        types = ['AND', 'OR', 'NOT']
        if type not in types:
            raise ValueError("Search type should be one of: " + ", ".join(types))

        element = self.copy()
        element.properties['search'] = {
            'type': type,
            'keywords': utils.wrap(keywords),
        }
        return element
 def initialize():
     # set stdout as non-buffered
     if hasattr(sys.stdout, 'fileno'):
         fl = fcntl.fcntl(sys.stdout.fileno(), fcntl.F_GETFL)
         fl |= os.O_DSYNC
         fcntl.fcntl(sys.stdout.fileno(), fcntl.F_SETFL)
     ctx = utils.FormattedDict()
     # Add environment variables
     for key, val in os.environ.iteritems():
         ctx[key] = wrap(val)
     # Convert JSON env variables
     ctx['VCAP_APPLICATION'] = json.loads(ctx.get('VCAP_APPLICATION',
                                          wrap('{}')))
     ctx['VCAP_SERVICES'] = json.loads(ctx.get('VCAP_SERVICES', wrap('{}')))
     # Build Pack Location
     ctx['BP_DIR'] = os.path.dirname(os.path.dirname(sys.argv[0]))
     # User's Application Files, build droplet here
     ctx['BUILD_DIR'] = sys.argv[1]
     # Cache space for the build pack
     ctx['CACHE_DIR'] = (len(sys.argv) == 3) and sys.argv[2] or None
     # Temp space
     if 'TMPDIR' not in ctx.keys():
         ctx['TMPDIR'] = tempfile.gettempdir()
     # Make sure cache & build directories exist
     if not os.path.exists(ctx['BUILD_DIR']):
         os.makedirs(ctx['BUILD_DIR'])
     if ctx['CACHE_DIR'] and not os.path.exists(ctx['CACHE_DIR']):
         os.makedirs(ctx['CACHE_DIR'])
     # Add place holder for extensions
     ctx['EXTENSIONS'] = []
     # Init Logging
     CloudFoundryUtil.init_logging(ctx)
     _log.info('CloudFoundry Initialized.')
     _log.debug("CloudFoundry Context Setup [%s]", ctx)
     # Git URL, if one exists
     ctx['BP_GIT_URL'] = find_git_url(ctx['BP_DIR'])
     _log.info('Build Pack Version: %s', ctx['BP_GIT_URL'])
     return ctx
Example #41
0
    def getHeaderInfo(self, element, name=None, all=0):
        log.debug("Getting info for the header...")

        encoding = self.getOption('encoding', element, 'utf-8')
        log.debug("Encoding for python files is set to %s" % encoding)
        
        authors, emails, authorline = self.getAuthors(element)
        copyright = COPYRIGHT.encode(encoding) % \
            (str(time.localtime()[0]),
             self.getOption('copyright', element, self.copyright) or
                 authorline)
        log.debug("Copyright = %r.", copyright)

        license = self.getLicenseInfo(element, all=all)

        if self.getOption('rcs_id', element, False):
            log.debug("Using id keyword.")
            filename_or_id = '$'+'Id'+'$'
        else:
            log.debug("Using filename.")
            filename_or_id = 'File: %s.py' % (name or element.getModuleName())

        if self.getOption('generated_date', element, False):
            date = '# Generated: %s\n' % time.ctime()
        else:
            date = ''

        if utils.isTGVTrue(self.getOption('version_info', element, True)):
            log.debug("We want version info in every file.")
            versiontext = utils.version()
        elif element.__class__ == xmiparser.XMIModel:
            log.debug("We don't want version info in all files, "
                      "but we do want them in the config and Install.")
            versiontext = utils.version()
        else:
            log.debug("We don't want version info in this file.")
            versiontext = ''
            
        moduleinfo = {
            'authors': ', '.join(authors),
            'emails': ', '.join(emails),
            'authorline': authorline,
            'version': versiontext,
            'date': date,
            'copyright': '\n# '.join(utils.wrap(copyright, 77).split('\n')),
            'license': license,
            'filename_or_id': filename_or_id,
            'encoding': encoding,
        }
        return moduleinfo
Example #42
0
 def linearized_model_output_matrix(self, phi, theta):
     """ Axhat, ayhat and azhat are used to compute the the expected accelerometer readings given the model (the flight dynamics of a fixed-wing aircraft). Once we have these we can look at the actual readings and adjust things accordingly. [ISEFMAV 2.26] """
     bxyz = matrix("0 0 0; 0 0 0; 0 0 0")
     self.psi = wrap(self.psi)
     bxyz[0,0] = cos(theta) * cos(self.psi)
     bxyz[0,1] = cos(theta) * sin(self.psi)
     bxyz[0,2] = -sin(theta)
     bxyz[1,0] = (sin(phi) * sin(theta) * cos(self.psi)) - (cos(phi) * sin(self.psi))
     bxyz[1,1] = (sin(phi) *sin(theta) * sin(self.psi)) + (cos(phi) * cos(self.psi))
     bxyz[1,2] = sin(phi) * cos(theta)
     bxyz[2,0] = (cos(phi) * sin(theta) * cos(self.psi)) + (sin(phi) * sin(self.psi))
     bxyz[2,1] = (cos(phi) * sin(theta) * sin(self.psi)) - (sin(phi) * cos(self.psi))
     bxyz[2,2] = cos(phi) * cos(theta)
     b = bxyz * self.mxyz
     self.bxhat = b[0,0]
     self.byhat = b[1,0]
     self.bzhat = b[2,0]
def basic_yaml__test():
    with open(PROJECT_ROOT + "/examples/basic.yaml", 'r') as f:
        yaml = f.read()

    with wrap() as wrapper:
        with open("foo.md", 'w') as f:
            f.write("1 + 1 {{ 1+1 }}")

        with open("example.py", 'w') as f:
            f.write("print 'hello'")

        with open("dexy.yaml", 'w') as f:
            f.write(yaml)

        wrapper.run_from_new()

        assert sorted(wrapper.nodes) == [
                'doc:example.py|pyg',
                'doc:foo.md|jinja|markdown',
                'pattern:*.py|pyg']

        assert "<pre>1</pre>" in str(wrapper.nodes["doc:example.py|pyg"].output_data())
        assert wrapper.nodes["doc:foo.md|jinja|markdown"].setting('output')
Example #44
0
 def generate_virtual_magnetometer_readings(self, phi, theta, psi):
     psi = wrap(psi)
     self.bxyz[0,0] = cos(theta) * cos(psi)
     self.bxyz[0,1] = cos(theta) * sin(psi)
     self.bxyz[0,2] = -sin(theta)
     self.bxyz[1,0] = (sin(phi) * sin(theta) * cos(psi)) - (cos(phi) * sin(psi))
     self.bxyz[1,1] = (sin(phi) *sin(theta) * sin(psi)) + (cos(phi) * cos(psi))
     self.bxyz[1,2] = sin(phi) * cos(theta)
     self.bxyz[2,0] = (cos(phi) * sin(theta) * cos(psi)) + (sin(phi) * sin(psi))
     self.bxyz[2,1] = (cos(phi) * sin(theta) * sin(psi)) - (sin(phi) * cos(psi))
     self.bxyz[2,2] = cos(phi) * cos(theta)
     #display.register_matrices({"bxyz":self.bxyz})
     b = self.bxyz * self.mxyz
     TD.BX = b[0,0]
     TD.BY = b[1,0]
     TD.BZ = b[2,0]
     # DCM
     pitch = -atan2(self.bxyz[2,1], self.bxyz[2,2])
     roll = asin(self.bxyz[2,0])
     yaw = -atan2(self.bxyz[1,0], self.bxyz[0,0])
     pitch = degrees(pitch)
     roll = degrees(roll)
     yaw = (degrees(yaw) + 360) % 360
Example #45
0
 def rellenar_tabla(self, resultados):
     """
     Rellena el model con los items de la consulta
     """        
     model = self.wids['tv_datos'].get_model()
     model.clear()
     totfact = totsiniva = totbeneficio = totbeneficio_cobro = 0.0
     self.wids['tv_datos'].freeze_child_notify()
     self.wids['tv_datos'].set_model(None)
     totcobrado = totpendiente = 0.0
     total_costo = total_costo_cobrado = 0.0
     for material in resultados:
         if material != None:
             nombre_mat = material.descripcion
         else:
             nombre_mat = ""
         padre_mat = model.append(None, (nombre_mat, 
                                         "", 
                                         "0", 
                                         "0", 
                                         "0", 
                                         "M:%d" % (material 
                                                   and material.id
                                                   or -1)))
         for fecha in resultados[material]:
             if fecha:
                 str_fecha = utils.str_fecha(fecha)
             else:
                 str_fecha = ""
             padre_fec = model.append(padre_mat, (str_fecha, 
                                                  "", 
                                                  "0", 
                                                  "0", 
                                                  "0", 
                                                  ""))
             for ldv in resultados[material][fecha]:
                 subtotal = ldv.get_subtotal(iva = True)
                 subtotal_siva = ldv.get_subtotal(iva = False)
                 beneficio = ldv.calcular_beneficio()
                 costo = ldv.calcular_precio_costo() * ldv.cantidad
                 if ldv.facturaVenta:
                     fac_alb_tic = ldv.facturaVenta.numfactura
                     cobradofra = ldv.facturaVenta.calcular_cobrado()
                     pendientefra = ldv.facturaVenta.calcular_pendiente_cobro()
                     try:
                         fraccion = cobradofra / (cobradofra + pendientefra)
                     except ZeroDivisionError:
                         fraccion = 1.0
                     cobrado = subtotal * fraccion
                     pendiente = subtotal - cobrado
                     beneficio_cobro = beneficio * fraccion
                     costo_cobrado = costo * fraccion
                 elif ldv.albaranSalida:
                     fac_alb_tic = ldv.albaranSalida.numalbaran
                     cobrado = 0.0
                     pendiente = subtotal
                     beneficio_cobro = 0.0
                     costo_cobrado = 0.0
                 elif ldv.ticket:
                     fac_alb_tic = "Ticket %d" % ldv.ticket.numticket
                     cobrado = subtotal
                     pendiente = 0.0
                     beneficio_cobro = beneficio
                     costo_cobrado = costo
                     # Los tickets se asume que se cobran siempre, por 
                     # tanto el costo de los productos sobre lo cobrado 
                     # es del 100%.
                 else:
                     fac_alb_tic = ""
                     cobrado = pendiente = beneficio_cobro = 0.0
                     costo_cobrado = 0.0
                 desc_producto = utils.wrap(ldv.producto.descripcion, 40)
                 try:
                     beneficio_costo = 100.0 * beneficio / costo
                 except ZeroDivisionError:
                     beneficio_costo = 0.0
                 model.append(padre_fec, (desc_producto, 
                                          fac_alb_tic, 
                                          utils.float2str(subtotal), 
                                          utils.float2str(subtotal_siva), 
                                          "%s (%s%%)" % (
                                             utils.float2str(beneficio), 
                                             utils.float2str(
                                                 beneficio_costo)), 
                                          "LDV:%d" % ldv.id))
                 # Actualizo totales en memoria y en nodos padre TreeView
                 totfact += subtotal
                 totsiniva += subtotal_siva
                 totbeneficio += beneficio
                 totbeneficio_cobro += beneficio_cobro
                 totcobrado += cobrado
                 totpendiente += pendiente
                 total_costo += costo
                 total_costo_cobrado += costo_cobrado
                 model[padre_fec][2] = utils.float2str(
                                         utils._float(model[padre_fec][2]) 
                                                      + subtotal)
                 model[padre_fec][3] = utils.float2str(
                                         utils._float(model[padre_fec][3]) 
                                                      + subtotal_siva)
                 model[padre_fec][4] = utils.float2str(
                                         utils._float(model[padre_fec][4]) 
                                                      + beneficio)
                 model[padre_mat][2] = utils.float2str(
                                         utils._float(model[padre_mat][2]) 
                                                      + subtotal)
                 model[padre_mat][3] = utils.float2str(
                                         utils._float(model[padre_mat][3]) 
                                                      + subtotal_siva)
                 model[padre_mat][4] = utils.float2str(
                                         utils._float(model[padre_mat][4]) 
                                                      + beneficio)
     self.rellenar_totales(totfact, totsiniva, totbeneficio, 
                           totcobrado, totpendiente, totbeneficio_cobro, 
                           total_costo, total_costo_cobrado)
     self.wids['tv_datos'].set_model(model)
     self.wids['tv_datos'].thaw_child_notify()
Example #46
0
def pkcs7_init(lib):
    wrap(lib.PKCS7_set_type, [c_void_p, c_int], c_int)
    wrap(lib.PKCS7_set_content, [c_void_p, c_void_p], c_int)
    wrap(lib.PKCS7_add_certificate, [c_void_p, c_void_p], c_int)
    wrap(lib.PKCS7_signatureVerify, [c_void_p, c_void_p, c_void_p, c_void_p], c_int)
    wrap(lib.PKCS7_dataVerify, [c_void_p, c_void_p, c_void_p, c_void_p, c_void_p], c_int)
    wrap(lib.PKCS7_dataInit, [c_void_p, c_void_p], c_void_p)
    wrap(lib.PKCS7_dataFinal, [c_void_p, c_void_p], c_int)
    wrap(lib.PKCS7_dataDecode, [c_void_p, c_void_p, c_void_p, c_void_p], c_void_p)
    wrap(lib.PKCS7_add_signature, [c_void_p, c_void_p, c_void_p, c_void_p], c_void_p)
    wrap(lib.PKCS7_verify, [c_void_p, c_void_p, c_void_p, c_void_p, c_void_p, c_int], c_int)
    wrap(lib.PKCS7_encrypt, [c_void_p, c_void_p, c_void_p, c_int], c_void_p)
    wrap(lib.PKCS7_decrypt, [c_void_p, c_void_p, c_void_p, c_void_p, c_int], c_int)
    wrap(lib.PKCS7_add_attrib_smimecap, [c_void_p, c_void_p], c_int)
    wrap(lib.PKCS7_get_smimecap, [c_void_p], c_void_p)
    wrap(lib.PKCS7_simple_smimecap, [c_void_p, c_int, c_int], c_int)
    wrap(lib.SMIME_write_PKCS7, [c_void_p, c_void_p, c_void_p, c_int], c_int)
    wrap(lib.SMIME_read_PKCS7, [c_void_p, c_void_p], c_void_p)
    wrap(lib.SMIME_crlf_copy, [c_void_p, c_void_p, c_int], c_int)
    wrap(lib.SMIME_text, [c_void_p, c_void_p], c_int)
    wrap(lib.PKCS7_new, [], c_void_p) 
Example #47
0
def wrapargs(text):
    try:
        return utils.wrap(text, subsequent_indent='    ')
    except:
        return text
Example #48
0

if __name__ == '__main__':
    from experiments import functions, get_D, get_lb, get_ub, get_min, gkls_function

    max_f_calls = 10000
    error = 0.01
    mirror_division = False

    for gkls_cls in range(1, 9):
        for gkls_fid in range(1, 101):
            f_name = 'gkls_cls%d_%d' % (gkls_cls, gkls_fid)
            D = get_D(f_name)
            lb = get_lb(f_name, D)
            ub = get_ub(f_name, D)
            f = wrap(gkls_function, lb, ub, gkls_cls=gkls_cls, gkls_fid=gkls_fid)
            # f = wrap(dict(functions)[f_name], lb, ub)
            print f_name + ':'
            min_x = get_min(f_name, D)[:-1]
            min_f = get_min(f_name, D)[-1]
            # draw_3d_objective_function(branin, lb, ub)
            start = datetime.now()
            pareto_front, simplexes, f = disimpl_v(f, lb, ub, error, max_f_calls, min_f, mirror_division)
            end = datetime.now()
            print '%s   calls %d' % (f_name, f.calls)
            # print "Calls:", f.calls, 'Found min f:', f.min_f, 'at x:', f.min_x[:-1]
            # print "f*:", min_f, "x*:", min_x
            # print "Duration", end-start
        # show_lower_pareto_bound(simplexes)
        # show_partitioning(simplexes)
        # show_potential(simplexes)
 def rellenar_tabla_por_ticket(self, resultados):
     """
     Rellena el model con los items de la consulta
     """        
     model = self.wids['tv_datos'].get_model()
     model.clear()
     totfact = totsiniva = totbeneficio = totbeneficio_cobro = 0.0
     self.wids['tv_datos'].freeze_child_notify()
     self.wids['tv_datos'].set_model(None)
     totcobrado = totpendiente = 0.0
     total_costo = total_costo_cobrado = 0.0
     tratados = {}
     for material in resultados:
         for fecha in resultados[material]:
             if fecha:
                 str_fecha = utils.str_fecha(fecha)
             else:
                 str_fecha = ""
             for ldv in resultados[material][fecha]:
                 # Para que coincidan los totales con la suma de las 
                 # columnas y por coherencia con todas las cifras de la 
                 # ventana, es necesario redondear a 2 decimales.
                 subtotal = round(ldv.get_subtotal(iva = True), 2)
                 subtotal_siva = round(ldv.get_subtotal(iva = False), 2)
                 beneficio = round(ldv.calcular_beneficio(), 2)
                 costo = round(ldv.calcular_precio_costo()*ldv.cantidad, 2)
                 fac_alb_tic = "Ticket %d" % ldv.ticket.numticket
                 cobrado = subtotal
                 pendiente = 0.0
                 beneficio_cobro = beneficio
                 costo_cobrado = costo
                     # Los tickets se asume que se cobran siempre, por 
                     # tanto el costo de los productos sobre lo cobrado 
                     # es del 100%.
                 desc_producto = utils.wrap(ldv.producto.descripcion, 40)
                 try:
                     beneficio_costo = 100.0 * beneficio / costo
                 except ZeroDivisionError:
                     beneficio_costo = 0.0
                 if ldv.ticket not in tratados:
                     padre_ticket = model.append(None, 
                         (str_fecha, 
                          ldv.ticket.numticket, 
                          "0", 
                          "0", 
                          "0", 
                          ""))
                     tratados[ldv.ticket] = padre_ticket
                 else:
                     padre_ticket = tratados[ldv.ticket]
                 model.append(padre_ticket, (desc_producto, 
                                             fac_alb_tic, 
                                             utils.float2str(subtotal), 
                                             utils.float2str(subtotal_siva), 
                                             "%s (%s%%)" % (
                                                utils.float2str(beneficio), 
                                                utils.float2str(
                                                    beneficio_costo)), 
                                             "LDV:%d" % ldv.id))
                 # Actualizo totales en memoria y en nodos padre TreeView
                 totfact += subtotal
                 totsiniva += subtotal_siva
                 totbeneficio += beneficio
                 totbeneficio_cobro += beneficio_cobro
                 totcobrado += cobrado
                 totpendiente += pendiente
                 total_costo += costo
                 total_costo_cobrado += costo_cobrado
                 model[padre_ticket][2] = utils.float2str(
                                         utils._float(model[padre_ticket][2]) 
                                                      + subtotal)
                 model[padre_ticket][3] = utils.float2str(
                                         utils._float(model[padre_ticket][3]) 
                                                      + subtotal_siva)
                 model[padre_ticket][4] = utils.float2str(
                                         utils._float(model[padre_ticket][4]) 
                                                      + beneficio)
     self.rellenar_totales(totfact, totsiniva, totbeneficio, 
                           totcobrado, totpendiente, totbeneficio_cobro, 
                           total_costo, total_costo_cobrado)
     self.wids['tv_datos'].set_model(model)
     self.wids['tv_datos'].thaw_child_notify()
 def rellenar_tabla_por_proveedor(self, resultados):
     """
     Rellena el model con los items de la consulta
     """        
     model = self.wids['tv_datos'].get_model()
     model.clear()
     totfact = totsiniva = totbeneficio = totbeneficio_cobro = 0.0
     self.wids['tv_datos'].freeze_child_notify()
     self.wids['tv_datos'].set_model(None)
     totcobrado = totpendiente = 0.0
     total_costo = total_costo_cobrado = 0.0
     padres = {}
     for material in resultados:
         for fecha in resultados[material]:
             for ldv in resultados[material][fecha]:
                 # Para que coincidan los totales con la suma de las 
                 # columnas y por coherencia con todas las cifras de la 
                 # ventana, es necesario redondear a 2 decimales.
                 subtotal = round(ldv.get_subtotal(iva = True), 2)
                 subtotal_siva = round(ldv.get_subtotal(iva = False), 2)
                 beneficio = round(ldv.calcular_beneficio(), 2)
                 costo = round(ldv.calcular_precio_costo()*ldv.cantidad, 2)
                 if ldv.facturaVenta:
                     fac_alb_tic = ldv.facturaVenta.numfactura
                     cobradofra = ldv.facturaVenta.calcular_cobrado()
                     pendientefra = ldv.facturaVenta.calcular_pendiente_cobro()
                     try:
                         fraccion = cobradofra / (cobradofra + pendientefra)
                     except ZeroDivisionError:
                         fraccion = 1.0
                     cobrado = subtotal * fraccion
                     pendiente = subtotal - cobrado
                     beneficio_cobro = beneficio * fraccion
                     costo_cobrado = costo * fraccion
                 elif ldv.albaranSalida:
                     fac_alb_tic = ldv.albaranSalida.numalbaran
                     cobrado = 0.0
                     pendiente = subtotal
                     beneficio_cobro = 0.0
                     costo_cobrado = 0.0
                 elif ldv.ticket:
                     fac_alb_tic = "Ticket %d" % ldv.ticket.numticket
                     cobrado = subtotal
                     pendiente = 0.0
                     beneficio_cobro = beneficio
                     costo_cobrado = costo
                     # Los tickets se asume que se cobran siempre, por 
                     # tanto el costo de los productos sobre lo cobrado 
                     # es del 100%.
                 else:
                     fac_alb_tic = ""
                     cobrado = pendiente = beneficio_cobro = 0.0
                     costo_cobrado = 0.0
                 desc_producto = utils.wrap(ldv.producto.descripcion, 40)
                 try:
                     beneficio_costo = 100.0 * beneficio / costo
                 except ZeroDivisionError:
                     beneficio_costo = 0.0
                 proveedor = ldv.get_proveedor()
                 try:
                     padre = padres[proveedor]
                 except KeyError:
                     padre = padres[proveedor] = model.append(None, 
                         (proveedor and proveedor.nombre 
                             or "Sin proveedor", 
                          "-", 
                          utils.float2str(0.0), 
                          utils.float2str(0.0), 
                          utils.float2str(0.0),  
                          proveedor and proveedor.get_puid() or ""
                         ))
                 model.append(padre, (desc_producto, 
                                      fac_alb_tic, 
                                      utils.float2str(subtotal), 
                                      utils.float2str(subtotal_siva), 
                                      "%s (%s%%)" % (
                                         utils.float2str(beneficio), 
                                         utils.float2str(
                                                 beneficio_costo)), 
                                      ldv.get_puid()
                                     ))
                 # Actualizo totales en memoria y en nodos padre TreeView
                 totfact += subtotal
                 totsiniva += subtotal_siva
                 totbeneficio += beneficio
                 totbeneficio_cobro += beneficio_cobro
                 totcobrado += cobrado
                 totpendiente += pendiente
                 total_costo += costo
                 total_costo_cobrado += costo_cobrado
                 model[padre][2] = utils.float2str(
                                         utils._float(model[padre][2]) 
                                                      + subtotal)
                 model[padre][3] = utils.float2str(
                                         utils._float(model[padre][3]) 
                                                      + subtotal_siva)
                 model[padre][4] = utils.float2str(
                                         utils._float(model[padre][4]) 
                                                      + beneficio)
     self.rellenar_totales(totfact, totsiniva, totbeneficio, 
                           totcobrado, totpendiente, totbeneficio_cobro, 
                           total_costo, total_costo_cobrado)
     self.wids['tv_datos'].set_model(model)
     self.wids['tv_datos'].thaw_child_notify()
Example #51
0
    def estimate(self, Vair, theta, psi, GPS_Pn, GPS_Pe, dt):
        # CHECK UNITS
        #psi = wrap(psi)
        psi = wrap(TD.HEADING)
        theta = TD.PITCH
        Vair = TD.AIRSPEED * 1.68780986 # m/s to ft/s
        display.register_scalars({"Vair":Vair,"psi":psi,"theta":theta,"dt":dt},"Dead reckoning")
        Qpn = (self.Qot*abs(cos(psi))) + (self.Qxt*abs(sin(psi)))
        Qpe = (self.Qot*abs(sin(psi))) + (self.Qxt*abs(cos(psi)))
        Qwn = 1.0
        Qwe = 1.0
        Qcpress = 0.1
        self.Q = matrix("%f,0,0,0,0; 0,%f,0,0,0; 0,0,%f,0,0; 0,0,0,%f,0; 0,0,0,0,%f" % \
                                                            (Qpn, Qpe, Qwn, Qwe, Qcpress))

        X_dot = matrix("%f;%f;%f;%f;%f" % (self.Cpress*Vair*cos(psi)*cos(theta) - self.Wn_est,
                                           self.Cpress*Vair*sin(psi)*cos(theta) - self.We_est,
                                           0,
                                           0,
                                           0))
        self.X = self.X+X_dot*dt

        self.A = matrix("0,0,-1,0,%f; 0,0,0,-1,%f; 0,0,0,0,0; 0,0,0,0,0; 0,0,0,0,0" % \
                                    #(1.0,1.0))
                                    (Vair*cos(psi)*cos(theta), Vair*cos(theta)*sin(psi)))
        display.register_scalars({"Vtrue/Vias":(TD.TRUEAIRSPEED*1.68780986)/Vair, "0":Vair*cos(psi)*cos(theta), "1":Vair*cos(theta)*sin(psi)},"Dead reckoning")

        P_dot = self.A*self.P + self.P*self.A.transpose() + self.Q
        self.P = self.P + P_dot*dt

        self.C = matrix("1,0,0,0,0; 0,1,0,0,0")

        self.L = self.P*self.C.transpose()*linalg.inv(self.R+self.C*self.P*self.C.transpose())
        #To invert the matrix it must not be singular ie have a det()=0

        self.P = (self.I-self.L*self.C)*self.P

        z = matrix("%f;%f" % (GPS_Pn,GPS_Pe))
        h = matrix("%f;%f" % (self.X[0,0],self.X[1,0]))

        display.register_scalars({"Vtrue_est":Vair*self.Cpress/1.68780986},"Dead reckoning")
        display.register_scalars({"z-h:0":(z-h)[0,0],"z-h:1":(z-h)[1,0]},"Dead reckoning")
        matrices = {"A":self.A,
                    "Q":self.Q,
                    "P":self.P,
                    "P_dot":P_dot,
                    "C":self.C,
                    "L":self.L,
                    "X":self.X,
                    "X_dot":X_dot,
                    "z":z,
                    "h":h,
                    "z-h":z-h}

        self.X = self.X + self.L*(z-h)
        self.Wn_est, self.We_est = self.X[2,0], self.X[3,0]
        self.Cpress = self.X[4,0]
        display.register_matrices(matrices, "Internal states")

        wind_direction_estimate = degrees(atan2(self.X[3,0], self.X[2,0]))
        wind_velocity_estimate = sqrt(self.X[3,0]**2 + self.X[2,0]**2) * 0.592483801 # convert from ft/s to knots
        FOUT.writerow([GPS_Pn, GPS_Pe, self.X[0,0], self.X[1,0], TD.WIND_VELOCITY, TD.WIND_DIRECTION, wind_velocity_estimate, wind_direction_estimate, (TD.TRUEAIRSPEED*1.68780986)/Vair, self.X[4,0]])

        return self.X
Example #52
0
            mirror_division = True
        algorithm = argv[3]

    comm = MPI.COMM_WORLD
    rank = comm.Get_rank()
    gkls_cls = 1
    gkls_fid_from = 1 + rank * 10
    gkls_fid_till = 1 + (rank+1) * 10

    for gkls_cls in [5]:
        for gkls_fid in range(gkls_fid_from, gkls_fid_till):
            f_name = 'gkls_cls%d_%d' % (gkls_cls, gkls_fid)
            D = get_D(f_name)
            lb = get_lb(f_name, D)
            ub = get_ub(f_name, D)
            f = wrap(gkls_function, lb, ub, gkls_cls=gkls_cls, gkls_fid=gkls_fid)   # f = wrap(dict(functions)[f_name], lb, ub)

            min_x = get_min(f_name, D)[:-1]
            min_f = get_min(f_name, D)[-1]
            # draw_3d_objective_function(branin, lb, ub)
            start = datetime.now()
            pareto_front, simplexes, f = algorithms[algorithm](f, lb, ub, error, max_f_calls, min_f, mirror_division)
            end = datetime.now()

            output_path = '/home/albertas/global_opt/results/cls%d/%s__e%.2f_%s__%s__%d' % (gkls_cls, f_name, error, algorithm, str(mirror_division), f.calls)
            output = open(output_path, 'w+')
            output.write('%s  %d  %f  %s\n' % (f_name, f.calls, f.min_f, str(f.min_x)))
            output.write('duration: %s\n' % (end-start,))
            output.write('Actual minimum: %f, %s' % (min_f, str(min_x)))
            output.write('D: %d,  lb: %s,  ub: %s' % (D, lb, ub))
            output.close()
Example #53
0
 def select(self, keys):
     element = self.copy()
     element.properties['selected'] = utils.wrap(keys)
     return element
Example #54
0
def _reconstruct(holo_data,sb_size,sb_pos,fresnel_ratio,fresnel_width):
    '''Core function for holographic reconstruction performing following steps:

    * 2D FFT without apodisation;

    * Cutting out sideband;

    * Centering sideband;

    * Applying round window;

    * Applying sinc filter;

    * Applying automatic filtering of Fresnel fringe (Fresnel filtering);

    * Inverse FFT.

    Parameters
    ----------
    holo_data : array_like
        Holographic data array
    sb_size : int
        Size of the sideband filter in px
    sb_pos : nparray (N=1)
        Vector of two elements with sideband coordinates [y,x]
    fresnel_ratio : float
        The ratio of Fresnel filter with respect to the sideband size
    fresnel_width : int
        Width of frsnel filter in px

    Returns
    -------
        wav : nparray
            Reconstructed electron wave

    Notes
    -----

    Disabeling of Fresnel filter is not implemented

    See Also
    --------

    reconstruct

    '''
    # TODO: Parsing of the input has to be redone
    # TODO: Add disabling of Fresnel filtering
    # TODO: Add smoothing of Fresnel filter
    # TODO: Add smoothing options?

    # Parse input
    if not fresnel_ratio: # fresnenl_ratio is empty or 0
        fresnel_ratio=0.3

    if not fresnel_width: # fresnel_width is emty or 0
        fresnel_width=6

    (sx,sy) = holo_data.shape
    holo_data = np.float64(holo_data);


    h_hw_fft = fftshift(fft2(holo_data)) # <---- NO Hanning filtering

    sb_roi = h_hw_fft[sb_pos[0]-sb_size/2:sb_pos[0]+sb_size/2,
                      sb_pos[1]-sb_size/2:sb_pos[1]+sb_size/2]

    (sb_ny,sb_nx) = sb_roi.shape
    sb_l=min(sb_ny/2, sb_nx/2)
    cen_yx=[sb_ny/2, sb_nx/2]

    # Circular Aperture
    cgrid_y = np.arange(-sb_ny/2, sb_ny/2, 1)
    cgrid_x = np.arange(-sb_nx/2, sb_nx/2, 1)
    (sb_xx,sb_yy) = np.meshgrid(cgrid_x,cgrid_y)
    sb_r = np.sqrt(sb_xx**2 + sb_yy**2)
    c_mask = np.zeros((sb_nx,sb_ny)) # Original: cMask=zeros(SB_Ny,SB_Nx);

    c_mask[sb_r < sb_l] = 1

    # Fresnel Mask
    ang = np.arctan2((sx/2-sb_pos[0]),(sy/2-sb_pos[1])); #[-pi pi]

    p_one = np.round([fresnel_ratio*sb_l*np.sin(ang), fresnel_ratio*sb_l*np.cos(ang)])
    p_two = np.round([sb_l*np.sin(ang), sb_l*np.cos(ang)])

    #ang_three = utils.wrap_to_pi(np.arctan2(p_two[0]-p_one[0], p_two[1]-p_one[1]))
    ang_one = utils.wrap(ang - np.pi/2)
    ang_two = utils.wrap(ang + np.pi/2)

    r = fresnel_width/2
    aa = np.round([p_one[0]+r*np.sin(ang_one), p_one[1]+r*np.cos(ang_one)])+cen_yx
    bb = np.round([p_one[0]+r*np.sin(ang_two), p_one[1]+r*np.cos(ang_two)])+cen_yx
    cc = np.round([p_two[0]+r*np.sin(ang_two), p_two[1]+r*np.cos(ang_two)])+cen_yx
    dd = np.round([p_two[0]+r*np.sin(ang_one), p_two[1]+r*np.cos(ang_one)])+cen_yx

    abcd=np.array([aa,bb,cc,dd])
    f_mask = utils.poly_to_mask(abcd[:,1],abcd[:,0],sb_roi.shape)

    sinc_k=5.0;    #Sink times SBsize
    w_one = np.sinc(np.linspace(-sb_size/2,sb_size/2,sb_size)*np.pi/(sinc_k*sb_size))
    w_one = w_one.reshape((sb_size,1))
    w_two = w_one.dot(w_one.reshape((1,sb_size)))

    # IFFT
    wav = ifft2(fftshift(sb_roi*c_mask*np.logical_not(f_mask)*w_two))
    return wav