예제 #1
0
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
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()