コード例 #1
0
def plot_line_profile(ax, filename, line_of_sight, bins, radial_cut, noise, label,linestyle,linewidth):
    """
    Doc string to come soon...

    :param      ax:             { parameter_description }
    :type       ax:             { type_description }
    :param      filename:       The filename
    :type       filename:       { type_description }
    :param      line_of_sight:  The line of sight
    :type       line_of_sight:  { type_description }
    :param      bins:           The bins
    :type       bins:           { type_description }
    :param      radial_cut:     The radial cut
    :type       radial_cut:     { type_description }
    """
    rc   = loaders.get_dataset(filename, 'radius')
    vx   = loaders.get_dataset(filename, 'x_velocity')
    vy   = loaders.get_dataset(filename, 'y_velocity')
    dA   = loaders.get_dataset(filename, 'cell_area')
    r0, r1  = radial_cut
    los_phi = line_of_sight * np.pi / 180.0
    los_vel = ((np.cos(los_phi) * vx + np.sin(los_phi) * vy) * km_per_sec) + np.random.normal(loc=0,size=vx.shape,scale=noise)

    line_amplitude, los_velocity_bins = np.histogram(los_vel.flatten(), bins=bins, density=True, weights= (dA  * (rc > r0) * (rc < r1)).flatten())
    ax.step(los_velocity_bins[1:], line_amplitude * 31.7, label=label, linestyle=linestyle, linewidth=linewidth)
    ax.set_xlim(-50,50)
    ax.set_ylim(0,1.4)
    ax.set_ylabel('Flux [Arb.]')
    ax.legend(loc='upper left', prop={'size':5})
コード例 #2
0
    def process_train(self):
        self.writer = h5py.File('processed.hdf', 'a')
        train_set = get_dataset('train')
        for index, instance in tqdm(enumerate(train_set),
                                    desc='processing train set'):
            if not len(instance[1]) >= 5:
                continue
            captions = instance[1]
            captions = [[self._vocab_t2i['<BOS>']] + self.str2id(i) +
                        [self._vocab_t2i['<EOS>']] for i in captions][:5]
            padded_captions = pad_sequences(captions, 65)
            captions_lenths = [len(i) for i in captions]

            self.writer['train']['feature'].resize([index + 1, 3, 224, 224])
            self.writer['train']['feature'][index:index +
                                            1] = instance[0].numpy()
            self.writer['train']['label'].resize([index + 1, 5, 65])
            self.writer['train']['label'][index:index + 1] = padded_captions
            self.writer['train']['lenth'].resize([
                index + 1,
                5,
            ])
            self.writer['train']['lenth'][index:index + 1] = captions_lenths
            gc.collect()
        self.writer.close()
コード例 #3
0
def plot_sigma_profile(ax, filename, bins, radial_cut, color):
    """
    Doc string to come soon...

    :param      ax:             { parameter_description }
    :type       ax:             { type_description }
    :param      filename:       The filename
    :type       filename:       { type_description }
    :param      line_of_sight:  The line of sight
    :type       line_of_sight:  { type_description }
    :param      bins:           The bins
    :type       bins:           { type_description }
    :param      radial_cut:     The radial cut
    :type       radial_cut:     { type_description }
    """
    r = loaders.get_dataset(filename, 'radius')
    dA = loaders.get_dataset(filename, 'cell_area')
    sigma = loaders.get_dataset(filename, 'sigma')
    phi = loaders.get_dataset(filename, 'phi')
    r0, r1 = radial_cut
    dM = dA * sigma
    domain_radius = h5py.File(filename, 'r')['run_config']['domain_radius'][()]
    planet_position = h5py.File(filename, 'r')['position_of_mass2'][()]
    rbins = np.linspace(0.0, domain_radius, bins)
    x_planet = planet_position[0]
    y_planet = planet_position[1]

    if x_planet > 0:
        phi_cut = (phi > (np.pi / 2.0)) * (phi < (-0.5 * np.pi))
    elif x_planet < 0:
        phi_cut = (phi < (np.pi / 2.0)) * (phi > (-0.5 * np.pi))

    dM_binned, _ = np.histogram(r, weights=dM * phi_cut, bins=rbins)
    dA_binned, _ = np.histogram(r, weights=dA * phi_cut, bins=rbins)
    sigma_vs_r = dM_binned / dA_binned
    gap_measurement = sigma_vs_r[0:150].min()

    ax1.plot(rbins[1:], sigma_vs_r, label=filename[22:25], color=color)
    ax1.set_xlabel(r'$v \rm{[km/s]}$')
    ax1.set_ylabel('Flux [Arb.]')
    ax1.set_yscale('log')
    ax1.set_xscale('log')
