Esempio n. 1
0
def choice_pairs(pairs, n_choice=100):
    """
    choice audios and texts to joint
    :param pairs: (audio_path, text)
    :param sr:
    :param n_choice:
    :return:
    """
    durs = [os.path.getsize(str(w)) / 3.2 for w, t in pairs]  # just sr=16k
    pairs = list(zip(pairs, durs))
    sidx = 0
    choices = cycle(range(5, 1, -1))
    cnt = 0
    cnt_shuffle = 0
    for n in choices:
        if sidx >= len(pairs):
            if cnt_shuffle >= n_choice:  # don't work forever
                print("Just choice <{}> joint audios for the speaker!".format(cnt))
                break
            cnt_shuffle += 1
            np.random.shuffle(pairs)
            sidx = 0
        eidx = sidx + n
        dur_joi = np.sum([d for _, d in pairs[sidx: eidx]])
        if dur_joi < 12000:  # 12000ms
            if cnt >= n_choice:
                break
            yield [p for p, d in pairs[sidx: eidx]]
            cnt += 1
            sidx = eidx
        elif n == 2:
            sidx += 1
Esempio n. 2
0
    def __init__(self,
                 list_cities_cards_cubes,
                 list_of_players,
                 num_events_cards,
                 num_produce_supplies=7,
                 num_portable_lab=3,
                 has_found_jade=True):
        self.list_of_players = cycle(list_of_players)
        self.has_found_jade = has_found_jade

        cities = [city for (city, good, card, cube) in list_cities_cards_cubes]
        good = [good for (city, good, card, cube) in list_cities_cards_cubes]
        cards = [card for (city, good, card, cube) in list_cities_cards_cubes]
        cubes = [cube for (city, good, card, cube) in list_cities_cards_cubes]

        self.num_good_cards = sum(good)
        self.num_epidemic_cards = _detect_number_of_epidemics(
            self.num_good_cards)
        print(f"Num good cards: {self.num_good_cards}, "
              f"num_epidemic: {self.num_epidemic_cards}")
        self.num_good_cards += (num_events_cards + num_produce_supplies +
                                num_portable_lab)
        self._till_epidemic = self.num_good_cards // self.num_epidemic_cards
        self.counter_till_epidemic = self._till_epidemic

        self.cities = cities
        self._num_cards_by_city = Counter(dict(zip(self.cities, cards)))
        self._stack_of_counters = [Counter(dict(zip(self.cities, cards)))]
        self._discarded = Counter()
        self._cubes_by_city = Counter(dict(zip(self.cities, cubes)))
        self._plague_cubes_by_city = Counter()
        self.emergency_level = 0
        self.num_epidemic = 0
        self._is_first_move = True

        self.inoculated_cards = Counter()
        self.hollowed_cities = Counter()
Esempio n. 3
0
            if not os.path.exists(outdir + '/ts' + ts + '/'):
                os.makedirs(outdir + '/ts' + ts + '/')

            fig = plt.figure(figsize=(6, 4))
            lines = 0
            plt.grid()
            if args.get('ymin', None):
                plt.ylim(ymin=args['ymin'])
            if args.get('ymax', None):
                plt.ylim(ymax=args['ymax'])

            plt.title('Ts: {}, Error: {}'.format(ts, error))
            plt.xlabel('#Turn')
            plt.ylabel('Relative error')

            markers = cycle(['+', 'x', 'v'])

            for bunchkey in inh5file.keys():
                if bunchkey not in bunches:
                    continue
                inh5 = inh5file[bunchkey]
                plt_data = {}
                marker = next(markers)
                colors = cycle(['tab:blue', 'tab:orange', 'tab:green'])

                for i in range(len(inh5[error])):
                    if inh5['reduce'][i][0] == 1 and inh5['reduce'][i][1] == 1:
                        if 'base_error' not in plt_data:
                            plt_data['base_error'] = []
                        plt_data['base_error'].append(
                            inh5[error][i])
Esempio n. 4
0
from cycler import cycle

import mpi4py
try:
    from mpi4py import MPE
except ImportError:
    pass
# Modes available:
# 'disabled'
# 'tracing'
mode = 'disabled'
times = {}
__logfile = 'mpelog'
colors = cycle(['blue', 'red', 'green', 'orange', 'magenta',
                'gray', 'pink', 'yellow',  'cyan',
                'brown', 'aquamarine', 'maroon',
                'ivory', 'coral', 'dark olive green', 'lavender',
                'rose', 'white', 'black'])


