Beispiel #1
0
def maos_get_list():
    msg = send_int(20) + send_int(1)
    ans = s.send(msg)
    msg = send_str("list")
    ans = s.send(msg)
    (ans, header) = readbin.readbin(s, 1)  #ans=aolib.readsock(s.fileno())
    ans = header.rstrip("\n\0").split("\n")[1:]
    return ans
Beispiel #2
0
def maos_get_var(name):
    msg = send_int(20) + send_int(1)
    ans = s.send(msg)
    msg = send_str(name)
    ans = s.send(msg)
    ans = readbin.readbin(s)  #ans=aolib.readsock(s.fileno())
    print(name, ans.shape, ans.dtype)
    return ans
Beispiel #3
0
def get_list():
    """Get the list of all variables"""
    if not s:
        print('Please run connect(host, port, [pid]) first')
        return None
    msg = _pack_int(20) + _pack_int(1)
    ans = s.send(msg)
    msg = _pack_str("list")
    ans = s.send(msg)
    (ans, header) = readbin.readbin(s, 1)  #ans=aolib.readsock(s.fileno())
    ans = header['COMMENT'].rstrip("\n\0").split("\n")[1:]
    return ans
Beispiel #4
0
def get_var(name):
    """Get value of an variable from maos with name"""
    if not s:
        print('Please run connect(host, port, [pid]) first')
        return None
    msg = _pack_int(20) + _pack_int(1)
    ans = s.send(msg)
    msg = _pack_str(name)
    ans = s.send(msg)
    ans = readbin.readbin(s)  #ans=aolib.readsock(s.fileno())
    print(name, ans.shape, ans.dtype)
    return ans
Beispiel #5
0
def test_read():
    path = b'/home/lianqiw/work/aos/comp/optim/bin/test/setup/'

    loc = readbin(path + b'aloc.bin')[0, 0]
    opd = np.arange(0, loc.shape[1])
    opdmap = loc_embed(loc, opd)
    plt.imshow(opdmap)

    #path=b'/home/lianqiw/.aos/cache/SELOTF/'

    for file in os.listdir(path):
        if file.endswith(b"_py.bin") or not file.endswith(b".bin"):
            continue

        tmp = readbin(path + file)
        file2 = file[0:-4] + b'_py.bin'
        if not os.path.isfile(path + file2):
            writebin(tmp, path + file2)
        tmp2 = readbin(path + file2)
        if isequal(tmp, tmp2):
            print(file, 'equal')
        else:
            raise (Exception(file, 'not equal'))
import numpy as np
from readbin import readbin
import matplotlib.pyplot as plt

data = readbin("temp.dat")

for each in data:
    plt.plot(each)

plt.savefig("result.png")
Beispiel #7
0
    def elaborate(self, platform):
        m = Module()

        # Read in the tilemap
        tile_map = readhex(self.char_file)

        tile_data = Memory(width=8 + self.inverse, depth=len(tile_map))

        tile_data.init = tile_map

        m.submodules.tr = tr = tile_data.read_port()
        m.submodules.tw = tw = tile_data.write_port()

        # Read in the font
        font = readbin(self.font_file)

        font_data = Memory(width=8, depth=4096)

        font_data.init = font

        m.submodules.fr = fr = font_data.read_port()

        ram_wr = Signal()
        ram_addr = Signal(32)
        ram_di = Signal(8)
        ram_do = Signal(8)
        osd_en = Signal(reset=self.init_on)
        osd_x = Signal(10)
        osd_y = Signal(10)
        dout = Signal(8)
        tile_addr = Signal(12)
        dout_align = Signal()
        osd_pixel = Signal()
        osd_r = Signal(8)
        osd_g = Signal(8)
        osd_b = Signal(8)

        m.submodules.spimem = spimem = SpiMem(addr_bits=32)

        m.d.comb += [
            # Connect spimem
            spimem.csn.eq(self.i_csn),
            spimem.sclk.eq(self.i_sclk),
            spimem.copi.eq(self.i_copi),
            spimem.din.eq(ram_di),
            self.o_cipo.eq(spimem.cipo),
            ram_do.eq(spimem.dout),
            ram_addr.eq(spimem.addr),
            ram_wr.eq(spimem.wr),
            # Connect tilemap
            tw.addr.eq(ram_addr),
            tw.en.eq(ram_wr & ram_addr[24:] == self.addr_display),
            tw.data.eq(Mux(self.inverse, Cat(ram_di, ram_addr[16]), ram_di)),
        ]

        with m.If(ram_wr & ram_addr[24:] == self.addr_enable):
            m.d.pixel += osd_en.eq(ram_di[0])

        m.d.comb += [
            tile_addr.eq((osd_y >> 4) * self.chars_y + (osd_x >> 3)),
            fr.data.eq(dout)
        ]

        if (self.inverse):
            m.d.comb += fr.addr.eq(
                Cat(osd_y[4], tr.data) ^ Repl(tr.data[8], 8))
        else:
            m.d.comb += fr.addr.eq(Cat(osd_y[:4], tr.data))

        m.submodules.osd = osd = Osd(
            x_start=self.start_x,
            x_stop=self.start_x + (8 * self.chars_x) - 1,
            y_start=self.start_y,
            y_stop=self.start_y + (8 * self.chars_y) - 1)

        m.d.comb += [
            osd.clk_ena.eq(1),
            osd.i_r.eq(self.i_r),
            osd.i_g.eq(self.i_g),
            osd.i_b.eq(self.i_b),
            osd.i_hsync.eq(self.i_hsync),
            osd.i_vsync.eq(self.i_vsync),
            osd.i_blank.eq(self.i_blank),
            osd.i_osd_ena.eq(osd_en),
            osd.i_osd_r.eq(osd_r),
            osd.i_osd_g.eq(osd_g),
            osd.i_osd_b.eq(osd_b),
            osd_x.eq(osd.o_osd_x),
            osd_y.eq(osd.o_osd_y),
            osd_r.eq(osd.o_r),
            osd_g.eq(osd.o_g),
            osd_b.eq(osd.o_b),
            self.o_hsync.eq(osd.o_hsync),
            self.o_vsync.eq(osd.o_vsync),
            self.o_blank.eq(osd.o_blank)
        ]

        return m
Beispiel #8
0
def maos_res_do(fdin, name, seeds=None, iframe1=0.2, iframe2=1):
    fds2 = glob.glob(fdin + "/", recursive=1)
    fds = []
    resall = None
    for fd in fds2:  #loop over directory
        if seeds is None:
            fns = glob.glob(fd + "/" + name + "_*.bin")
        else:
            fns = list()
            for seed in seeds:
                fns.append(fd + '/{}_{}.bin'.format(name, seed))

        nseed = 0
        mres = 0
        split = -1
        for fn in fns:  #loop over seed
            if not os.path.exists(fn):
                print(fn, 'does not exist')
                continue
            res = readbin(fn)
            if res is None:
                continue
            if len(res) > 4:  #per direction, take on axis
                res = res[0]
                split = 0
            elif len(res) == 4:
                if res[3].size > 0:  #split tomography
                    res = res[3]
                    split = 1
                else:  #integrated
                    res = res[2]
                    split = 0
            else:
                print('Invalid result')
                continue
            if iframe1 < 1:
                n1 = round(iframe1 * res.shape[0])
            else:
                n1 = iframe1
            if iframe2 <= 1:
                n2 = round(iframe2 * res.shape[0])
            else:
                n2 = iframe2
            res = res[n1:n2, :]
            if max(res[-1, :]) == 0:
                print(fn, 'Incomplete result')
                continue  #unfinished result
            res = res.mean(0) * 1e18
            mres += res
            nseed += 1
        if nseed > 0:
            fds.append(fd[0:-1])
            mres = mres * (1 / nseed)
            if resall is None:
                resall = mres
            else:
                resall = np.vstack((resall, mres))
        else:
            print(fd, fns, nseed, ' has no valid results')
    if resall is None:
        resall = np.array([nan, nan, nan])
        if not os.path.exists(fdin):
            print(fdin, 'does not exist')
        else:
            print(fdin, ' has no valid results')
    #if len(fds)>1:
    #    print(*fds, sep="\n")
    return (resall, fds)
    #else:
    return resall
Beispiel #9
0
def maos_res_do(fdin, name, seeds=None, iframe1=0.2, iframe2=1):
    fds2 = sorted(glob.glob(fdin + "/", recursive=1))
    fds = []
    resall = None
    for fd in fds2:  #loop over directory
        if seeds is None:
            fns = sorted(glob.glob(fd + "/" + name + "_*.bin"))
        else:
            fns = list()
            for seed in seeds:
                fns.append(fd + '/{}_{}.bin'.format(name, seed))

        nseed = 0
        mres = 0
        split = -1
        for fn in fns:  #loop over seed
            if not os.path.exists(fn):
                print(fn, 'does not exist')
                continue
            res = readbin(fn)
            if res is None:
                continue
            if name == "Res":
                if res[3].size > 0:  #split tomography
                    res = res[3]
                    split = 1
                else:  #integrated
                    res = res[2]
                    split = 0
            elif name == "Resclep":
                res = np.stack(res, axis=1)
                split = 0
            elif name == "extra/Resp":
                res = np.stack(res[-1], axis=1)
                split = 0
            else:
                print('Invalid result')
                continue
            if iframe1 < 1:
                n1 = round(iframe1 * res.shape[0])
            else:
                n1 = iframe1
            if iframe2 <= 1:
                n2 = round(iframe2 * res.shape[0])
            else:
                n2 = iframe2
            if n1 > n2 or n2 > res.shape[0]:
                print(fn, 'Invalid range', n1, n2, '>', res.shape[0])
                res = np.nan * res[0:1]
            else:
                res = res[n1:n2]
            #if max(res[-1]).all()==0:
            #    print(fn, 'Incomplete result')
            #    continue #unfinished result
            res = res.mean(0, keepdims=1) * 1e18
            mres += res
            nseed += 1
        if nseed > 0:
            fds.append(fd[0:-1])
            mres = mres * (1 / nseed)
            if resall is None:
                resall = mres
            else:
                resall = np.vstack((resall, mres))
        else:
            print(fd, fns, nseed, ' has no valid results')
    if resall is None:
        resall = np.array([nan, nan, nan])
        if not os.path.exists(fdin):
            print(fdin, 'does not exist')
        else:
            print(fdin, ' has no valid results')
    #if len(fds)>1:
    #    print(*fds, sep="\n")
    print(len(fds), ' results are read')
    return (resall, np.array(fds))