コード例 #4
0
def get_gap_depth_vs_q(filename,bins,radial_cut):
    r       = loaders.get_dataset(filename, 'radius')
    dA      = loaders.get_dataset(filename, 'cell_area')
    sigma   = loaders.get_dataset(filename, 'sigma')
    phi     = loaders.get_dataset(filename, 'phi')
    vr      = loaders.get_dataset(filename, 'radial_velocity')
    vp      = loaders.get_dataset(filename, 'phi_velocity')
    r0, r1  = radial_cut
    dM      = dA * sigma
    domain_radius   = h5py.File(filename, 'r')['run_config']['domain_radius'][()]
    mass_ratio      = h5py.File(filename, 'r')['run_config']['mass_ratio'][()]
    planet_position = h5py.File(filename, 'r')['position_of_mass2'][()]
    x_planet = planet_position[0]
    y_planet = planet_position[1]
    rbins = np.linspace(0.0, domain_radius, bins)

    if x_planet > 0:
        phi_cut = (phi > (np.pi / 2.0)) * (phi < (-0.5 * np.pi))
    elif x_planet < 0: 
        phi_cut = (phi < (np.pi / 2.0)) * (phi > (-0.5 * np.pi))


    dM_binned,   _  = np.histogram(r, weights=dM * phi_cut , bins=rbins)
    dA_binned,   _  = np.histogram(r, weights=dA * phi_cut , bins=rbins)
    sigma_vs_r      = dM_binned / dA_binned
    gap_measurement = sigma_vs_r[0:22].min()  #sigma_vs_r[0:22].max() 
    return gap_measurement,mass_ratio
コード例 #5
0
    def handle_vocab(self):
        train_set = get_dataset('train')
        counter = Counter()

        for instance in tqdm(train_set, desc='handling vocab'):
            captions = instance[1]
            for caption in captions:
                token_list = [i.text.lower() for i in self.nlp(caption)]
                counter.update(token_list)
        for i in counter.items():
            if i[1] >= 5:
                index = len(self._vocab_i2t)
                self._vocab_i2t[index] = i[0]
                self._vocab_t2i[i[0]] = index
        vocab = {'t2i': self._vocab_t2i, 'i2t': self._vocab_i2t}
        pk.dump(vocab, open('vocab.pkl', 'wb'))
コード例 #6
0
def load_data():
    h5f = h5py.File(filename, 'r')
    domain_radius = np.array(h5f['run_config']['domain_radius'])
    block_size = np.array(h5f['run_config']['block_size'])
    depth = np.array(h5f['run_config']['depth'])
    real_depth = depth - 3
    step = (2 * domain_radius) / (2**real_depth * block_size)
    vertices = h5f['vertices'].values()
    helpers = loaders.HelperFunctions()
    xc = np.array([helpers.cell_center_x_array(g[...]) for g in vertices])
    yc = np.array([helpers.cell_center_y_array(g[...]) for g in vertices])
    mass = loaders.get_dataset(filename, 'mass')
    nbins = 32
    bins = np.linspace(-nbins * step, nbins * step, (2 * nbins) + 1)

    masses, xedges, yedges = np.histogram2d(xc.flatten(),
                                            yc.flatten(),
                                            weights=mass.flatten(),
                                            bins=bins)
    #plt.imshow(masses)

    return masses, xedges, yedges