def init(logfile=__logfile):
    if mode != 'tracing':
        return
    mpi4py.profile(name='mpe', logfile=logfile)
    mpi4py.MPI.Pcontrol(1)
    MPE.initLog(logfile=logfile)
    MPE.setLogFileName(logfile)


def finalize():
    if mode != 'tracing':
Esempio n. 5
0
        'slices': 10496,
        'dE_ref': 25.9e9,
        'dt_ref': 5.e-9,
        'n_macroparticles': 2e6

    }
}

if __name__ == '__main__':
    args = parser.parse_args()
    args = vars(args)

    infiles = args['infiles']
    outdir = args['outdir']
    tss = args['ts']
    names = cycle(args['names'])
    points = int(args['points'])
    #  slicess = cycle(args['slices'])
    if not os.path.exists(outdir):
        os.makedirs(outdir)

    for ts in tss:
        for error in errors:
            outfiles = [outdir + '/ts' + ts + '/' +
                        error + '_' + error + '.jpeg']

            fig = plt.figure(figsize=(6, 4))
            plt.yscale('log')
            lines = 0
            plt.grid()
            if args.get('ymin', None):
Esempio n. 6
0
import pandas as pd
from collections import OrderedDict
import datetime
import matplotlib
import matplotlib.pyplot as plt
from cycler import cycle
from databroker import DataBroker as db
import ipywidgets
from traitlets import TraitError

# Set defaults
pd.set_option('max_rows', 500)
matplotlib.rcdefaults()
markers = cycle(['o', 's', '^', 'v', 'p', '<', '>', 'h'])


# Functions
def stopped(header):
    """ Test if header stopped sucessfully."""
    try:
        status = header.stop['exit_status']
    except KeyError:
        status = 'Python crash before exit'

    if status == 'success':
        return True
    else:
        return False


def get_scan_id_dict(headers):
Esempio n. 7
0
    return z


halo_readers = {'fof':read_halos_FoF,
                'rockstar':read_halos_Rockstar,
                'rockstar_so':read_halos_Rockstar_SO}
subsample_readers = {'fof':read_subsamples_FoF,
                     'rockstar':read_subsamples_Rockstar,
                     'rockstar_so':read_subsamples_Rockstar}
uniform_subsample_readers = {'fof':read_uniform_subsample_FoF,
                             'rockstar':None,  # not implemented
                             'rockstar_so':None}
    
prop_cycle = plt.rcParams['axes.prop_cycle']
colors = prop_cycle.by_key()['color']
color_cycle = cycler.cycle(colors)
del colors, prop_cycle
    
def halo_mass_hist(masses, bin_width_dex=.15, min_mass=None, max_mass=None, bin_edges=None):
    '''
    Take a single list of masses
    and compute the halo mass function
    
    Returns
    -------
    bin_edges, bin_centers, hist
    '''
    if not min_mass:
        min_mass = masses.min()
    if not max_mass:
        max_mass = masses.max()
