How to use tb_lineno method in Slash

Best Python code snippet using slash

cosmo-serv.py

Source:cosmo-serv.py Github

copy

Full Screen

1import eventlet2eventlet.monkey_patch()3# app.py4import multiprocessing5import threading6from flask import Flask, jsonify, request, render_template, session, copy_current_request_context7from flask_compress import Compress8import yt9from yt import YTArray10import trident11import numpy as np12from astropy.io import fits13from astropy.table import Table14import json15import yt.units as units16from yt.visualization.volume_rendering.api import PointSource17from yt.units import kpc18import pylab19from itertools import product20from flask import Response21from flask_socketio import SocketIO, emit, join_room, leave_room, close_room, rooms, disconnect22import random23import mpi4py24from mpi4py import MPI25import os.path26from os import path27from trident.config import trident_path28from scipy import interpolate29import sys,os30import copy31import pprint32import psutil33import time34#Flask is used as web framework to run python scripts35#Flask-io / socketio : gives Flask applications 36# access to low latency bi-directional communications37# between the clients and the server.38 39async_mode = 'eventlet'40app = Flask(__name__)41app.config['SEND_FILE_MAX_AGE_DEFAULT'] = 0 # clears cache on load for debugging42app.config['SECRET_KEY'] = 'secret!'43app.config['TEMPLATES_AUTO_RELOAD'] = True44Compress(app)45# socketio = SocketIO(app, cors_allowed_origins="*", async_mode=async_mode,async_handlers=True,upgradeTimeout=240000,logger=True, engineio_logger=True)46socketio = SocketIO(app,cors_allowed_origins="https://cosmovis-dev.nrp-nautilus.io", async_mode=async_mode,async_handlers=True,upgradeTimeout=240000)#,logger=True, engineio_logger=True)47# thread = None48# thread_lock = Lock()49multiprocessing.set_start_method('spawn')50yt.enable_parallelism()51sgs = []52rpts = {}53spectrum_hdul = fits.HDUList()54try:55 EAGLE_12Mpc = yt.load('static/data/RefL0012N0188/snapshot_028_z000p000/snap_028_z000p000.0.hdf5')56 EAGLE_12Mpc_ad = EAGLE_12Mpc.all_data()57except Exception as e:58 print('error: '+ str( e ))59 exc_type, exc_obj, exc_tb = sys.exc_info()60 fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]61 print(exc_type, fname, exc_tb.tb_lineno) 62try:63 EAGLE_25Mpc = yt.load('static/data/RefL0025N0376/snapshot_028_z000p000/snap_028_z000p000.0.hdf5')64 #EAGLE_25Mpc = yt.load('/cv-vol/EAGLE25_z0_0/RefL0025N0376/snapshot_028_z000p000/snap_028_z000p000.0.hdf5')65 EAGLE_25Mpc_ad = EAGLE_25Mpc.all_data()66except Exception as e:67 print('error: '+ str( e ))68 exc_type, exc_obj, exc_tb = sys.exc_info()69 fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]70 print(exc_type, fname, exc_tb.tb_lineno) 71try:72 EAGLE_100Mpc = yt.load('static/data/RefL0100N1504/snapshot/RefL0100N1504/snapshot_028_z000p000/snap_028_z000p000.0.hdf5')73 # EAGLE_100Mpc = yt.load('/cv-vol/EAGLE100_z0_0/RefL0100N1504/snapshot_028_z000p000/snap_028_z000p000.0.hdf5')74 EAGLE_100Mpc_ad = EAGLE_100Mpc.all_data()75except Exception as e:76 print('error: '+ str( e ))77 exc_type, exc_obj, exc_tb = sys.exc_info()78 fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]79 print(exc_type, fname, exc_tb.tb_lineno)80try:81 TNG100_snap030 = yt.load('static/data/TNG100_z2.3/snapshot/snap_030.0.hdf5')82 # TNG100_snap030 = yt.load('/cv-vol/TNG100_z2_3/snap_030.0.hdf5')83 TNG100_snap030_ad = TNG100_snap030.all_data()84except Exception as e:85 print('error: '+ str( e ))86 exc_type, exc_obj, exc_tb = sys.exc_info()87 fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]88 print(exc_type, fname, exc_tb.tb_lineno) 89try:90 TNG100_snap099 = yt.load('static/data/TNG100_z0.0/snapshot/snap_099.0.hdf5')91 # TNG100_snap099 = yt.load('/cv-vol/TNG100_z0.0/snap_099.0.hdf5')92 TNG100_snap099_ad = TNG100_snap099.all_data()93except Exception as e:94 print('error: '+ str( e ))95 exc_type, exc_obj, exc_tb = sys.exc_info()96 fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]97 print(exc_type, fname, exc_tb.tb_lineno) 98def truncate(f, n):99 '''Truncates/pads a float f to n decimal places without rounding'''100 s = '{}'.format(f)101 if 'e' in s or 'E' in s:102 return '{0:.{1}f}'.format(f, n)103 i, p, d = s.partition('.')104 return '.'.join([i, (d+'0'*n)[:n]])105def interpol8(oldx,oldy,newdx):106 107 # H_I = n.array([np.array(ray.r[('gas', 'l')].to('kpc').tolist()),np.array(ray.r[('gas', 'H_p0_number_density')] * ray.r[('gas', 'dl')].to('kpc').tolist())])108 oldx = np.array(oldx.tolist())109 oldy = np.array(oldy.tolist())110 # newdx = 1111 terpfunc = interpolate.interp1d(oldx, oldy,fill_value="extrapolate")112 newx = np.arange(np.min(oldx), np.max(oldx)+newdx, newdx)113 newy = terpfunc(newx)114 return newx.tolist(), newy.tolist()115# createLookup()116# import pdb; pdb.set_trace()117# host the index.html web page118# default is localhost:5000119@app.route('/webhook', methods=['POST'])120def webhook():121 if request.headers['Content-Type'] == 'application/json':122 info = json.dumps(request.json)123 print(info)124# threading.Thread(target=lambda: [time.sleep(2), os.system('systemctl restart cosmovis.service')]).start()125 os.system('/bin/bash update.sh')126 return info127@app.route('/')128def index():129 return render_template('index.html', async_mode=socketio.async_mode)130#getSkewerSimpleRay -- this function is used to get the 'quick' data along the skewer and sends it back to the frontend131@socketio.on('getSkewerSimpleRay',namespace="/test")132def handle_ray_selection(simID,idx, start, end):133 # try:134 135 print(multiprocessing.cpu_count())136 sys.stdout.flush()137 socketio.start_background_task(handle_skewer_simple_ray,simID,idx, start, end)138 # th = multiprocessing.Process(target=handle_skewer_simple_ray(simID,idx, start, end))139 # th.start()140 # th.join()141 # except Exception as e:142 # print('error: '+ str( e ))143 # exc_type, exc_obj, exc_tb = sys.exc_info()144 # fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]145 # print(exc_type, fname, exc_tb.tb_lineno) 146def handle_skewer_simple_ray(simID,idx,start,end):147 yt.enable_parallelism()148 print('system cpu cores: ' + str(multiprocessing.cpu_count()))149 sys.stdout.flush()150 print('cpu cores available to python: ' + str(len(psutil.Process().cpu_affinity())))151 sys.stdout.flush()152 print('mpi parallelism: ' + str(yt.enable_parallelism()))153 sys.stdout.flush()154 print('received simple ray request')155 socketio.emit( 'retrievingLineData', {'index': idx}, namespace = '/test' )156 socketio.sleep(0)157 fn = ''158 # ds = []159 160 if simID == 'RefL0012N0188':161 ds = EAGLE_12Mpc162 elif simID == 'RefL0025N0376':163 ds = EAGLE_25Mpc164 elif simID == 'RefL0100N1504':165 ds = EAGLE_100Mpc166 elif simID == 'TNG100_z2.3':167 ds = TNG100_snap030168 elif simID == 'TNG100_z0.0':169 ds = TNG100_snap099170 else:171 # if 'RefL' in simID:172 # fn = 'static/data/'+simID+'/snapshot_028_z000p000/snap_028_z000p000.0.hdf5'173 # if 'TNG' in simID:174 # fn = 'static/data/'+simID+'/snapshot/snap_030.0.hdf5'175 # print("loading" + str(fn))176 print(fn)177 ds = yt.load(fn)178 socketio.sleep(0)179 ad = ds.all_data()180 socketio.sleep(0)181 print(simID)182 socketio.sleep(0)183 sim_width = np.float(ds.domain_right_edge[0].in_units('Mpc') - ds.domain_left_edge[0].in_units('Mpc'))184 # print(ds.domain_right_edge)185 ray_start = np.float_(start)186 ray_end = np.float_(end)187 # print('ray start: ' + str(ray_start))188 # print('ray end : ' + str(ray_end))189 ray_start = ds.arr(ray_start/sim_width * np.float(ds.domain_right_edge[0]), 'code_length') #list(np.float_(start))190 ray_end = ds.arr(ray_end/sim_width * np.float(ds.domain_right_edge[0]), 'code_length') #list(np.float_(end))191 # ray_start = ds.arr(ray_start, 'Mpc')/sim_width #list(np.float_(start))192 # ray_end = ds.arr(ray_end, 'Mpc')/sim_width #list(np.float_(end))193 print(ray_start.in_units('Mpc'))194 print(ray_end.in_units('Mpc'))195 line_list = ['H', 'C', 'N', 'O', 'Mg']196 socketio.sleep(0)197 # This LightRay object is a yt dataset of a 1D data structure representing the skewer path as it traverses the dataset. 198 if simID[:3] == 'Ref':199 ray = trident.make_simple_ray(ds, start_position=ray_start,200 end_position=ray_end,201 data_filename="ray.h5",202 lines=line_list,203 ftype='gas',204 fields=[('PartType0','Entropy')])205 elif simID[:3] == 'TNG':206 ray = trident.make_simple_ray(ds, start_position=ray_start,207 end_position=ray_end,208 data_filename="ray.h5",209 lines=line_list)210 socketio.sleep(0)211 trident.add_ion_fields(ray, ions=['O VI', 'C IV', 'N', 'He I', 'He II', 'He III', 'O II', 'O III', 'O V', 'Ne III', 'Ne IV', 'Ne V', 'Ne VI', 'Ne VIII', 'Na I', 'Na IX', 'Mg X', 'Si II', 'Si III', 'Si IV', 'Si XII', 'S II', 'S III', 'S IV', 'S V', 'S VI', 'O IV'], ftype="PartType0")212 socketio.sleep(0)213 # for field in ray.derived_field_list: print(field)214 # ('gas', 'l') -- the 1D location of the gas going from nearby (0) to faraway along the LightRay215 # convert to kpc216 l = ray.r[('gas', 'l')].to('kpc')217 print(ray)218 # ('gas', 'temperature') -- the gas temperature along l (K)219 # the way trident+yt represents ions as fields is a little weird220 # ex: For H I, which is neutral hydrogen, which is H (plus zero energy state), it's represented as H_p0221 # multiply number density by path length (dl) to get column density of ions (units cm^-2)222 socketio.sleep(0)223 dx = 4224 # n_density in units of particles/cm^3225 226 dl_cm = ray.r[('gas', 'dl')].to('cm')227 ## FULL RANGE VALUES228 ## used for graphing229 socketio.sleep(0)230 try:231 H_I = (ray.r[('gas', 'H_p0_number_density')] * dl_cm).tolist()232 i_H_I = interpol8(l,ray.r[('gas', 'H_p0_number_density')] * dl_cm,dx)[1]233 except Exception as e:234 H_I = [] 235 i_H_I = []236 print('error: '+ str( e ))237 exc_type, exc_obj, exc_tb = sys.exc_info()238 fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]239 print(exc_type, fname, exc_tb.tb_lineno) 240 241 socketio.sleep(0)242 try:243 H_II = (ray.r[('gas', 'H_p1_number_density')] * dl_cm).tolist()244 i_H_II = interpol8(l,ray.r[('gas', 'H_p1_number_density')] * dl_cm,dx)[1]245 except Exception as e:246 H_II = []247 i_H_II= []248 print('error: '+ str( e ))249 exc_type, exc_obj, exc_tb = sys.exc_info()250 fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]251 print(exc_type, fname, exc_tb.tb_lineno) 252 socketio.sleep(0)253 try:254 C_I = (ray.r[('gas', 'C_p0_number_density')] * dl_cm).tolist()255 i_C_I = interpol8(l,ray.r[('gas', 'C_p0_number_density')] * dl_cm,dx)[1]256 except Exception as e:257 C_I = []258 i_C_I = []259 print('error: '+ str( e ))260 exc_type, exc_obj, exc_tb = sys.exc_info()261 fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]262 print(exc_type, fname, exc_tb.tb_lineno) 263 socketio.sleep(0)264 try:265 C_II = (ray.r[('gas', 'C_p1_number_density')] * dl_cm).tolist()266 i_C_II = interpol8(l,ray.r[('gas', 'C_p1_number_density')] * dl_cm,dx)[1]267 except Exception as e:268 C_II = []269 i_C_II= []270 print('error: '+ str( e ))271 exc_type, exc_obj, exc_tb = sys.exc_info()272 fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]273 print(exc_type, fname, exc_tb.tb_lineno) 274 socketio.sleep(0)275 try:276 C_III = (ray.r[('gas', 'C_p2_number_density')] * dl_cm).tolist()277 i_C_III = interpol8(l,ray.r[('gas', 'C_p2_number_density')] * dl_cm,dx)[1]278 except Exception as e:279 C_III = []280 i_C_III= []281 print('error: '+ str( e ))282 exc_type, exc_obj, exc_tb = sys.exc_info()283 fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]284 print(exc_type, fname, exc_tb.tb_lineno) 285 socketio.sleep(0)286 try:287 C_IV = (ray.r[('gas', 'C_p3_number_density')] * dl_cm).tolist()288 i_C_IV = interpol8(l,ray.r[('gas', 'C_p3_number_density')] * dl_cm,dx)[1]289 except Exception as e:290 C_IV = []291 i_C_IV= []292 print('error: '+ str( e ))293 exc_type, exc_obj, exc_tb = sys.exc_info()294 fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]295 print(exc_type, fname, exc_tb.tb_lineno) 296 socketio.sleep(0)297 try:298 C_V = (ray.r[('gas', 'C_p4_number_density')] * dl_cm).tolist()299 i_C_V = interpol8(l,ray.r[('gas', 'C_p4_number_density')] * dl_cm,dx)[1]300 except Exception as e:301 C_V = []302 i_C_V = []303 print('error: '+ str( e ))304 exc_type, exc_obj, exc_tb = sys.exc_info()305 fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]306 print(exc_type, fname, exc_tb.tb_lineno) 307 socketio.sleep(0)308 try:309 C_VI = (ray.r[('gas', 'C_p5_number_density')] * dl_cm).tolist()310 i_C_VI = interpol8(l,ray.r[('gas', 'C_p5_number_density')] * dl_cm,dx)[1]311 except Exception as e:312 C_VI = []313 i_C_VI = []314 print('error: '+ str( e ))315 exc_type, exc_obj, exc_tb = sys.exc_info()316 fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]317 print(exc_type, fname, exc_tb.tb_lineno) 318 socketio.sleep(0)319 try:320 He_I = (ray.r[('gas', 'He_p0_number_density')] * dl_cm).tolist()321 i_He_I = interpol8(l,ray.r[('gas', 'He_p0_number_density')] * dl_cm,dx)[1]322 except Exception as e:323 He_I = []324 i_He_I = []325 print('error: '+ str( e ))326 exc_type, exc_obj, exc_tb = sys.exc_info()327 fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]328 print(exc_type, fname, exc_tb.tb_lineno) 329 socketio.sleep(0)330 try:331 He_II = (ray.r[('gas', 'He_p1_number_density')] * dl_cm).tolist()332 i_He_II = interpol8(l,ray.r[('gas', 'He_p1_number_density')] * dl_cm,dx)[1]333 except Exception as e:334 He_II = []335 i_He_II= []336 print('error: '+ str( e ))337 exc_type, exc_obj, exc_tb = sys.exc_info()338 fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]339 print(exc_type, fname, exc_tb.tb_lineno) 340 socketio.sleep(0)341 try:342 He_III = (ray.r[('gas', 'He_p2_number_density')] * dl_cm).tolist()343 i_He_III= interpol8(l,ray.r[('gas', 'He_p2_number_density')] * dl_cm,dx)[1]344 except Exception as e:345 He_III = []346 i_He_III= []347 print('error: '+ str( e ))348 exc_type, exc_obj, exc_tb = sys.exc_info()349 fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]350 print(exc_type, fname, exc_tb.tb_lineno) 351 socketio.sleep(0)352 try:353 Mg_I = (ray.r[('gas', 'Mg_p0_number_density')] * dl_cm).tolist()354 i_Mg_I = interpol8(l,ray.r[('gas', 'Mg_p0_number_density')] * dl_cm,dx)[1]355 except Exception as e:356 Mg_I = []357 i_Mg_I= []358 print('error: '+ str( e ))359 exc_type, exc_obj, exc_tb = sys.exc_info()360 fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]361 print(exc_type, fname, exc_tb.tb_lineno) 362 socketio.sleep(0)363 try:364 Mg_II = (ray.r[('gas', 'Mg_p1_number_density')] * dl_cm).tolist()365 i_Mg_II = interpol8(l,ray.r[('gas', 'Mg_p1_number_density')] * dl_cm,dx)[1]366 except Exception as e:367 Mg_II = []368 i_Mg_II= []369 print('error: '+ str( e ))370 exc_type, exc_obj, exc_tb = sys.exc_info()371 fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]372 print(exc_type, fname, exc_tb.tb_lineno) 373 socketio.sleep(0)374 try:375 Mg_X = (ray.r[('gas', 'Mg_p9_number_density')] * dl_cm).tolist()376 i_Mg_X = interpol8(l,ray.r[('gas', 'Mg_p9_number_density')] * dl_cm,dx)[1]377 except Exception as e:378 Mg_X = []379 i_Mg_X= []380 print('error: '+ str( e ))381 exc_type, exc_obj, exc_tb = sys.exc_info()382 fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]383 print(exc_type, fname, exc_tb.tb_lineno) 384 socketio.sleep(0)385 try:386 N_II = (ray.r[('gas', 'N_p1_number_density')] * dl_cm).tolist()387 i_N_II = interpol8(l,ray.r[('gas', 'N_p1_number_density')] * dl_cm,dx)[1]388 389 except Exception as e:390 N_II = []391 i_N_II= []392 print('error: '+ str( e ))393 exc_type, exc_obj, exc_tb = sys.exc_info()394 fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]395 print(exc_type, fname, exc_tb.tb_lineno) 396 socketio.sleep(0)397 try:398 N_III = (ray.r[('gas', 'N_p2_number_density')] * dl_cm).tolist()399 i_N_III = interpol8(l,ray.r[('gas', 'N_p2_number_density')] * dl_cm,dx)[1]400 except Exception as e:401 N_III = []402 i_N_III= []403 print('error: '+ str( e ))404 exc_type, exc_obj, exc_tb = sys.exc_info()405 fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]406 print(exc_type, fname, exc_tb.tb_lineno) 407 socketio.sleep(0)408 try:409 N_IV = (ray.r[('gas', 'N_p3_number_density')] * dl_cm).tolist()410 i_N_IV = interpol8(l,ray.r[('gas', 'N_p3_number_density')] * dl_cm,dx)[1]411 except Exception as e:412 N_IV = []413 i_N_IV= []414 print('error: '+ str( e ))415 exc_type, exc_obj, exc_tb = sys.exc_info()416 fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]417 print(exc_type, fname, exc_tb.tb_lineno) 418 socketio.sleep(0)419 try:420 N_V = (ray.r[('gas', 'N_p4_number_density')] * dl_cm).tolist()421 i_N_V = interpol8(l,ray.r[('gas', 'N_p4_number_density')] * dl_cm,dx)[1]422 except Exception as e:423 N_V = []424 i_N_V = []425 print('error: '+ str( e ))426 exc_type, exc_obj, exc_tb = sys.exc_info()427 fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]428 print(exc_type, fname, exc_tb.tb_lineno) 429 socketio.sleep(0)430 try:431 N_VI = (ray.r[('gas', 'N_p5_number_density')] * dl_cm).tolist()432 i_N_VI = interpol8(l,ray.r[('gas', 'N_p5_number_density')] * dl_cm,dx)[1]433 except Exception as e:434 N_VI = []435 i_N_VI = []436 print('error: '+ str( e ))437 exc_type, exc_obj, exc_tb = sys.exc_info()438 fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]439 print(exc_type, fname, exc_tb.tb_lineno) 440 socketio.sleep(0)441 try:442 N_VII = (ray.r[('gas', 'N_p6_number_density')] * dl_cm).tolist()443 i_N_VII = interpol8(l,ray.r[('gas', 'N_p6_number_density')] * dl_cm,dx)[1]444 except Exception as e:445 N_VII = []446 i_N_VII= []447 print('error: '+ str( e ))448 exc_type, exc_obj, exc_tb = sys.exc_info()449 fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]450 print(exc_type, fname, exc_tb.tb_lineno) 451 socketio.sleep(0)452 try:453 Na_I = (ray.r[('gas', 'Na_p0_number_density')] * dl_cm).tolist()454 i_Na_I = interpol8(l,ray.r[('gas', 'Na_p0_number_density')] * dl_cm,dx)[1]455 except Exception as e:456 Na_I = []457 i_Na_I= []458 print('error: '+ str( e ))459 exc_type, exc_obj, exc_tb = sys.exc_info()460 fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]461 print(exc_type, fname, exc_tb.tb_lineno) 462 socketio.sleep(0)463 try:464 Na_IX = (ray.r[('gas', 'Na_p8_number_density')] * dl_cm).tolist()465 i_Na_IX = interpol8(l,ray.r[('gas', 'Na_p8_number_density')] * dl_cm,dx)[1]466 except Exception as e:467 Na_IX = []468 i_Na_IX= []469 print('error: '+ str( e ))470 exc_type, exc_obj, exc_tb = sys.exc_info()471 fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]472 print(exc_type, fname, exc_tb.tb_lineno) 473 socketio.sleep(0)474 try:475 Ne_III = (ray.r[('gas', 'Ne_p2_number_density')] * dl_cm).tolist()476 i_Ne_III= interpol8(l,ray.r[('gas', 'Ne_p2_number_density')] * dl_cm,dx)[1]477 except Exception as e:478 Ne_III = []479 i_Ne_III= []480 print('error: '+ str( e ))481 exc_type, exc_obj, exc_tb = sys.exc_info()482 fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]483 print(exc_type, fname, exc_tb.tb_lineno) 484 socketio.sleep(0)485 try:486 Ne_IV = (ray.r[('gas', 'Ne_p3_number_density')] * dl_cm).tolist()487 i_Ne_IV = interpol8(l,ray.r[('gas', 'Ne_p3_number_density')] * dl_cm,dx)[1]488 except Exception as e:489 Ne_IV = []490 i_Ne_IV= []491 print('error: '+ str( e ))492 exc_type, exc_obj, exc_tb = sys.exc_info()493 fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]494 print(exc_type, fname, exc_tb.tb_lineno) 495 socketio.sleep(0)496 try:497 Ne_V = (ray.r[('gas', 'Ne_p4_number_density')] * dl_cm).tolist()498 i_Ne_V = interpol8(l,ray.r[('gas', 'Ne_p4_number_density')] * dl_cm,dx)[1]499 except Exception as e:500 Ne_V = []501 i_Ne_V= []502 print('error: '+ str( e ))503 exc_type, exc_obj, exc_tb = sys.exc_info()504 fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]505 print(exc_type, fname, exc_tb.tb_lineno) 506 socketio.sleep(0)507 try:508 Ne_VI = (ray.r[('gas', 'Ne_p5_number_density')] * dl_cm).tolist()509 i_Ne_VI = interpol8(l,ray.r[('gas', 'Ne_p5_number_density')] * dl_cm,dx)[1]510 except Exception as e:511 Ne_VI = []512 i_Ne_VI= []513 print('error: '+ str( e ))514 exc_type, exc_obj, exc_tb = sys.exc_info()515 fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]516 print(exc_type, fname, exc_tb.tb_lineno) 517 socketio.sleep(0)518 try:519 Ne_VIII= (ray.r[('gas', 'Ne_p7_number_density')] * dl_cm).tolist()520 i_Ne_VIII=interpol8(l,ray.r[('gas', 'Ne_p7_number_density')] * dl_cm,dx)[1]521 except Exception as e:522 Ne_VIII = []523 i_Ne_VIII= []524 print('error: '+ str( e ))525 exc_type, exc_obj, exc_tb = sys.exc_info()526 fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]527 print(exc_type, fname, exc_tb.tb_lineno) 528 socketio.sleep(0)529 try:530 O_I = (ray.r[('gas', 'O_p0_number_density')] * dl_cm).tolist()531 i_O_I = interpol8(l,ray.r[('gas', 'O_p0_number_density')] * dl_cm,dx)[1]532 except Exception as e:533 O_I = []534 i_O_I = []535 print('error: '+ str( e ))536 exc_type, exc_obj, exc_tb = sys.exc_info()537 fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]538 print(exc_type, fname, exc_tb.tb_lineno) 539 socketio.sleep(0)540 try:541 O_II = (ray.r[('gas', 'O_p1_number_density')] * dl_cm).tolist()542 i_O_II = interpol8(l,ray.r[('gas', 'O_p1_number_density')] * dl_cm,dx)[1]543 except Exception as e:544 O_II = []545 i_O_II= []546 print('error: '+ str( e ))547 exc_type, exc_obj, exc_tb = sys.exc_info()548 fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]549 print(exc_type, fname, exc_tb.tb_lineno) 550 socketio.sleep(0)551 try:552 O_III = (ray.r[('gas', 'O_p2_number_density')] * dl_cm).tolist()553 i_O_III = interpol8(l,ray.r[('gas', 'O_p2_number_density')] * dl_cm,dx)[1]554 except Exception as e:555 O_III = []556 i_O_III= []557 print('error: '+ str( e ))558 exc_type, exc_obj, exc_tb = sys.exc_info()559 fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]560 print(exc_type, fname, exc_tb.tb_lineno) 561 socketio.sleep(0)562 try:563 O_IV = (ray.r[('gas', 'O_p3_number_density')] * dl_cm).tolist()564 i_O_IV = interpol8(l,ray.r[('gas', 'O_p3_number_density')] * dl_cm,dx)[1]565 except Exception as e:566 O_IV = []567 i_O_IV= []568 print('error: '+ str( e ))569 exc_type, exc_obj, exc_tb = sys.exc_info()570 fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]571 print(exc_type, fname, exc_tb.tb_lineno) 572 socketio.sleep(0)573 try:574 O_V = (ray.r[('gas', 'O_p4_number_density')] * dl_cm).tolist()575 i_O_V = interpol8(l,ray.r[('gas', 'O_p4_number_density')] * dl_cm,dx)[1]576 except Exception as e:577 O_V = []578 i_O_V= []579 print('error: '+ str( e ))580 exc_type, exc_obj, exc_tb = sys.exc_info()581 fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]582 print(exc_type, fname, exc_tb.tb_lineno) 583 socketio.sleep(0)584 try:585 O_VI = (ray.r[('gas', 'O_p5_number_density')] * dl_cm).tolist()586 i_O_VI = interpol8(l,ray.r[('gas', 'O_p5_number_density')] * dl_cm,dx)[1]587 except Exception as e:588 O_VI = []589 i_O_VI= []590 print('error: '+ str( e ))591 exc_type, exc_obj, exc_tb = sys.exc_info()592 fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]593 print(exc_type, fname, exc_tb.tb_lineno) 594 socketio.sleep(0)595 try:596 O_VII = (ray.r[('gas', 'O_p6_number_density')] * dl_cm).tolist()597 i_O_VII = interpol8(l,ray.r[('gas', 'O_p6_number_density')] * dl_cm,dx)[1]598 except Exception as e:599 O_VII = []600 i_O_VII= []601 print('error: '+ str( e ))602 exc_type, exc_obj, exc_tb = sys.exc_info()603 fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]604 print(exc_type, fname, exc_tb.tb_lineno) 605 socketio.sleep(0)606 try:607 O_VIII = (ray.r[('gas', 'O_p7_number_density')] * dl_cm).tolist()608 i_O_VIII= interpol8(l,ray.r[('gas', 'O_p7_number_density')] * dl_cm,dx)[1]609 except Exception as e:610 O_VIII = []611 i_O_VIII= []612 print('error: '+ str( e ))613 exc_type, exc_obj, exc_tb = sys.exc_info()614 fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]615 print(exc_type, fname, exc_tb.tb_lineno) 616 socketio.sleep(0)617 try:618 S_II = (ray.r[('gas', 'S_p1_number_density')] * dl_cm).tolist()619 i_S_II = interpol8(l,ray.r[('gas', 'S_p1_number_density')] * dl_cm,dx)[1]620 except Exception as e:621 S_II = []622 i_S_II= []623 print('error: '+ str( e ))624 exc_type, exc_obj, exc_tb = sys.exc_info()625 fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]626 print(exc_type, fname, exc_tb.tb_lineno) 627 socketio.sleep(0)628 try:629 S_III = (ray.r[('gas', 'S_p2_number_density')] * dl_cm).tolist()630 i_S_III = interpol8(l,ray.r[('gas', 'S_p2_number_density')] * dl_cm,dx)[1]631 except Exception as e:632 S_III = []633 i_S_III= []634 print('error: '+ str( e ))635 exc_type, exc_obj, exc_tb = sys.exc_info()636 fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]637 print(exc_type, fname, exc_tb.tb_lineno) 638 socketio.sleep(0)639 try:640 S_IV = (ray.r[('gas', 'S_p3_number_density')] * dl_cm).tolist()641 i_S_IV = interpol8(l,ray.r[('gas', 'S_p3_number_density')] * dl_cm,dx)[1]642 except Exception as e:643 S_IV = []644 i_S_IV= []645 print('error: '+ str( e ))646 exc_type, exc_obj, exc_tb = sys.exc_info()647 fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]648 print(exc_type, fname, exc_tb.tb_lineno) 649 socketio.sleep(0)650 try:651 S_V = (ray.r[('gas', 'S_p4_number_density')] * dl_cm).tolist()652 i_S_V = interpol8(l,ray.r[('gas', 'S_p4_number_density')] * dl_cm,dx)[1]653 except Exception as e:654 S_V = []655 i_S_V= []656 print('error: '+ str( e ))657 exc_type, exc_obj, exc_tb = sys.exc_info()658 fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]659 print(exc_type, fname, exc_tb.tb_lineno) 660 socketio.sleep(0)661 try:662 S_VI = (ray.r[('gas', 'S_p5_number_density')] * dl_cm).tolist()663 i_S_VI = interpol8(l,ray.r[('gas', 'S_p5_number_density')] * dl_cm,dx)[1]664 except Exception as e:665 S_VI = []666 i_S_VI= []667 print('error: '+ str( e ))668 exc_type, exc_obj, exc_tb = sys.exc_info()669 fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]670 print(exc_type, fname, exc_tb.tb_lineno) 671 socketio.sleep(0)672 try:673 Si_II = (ray.r[('gas', 'Si_p1_number_density')] * dl_cm).tolist()674 i_Si_II = interpol8(l,ray.r[('gas', 'Si_p1_number_density')] * dl_cm,dx)[1]675 except Exception as e:676 Si_II = []677 i_Si_II= []678 print('error: '+ str( e ))679 exc_type, exc_obj, exc_tb = sys.exc_info()680 fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]681 print(exc_type, fname, exc_tb.tb_lineno) 682 socketio.sleep(0)683 try:684 Si_III = (ray.r[('gas', 'Si_p2_number_density')] * dl_cm).tolist()685 i_Si_III= interpol8(l,ray.r[('gas', 'Si_p2_number_density')] * dl_cm,dx)[1]686 except Exception as e:687 Si_III = []688 i_Si_III= []689 print('error: '+ str( e ))690 exc_type, exc_obj, exc_tb = sys.exc_info()691 fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]692 print(exc_type, fname, exc_tb.tb_lineno) 693 socketio.sleep(0)694 try:695 Si_IV = (ray.r[('gas', 'Si_p3_number_density')] * dl_cm).tolist()696 i_Si_IV = interpol8(l,ray.r[('gas', 'Si_p3_number_density')] * dl_cm,dx)[1]697 except Exception as e:698 Si_IV = []699 i_Si_IV= []700 print('error: '+ str( e ))701 exc_type, exc_obj, exc_tb = sys.exc_info()702 fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]703 print(exc_type, fname, exc_tb.tb_lineno) 704 socketio.sleep(0)705 try:706 Si_XII = (ray.r[('gas', 'Si_p11_number_density')] * dl_cm).tolist()707 i_Si_XII= interpol8(l,ray.r[('gas', 'Si_p11_number_density')] *dl_cm,dx)[1]708 except Exception as e:709 Si_XII = []710 i_Si_XII = []711 print('error: '+ str( e ))712 exc_type, exc_obj, exc_tb = sys.exc_info()713 fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]714 print(exc_type, fname, exc_tb.tb_lineno) 715 716 finally:717 socketio.sleep(0)718 log_density = np.log10(ray.r[('gas', 'density')])+23.77+0.21 # dividing by mean molecular mass, mass of proton719 density = (10**log_density).tolist() # divide by mean molecular mass... somewhere between ~(10^-6, 1)720 try:721 if simID[:3] == 'Ref':722 entropy = (ray.r[('gas', 'Entropy')]).tolist()723 i_entropy = interpol8(l,ray.r[('gas', 'Entropy')],dx)[1]724 elif simID[:3] == 'TNG':725 entropy = (ray.r[('gas', 'entropy')]).tolist()726 i_entropy = interpol8(l,ray.r[('gas', 'entropy')],dx)[1]727 except Exception as e:728 entropy = []729 i_entropy = []730 print('error: '+ str( e ))731 exc_type, exc_obj, exc_tb = sys.exc_info()732 fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]733 print(exc_type, fname, exc_tb.tb_lineno) 734 socketio.sleep(0)735 metallicity = (ray.r[('gas', 'metallicity')].to('Zsun')).tolist()736 temperature = (ray.r[('gas', 'temperature')]).tolist()737 log_density = np.log10(ray.r[('gas', 'density')])+23.77+0.21 # dividing by mean molecular mass, mass of proton738 i_density = (10**np.array(interpol8(l, log_density,dx)[1])).tolist() # divide by mean molecular mass... somewhere between ~(10^-6, 1)739 i_metallicity = interpol8(l,ray.r[('gas', 'metallicity')].to('Zsun'),dx)[1]740 i_l, i_temperature = interpol8(l,ray.r[('gas', 'temperature')],dx)741 socketio.sleep(0)742 socketio.emit('simple_line_data',{ 'index': idx,743 'start': start,744 'end': end,745 'l': l.tolist(),746 'N(H I)': H_I,747 'N(H II)': H_II,748 'N(C I)': C_I,749 'N(C II)': C_II,750 'N(C III)': C_III,751 'N(C IV)': C_IV,752 'N(C V)': C_V,753 'N(C VI)': C_VI,754 'N(He I)': He_I,755 'N(He II)': He_II,756 'N(He III)': He_III,757 'N(Mg I)': Mg_I,758 'N(Mg II)': Mg_II,759 'N(Mg X)': Mg_X,760 'N(N II)': N_II,761 'N(N III)': N_III,762 'N(N IV)': N_IV,763 'N(N V)': N_V,764 'N(N VI)': N_VI,765 'N(N VII)': N_VII,766 'N(Na I)': Na_I,767 'N(Na IX)': Na_IX,768 'N(Ne III)': Ne_III,769 'N(Ne IV)': Ne_IV,770 'N(Ne V)': Ne_V,771 'N(Ne VI)': Ne_VI,772 'N(Ne VIII)': Ne_VIII,773 'N(O I)': O_I,774 'N(O II)': O_II,775 'N(O III)': O_III,776 'N(O IV)': O_IV,777 'N(O V)': O_V,778 'N(O VI)': O_VI,779 'N(O VII)': O_VII,780 'N(O VIII)': O_VIII,781 'N(S II)': S_II,782 'N(S III)': S_III,783 'N(S IV)': S_IV,784 'N(S V)': S_V,785 'N(S VI)': S_VI,786 'N(Si II)': Si_II,787 'N(Si III)': Si_III,788 'N(Si IV)': Si_IV,789 'N(Si XII)': Si_XII,790 'density': density,791 'entropy': entropy,792 'metallicity': metallicity,793 'temperature': temperature,794 'i_l': i_l,795 'i_N(H I)': i_H_I,796 'i_N(H II)': i_H_II,797 'i_N(C I)': i_C_I,798 'i_N(C II)': i_C_II,799 'i_N(C III)': i_C_III,800 'i_N(C IV)': i_C_IV,801 'i_N(C V)': i_C_V,802 'i_N(C VI)': i_C_VI,803 'i_N(He I)': i_He_I,804 'i_N(He II)': i_He_II,805 'i_N(He III)': i_He_III,806 'i_N(Mg I)': i_Mg_I,807 'i_N(Mg II)': i_Mg_II,808 'i_N(Mg X)': i_Mg_X,809 'i_N(N II)': i_N_II,810 'i_N(N III)': i_N_III,811 'i_N(N IV)': i_N_IV,812 'i_N(N V)': i_N_V,813 'i_N(N VI)': i_N_VI,814 'i_N(N VII)': i_N_VII,815 'i_N(Na I)': i_Na_I,816 'i_N(Na IX)': i_Na_IX,817 'i_N(Ne III)': i_Ne_III,818 'i_N(Ne IV)': i_Ne_IV,819 'i_N(Ne V)': i_Ne_V,820 'i_N(Ne VI)': i_Ne_VI,821 'i_N(Ne VIII)': i_Ne_VIII,822 'i_N(O I)': i_O_I,823 'i_N(O II)': i_O_II,824 'i_N(O III)': i_O_III,825 'i_N(O IV)': i_O_IV,826 'i_N(O V)': i_O_V,827 'i_N(O VI)': i_O_VI,828 'i_N(O VII)': i_O_VII,829 'i_N(O VIII)': i_O_VIII,830 'i_N(S II)': i_S_II,831 'i_N(S III)': i_S_III,832 'i_N(S IV)': i_S_IV,833 'i_N(S V)': i_S_V,834 'i_N(S VI)': i_S_VI,835 'i_N(Si II)': i_Si_II,836 'i_N(Si III)': i_Si_III,837 'i_N(Si IV)': i_Si_IV,838 'i_N(Si XII)': i_Si_XII,839 'i_density': i_density,840 'i_entropy': i_entropy,841 'i_metallicity': i_metallicity,842 'i_temperature': i_temperature843 }, namespace='/test')844 socketio.sleep(0)845 print('sent simple ray data')846# selectRay is called from index.html when 847@socketio.on('selectRay', namespace='/test')848def handle_ray_selection(simID,idx, start, end):849 try:850 if path.exists('static/data/skewers/'+simID+'_'+str(idx)+'_'+str(start)+'_'+str(end)+'.json'):851 socketio.emit( 'synthetic_spectrum_saved', {'index': 'static/data/skewers/'+simID+'_'+str(idx)+'_'+str(start)+'_'+str(end)+'.json'}, namespace = '/test' )852 else:853 socketio.start_background_task(handle_ray_selection_background,simID,idx, start, end)854 except:855 socketio.emit( 'spectrumError', {'index': idx}, namespace = '/test' )856 857def handle_ray_selection_background(simID,idx,start,end):858 # socketio = SocketIO(message_queue='amqp://')859 socketio.emit( 'processingRay', {'index': idx}, namespace = '/test' )860 eventlet.sleep()861 socketio.sleep(0)862 # fn = ''863 # if 'RefL' in simID:864 # fn = 'static/data/'+simID+'/snapshot_028_z000p000/snap_028_z000p000.0.hdf5'865 # if 'TNG' in simID:866 # fn = 'static/data/'+simID+'/snapshot/snap_030.0.hdf5'867 # # ds = yt.load(fn)868 # socketio.sleep(0)869 # # ad = ds.all_data()870 fn = ''871 # ds = []872 873 if simID == 'RefL0012N0188':874 ds = EAGLE_12Mpc875 elif simID == 'RefL0025N0376':876 ds = EAGLE_25Mpc877 elif simID == 'RefL0100N1504':878 ds = EAGLE_100Mpc879 elif simID == 'TNG100_z2.3':880 ds = TNG100_snap030881 elif simID == 'TNG100_z0.0':882 ds = TNG100_snap099883 else:884 # if 'RefL' in simID:885 # fn = 'static/data/'+simID+'/snapshot_028_z000p000/snap_028_z000p000.0.hdf5'886 # if 'TNG' in simID:887 # fn = 'static/data/'+simID+'/snapshot/snap_030.0.hdf5'888 # print("loading" + str(fn))889 print(fn)890 ds = yt.load(fn)891 ad = ds.all_data()892 print(simID)893 print('received args: ' + str(start) + str(end))894 ray_start = np.float_(start)895 ray_end = np.float_(end)896 sim_width = np.float(ds.domain_right_edge[0].in_units('Mpc') - ds.domain_left_edge[0].in_units('Mpc'))897 # ray_start = ds.arr(ray_start, 'Mpc') #list(np.float_(start))898 # ray_end = ds.arr(ray_end, 'Mpc')899 ray_start = ds.arr(ray_start/sim_width * np.float(ds.domain_right_edge[0]), 'code_length') #list(np.float_(start))900 ray_end = ds.arr(ray_end/sim_width * np.float(ds.domain_right_edge[0]), 'code_length') #list(np.float_(end))901 print(ray_start.in_units('Mpc'))902 print(ray_end.in_units('Mpc'))903 line_list = ['H', 'C', 'N', 'O', 'Mg']904 instrument = 'COS'905 grating = 'G130M'906 inst = instrument + '-' + grating907 lambda_min = float(trident.valid_instruments[inst].lambda_min)908 lambda_max = float(trident.valid_instruments[inst].lambda_max)909 path = trident_path() + '/data/line_lists/lines.txt'910 path2 = trident_path() + '/data/line_lists/lines_subset_test.txt'911 912 lines_data = open(path,"r")913 open(path2, 'w').close()914 lines_subset_test = open(path2,"a")915 socketio.sleep(0)916 c = 0917 lines = {} # keeps track of lines and whether or not they are added to the subset918 for line in lines_data:919 if c == 0:920 lines_subset_test.write(line)921 c+=1922 continue923 field = line.split()924 # print(field)925 wavelength = float(field[2])926 element = field[0] + field[1] + truncate(wavelength,0)927 element = element[:-1]928 if (wavelength >= lambda_min) and (wavelength <= lambda_max):929 lines_subset_test.write(line)930 lines[element] = True931 else:932 lines[element] = False933 continue934 # import pdb; pdb.set_trace()935 936 lines_data.close()937 lines_subset_test.close()938 print("making simple ray")939 socketio.sleep(0)940 ray = trident.make_simple_ray(ds, start_position=ray_start,941 end_position=ray_end,942 data_filename="ray.h5", # update file name if we need multiple943 lines=line_list)944 socketio.sleep(0)945 sg = trident.SpectrumGenerator(inst ,line_database="lines_subset_test.txt")#, dlambda=1)946 # sg = trident.SpectrumGenerator('COS-G130M',line_database="lines.txt")947 948 # emit('my_response', {'data': 'Connected', 'count': -1})949 socketio.sleep(0)950 print('making spectrum')951 sg.make_spectrum(ray, lines=line_list) #spitting information through std_out, scrape information952 socketio.sleep(0)953 # sg.add_qso_spectrum(emitting_redshift=0.5)954 955 MW = False956 if MW == True:957 sg.add_milky_way_foreground() #fine with COS G130M958 socketio.sleep(0)959 sg.apply_lsf() #instrumental profile960 socketio.sleep(0)961 noise = True962 SNR = 50963 if noise == True:964 sg.add_gaussian_noise(SNR)965 socketio.sleep(0)966 error = sg.error_func(sg.flux_field)967 968 socketio.sleep(0)969 sgs.append([start,end,sg,idx])970 socketio.sleep(0)971 socketio.emit( 'sentRay', {'index': idx}, namespace = '/test' )972 socketio.sleep(0)973 print('emitting spectrum')974 socketio.sleep(0)975 socketio.emit('synthetic_spectrum',{'index':idx,'start':start,'end':end,'lambda':sgs[-1][2].lambda_field.tolist(),'flux':sgs[-1][2].flux_field.tolist()}, namespace='/test')976 socketio.sleep(0)977 print('sent spectrum')978 # sg.save_spectrum('spec_raw.txt')979 # sg.plot_spectrum('spec_raw.png')980 # print(jsonify(sg.lambda_field.tolist()))981 # print(sg.flux_field.tolist())982 tab = Table((sgs[-1][2].lambda_field.tolist(), sgs[-1][2].flux_field.tolist(), error.tolist() ), names=["lambda","flux","error"])983 # tab = Table((sgs[-1][2].lambda_field.tolist(), sgs[-1][2].flux_field.tolist() ), names=["lambda","flux"])984 hdul = fits.table_to_hdu(tab)985 hdr = hdul.header986 # Software987 hdr['COSMOVIS'] = 0.1 # Cosmovis version988 hdr['TRIDENT'] = trident.__version__ # Trident version989 hdr['YT'] = yt.__version__ # Yt version990 # Simulation991 hdr['SIM'] = 'EAGLE' # Simulation (EAGLE, FIRE, etc.)992 hdr['SIM_VERS'] = 'RefL0012N0188' # Sim version993 hdr['BOX_SIZE'] = ds.parameters['BoxSize'] # Box size994 hdr['Z'] = ds.parameters['Redshift'] # Redshift995 # Spectrum996 hdr['X1Y1Z1'] = str(start[0]) + ', ' + str(start[1]) + ', ' + str(start[2]) 997 # X1, Y1, Z1998 hdr['X2Y2Z2'] = str(end[0]) + ', ' + str(end[1]) + ', ' + str(end[2]) 999 # X2, Y2, Z2 1000 hdr['MW_FRGND'] = MW # MWforeground (True, False)1001 hdr['NOISEADD'] = noise # NoiseAdded (True, False)1002 hdr['NOISETYP'] = 'Gaussian' # NoiseType (Gaussian, custom)1003 hdr['SNR'] = SNR # SNR1004 hdr['SEED'] = False # NoiseSeed1005 hdr['INSTRMNT'] = instrument # Instrument1006 hdr['GRATING'] = grating # Grating1007 hdr['ROTATION'] = 'null' # Grating rotation1008 hdr['RESOLUTN'] = float(sg.dlambda*6) # Spectral resolution (Angstroms)1009 # Lines added (each boolean)1010 for line in lines:1011 # print(lines[line])1012 hdr[line] = lines[line]1013 # HI12151014 # HI10251015 # HI9721016 # OVI10311017 # OVI10371018 spectrum_hdul.append(hdul)1019 spectrum_hdul.writeto('static/data/spectra.fits', overwrite=True)1020 1021 socketio.sleep(0)1022 spec = {'index':idx,'start':start,'end':end,'lambda':sgs[-1][2].lambda_field.tolist(),'flux':sgs[-1][2].flux_field.tolist()}1023 socketio.sleep()1024 with open('static/data/skewers/'+simID+'_'+str(idx)+'_'+str(start)+'_'+str(end)+'.json', 'w') as file:1025 json.dump(spec, file)1026 socketio.sleep(0)1027 socketio.emit( 'synthetic_spectrum_saved', {'index': 'static/data/skewers/'+simID+'_'+str(idx)+'_'+str(start)+'_'+str(end)+'.json'}, namespace = '/test' )1028 socketio.sleep(0)1029 print("spectrum saved")1030 1031@socketio.on('simIDtoServer', namespace='/test')1032def updateSimID(simID):1033 1034 global fn1035 global ds1036 global fl 1037 global ad1038 global right_edge 1039 global left_edge1040 if simID == 'RefL0012N0188':1041 if fn != 'static/data/RefL0012N0188/snapshot_028_z000p000/snap_028_z000p000.0.hdf5':1042 fn = 'static/data/RefL0012N0188/snapshot_028_z000p000/snap_028_z000p000.0.hdf5'1043 # ds = yt.load(fn)1044 fl = sorted(ds.field_list) # contains list of fields in the dataset1045 ad = ds.all_data()1046 right_edge = [float(ad.right_edge[0]),float(ad.right_edge[1]),float(ad.right_edge[2])]1047 left_edge = [float(ad.left_edge[0]),float(ad.left_edge[1]),float(ad.left_edge[2])]1048 emit('field_list', {'data': fl},namespace='/test')1049 emit('domain_edges', {'left_edge': left_edge, 'right_edge': right_edge},namespace='/test')1050 elif simID == 'RefL0025N0376':1051 if fn != 'static/data/RefL0025N0376/snapshot_028_z000p000/snap_028_z000p000.0.hdf5':1052 fn = 'static/data/RefL0025N0376/snapshot_028_z000p000/snap_028_z000p000.0.hdf5'1053 # ds = yt.load(fn)1054 fl = sorted(ds.field_list) # contains list of fields in the dataset1055 ad = ds.all_data()1056 right_edge = [float(ad.right_edge[0]),float(ad.right_edge[1]),float(ad.right_edge[2])]1057 left_edge = [float(ad.left_edge[0]),float(ad.left_edge[1]),float(ad.left_edge[2])]1058 emit('field_list', {'data': fl},namespace='/test')1059 emit('domain_edges', {'left_edge': left_edge, 'right_edge': right_edge},namespace='/test')1060 with open('static/data/'+simID+'/simMetadata.json', 'w') as file:1061 simMetadata = {1062 "left_edge": left_edge,1063 "right_edge": right_edge,1064 "field_list": fl1065 }1066 json.dump(simMetadata, file)1067@socketio.on('connect', namespace='/test')1068def test_connect():1069 print("connected")1070 emit('my_response', {'data': 'Connected', 'count': 0})1071if __name__ == '__main__':1072 # socketio.run(app, debug=False)1073 # socketio.run(app, host='0.0.0.0', debug=True)...

