def cdisp(argv): try: opts, args = getopt.getopt(argv, "c:s:v", ["compress="]) if len(opts) == 0: print(help_msg) except getopt.GetoptError: print(help_msg) sys.exit(2) for opt, arg in opts: if opt == '-h': print(help_msg) sys.exit() img = core.decode(img_path, color_mode, mode) elif opt in ("-c", "--compress"): img_path = arg color_mode = args[0] if len(args) > 0 else "F" mode = args[1] if len(args) > 1 else "D2" threshold_1 = float(args[2]) if len(args) > 2 else 0.05 threshold_2 = float(args[3]) if len(args) > 3 else threshold_1 threshold_3 = float(args[4]) if len(args) > 4 else threshold_1 encoded_img = core.encode(img_path, color_mode, mode, [threshold_1,threshold_2, threshold_3]) img = core.decode(encoded_img,color_mode,mode) elif opt in ("-s", "--save"): #save as image core.save(img, arg) elif opt == "-v": #verbose core.verbose = True print("Verbose: " + str(core.verbose))
def kill(): id_ = int(request.args.get('id')) ret = core.kill(id_) if ret: return json.dumps({'code': 'failure', 'message': ret}) core.save() return json.dumps({'code': 'success'})
def init(): # 자동으로 SSH 포트를 등록한다. 이게 옳은 건지 판단해보아야. # restore core.restore() # SSH channel = socket.gethostname().lower().replace('.', '-') add_server_if_not_registered(channel + '-ssh', 22) core.save()
def init(): # 자동으로 SSH 포트를 등록한다. 이게 옳은 건지 판단해보아야. # restore core.restore() # SSH # (위 29라인 의견) SW 설치자, 사용자에게 y / n 를 물어보면 좋겠음. 디폴트는 n channel = socket.gethostname().lower().replace('.', '-') add_server_if_not_registered(channel + '-ssh', 22) core.save()
def server(): channel = str(request.args.get('channel')) addr = str(request.args.get('address')) port = int(request.args.get('port')) ret = core.server(channel, (addr, port)) if ret: return json.dumps({'code': 'failure', 'message': ret}) core.save() return json.dumps({'code': 'success'})
def run_once(): try: Session = core.init_db() except OperationalError as e: print("数据库初始化失败: {}".format(e)) print("程序即将终止") exit() nv = core.extract_data() core.save(Session, nv)
def main(): init() # constants service_port: int = core.conf.PORT # parse options parser = optparse.OptionParser() parser.add_option('--service-port', dest='service_port', type=int, default=service_port) options, args = parser.parse_args() service_port = options.service_port t = threading.Thread(target=broadcast) t.setDaemon(True) t.start() # web ui t = threading.Thread(target=webui.run) t.setDaemon(True) t.start() # service loop s = socket.socket(AF_INET, SOCK_STREAM) s.setsockopt(SOL_SOCKET, SO_REUSEADDR, 1) s.setsockopt(SOL_SOCKET, SO_KEEPALIVE, 1) s.bind(('localhost', service_port)) save_on_exit = True try: while True: s.listen(5) c, addr = s.accept() t = threading.Thread(target=service_handler, args=(c, addr)) t.setDaemon(True) t.start() except KeyboardInterrupt: print('Shutting down...') core.killall() save_on_exit = False finally: if save_on_exit: print('saving...') core.save() print('Good bye.')
def scan(): try: Session = core.init_db() except OperationalError as e: print("数据库初始化失败: {}".format(e)) print("程序即将终止") exit() data = core.scan() for i in data: value, date_str = i['value'], i['date'] date = datetime.strptime(date_str, '%Y-%m-%d').date() core.save(Session, value, date)
def client(): channel = str(request.args.get('channel')) try: port = int(request.args.get('port')) except TypeError: port = None ret = json.loads(core.client(channel, port)) if isinstance(ret, (str, unicode)): return json.dumps({'code': 'failure', 'message': ret}) core.save() return json.dumps({'code': 'success', 'port': ret})
def network_save(iface, ssid, lat, lng, passkey=None): """ store new network scheme in /etc/network/interfaces :param iface: network interface :param ssid: network name :param lat: latitude :param lng: longitude :param passkey: authentication passphrase :return: JSON response """ core.save(iface, ssid, passkey, _get_db(), float(lat), float(lng)) code = 201 resp = jsonify(message='created {}:{}'.format(iface, ssid), code=code) resp.status_code = code return resp
def main(): try: Session = core.init_db() except OperationalError as e: print("数据库初始化失败: {}".format(e)) print("程序即将终止") exit() frequency = is_every_n_minutes(5) while True: current = datetime.now() if frequency(current): nv = core.extract_data() if nv is not None: core.save(Session, nv) sys.stdout.flush() sleep(30)
def process_line(l): args = l.split() cmd = args[0] if cmd == 'status': return core.status() elif cmd == 'server': channel = args[1] addr = args[2] port = int(args[3]) ret = core.server(channel, (addr, port)) core.save() return ret elif cmd == 'client': channel = args[1] try: port = int(args[2]) except IndexError: port = None ret = core.client(channel, port) core.save() return ret elif cmd == 'kill': id = int(args[1]) ret = core.kill(id) core.save() return ret assert False
def process_line(line: bytes): line: str = line.decode() args: Sequence[str] = line.split() cmd = args[0] if cmd == 'status': return core.status() elif cmd == 'server': channel = args[1] addr = args[2] port = int(args[3]) ret = core.server(channel, (addr, port)) core.save() return ret elif cmd == 'client': channel = args[1] try: port = int(args[2]) except IndexError: port = None ret = core.client(channel, port) core.save() return ret elif cmd == 'kill': pid = int(args[1]) ret = core.kill(pid) core.save() return ret assert False
# service loop s = socket.socket(AF_INET, SOCK_STREAM) s.setsockopt(SOL_SOCKET, SO_REUSEADDR, 1) s.setsockopt(SOL_SOCKET, SO_KEEPALIVE, 1) s.bind(('localhost', service_port)) save_on_exit = True try: while True: s.listen(5) c, addr = s.accept() t = threading.Thread(target=service_handler, args=(c, addr)) t.setDaemon(True) t.start() except KeyboardInterrupt: print 'Shutting down...' core.killall() save_on_exit = False finally: web_ssh_process.kill() if save_on_exit: print 'saving...' core.save() print 'Good bye.'
def create_bitmaps(lens, slm, sample, window=None, slit=None): """ The main function of the script, which initiates the calculation of hologram bitmaps based on the input conditions. Parameters ---------- lens : `ObjectiveLens` instance Carries details about objective lens and laser parameters. slm : `SLM` instance Carries details about SLM parameters. sample : `Sample` instance Carries details about sample and focal depths of interest. window : `Window` instance Carries details about window, if applicable. slit : `Slit` instance Carries details about slit beamshaping, if applicable. """ if not window: window = Window(1, [0]) for d_w in window.thicknesses: for d_s in sample.focal_depths: if d_w != 0: print ('Processing window thickness {} micron and sample ' 'depth {} micron...').format(d_w*1e6, d_s*1e6) else: print 'Processing sample depth {} micron...'.format(d_s*1e6) d_f = optimize_d_f(lens.wavelength, d_s, lens.f, lens.alpha, sample.n_s, lens.n_a, d_w, window.n_w) d_shift = -optimize_d_f(lens.wavelength, 0, lens.f, lens.alpha, sample.n_s, lens.n_a, d_w, window.n_w) z = d_shift + d_f ab_corrected, ab_dist_corrected = calculate_phasemap( slm.px, slm.nx, slm.ny, lens.wavelength, d_s, lens.f, lens.alpha, sample.n_s, lens.n_a, d_w, window.n_w, slm.m_tel, slm.correction_file, slm.scale, slit) if d_w != 0: filename = 'window{}_depth{}_z{}'.format( int(d_w*1e6), int(d_s*1e6), int(z*1e6)) else: filename = 'depth{}_z{}'.format(int(d_s*1e6), int(z*1e6)) try: save('bitmaps/aberration_corrected/'+filename, ab_corrected) except: os.makedirs('bitmaps/aberration_corrected') save('bitmaps/aberration_corrected/'+filename, ab_corrected) if ab_dist_corrected is not None: try: save('bitmaps/aberration_distortion_corrected/'+filename, ab_dist_corrected) except: os.makedirs('bitmaps/aberration_distortion_corrected') save('bitmaps/aberration_distortion_corrected/'+filename, ab_dist_corrected)
def save_post(): core.save(self.post, self.suffix, self.path.get())
]) # service loop s = socket.socket(AF_INET, SOCK_STREAM) s.setsockopt(SOL_SOCKET, SO_REUSEADDR, 1) s.setsockopt(SOL_SOCKET, SO_KEEPALIVE, 1) s.bind(('localhost', service_port)) save_on_exit = True try: while True: s.listen(5) c, addr = s.accept() t = threading.Thread(target=service_handler, args=(c, addr)) t.setDaemon(True) t.start() except KeyboardInterrupt: print 'Shutting down...' core.killall() save_on_exit = False finally: web_ssh_process.kill() if save_on_exit: print 'saving...' core.save() print 'Good bye.'
feature = args.feature num_layer = args.num_layer num_model = args.num_model print(f'{device=},{feature=},{num_layer=},{num_model=}') model = Model(feature=feature, num_layer=num_layer, num_model=num_model).to(device) writer = {} batchsize = 512 dataset = Dataset('../data/doboku/box_aprx/data3') traindataset, valdataset = torch.utils.data.random_split( dataset, [dsize := int(len(dataset) * 0.8), len(dataset) - dsize]) trainloader = torch.utils.data.DataLoader(traindataset, batch_size=batchsize, num_workers=cpu_count()) valloader = torch.utils.data.DataLoader(valdataset, batch_size=batchsize, num_workers=cpu_count()) optimizer = torch.optim.Adam(model.parameters()) lossf = nn.MSELoss() esp = 1 epochs = 1000 est_epochs = 200 savefolder = f'data/{num_model}_{num_layer}_{feature}' os.makedirs(savefolder, exist_ok=True) data = torch.rand(116) for e in range(epochs): operate('train') operate('val ') save(model, savefolder, writer, f'{feature=},{num_layer=},{num_model=}')
import torch from core import CharLSTM, save state = torch.load("save_1", map_location="cpu") save(state)