Esempio n. 8
0
 #     'approx': cycle([0]),
 #     'timing': cycle(['-time']), # otherwise pass -time
 #     'w': []
 #     # + [1, 2, 4, 8, 16],
 #     + list(np.arange(2, 17, 2)),
 #     # + list(np.arange(2, 9, 1)),
 #     'o': cycle([10]),
 #     # + [10] * 5,
 #     # + [10]*8,
 #     # + [20]*7,
 #     'mpi': cycle(['mvapich2']),
 #     'time': cycle([90]),
 #     'partition': cycle(['be-short'])
 # }
 'PS-sync-mpich3': {
     'exe': cycle([yc['exe_home'] + 'PS_main_test.py']),
     'p': cycle([4000000]),
     # 'p': [0.5e6, 1e6, 2e6, 3e6, 4e6, 5e6, 6e6, 7e6, 8e6],
     'b': cycle([21]),  # 21
     's': cycle([128]),
     't': cycle([10000]),
     'm': cycle([0]),
     'seed': cycle([0]),
     'reduce': cycle([1]),
     'load': cycle([0.0]),
     'mtw': cycle([50]),
     'approx': cycle([2]),
     'timing': cycle(['-time']),  # otherwise pass -time
     'w': [] + [2, 4, 6, 8, 10, 12, 14, 16],
     # + list(np.arange(2, 17, 2)),
     'o': cycle([10]),
Esempio n. 9
0
import numpy as np
import random
import yaml

this_directory = os.path.dirname(os.path.realpath(__file__)) + "/"
this_filename = sys.argv[0].split('/')[-1]

yc = yaml.load(open(this_directory + 'config.yml', 'r'))
result_dir = yc['result_dir'] + '{}/{}/{}/{}'
os.environ['PYTHONPATH'] = '{}:{}'.format(yc['blond_repos'],
                                          os.environ['PYTHONPATH'])
job_name_form = '_p{}_b{}_s{}_t{}_w{}_o{}_N{}_r{}_m{}_seed{}_approx{}_mpi{}'

configs = {
    'LHC-48B-2MPPB-approx2': {
        'exe': cycle([yc['exe_home'] + '_LHC_BUP_2017.py']),
        'p': cycle([2000000]),
        'b': cycle([48]),  # 96
        's': cycle([1000]),
        't': cycle([200000]),
        'm': cycle([250]),
        'reduce': cycle([1]),
        'load': cycle([0.0]),
        'mtw': cycle([50]),
        'approx': cycle([2]),
        'timing': cycle(['']),  # otherwise pass -time
        'seed': [0] * 4 + [1] * 4 + [2] * 4 + [3] * 4 + [4] * 4 + [5] * 4,
        'w': [] + [2, 4, 8, 16] * 6,
        'o': cycle([10]),
        'time': cycle([1000]),
        'mpi': cycle(['mpich3']),
Esempio n. 10
0
 #     'load': cycle([0.0]),
 #     'mtw': cycle([0]),
 #     'approx': cycle([0]),
 #     'timing': cycle(['-time']), # otherwise pass -time
 #     'seed': cycle([0]),
 #     'w': []
 #     + [14, 16],
 #     # + list(np.arange(2, 17, 2)),
 #     'o': cycle([10]),
 #     'mpi': cycle(['mvapich2']),
 #     'time': cycle([180]),
 #     'partition': cycle(['be-long']),
 #     # 'repeats': cycle([5])
 # },
 'SPS-sync-mpich3': {
     'exe': cycle([yc['exe_home'] + 'SPS_main_random_test.py']),
     'p': cycle([4000000]),
     # 'p': [1e6, 2e6, 4e6, 3e6, 4e6, 2.5e6, 3e6, 3.5e6, 4e6],
     'b': cycle([72]),  # 72
     # 'b': [18, 18, 18, 36, 36, 72, 72, 72, 72], # 72
     's': cycle([1408]),
     't': cycle([10000]),  # 4000
     'm': cycle([0]),
     'reduce': cycle([1]),
     'load': cycle([0.0]),
     'mtw': cycle([0]),
     'approx': cycle([2]),
     'timing': cycle(['-time']),  # otherwise pass -time
     'seed': cycle([0]),
     'w': [2, 4, 6, 8, 10, 12, 14, 16],
     # + list(np.arange(2, 17, 2)),
Esempio n. 11
0
P = np.loadtxt(os.path.join(data_dir, "reconstruction_odometry.csv"),
               delimiter=",",
               skiprows=1)
for t in range(len(P)):
    P[t, 3:] = pr.quaternion_wxyz_from_xyzw(P[t, 3:])
cam2world_trajectory = ptr.transforms_from_pqs(P)

plt.figure(figsize=(5, 5))
ax = pt.plot_transform(s=0.3)
ax = ptr.plot_trajectory(ax, P=P, s=0.1, n_frames=10)

image_size = np.array([1920, 1440])

key_frames_indices = np.linspace(0, len(P) - 1, 10, dtype=int)
colors = cycle("rgb")
for i, c in zip(key_frames_indices, colors):
    pc.plot_camera(ax,
                   intrinsic_matrix,
                   cam2world_trajectory[i],
                   sensor_size=image_size,
                   virtual_image_distance=0.2,
                   c=c)

pos_min = np.min(P[:, :3], axis=0)
pos_max = np.max(P[:, :3], axis=0)
center = (pos_max + pos_min) / 2.0
max_half_extent = max(pos_max - pos_min) / 2.0
ax.set_xlim((center[0] - max_half_extent, center[0] + max_half_extent))
ax.set_ylim((center[1] - max_half_extent, center[1] + max_half_extent))
ax.set_zlim((center[2] - max_half_extent, center[2] + max_half_extent))