Ejemplo n.º 1
0
def regulateDiffVnData(dir_path, piece=1, reg_path="spectra/thermal_211_vn.dat", diff_vn_path="spectra/v2data.dat"):
	"""
		Regulate the file specified by diff_vn_path by extracting only the n-th particle data
		and write it to a separated file specified by reg_path. The variable n is specified
		by "piece".
	"""

	piece = int(piece);
	data = range(number_of_pts); # resulting list place holder
	#data = map(lambda x:[], range(number_of_moments+1)); # build an empty list for results. data[i] holds results for moment i (thus index 0 is not used)

	for sub_dir in listSubDirectories(dir_path):
		if (not path.exists(path.join(sub_dir, diff_vn_path))):
			print("Missing data files in subdirectory "+sub_dir);
			continue;

		# declare data buffer
		tmp_data = [];

		# read and add v_n file:
		diff_vn_data = readData(path.join(sub_dir, diff_vn_path));

		# get the n-th piece of data
		diff_vn_data_piece = map(lambda ii: diff_vn_data[ii], lines_to_read(piece));

		for aLine in diff_vn_data_piece: # loop through indices
			tmp_data.append(aLine[:]); # add desired v_n data
			# tmp_data.append(map(lambda ii: aLine[ii], cols_to_read)); # add desired v_n data

		# write to file
		reg_full = reg_path;
		writeData(path.join(sub_dir, reg_full), tmp_data);

	print("Finished.")
Ejemplo n.º 2
0
def regulateVnData(dir_path, piece=2, reg_path="thermal_211_integrated_vn.dat", vn_path="v2data-inte.dat"):
    """
        Regulate the file specified by vn_path by extracting only the n-th particle data
        and write it to a separated file specified by reg_path. The variable n is specified
        by "piece".
    """

    piece = int(piece);
    data = map(lambda x:[], range(number_of_moments+1)); # build an empty list for results. data[i] holds results for moment i (thus index 0 is not used)

    if (not path.exists(path.join(dir_path, vn_path))):
        print("Missing data files in directory "+dir_path);
        return;

    # declare data buffer
    tmp_data = [];

    # read and add v_n file:
    vn_data = readData(path.join(dir_path, vn_path), "!");

    # the data in the n-th piece starts from line (format_vn[-1][1]+1)*(n-1)
    vn_data_piece = vn_data[(format_vn[-1][1]+1)*(piece-1):(format_vn[-1][1]+1)*piece];

    order = 0;
    for idx in format_vn: # loop through indices
        tmp_line = map(lambda ii: vn_data_piece[idx[1]][ii], data_indices_vn); # v_n data
        tmp_line.insert(0, order);
        # tmp_line.append(vn_data_piece[format_vn[0][1]-1][1]); # add number of particles for this species
        tmp_data.append(tmp_line); # add desired v_n data
        order += 1;
    # write to file
    reg_full = reg_path;
    writeData(path.join(dir_path, reg_full), tmp_data);

    print("Finished.")
Ejemplo n.º 3
0
def regulateDiffVnData(dir_path,
                       piece=1,
                       reg_path="spectra/thermal_211_vn.dat",
                       diff_vn_path="spectra/v2data.dat"):
    """
		Regulate the file specified by diff_vn_path by extracting only the n-th particle data
		and write it to a separated file specified by reg_path. The variable n is specified
		by "piece".
	"""

    piece = int(piece)
    data = range(number_of_pts)
    # resulting list place holder
    #data = map(lambda x:[], range(number_of_moments+1)); # build an empty list for results. data[i] holds results for moment i (thus index 0 is not used)

    for sub_dir in listSubDirectories(dir_path):
        if (not path.exists(path.join(sub_dir, diff_vn_path))):
            print("Missing data files in subdirectory " + sub_dir)
            continue

        # declare data buffer
        tmp_data = []

        # read and add v_n file:
        diff_vn_data = readData(path.join(sub_dir, diff_vn_path))

        # get the n-th piece of data
        diff_vn_data_piece = map(lambda ii: diff_vn_data[ii],
                                 lines_to_read(piece))

        for aLine in diff_vn_data_piece:  # loop through indices
            tmp_data.append(aLine[:])
            # add desired v_n data
            # tmp_data.append(map(lambda ii: aLine[ii], cols_to_read)); # add desired v_n data

        # write to file
        reg_full = reg_path
        writeData(path.join(sub_dir, reg_full), tmp_data)

    print("Finished.")
Ejemplo n.º 4
0
def restrictToFirstQuadrant(file_path=getcwd()):
    """ Generate surface and decoupling data files in the first quadrant
	based on the data files on the whole transverse plane. """

    surf_from_full = path.join(file_path, surf_from)
    dec_from_full = path.join(file_path, dec_from)
    print("Read surface data file from " + surf_from_full)
    print("Read decoupling data file from " + dec_from_full)

    if not path.exists(surf_from_full) or not path.exists(dec_from_full):
        print("Surface or decoupling data files not found at " + file_path)
        return
    else:
        surf_to_full = path.join(file_path, surf_to)
        dec_to_full = path.join(file_path, dec_to)
        print("Write surface data file to " + surf_to_full)
        print("Write decoupling data file to " + dec_to_full)
        surf_buffer_read = readData(surf_from_full)
        dec_buffer_read = readData(dec_from_full)
        surf_buffer_write = []
        dec_buffer_write = []
        if len(2 * surf_buffer_read) != len(dec_buffer_read):
            print("Number of data unmatch:" + "surface data file has " +
                  str(len(surf_buffer_read)) + "entries; " +
                  "decoupling data file has " + str(len(dec_buffer_read)) +
                  "entries.")
            return
        else:
            record = 0
            for i in range(len(surf_buffer_read)):
                if surf_buffer_read[i][2] >= 0 and surf_buffer_read[i][3] >= 0:
                    surf_buffer_write.append(surf_buffer_read[i])
                    dec_buffer_write.append(dec_buffer_read[2 * i])
                    dec_buffer_write.append(dec_buffer_read[2 * i + 1])
                    record = record + 1
            writeData(surf_to_full, surf_buffer_write)
            writeData(dec_to_full, dec_buffer_write)
            print("Number of entries written: " + str(record))