Full Screen

Full Screen

element.py

Source:element.py Github

copy

Full Screen

1class Element:2 element = None3 def __init__(self, element):4 self.element = element5 def click(self):6 try:7 self.element.click()8 return True9 except Exception as e:10 print(e, e.__traceback__.tb_lineno)11 return False12 # 点击13 def write(self, text):14 try:15 self.element.send_keys(text)16 return True17 except Exception as e:18 print(e, e.__traceback__.tb_lineno)19 return False20 # 写入21 def clear(self):22 try:23 self.element.clear()24 return True25 except Exception as e:26 print(e, e.__traceback__.tb_lineno)27 return False28 # 清空文本内容29 def submit(self):30 try:31 self.element.submit()32 return True33 except Exception as e:34 print(e, e.__traceback__.tb_lineno)35 return False36 # 提交表单37 def clear(self):38 try:39 self.element.clear()40 return True41 except Exception as e:42 print(e, e.__traceback__.tb_lineno)43 return False44 def clear(self):45 try:46 self.element.clear()47 return True48 except Exception as e:49 print(e, e.__traceback__.tb_lineno)50 return False51 def clear(self):52 try:53 self.element.clear()54 return True55 except Exception as e:56 print(e, e.__traceback__.tb_lineno)57 return False58 def clear(self):59 try:60 self.element.clear()61 return True62 except Exception as e:63 print(e, e.__traceback__.tb_lineno)64 return False65 def clear(self):66 try:67 self.element.clear()68 return True69 except Exception as e:70 print(e, e.__traceback__.tb_lineno)71 return False72 def clear(self):73 try:74 self.element.clear()75 return True76 except Exception as e:77 print(e, e.__traceback__.tb_lineno)78 return False79 def clear(self):80 try:81 self.element.clear()82 return True83 except Exception as e:84 print(e, e.__traceback__.tb_lineno)85 return False86 def clear(self):87 try:88 self.element.clear()89 return True90 except Exception as e:91 print(e, e.__traceback__.tb_lineno)92 return False93 def clear(self):94 try:95 self.element.clear()96 return True97 except Exception as e:98 print(e, e.__traceback__.tb_lineno)99 return False100 def clear(self):101 try:102 self.element.clear()103 return True104 except Exception as e:105 print(e, e.__traceback__.tb_lineno)106 return False107 def get_attr(self, attr_name: str):108 try:109 return self.element.get_attribute(attr_name)110 except Exception as e:111 print(e, e.__traceback__.tb_lineno)112 return None113 # 获取属性值114 def get_css(self, property_name):115 try:116 return self.element.value_of_css_property(property_name)117 except Exception as e:118 print(e, e.__traceback__.tb_lineno)119 return None120 # 获取CSS值121 @property122 def text(self):123 try:124 return self.element.text125 except Exception as e:126 print(e, e.__traceback__.tb_lineno)127 return None128 @property129 def selected(self):130 try:131 return self.element.is_selected()132 except Exception as e:133 print(e, e.__traceback__.tb_lineno)134 return None135 @property136 def enabled(self):137 try:138 return self.element.is_enabled()139 except Exception as e:140 print(e, e.__traceback__.tb_lineno)141 return None142 @property143 def displayed(self):144 try:145 return self.element.is_displayed()146 except Exception as e:147 print(e, e.__traceback__.tb_lineno)148 return None149 @property150 def x(self):151 try:152 return int(self.element.location['x'])153 except Exception as e:154 print(e, e.__traceback__.tb_lineno)155 return None156 @property157 def y(self):158 try:159 return int(self.element.location['y'])160 except Exception as e:161 print(e, e.__traceback__.tb_lineno)162 return None163 @property164 def src(self):165 try:166 return self.element.get_attribute("src")167 except Exception as e:168 print(e, e.__traceback__.tb_lineno)169 return None170 @property171 def class_name(self):172 try:173 return self.element.get_attribute("class")174 except Exception as e:175 print(e, e.__traceback__.tb_lineno)176 return None177 @property178 def node_type(self):179 try:180 return self.element.get_attribute("node-type")181 except Exception as e:182 print(e, e.__traceback__.tb_lineno)183 return None184 @property185 def action_data(self):186 try:187 return self.element.get_attribute("action-data")188 except Exception as e:189 print(e, e.__traceback__.tb_lineno)190 return None191 @property192 def action_type(self):193 try:194 return self.element.get_attribute("action-type")195 except Exception as e:196 print(e, e.__traceback__.tb_lineno)197 return None198 @property199 def href(self):200 try:201 return self.element.get_attribute("href")202 except Exception as e:203 print(e, e.__traceback__.tb_lineno)204 return None205 @property206 def action_history(self):207 try:208 return self.element.get_attribute("action-history")209 except Exception as e:210 print(e, e.__traceback__.tb_lineno)211 return None212 @property213 def value(self):214 try:215 return self.element.get_attribute("value")216 except Exception as e:217 print(e, e.__traceback__.tb_lineno)218 return None219 @property220 def suda_uatrack(self):221 try:222 return self.element.get_attribute("suda-uatrack")223 except Exception as e:224 print(e, e.__traceback__.tb_lineno)225 return None226 @property227 def behavior(self):228 try:229 return self.element.get_attribute("behavior")230 except Exception as e:231 print(e, e.__traceback__.tb_lineno)232 return None233 @property234 def direction(self):235 try:236 return self.element.get_attribute("direction")237 except Exception as e:238 print(e, e.__traceback__.tb_lineno)239 return None240 @property241 def loop(self):242 try:243 return self.element.get_attribute("loop")244 except Exception as e:245 print(e, e.__traceback__.tb_lineno)246 return None247 @property248 def width(self):249 try:250 return self.element.get_attribute("width")251 except Exception as e:252 print(e, e.__traceback__.tb_lineno)253 return None254 @property255 def height(self):256 try:257 return self.element.get_attribute("height")258 except Exception as e:259 print(e, e.__traceback__.tb_lineno)260 return None261 @property262 def bgcolor(self):263 try:264 return self.element.get_attribute("bgcolor")265 except Exception as e:266 print(e, e.__traceback__.tb_lineno)267 return None268 @property269 def scrollamount(self):270 try:271 return self.element.get_attribute("scrollamount")272 except Exception as e:273 print(e, e.__traceback__.tb_lineno)274 return None275 @property276 def scrolldelay(self):277 try:278 return self.element.get_attribute("scrolldelay")279 except Exception as e:280 print(e, e.__traceback__.tb_lineno)281 return None282 @property283 def onmouseover(self):284 try:285 return self.element.get_attribute("onmouseover")286 except Exception as e:287 print(e, e.__traceback__.tb_lineno)288 return None289 @property290 def color(self):291 try:292 return self.element.get_attribute("color")293 except Exception as e:294 print(e, e.__traceback__.tb_lineno)295 return None296 @property297 def alt(self):298 try:299 return self.element.get_attribute("alt")300 except Exception as e:301 print(e, e.__traceback__.tb_lineno)302 return None303 @property304 def border(self):305 try:306 return self.element.get_attribute("border")307 except Exception as e:308 print(e, e.__traceback__.tb_lineno)309 return None310 @property311 def aling(self):312 try:313 return self.element.get_attribute("aling")314 except Exception as e:315 print(e, e.__traceback__.tb_lineno)316 return None317 @property318 def background(self):319 try:320 return self.element.get_attribute("background")321 except Exception as e:322 print(e, e.__traceback__.tb_lineno)323 return None324 @property325 def borderclor(self):326 try:327 return self.element.get_attribute("borderclor")328 except Exception as e:329 print(e, e.__traceback__.tb_lineno)330 return None331 @property332 def borderclordark(self):333 try:334 return self.element.get_attribute("borderclordark")335 except Exception as e:336 print(e, e.__traceback__.tb_lineno)337 return None338 @property339 def borderclorlight(self):340 try:341 return self.element.get_attribute("borderclorlight")342 except Exception as e:343 print(e, e.__traceback__.tb_lineno)344 return None345 @property346 def cellpadding(self):347 try:348 return self.element.get_attribute("cellpadding")349 except Exception as e:350 print(e, e.__traceback__.tb_lineno)351 return None352 @property353 def cellspacing(self):354 try:355 return self.element.get_attribute("cellspacing")356 except Exception as e:357 print(e, e.__traceback__.tb_lineno)358 return None359 @property360 def cols(self):361 try:362 return self.element.get_attribute("cols")363 except Exception as e:364 print(e, e.__traceback__.tb_lineno)365 return None366 @property367 def frame(self):368 try:369 return self.element.get_attribute("frame")370 except Exception as e:371 print(e, e.__traceback__.tb_lineno)372 return None373 @property374 def colspan(self):375 try:376 return self.element.get_attribute("colspan")377 except Exception as e:378 print(e, e.__traceback__.tb_lineno)379 return None380 @property381 def rowspan(self):382 try:383 return self.element.get_attribute("rowspan")384 except Exception as e:385 print(e, e.__traceback__.tb_lineno)386 return None387 @property388 def rows(self):389 try:390 return self.element.get_attribute("rows")391 except Exception as e:392 print(e, e.__traceback__.tb_lineno)393 return None394 @property395 def name(self):396 try:397 return self.element.get_attribute("name")398 except Exception as e:399 print(e, e.__traceback__.tb_lineno)400 return None401 @property402 def noresize(self):403 try:404 return self.element.get_attribute("noresize")405 except Exception as e:406 print(e, e.__traceback__.tb_lineno)407 return None408 # ERROR?!409 @property410 def action(self):411 try:412 return self.element.get_attribute("action")413 except Exception as e:414 print(e, e.__traceback__.tb_lineno)415 return None416 @property417 def method(self):418 try:419 return self.element.get_attribute("method")420 except Exception as e:421 print(e, e.__traceback__.tb_lineno)422 return None423 @property424 def type(self):425 try:426 return self.element.get_attribute("type")427 except Exception as e:428 print(e, e.__traceback__.tb_lineno)429 return None430 @property431 def accesskey(self):432 try:433 return self.element.get_attribute("accesskey")434 except Exception as e:435 print(e, e.__traceback__.tb_lineno)436 return None437 @property438 def contenteditable(self):439 try:440 return self.element.get_attribute("contenteditable")441 except Exception as e:442 print(e, e.__traceback__.tb_lineno)443 return None444 @property445 def contextmenu(self):446 try:447 return self.element.get_attribute("contextmenu")448 except Exception as e:449 print(e, e.__traceback__.tb_lineno)450 return None451 @property452 def dir(self):453 try:454 return self.element.get_attribute("dir")455 except Exception as e:456 print(e, e.__traceback__.tb_lineno)457 return None458 @property459 def draggable(self):460 try:461 return self.element.get_attribute("draggable")462 except Exception as e:463 print(e, e.__traceback__.tb_lineno)464 return None465 @property466 def dropzone(self):467 try:468 return self.element.get_attribute("dropzone")469 except Exception as e:470 print(e, e.__traceback__.tb_lineno)471 return None472 @property473 def hidden(self):474 try:475 return self.element.get_attribute("hidden")476 except Exception as e:477 print(e, e.__traceback__.tb_lineno)478 return None479 @property480 def id(self):481 try:482 return self.element.get_attribute("id")483 except Exception as e:484 print(e, e.__traceback__.tb_lineno)485 return None486 @property487 def lang(self):488 try:489 return self.element.get_attribute("lang")490 except Exception as e:491 print(e, e.__traceback__.tb_lineno)492 return None493 @property494 def spellcheck(self):495 try:496 return self.element.get_attribute("spellcheck")497 except Exception as e:498 print(e, e.__traceback__.tb_lineno)499 return None500 @property501 def style(self):502 try:503 return self.element.get_attribute("style")504 except Exception as e:505 print(e, e.__traceback__.tb_lineno)506 return None507 @property508 def tabindex(self):509 try:510 return self.element.get_attribute("tabindex")511 except Exception as e:512 print(e, e.__traceback__.tb_lineno)513 return None514 @property515 def title(self):516 try:517 return self.element.get_attribute("title")518 except Exception as e:519 print(e, e.__traceback__.tb_lineno)520 return None521 @property522 def translate(self):523 try:524 return self.element.get_attribute("translate")525 except Exception as e:526 print(e, e.__traceback__.tb_lineno)527 return None528 @property529 def charset(self):530 try:531 return self.element.get_attribute("charset")532 except Exception as e:533 print(e, e.__traceback__.tb_lineno)534 return None535 @property536 def coords(self):537 try:538 return self.element.get_attribute("coords")539 except Exception as e:540 print(e, e.__traceback__.tb_lineno)541 return None542 @property543 def download(self):544 try:545 return self.element.get_attribute("download")546 except Exception as e:547 print(e, e.__traceback__.tb_lineno)548 return None549 @property550 def hreflang(self):551 try:552 return self.element.get_attribute("hreflang")553 except Exception as e:554 print(e, e.__traceback__.tb_lineno)555 return None556 @property557 def media(self):558 try:559 return self.element.get_attribute("media")560 except Exception as e:561 print(e, e.__traceback__.tb_lineno)562 return None563 @property564 def rel(self):565 try:566 return self.element.get_attribute("rel")567 except Exception as e:568 print(e, e.__traceback__.tb_lineno)569 return None570 @property571 def rev(self):572 try:573 return self.element.get_attribute("rev")574 except Exception as e:575 print(e, e.__traceback__.tb_lineno)576 return None577 @property578 def shape(self):579 try:580 return self.element.get_attribute("shape")581 except Exception as e:582 print(e, e.__traceback__.tb_lineno)583 return None584 @property585 def target(self):586 try:587 return self.element.get_attribute("target")588 except Exception as e:589 print(e, e.__traceback__.tb_lineno)590 return None591 @property592 def onclick(self):593 try:594 return self.element.get_attribute("onclick")595 except Exception as e:596 print(e, e.__traceback__.tb_lineno)597 return None598 @property599 def ondblclick(self):600 try:601 return self.element.get_attribute("ondblclick")602 except Exception as e:603 print(e, e.__traceback__.tb_lineno)604 return None605 @property606 def onmousedown(self):607 try:608 return self.element.get_attribute("onmousedown")609 except Exception as e:610 print(e, e.__traceback__.tb_lineno)611 return None612 @property613 def onmouseup(self):614 try:615 return self.element.get_attribute("onmouseup")616 except Exception as e:617 print(e, e.__traceback__.tb_lineno)618 return None619 @property620 def onmousemove(self):621 try:622 return self.element.get_attribute("onmousemove")623 except Exception as e:624 print(e, e.__traceback__.tb_lineno)625 return None626 @property627 def onmouseout(self):628 try:629 return self.element.get_attribute("onmouseout")630 except Exception as e:631 print(e, e.__traceback__.tb_lineno)632 return None633 @property634 def onkeypress(self):635 try:636 return self.element.get_attribute("onkeypress")637 except Exception as e:638 print(e, e.__traceback__.tb_lineno)639 return None640 @property641 def onkeydown(self):642 try:643 return self.element.get_attribute("onkeydown")644 except Exception as e:645 print(e, e.__traceback__.tb_lineno)646 return None647 @property648 def onkeyup(self):649 try:650 return self.element.get_attribute("onkeyup")651 except Exception as e:652 print(e, e.__traceback__.tb_lineno)653 return None654 @property655 def code(self):656 try:657 return self.element.get_attribute("code")658 except Exception as e:659 print(e, e.__traceback__.tb_lineno)660 return None661 @property662 def object(self):663 try:664 return self.element.get_attribute("object")665 except Exception as e:666 print(e, e.__traceback__.tb_lineno)667 return None668 @property669 def align(self):670 try:671 return self.element.get_attribute("align")672 except Exception as e:673 print(e, e.__traceback__.tb_lineno)674 return None675 # ERROR?!676 @property677 def archive(self):678 try:679 return self.element.get_attribute("archive")680 except Exception as e:681 print(e, e.__traceback__.tb_lineno)682 return None683 @property684 def codebase(self):685 try:686 return self.element.get_attribute("codebase")687 except Exception as e:688 print(e, e.__traceback__.tb_lineno)689 return None690 @property691 def hspace(self):692 try:693 return self.element.get_attribute("hspace")694 except Exception as e:695 print(e, e.__traceback__.tb_lineno)696 return None697 @property698 def vspace(self):699 try:700 return self.element.get_attribute("vspace")701 except Exception as e:702 print(e, e.__traceback__.tb_lineno)703 return None704 @property705 def nohref(self):706 try:707 return self.element.get_attribute("nohref")708 except Exception as e:709 print(e, e.__traceback__.tb_lineno)710 return None711 @property712 def autoplay(self):713 try:714 return self.element.get_attribute("autoplay")715 except Exception as e:716 print(e, e.__traceback__.tb_lineno)717 return None718 @property719 def controls(self):720 try:721 return self.element.get_attribute("controls")722 except Exception as e:723 print(e, e.__traceback__.tb_lineno)724 return None725 @property726 def muted(self):727 try:728 return self.element.get_attribute("muted")729 except Exception as e:730 print(e, e.__traceback__.tb_lineno)731 return None732 @property733 def preload(self):734 try:735 return self.element.get_attribute("preload")736 except Exception as e:737 print(e, e.__traceback__.tb_lineno)738 return None739 @property740 def face(self):741 try:742 return self.element.get_attribute("face")743 except Exception as e:744 print(e, e.__traceback__.tb_lineno)745 return None746 @property747 def size(self):748 try:749 return self.element.get_attribute("size")750 except Exception as e:751 print(e, e.__traceback__.tb_lineno)752 return None753 @property754 def cite(self):755 try:756 return self.element.get_attribute("cite")757 except Exception as e:758 print(e, e.__traceback__.tb_lineno)759 return None760 @property761 def alink(self):762 try:763 return self.element.get_attribute("alink")764 except Exception as e:765 print(e, e.__traceback__.tb_lineno)766 return None767 @property768 def link(self):769 try:770 return self.element.get_attribute("link")771 except Exception as e:772 print(e, e.__traceback__.tb_lineno)773 return None774 @property775 def vlink(self):776 try:777 return self.element.get_attribute("vlink")778 except Exception as e:779 print(e, e.__traceback__.tb_lineno)780 return None781 @property782 def autofocus(self):783 try:784 return self.element.get_attribute("autofocus")785 except Exception as e:786 print(e, e.__traceback__.tb_lineno)787 return None788 @property789 def disabled(self):790 try:791 return self.element.get_attribute("disabled")792 except Exception as e:793 print(e, e.__traceback__.tb_lineno)794 return None795 @property796 def form(self):797 try:798 return self.element.get_attribute("form")799 except Exception as e:800 print(e, e.__traceback__.tb_lineno)801 return None802 @property803 def formaction(self):804 try:805 return self.element.get_attribute("formaction")806 except Exception as e:807 print(e, e.__traceback__.tb_lineno)808 return None809 @property810 def formenctype(self):811 try:812 return self.element.get_attribute("formenctype")813 except Exception as e:814 print(e, e.__traceback__.tb_lineno)815 return None816 @property817 def formmethod(self):818 try:819 return self.element.get_attribute("formmethod")820 except Exception as e:821 print(e, e.__traceback__.tb_lineno)822 return None823 @property824 def formnovalidate(self):825 try:826 return self.element.get_attribute("formnovalidate")827 except Exception as e:828 print(e, e.__traceback__.tb_lineno)829 return None830 @property831 def formtarget(self):832 try:833 return self.element.get_attribute("formtarget")834 except Exception as e:835 print(e, e.__traceback__.tb_lineno)836 return None837 @property838 def valign(self):839 try:840 return self.element.get_attribute("valign")841 except Exception as e:842 print(e, e.__traceback__.tb_lineno)843 return None844 @property845 def char(self):846 try:847 return self.element.get_attribute("char")848 except Exception as e:849 print(e, e.__traceback__.tb_lineno)850 return None851 @property852 def charoff(self):853 try:854 return self.element.get_attribute("charoff")855 except Exception as e:856 print(e, e.__traceback__.tb_lineno)857 return None858 @property859 def span(self):860 try:861 return self.element.get_attribute("span")862 except Exception as e:863 print(e, e.__traceback__.tb_lineno)864 return None865 @property866 def checked(self):867 try:868 return self.element.get_attribute("checked")869 except Exception as e:870 print(e, e.__traceback__.tb_lineno)871 return None872 @property873 def icon(self):874 try:875 return self.element.get_attribute("icon")876 except Exception as e:877 print(e, e.__traceback__.tb_lineno)878 return None879 @property880 def label(self):881 try:882 return self.element.get_attribute("label")883 except Exception as e:884 print(e, e.__traceback__.tb_lineno)885 return None886 @property887 def radiogroup(self):888 try:889 return self.element.get_attribute("radiogroup")890 except Exception as e:891 print(e, e.__traceback__.tb_lineno)892 return None893 @property894 def datetime(self):895 try:896 return self.element.get_attribute("datetime")897 except Exception as e:898 print(e, e.__traceback__.tb_lineno)899 return None900 @property901 def open(self):902 try:903 return self.element.get_attribute("open")904 except Exception as e:905 print(e, e.__traceback__.tb_lineno)906 return None907 @property908 def compact(self):909 try:910 return self.element.get_attribute("compact")911 except Exception as e:912 print(e, e.__traceback__.tb_lineno)913 return None914 @property915 def accept(self):916 try:917 return self.element.get_attribute("accept")918 except Exception as e:919 print(e, e.__traceback__.tb_lineno)920 return None921 @property922 def accept_charset(self):923 try:924 return self.element.get_attribute("accept-charset")925 except Exception as e:926 print(e, e.__traceback__.tb_lineno)927 return None928 @property929 def autocomplete(self):930 try:931 return self.element.get_attribute("autocomplete")932 except Exception as e:933 print(e, e.__traceback__.tb_lineno)934 return None935 @property936 def enctype(self):937 try:938 return self.element.get_attribute("enctype")939 except Exception as e:940 print(e, e.__traceback__.tb_lineno)941 return None942 @property943 def novalidate(self):944 try:945 return self.element.get_attribute("novalidate")946 except Exception as e:947 print(e, e.__traceback__.tb_lineno)948 return None949 @property950 def frameborder(self):951 try:952 return self.element.get_attribute("frameborder")953 except Exception as e:954 print(e, e.__traceback__.tb_lineno)955 return None956 @property957 def longdesc(self):958 try:959 return self.element.get_attribute("longdesc")960 except Exception as e:961 print(e, e.__traceback__.tb_lineno)962 return None963 @property964 def marginheight(self):965 try:966 return self.element.get_attribute("marginheight")967 except Exception as e:968 print(e, e.__traceback__.tb_lineno)969 return None970 @property971 def marginwidth(self):972 try:973 return self.element.get_attribute("marginwidth")974 except Exception as e:975 print(e, e.__traceback__.tb_lineno)976 return None977 @property978 def scrolling(self):979 try:980 return self.element.get_attribute("scrolling")981 except Exception as e:982 print(e, e.__traceback__.tb_lineno)983 return None984 @property985 def profile(self):986 try:987 return self.element.get_attribute("profile")988 except Exception as e:989 print(e, e.__traceback__.tb_lineno)990 return None991 @property992 def noshade(self):993 try:994 return self.element.get_attribute("noshade")995 except Exception as e:996 print(e, e.__traceback__.tb_lineno)997 return None998 @property999 def manifest(self):1000 try:1001 return self.element.get_attribute("manifest")1002 except Exception as e:1003 print(e, e.__traceback__.tb_lineno)1004 return None1005 @property1006 def xmlns(self):1007 try:1008 return self.element.get_attribute("xmlns")1009 except Exception as e:1010 print(e, e.__traceback__.tb_lineno)1011 return None1012 @property1013 def sandbox(self):1014 try:1015 return self.element.get_attribute("sandbox")1016 except Exception as e:1017 print(e, e.__traceback__.tb_lineno)1018 return None1019 @property1020 def seamless(self):1021 try:1022 return self.element.get_attribute("seamless")1023 except Exception as e:1024 print(e, e.__traceback__.tb_lineno)1025 return None1026 @property1027 def srcdoc(self):1028 try:1029 return self.element.get_attribute("srcdoc")1030 except Exception as e:1031 print(e, e.__traceback__.tb_lineno)1032 return None1033 @property1034 def ismap(self):1035 try:1036 return self.element.get_attribute("ismap")1037 except Exception as e:1038 print(e, e.__traceback__.tb_lineno)1039 return None1040 @property1041 def usemap(self):1042 try:1043 return self.element.get_attribute("usemap")1044 except Exception as e:1045 print(e, e.__traceback__.tb_lineno)1046 return None1047 @property1048 def list(self):1049 try:1050 return self.element.get_attribute("list")1051 except Exception as e:1052 print(e, e.__traceback__.tb_lineno)1053 return None1054 @property1055 def max(self):1056 try:1057 return self.element.get_attribute("max")1058 except Exception as e:1059 print(e, e.__traceback__.tb_lineno)1060 return None1061 @property1062 def maxlength(self):1063 try:1064 return self.element.get_attribute("maxlength")1065 except Exception as e:1066 print(e, e.__traceback__.tb_lineno)1067 return None1068 @property1069 def min(self):1070 try:1071 return self.element.get_attribute("min")1072 except Exception as e:1073 print(e, e.__traceback__.tb_lineno)1074 return None1075 @property1076 def multiple(self):1077 try:1078 return self.element.get_attribute("multiple")1079 except Exception as e:1080 print(e, e.__traceback__.tb_lineno)1081 return None1082 @property1083 def pattern(self):1084 try:1085 return self.element.get_attribute("pattern")1086 except Exception as e:1087 print(e, e.__traceback__.tb_lineno)1088 return None1089 @property1090 def placeholder(self):1091 try:1092 return self.element.get_attribute("placeholder")1093 except Exception as e:1094 print(e, e.__traceback__.tb_lineno)1095 return None1096 @property1097 def readonly(self):1098 try:1099 return self.element.get_attribute("readonly")1100 except Exception as e:1101 print(e, e.__traceback__.tb_lineno)1102 return None1103 @property1104 def required(self):1105 try:1106 return self.element.get_attribute("required")1107 except Exception as e:1108 print(e, e.__traceback__.tb_lineno)1109 return None1110 @property1111 def step(self):1112 try:1113 return self.element.get_attribute("step")1114 except Exception as e:1115 print(e, e.__traceback__.tb_lineno)1116 return None1117 @property1118 def challenge(self):1119 try:1120 return self.element.get_attribute("challenge")1121 except Exception as e:1122 print(e, e.__traceback__.tb_lineno)1123 return None1124 @property1125 def keytype(self):1126 try:1127 return self.element.get_attribute("keytype")1128 except Exception as e:1129 print(e, e.__traceback__.tb_lineno)1130 return None1131 @property1132 def attr_for(self):1133 try:1134 return self.element.get_attribute("for")1135 except Exception as e:1136 print(e, e.__traceback__.tb_lineno)1137 return None1138 @property1139 def default(self):1140 try:1141 return self.element.get_attribute("default")1142 except Exception as e:1143 print(e, e.__traceback__.tb_lineno)1144 return None1145 @property1146 def content(self):1147 try:1148 return self.element.get_attribute("content")1149 except Exception as e:1150 print(e, e.__traceback__.tb_lineno)1151 return None1152 @property1153 def http_equiv(self):1154 try:1155 return self.element.get_attribute("http-equiv")1156 except Exception as e:1157 print(e, e.__traceback__.tb_lineno)1158 return None1159 @property1160 def scheme(self):1161 try:1162 return self.element.get_attribute("scheme")1163 except Exception as e:1164 print(e, e.__traceback__.tb_lineno)1165 return None1166 @property1167 def low(self):1168 try:1169 return self.element.get_attribute("low")1170 except Exception as e:1171 print(e, e.__traceback__.tb_lineno)1172 return None1173 @property1174 def high(self):1175 try:1176 return self.element.get_attribute("high")1177 except Exception as e:1178 print(e, e.__traceback__.tb_lineno)1179 return None1180 @property1181 def optimum(self):1182 try:1183 return self.element.get_attribute("optimum")1184 except Exception as e:1185 print(e, e.__traceback__.tb_lineno)1186 return None1187 @property1188 def classid(self):1189 try:1190 return self.element.get_attribute("classid")1191 except Exception as e:1192 print(e, e.__traceback__.tb_lineno)1193 return None1194 @property1195 def codetype(self):1196 try:1197 return self.element.get_attribute("codetype")1198 except Exception as e:1199 print(e, e.__traceback__.tb_lineno)1200 return None1201 @property1202 def data(self):1203 try:1204 return self.element.get_attribute("data")1205 except Exception as e:1206 print(e, e.__traceback__.tb_lineno)1207 return None1208 @property1209 def declare(self):1210 try:1211 return self.element.get_attribute("declare")1212 except Exception as e:1213 print(e, e.__traceback__.tb_lineno)1214 return None1215 @property1216 def standby(self):1217 try:1218 return self.element.get_attribute("standby")1219 except Exception as e:1220 print(e, e.__traceback__.tb_lineno)1221 return None1222 @property1223 def reversed(self):1224 try:1225 return self.element.get_attribute("reversed")1226 except Exception as e:1227 print(e, e.__traceback__.tb_lineno)1228 return None1229 @property1230 def start(self):1231 try:1232 return self.element.get_attribute("start")1233 except Exception as e:1234 print(e, e.__traceback__.tb_lineno)1235 return None1236 @property1237 def selected(self):1238 try:1239 return self.element.get_attribute("selected")1240 except Exception as e:1241 print(e, e.__traceback__.tb_lineno)1242 return None1243 @property1244 def valuetype(self):1245 try:1246 return self.element.get_attribute("valuetype")1247 except Exception as e:1248 print(e, e.__traceback__.tb_lineno)1249 return None1250 @property1251 def attr_async(self):1252 try:1253 return self.element.get_attribute("async")1254 except Exception as e:1255 print(e, e.__traceback__.tb_lineno)1256 return None1257 @property1258 def defer(self):1259 try:1260 return self.element.get_attribute("defer")1261 except Exception as e:1262 print(e, e.__traceback__.tb_lineno)1263 return None1264 @property1265 def language(self):1266 try:1267 return self.element.get_attribute("language")1268 except Exception as e:1269 print(e, e.__traceback__.tb_lineno)1270 return None1271 @property1272 def rules(self):1273 try:1274 return self.element.get_attribute("rules")1275 except Exception as e:1276 print(e, e.__traceback__.tb_lineno)1277 return None1278 @property1279 def summary(self):1280 try:1281 return self.element.get_attribute("summary")1282 except Exception as e:1283 print(e, e.__traceback__.tb_lineno)1284 return None1285 @property1286 def abbr(self):1287 try:1288 return self.element.get_attribute("abbr")1289 except Exception as e:1290 print(e, e.__traceback__.tb_lineno)1291 return None1292 @property1293 def axis(self):1294 try:1295 return self.element.get_attribute("axis")1296 except Exception as e:1297 print(e, e.__traceback__.tb_lineno)1298 return None1299 @property1300 def nowrap(self):1301 try:1302 return self.element.get_attribute("nowrap")1303 except Exception as e:1304 print(e, e.__traceback__.tb_lineno)1305 return None1306 @property1307 def scope(self):1308 try:1309 return self.element.get_attribute("scope")1310 except Exception as e:1311 print(e, e.__traceback__.tb_lineno)1312 return None1313 @property1314 def wrap(self):1315 try:1316 return self.element.get_attribute("wrap")1317 except Exception as e:1318 print(e, e.__traceback__.tb_lineno)1319 return None1320 @property1321 def pubdate(self):1322 try:1323 return self.element.get_attribute("pubdate")1324 except Exception as e:1325 print(e, e.__traceback__.tb_lineno)1326 return None1327 @property1328 def kind(self):1329 try:1330 return self.element.get_attribute("kind")1331 except Exception as e:1332 print(e, e.__traceback__.tb_lineno)1333 return None1334 @property1335 def srclang(self):1336 try:1337 return self.element.get_attribute("srclang")1338 except Exception as e:1339 print(e, e.__traceback__.tb_lineno)1340 return None1341 @property1342 def poster(self):1343 try:1344 return self.element.get_attribute("poster")1345 except Exception as e:1346 print(e, e.__traceback__.tb_lineno)...

