コード例 #1
0
ファイル: util.py プロジェクト: SWAT-Sheffield/pysac
def split_arrays(header,x,w,n0,n1,n2,outfname,axis_skip=1):
    """
    Read in a VACdata class and save n0xn1xn2 VACfile classes following a
    nameing template.

    Parameters
    ----------
    header: dict
        The header as if it was a full file.
        i.e. this routine will change nx

    x: np.ndarray
        The x array to split and save

    w: np.array
        The w array to split and save

    n0,n1,n2: int
        The number of axes splits

    outfname: str
        The output filename template (see below)

    Notes
    -----
    
    **Filename Template:**
    
    outfname should be a file in the form:
    */<path>/<filename>.<ext>*

    The output will be:
    */<path>/<filename>_np<n0><n1><n2>_<00x>.<ext>*
    """
    nx = header['nx']
    nx_out = [nx[0]/n0, nx[1]/n1, nx[2]/n2]

    header_out = header
    header_out['nx'] = nx_out

    #Split arrays
    x_split = SAC_split_array(x, n0, n1, n2, axis_skip=axis_skip)
    w_split = SAC_split_array(w, n0, n1, n2, axis_skip=axis_skip)

    #Filename processing:
    fileName, fileExtension = os.path.splitext(outfname)

    for n in range(n0*n1*n2):
        out = VACfile(fileName + '_np%02i%02i%02i_%03i'%(n0,n1,n2,n) + fileExtension,
                         mode='w')

        out.header = header_out
        out.x = x_split[n]
        out.w = w_split[n]

        out.write_step()
        out.close()
コード例 #2
0
ファイル: util.py プロジェクト: SWAT-Sheffield/pysac
def split_file(vac_data,n0,n1,n2,outfname):
    """
    Read in a VACdata class and save n0xn1xn2 VACfile classes following a
    nameing template.

    Parameters
    ----------
    vac_data: io.VACdata
        The input file

    n0,n1,n2: int
        The number of axes splits

    outfname: str
        The output filename template (see below)

    Notes
    -----
    
    **Filename Template:**
    
    outfname should be a file in the form:
    */<path>/<filename>.<ext>*

    The output will be:
    */<path>/<filename>_np<n0><n1><n2>_<00x>.<ext>*
    """
    nx = vac_data.header['nx']
    nx_out = [nx[0]/n0, nx[1]/n1, nx[2]/n2]

    header_out = vac_data.header
    header_out['nx'] = nx_out

    #Split arrays
    x_split = SAC_split_array(vac_data.x,n0,n1,n2,axis_skip=1)
    w_split = SAC_split_array(vac_data.w,n0,n1,n2,axis_skip=1)

    #Filename processing:
    fileName, fileExtension = os.path.splitext(outfname)

    for n in range(n0*n1*n2):
        out = VACfile(fileName + '_np%02i%02i%02i_%03i'%(n0,n1,n2,n) + fileExtension,
                         mode='w')

        out.header = header_out
        out.x = x_split[n]
        out.w = w_split[n]

        out.write_step()
        out.close()
コード例 #3
0
sys.path.append('../')
from scripts import sacconfig
cfg = sacconfig.SACConfig()

output_path = cfg.gdf_dir
if rank == 0:
    if not os.path.exists(output_path):
        os.makedirs(output_path)

input_fname = os.path.join(cfg.out_dir,
        'fredatmos_{}_{}_{:03d}.out'.format(cfg.get_identifier(), cfg.mpi_config, rank))
#        '3D_tube_128_128_128_{}_{}_{:03d}.out'.format(cfg.get_identifier(), cfg.mpi_config, rank))

print '#', rank, '#:', input_fname

vfile = VACfile(input_fname)

#==============================================================================
# Monkey patch varnames and make fields dictionary
#==============================================================================
def get_header_fields(vfile):
    header = vfile.header
#    header['varnames'] = cfg.varnames
#    indices = range(0,len(header['varnames']))
#    w_ = dict(zip(header['varnames'],indices))
#    
    #Convert w
    w = mag_convert(vfile.w, vfile.w_)
    fields = convert_w_3D(np.ascontiguousarray(w), vfile.w_)
    
    for field in fields.values():