Exemple #1
0
 def __init__(self, path, accessmode='r'):
     frames = darr.Array(path=path, accessmode=accessmode)
     self.metadata = frames.metadata
     fs = frames.metadata['fs']
     BaseSnd.__init__(self=self,
                      nframes=frames.shape[0],
                      nchannels=frames.shape[1],
                      fs=fs)
     self.frames = frames
def create_codefile_array_julia(arraydirpath):
    allcode = []
    for arraypath in Path(arraydirpath).glob('*.darr'):
        ar = darr.Array(arraypath)
        code = ar.readcode('julia_ver1', abspath=True)
        if code is not None:
            code = code[:-1]  # get rid of EOL
            allcode.append(f'# {arraypath.name}')
            allcode.append(code)
            if len(ar.shape) > 1:  # 2d
                allcode.append(f'# next should sum to {np.sum(ar)}')
                allcode.append(f'print(sum(a[:]))')
                allcode.append(f'# next should sum to {np.sum(ar[:,0])}')
                allcode.append(f'print(sum(a[1,:]))\n')
                allcode.append(f'# next should sum to {np.sum(ar[:, 1])}')
                allcode.append(f'print(sum(a[2,:]))\n')
            else:  # 1D
                allcode.append(f'# next should sum to {np.sum(ar[:7])}')
                allcode.append(f'print(sum(a[1:7]))')
                if 'int' in ar.dtype.name:
                    allcode.append(f'# next should be {ar[7:]}')
                    allcode.append(f'print(a[8:9])')
    return '\n'.join(allcode)
def create_codefile_array_matlab(arraydirpath):
    allcode = []
    for arraypath in Path(arraydirpath).glob('*.darr'):
        ar = darr.Array(arraypath)
        code = ar.readcode('matlab', abspath=True)
        if code is not None:
            code = code[:-1]  # get rid of EOL
            allcode.append(f'# {arraypath.name}')
            allcode.append(code)
            if len(ar.shape) > 1:  # 2d
                allcode.append(f'# next should sum to {np.sum(ar)}')
                allcode.append(f'sum(a(:))')
                allcode.append(f'# next should sum to {np.sum(ar[:,0])}')
                allcode.append(f'sum(a(1,:))\n')
                allcode.append(f'# next should sum to {np.sum(ar[:, 1])}')
                allcode.append(f'sum(a(2,:))\n')
            else:  # 1D
                allcode.append(f'# next should sum to {np.sum(ar[:7])}')
                allcode.append(f'sum(a(1:7))')
                if 'int' in ar.dtype.name:
                    allcode.append(f'# next should be {ar[7:]}')
                    allcode.append(f'a(8:9)')
    return '\n'.join(allcode)
def create_codefile_array_idl(arraydirpath):
    allcode = []
    for arraypath in Path(arraydirpath).glob('*.darr'):
        ar = darr.Array(arraypath)
        code = ar.readcode('idl', abspath=True)
        if code is not None:
            code = code[:-1]  # get rid of EOL
            allcode.append(f'; {arraypath.name}')
            allcode.append(code)
            if len(ar.shape) > 1:  #2D
                allcode.append(f'; next should sum to {np.sum(ar)}')
                allcode.append(f'TOTAL(a)')
                allcode.append(f'; next should sum to {np.sum(ar[:,0])}')
                allcode.append(f'TOTAL(a[0,*])\n')
                allcode.append(f'; next should sum to {np.sum(ar[:, 1])}')
                allcode.append(f'TOTAL(a[1,*])\n')
            else:  # 1D
                allcode.append(f'; next should sum to {np.sum(ar[:7])}')
                allcode.append(f'TOTAL(a[0:6])')
                if 'int' in ar.dtype.name:
                    allcode.append(f'; next should be {ar[7:]}')
                    allcode.append(f'a[7:*]')

    return '\n'.join(allcode)