コード例 #7
0
    domain_radius_3 = h5py.File(file3, 'r')['run_config']['domain_radius'][()]
    domain_radius_4 = h5py.File(file4, 'r')['run_config']['domain_radius'][()]
    time_1          = h5py.File(file1, 'r')['time'][()]
    time_2          = h5py.File(file2, 'r')['time'][()]
    time_3          = h5py.File(file3, 'r')['time'][()]
    time_4          = h5py.File(file4, 'r')['time'][()]
    mass_ratio_1    = h5py.File(file1, 'r')['run_config']['mass_ratio'][()]
    mass_ratio_2    = h5py.File(file2, 'r')['run_config']['mass_ratio'][()]
    mass_ratio_3    = h5py.File(file3, 'r')['run_config']['mass_ratio'][()]
    mass_ratio_4    = h5py.File(file4, 'r')['run_config']['mass_ratio'][()]
    run_1           = mass_ratio_1 * 1000
    run_2           = mass_ratio_2 * 1000
    run_3           = mass_ratio_3 * 1000
    run_4           = mass_ratio_4 * 1000

    r_1     = loaders.get_dataset(file1, 'radius')
    r_2     = loaders.get_dataset(file2, 'radius')
    r_3     = loaders.get_dataset(file3, 'radius')
    r_4     = loaders.get_dataset(file4, 'radius')
    phi_1   = loaders.get_dataset(file1, 'phi')
    phi_2   = loaders.get_dataset(file2, 'phi')
    phi_3   = loaders.get_dataset(file3, 'phi')
    phi_4   = loaders.get_dataset(file4, 'phi')
    dA_1    = loaders.get_dataset(file1, 'cell_area')
    dA_2    = loaders.get_dataset(file2, 'cell_area')
    dA_3    = loaders.get_dataset(file3, 'cell_area')
    dA_4    = loaders.get_dataset(file4, 'cell_area')
    vr_1    = loaders.get_dataset(file1, 'radial_velocity')
    vr_2    = loaders.get_dataset(file2, 'radial_velocity')
    vr_3    = loaders.get_dataset(file3, 'radial_velocity')
    vr_4    = loaders.get_dataset(file4, 'radial_velocity')
コード例 #8
0
def plot_line_profile(ax, filename, line_of_sight, bins, radial_cut, noise,
                      label, dv, amd, rvm):
    """
    Doc string to come soon...

    :param      ax:             { parameter_description }
    :type       ax:             { type_description }
    :param      filename:       The filename
    :type       filename:       { type_description }
    :param      line_of_sight:  The line of sight
    :type       line_of_sight:  { type_description }
    :param      bins:           The bins
    :type       bins:           { type_description }
    :param      radial_cut:     The radial cut
    :type       radial_cut:     { type_description }
    """
    rc = loaders.get_dataset(filename, 'radius')
    vx = loaders.get_dataset(filename, 'x_velocity')
    vy = loaders.get_dataset(filename, 'y_velocity')
    dA = loaders.get_dataset(filename, 'cell_area')
    r0, r1 = radial_cut
    los_phi = line_of_sight * np.pi / 180.0
    np.random.seed(1)
    gaussian_noise = np.random.normal(loc=0, size=vx.shape, scale=noise)
    los_vel = ((np.cos(los_phi) * vx + np.sin(los_phi) * vy) *
               km_per_sec) + gaussian_noise

    line_amplitude, los_velocity_bins = np.histogram(
        los_vel.flatten(),
        bins=bins,
        density=True,
        weights=(dA * (rc > r0) * (rc < r1)).flatten())
    ax.step(los_velocity_bins[1:],
            line_amplitude,
            color='black',
            linewidth=0.8)

    dF = abs(np.max(line_amplitude[0:100]) - np.max(line_amplitude[100:]))
    F_rms = np.sqrt(np.mean(line_amplitude**2))
    #print(F_rms)
    asymmetry = dF / F_rms

    print("Asymmetry : ", asymmetry)

    ax.fill_between(los_velocity_bins[1:],
                    line_amplitude,
                    0,
                    alpha=0.3,
                    color='black',
                    step='pre')
    #ax.legend(loc='upper left')
    ax.text(-50, 0.022, label, fontsize=6.5)
    ax.text(22.1, 0.022, dv, fontsize=6.5)
    ax.text(26, 0.009, amd, fontsize=6.5)
    ax.text(26, 0.014, rvm, fontsize=6.5)
    ax.set_ylim(0, 0.033)

    # def double_gaussian(x, x0, x1, y0, y1, s0, s1):
    #     return y0 * np.exp(-(x - x0)**2 / 2 / s0**2) + y1 * np.exp(-(x - x1)**2 / 2 / s1**2)

    # popt, pcov = scipy.optimize.curve_fit(double_gaussian, los_velocity_bins[1:], line_amplitude, (-20.0, 20.0, 0.1, 0.1, 1.0, 1.0))
    # v = np.linspace(los_velocity_bins[0], los_velocity_bins[-1], 10000)

    # ax1.plot(v, double_gaussian(v, *popt))
    ax.axvline(0.0, c='grey', lw=0.5, color='grey')