Full Screen

Full Screen

compaign.py

Source:compaign.py Github

copy

Full Screen

1from aiohttp import ClientSession2import asyncio3from db_utils import *4import os, sys5from aiogram import Bot67import logging8logging.basicConfig(filename="/compaign/log.txt", level=logging.ERROR)910from dotenv import load_dotenv11load_dotenv('/compaign/main_config/.env')1213import json1415def get_filename(s):1617 p1 = s.rfind('/')18 if p1 == -1:19 return 'file'2021 s_ = s[p1 + 1:]2223 p2 = s_.rfind('_')24 if p2 == -1:25 return 'file'2627 return s_[p2 + 1:]282930def find_screen(screen_id, data):3132 try:3334 for column in data:35 for screen in column:36 if screen['id'] == screen_id:37 return screen38 return None3940 except Exception as e:4142 exc_type, exc_obj, exc_tb = sys.exc_info()43 print("sys.exc_info() : ", sys.exc_info())44 fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]45 print(exc_type, fname, exc_tb.tb_lineno)46 print(str(e))47 logging.error("find_screen {} {} {} \n {}".format(exc_type, fname, exc_tb.tb_lineno, str(e)))484950def find_menu_element_in_screen(screen):5152 try:5354 for element in screen['elements']:55 if element['type'] == 'menu':56 return element57 return None5859 except Exception as e:60 exc_type, exc_obj, exc_tb = sys.exc_info()61 print("sys.exc_info() : ", sys.exc_info())62 fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]63 print(exc_type, fname, exc_tb.tb_lineno)64 print(str(e))65 logging.error("find_menu_element_in_screen {} {} {} \n {}".format(exc_type, fname, exc_tb.tb_lineno, str(e)))666768async def send_text_message(api_key, api_url, chat_id, text):6970 try:7172 async with ClientSession() as session:73 url = f"{api_url}/sendMessage?token={api_key}"74 data = {"chatId": chat_id,75 "body": text}76 async with session.post(url, data=data) as resp:77 pass78 #print(resp.status)79 #print(await resp.text())8081 except Exception as e:82 exc_type, exc_obj, exc_tb = sys.exc_info()83 print("sys.exc_info() : ", sys.exc_info())84 fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]85 print(exc_type, fname, exc_tb.tb_lineno)86 print(str(e))87 logging.error("send_text_message {} {} {} \n {}".format(exc_type, fname, exc_tb.tb_lineno, str(e)))888990async def send_file_message(api_key, api_url, chat_id, file_url, filename):9192 try:9394 async with ClientSession() as session:95 url = f"{api_url}/sendFile?token={api_key}"96 data = {"chatId": chat_id,97 "body": file_url,98 "filename": filename}99 async with session.post(url, data=data) as resp:100 pass101 #print(resp.status)102 #print(await resp.text())103104 except Exception as e:105 exc_type, exc_obj, exc_tb = sys.exc_info()106 print("sys.exc_info() : ", sys.exc_info())107 fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]108 print(exc_type, fname, exc_tb.tb_lineno)109 print(str(e))110 logging.error("send_file_message {} {} {} \n {}".format(exc_type, fname, exc_tb.tb_lineno, str(e)))111112113async def check_podpiska():114 while True:115116 try:117118 bots = await get_old_podpiska_bots()119120 for bot in bots:121 await update_bot(bot['id'], podpiska_do=None)122123 except Exception as e:124125 exc_type, exc_obj, exc_tb = sys.exc_info()126 print("sys.exc_info() : ", sys.exc_info())127 fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]128 print(exc_type, fname, exc_tb.tb_lineno)129 print(str(e))130 logging.error("check_podpiska {} {} {} \n {}".format(exc_type, fname, exc_tb.tb_lineno, str(e)))131132 await asyncio.sleep(60)133134135async def check_compaign():136 while True:137138 try:139140 print('check_compaign')141 compaign = await new_compaign()142 if compaign:143 bot = await get_bot(compaign['bot_id'])144 asyncio.ensure_future(make_compaign(bot, compaign))145146 except Exception as e:147148 exc_type, exc_obj, exc_tb = sys.exc_info()149 print("sys.exc_info() : ", sys.exc_info())150 fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]151 print(exc_type, fname, exc_tb.tb_lineno)152 print(str(e))153 logging.error("check_compaign {} {} {} \n {}".format(exc_type, fname, exc_tb.tb_lineno, str(e)))154155 await asyncio.sleep(20)156157158async def make_compaign(bot, compaign):159 print('make_compaign')160161 try:162163 # c = await get_compaign(compaign['id'])164 # if not c:165 # return166167 await update_compaign(compaign['id'], status='in_progress')168169 users = await get_users(bot)170171 tg_bot = Bot(token=bot['token'])172173 for user in users:174175 print(str(user["chat_id"]) + 'send')176 #if user["chat_id"] == "380635275370@c.us":177 await send_message(tg_bot, user, compaign)178179 # await asyncio.sleep(sleep_sec)180181 await update_compaign(compaign['id'], status='success', is_done=True)182183 except Exception as e:184185 await update_compaign(compaign['id'], status='error')186187 exc_type, exc_obj, exc_tb = sys.exc_info()188 print("sys.exc_info() : ", sys.exc_info())189 fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]190 print(exc_type, fname, exc_tb.tb_lineno)191 print(str(e))192 logging.error("make_compaign {} {} {} \n {}".format(exc_type, fname, exc_tb.tb_lineno, str(e)))193194195async def send_message(bot, user, compaign):196 print('send_message')197 try:198199 if compaign['photo']:200 file_url = f"https://inbot24.ru/media/{compaign['photo']}"201 await bot.send_photo(user['chat_id'], file_url)202203 if compaign['video']:204 file_url = f"https://inbot24.ru/media/{compaign['video']}"205 await bot.send_video(user['chat_id'], file_url)206207 if compaign['text']:208 await bot.send_message(user['chat_id'], compaign['text'])209210 except Exception as e:211212 exc_type, exc_obj, exc_tb = sys.exc_info()213 print("sys.exc_info() : ", sys.exc_info())214 fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]215 print(exc_type, fname, exc_tb.tb_lineno)216 print(str(e))217 logging.error("compaign send_message {} {} {} \n {}".format(exc_type, fname, exc_tb.tb_lineno, str(e)))218219try:220221 loop = asyncio.get_event_loop()222 loop.run_until_complete(init_db())223224 asyncio.ensure_future(check_compaign(), loop=loop)225 asyncio.ensure_future(check_podpiska(), loop=loop)226227 loop.run_forever()228229except KeyboardInterrupt:230 pass231finally:232 loop.stop() ...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Slash automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful