How to use exclude_elements method in toolium

Best Python code snippet using toolium_python

laser_ranging.py

Source:laser_ranging.py Github

copy

Full Screen

1#!/usr/bin/python32# laser_ranging.py3"""Constraints on the stochastic GW background from laser ranging."""4__author__ = ("Alexander C. Jenkins",)5__contact__ = ("alexander.jenkins@kcl.ac.uk",)6__version__ = "0.1"7__date__ = "2021/07"8import numpy as np9from scipy.optimize import root_scalar10from scipy.stats import chi211from gwresonance import Binary, gamma, sma_from_per, v_rms, AU, NMAX12#-----------------------------------------------------------------------------#13def fisher(x,14 t_obs,15 n_obs,16 sigma=3.e-3,17 m1=3.00345e-06,18 m2=3.69223e-08,19 ):20 """Laser-ranging Fisher matrix for measuring orbital elements.21 Parameters22 ----------23 x : array_like, shape (6,)24 Orbital elements of the binary.25 t_obs : float26 Observation period over which each measurement of the binary27 orbital elements is performed, in seconds.28 n_obs : float29 Mean number of normal point observations recorded per30 observation period.31 sigma : float, optional32 RMS distance noise for each normal point, in metres. Default is33 3mm.34 m1 : float, optional35 Mass of the primary body in solar units. Default is the Earth's36 mass.37 m2 : float, optional38 Mass of the secondary body in solar units. Default is the39 Moon's mass.40 Returns41 -------42 array, shape (6,6)43 Fisher matrix for the orbital elements.44 """45 out = np.zeros((6, 6))46 (per, ecc, inc, asc, arg, eps) = x47 if ecc == None:48 out[0, 0] = 4. / 9. / per**2.49 else:50 g = gamma(ecc)51 out[0, 0] = (4. / 9. / per**2. * (1. + 3.*ecc + 27./16.*ecc**2.52 + 4.*ecc**3. + 315./256.*ecc**4.)53 + 2. / 3. * (np.pi * ecc * t_obs)**2. / per**4.54 * (1. + 0.25*ecc**2.))55 out[0, 1] = 0.75 / per * ecc * (1. + 8./9.*ecc + 5./8.*ecc**2.56 + 8./45.*ecc**3.)57 out[1, 0] = out[0, 1]58 out[1, 1] = 2. - g - (1. - g) / ecc**2.59 out[5, 5] = 1. - g60 return out * n_obs * (sma_from_per(per, m1+m2) * AU / sigma) ** 2.61def likelihood_ratio(sgwb,62 x_init,63 times,64 t_obs,65 n_obs,66 sigma=3.e-3,67 m1=3.00345e-06,68 m2=3.69223e-08,69 exclude_elements=None,70 ):71 """Calculate the likelihood ratio statistic for a binary pulsar.72 Parameters73 ----------74 sgwb : float or function75 SGWB energy density spectrum. If ``sgwb'' is a float, the76 spectrum is assumed to be scale-invariant.77 x_init : array_like, shape (6,)78 Initial orbital elements of the binary.79 times : array_like80 Array of times at which the binary orbital elements are81 measured, in seconds.82 t_obs : float83 Observation period over which each measurement of the binary84 orbital elements is performed, in seconds.85 n_obs : float86 Mean number of normal point observations recorded per87 observation period.88 sigma : float, optional89 RMS distance noise for each normal point, in metres. Default is90 3mm.91 m1 : float, optional92 Mass of the primary body in solar units. Default is the Earth's93 mass.94 m2 : float, optional95 Mass of the secondary body in solar units. Default is the96 Moon's mass.97 exclude_elements : array_like, shape (6,), optional98 Exclude orbital elements from the calculation by setting the99 corresponding elements of this array to ``False'', and the100 rest to ``True''. Default depends on the value of ``low_ecc''.101 Returns102 -------103 float104 Value of the maximum likelihood ratio statistic.105 """106 b = Binary(sgwb,107 x_init,108 m1=m1,109 m2=m2,110 )111 b.evolve(times[-1],112 t_eval=times)113 out = 0.114 if exclude_elements is None:115 exclude_elements = np.array([True]*2 +[False]*2 +[True] +[False])116 ex = exclude_elements117 for t in times:118 x0 = b.x0[b.t == t][0]119 dx = b.dx[b.t == t][0][ex]120 cov = b.cov[b.t == t][0][:,ex][ex,:]121 fish = fisher(x0, t_obs, n_obs, sigma=sigma, m1=m1, m2=m2)[:,ex][ex,:]122 out += np.linalg.multi_dot([dx, fish, dx])123 out += np.dot(fish, cov).trace()124 (s, logdet) = np.linalg.slogdet(np.eye(len(dx)) + np.dot(fish, cov))125 out -= s * logdet126 return out127def power_law_ul(alpha,128 f_ref,129 x_init,130 times,131 t_obs,132 n_obs,133 sigma=3.e-3,134 m1=3.00345e-06,135 m2=3.69223e-08,136 confidence=0.95,137 exclude_elements=None,138 bracket=(-20., +20.),139 ):140 r"""Calculate a pulsar-timing upper limit on a power-law SGWB.141 Outputs a forecast upper limit on :math:`\Omega_\mathrm{ref}`,142 where the SGWB spectrum is given by143 .. math::144 \Omega_\mathrm{gw}(f)145 = \Omega_\mathrm{ref} (f / f_\mathrm{ref})^\alpha.146 Parameters147 ----------148 alpha : float149 SGWB power-law index.150 f_ref : float151 SGWB reference frequency at which the upper limit is computed.152 x_init : array_like, shape (6,) or (N, 6)153 Initial orbital elements of the binary.154 times : array_like155 Array of times at which the binary orbital elements are156 measured, in seconds.157 t_obs : float158 Observation period over which each measurement of the binary159 orbital elements is performed, in seconds.160 n_obs : float161 Mean number of normal point observations recorded per162 observation period.163 sigma : float, optional164 RMS distance noise for each normal point, in metres. Default is165 3mm.166 m1 : float, optional167 Mass of the primary body in solar units. Default is the Earth's168 mass.169 m2 : float, optional170 Mass of the secondary body in solar units. Default is the171 Moon's mass.172 confidence : float, optional173 Set the p-value of the upper limit.174 exclude_elements : array_like, shape (6,), optional175 Exclude orbital elements from the calculation by setting the176 corresponding elements of this array to ``False'', and the177 rest to ``True''.178 bracket : array_like, shape (2,), optional179 Bracket for the root-finding algorithm. The entries should be180 estimated maximum and minimum values of181 :math:`log_{10}\Omega_\mathrm{ref}`.182 Returns183 -------184 float185 Upper limit on :math:`\Omega_\mathrm{ref}`.186 """187 chi2_crit = chi2.ppf(confidence, 1)188 func = (lambda logohm:189 likelihood_ratio(lambda f: 10.**logohm * (f/f_ref)**alpha,190 x_init, times, t_obs, n_obs, sigma=sigma,191 m1=m1, m2=m2, exclude_elements=exclude_elements)192 - chi2_crit)193 if func(bracket[1]) < 0.:194 print("Warning: upper limit lies above bracket.")195 return 10. ** bracket[1]196 elif func(bracket[0]) > 0.:197 print("Warning: upper limit lies below bracket.")198 return 10. ** bracket[0]199 else:200 sol = root_scalar(func,201 method="brentq",202 bracket=bracket,203 )204 return 10. ** sol.root205def pi_curve(freqs,206 x_init,207 times,208 t_obs,209 n_obs,210 sigma=3.e-3,211 m1=3.00345e-06,212 m2=3.69223e-08,213 confidence=0.95,214 alphas=None,215 exclude_elements=None,216 bracket=(-20., +20.),217 verbose=False,218 ):219 """Calculate a binary pulsar's SGWB sensitivity curve.220 Returns the power-law integrated (PI) curve, as defined in [1]_.221 Parameters222 ----------223 freqs : array_like of floats224 Frequencies at which the sensitivity should be computed.225 x_init : array_like, shape (6,) or (N, 6)226 Initial orbital elements of the binary.227 times : array_like228 Array of times at which the binary orbital elements are229 measured, in seconds.230 t_obs : float231 Observation period over which each measurement of the binary232 orbital elements is performed, in seconds.233 n_obs : float234 Mean number of normal point observations recorded per235 observation period.236 sigma : float, optional237 RMS distance noise for each normal point, in metres. Default is238 3mm.239 m1 : float, optional240 Mass of the primary body in solar units. Default is the Earth's241 mass.242 m2 : float, optional243 Mass of the secondary body in solar units. Default is the244 Moon's mass.245 confidence : float, optional246 Set the p-value of the upper limit.247 alphas : array_like of floats, optional248 Set of power-law indices which should be used to construct the249 sensitivity curve.250 exclude_elements : array_like, shape (6,), optional251 Exclude orbital elements from the calculation by setting the252 corresponding elements of this array to ``False'', and the253 rest to ``True''.254 bracket : array_like, shape (2,), optional255 Bracket for the root-finding algorithm. The entries should be256 estimated maximum and minimum values of257 :math:`log_{10}\Omega_\mathrm{ref}`.258 verbose : bool, optional259 Control the level of output.260 Returns261 -------262 array of floats263 The value of the sensitivity curve at each of the frequencies264 in ``freqs''.265 References266 ----------267 .. [1] Eric Thrane and Joseph D. Romano, "Sensitivity curves for268 searches for gravitational-wave backgrounds," Phys. Rev. D 88,269 124032 (2013).270 """271 if alphas is None:272 alphas = np.linspace(-10., 10., 81)273 nf = len(freqs)274 na = len(alphas)275 curves = np.zeros((nf, na))276 x_init = np.array(x_init)277 f_ref = 1. / x_init[0]278 if verbose:279 print("Calculating PI curve...")280 for i, alpha in enumerate(alphas):281 if verbose:282 print("alpha = "+str(alpha))283 ul = power_law_ul(alpha, f_ref, x_init, times, t_obs, n_obs,284 sigma=sigma, m1=m1, m2=m2, confidence=confidence,285 exclude_elements=exclude_elements, bracket=bracket)286 curves[:, i] = ul * (freqs / f_ref) ** alpha287 return np.max(curves, -1)288def comb_ul(x_init,289 times,290 t_obs,291 n_obs,292 sigma=3.e-3,293 m1=3.00345e-06,294 m2=3.69223e-08,295 confidence=0.95,296 alphas=None,297 exclude_elements=None,298 bracket=(-20., +20.),299 verbose=False,300 ):301 """Calculate a binary pulsar's SGWB sensitivity at each harmonic.302 Returns the SGWB upper limit corresponding to the discrete set of303 frequencies ``[f0, 2*f0, 3*f0, ..., nmax*f0]'', where ``f0'' is the304 base frequency (inverse of the binary period), and ``nmax'' is the305 maximum harmonic (usually 20, but may be less for short periods).306 Parameters307 ----------308 x_init : array_like, shape (6,)309 Initial orbital elements of the binary.310 times : array_like311 Array of times at which the binary orbital elements are312 measured, in seconds.313 t_obs : float314 Observation period over which each measurement of the binary315 orbital elements is performed, in seconds.316 n_obs : float317 Mean number of normal point observations recorded per318 observation period.319 sigma : float, optional320 RMS distance noise for each normal point, in metres. Default is321 3mm.322 m1 : float, optional323 Mass of the primary body in solar units. Default is the Earth's324 mass.325 m2 : float, optional326 Mass of the secondary body in solar units. Default is the327 Moon's mass.328 confidence : float, optional329 Set the p-value of the upper limit.330 alphas : array_like of floats, optional331 Set of power-law indices which should be used to construct the332 sensitivity curve.333 exclude_elements : array_like, shape (6,), optional334 Exclude orbital elements from the calculation by setting the335 corresponding elements of this array to ``False'', and the336 rest to ``True''.337 bracket : array_like, shape (2,), optional338 Bracket for the root-finding algorithm. The entries should be339 estimated maximum and minimum values of340 :math:`log_{10}\Omega_\mathrm{ref}`.341 verbose : bool, optional342 Control the level of output.343 Returns344 -------345 array of floats346 The SGWB upper limit at the first few of the binary's harmonic347 frequencies.348 """349 per = x_init[0]350 f0 = 1. / per351 nmax = min(int(np.floor(v_rms(per, m1+m2) ** -1.)), NMAX)352 chi2_crit = chi2.ppf(confidence, 1)353 comb = []354 if verbose:355 print("Calculating comb...")356 for n in range(1, nmax+1):357 if verbose:358 print("Harmonic {} of {}".format(n, nmax))359 func = (lambda logohm:360 likelihood_ratio(lambda f: 10.**logohm361 * np.heaviside(0.1*f0 - abs(f-n*f0), 0.),362 x_init, times, t_obs, n_obs, sigma=sigma,363 m1=m1, m2=m2, exclude_elements=exclude_elements)364 - chi2_crit)365 if func(bracket[1]) < 0.:366 print("Warning: upper limit lies above bracket.")367 comb.append(10. ** bracket[1])368 elif func(bracket[0]) > 0.:369 print("Warning: upper limit lies below bracket.")370 comb.append(10. ** bracket[0])371 else:372 sol = root_scalar(func,373 method="brentq",374 bracket=bracket,375 )376 comb.append(10. ** sol.root)377 return np.array(comb)...

Full Screen

Full Screen

config.py

Source:config.py Github

copy

Full Screen

1from common.configuration_loader import *2from logic_actions import logic_actions_camera3from logic_actions import logic_actions_dns4from logic_actions import logic_actions_elk5from logic_actions import logic_actions_filebeat6from logic_actions import logic_actions_ldap7from logic_actions import logic_actions_mail8from logic_actions import logic_actions_proxy9from logic_actions import logic_actions_rsyslog10from logic_actions import logic_actions_samba11from logic_actions import logic_actions_security12from logic_actions import logic_actions_vpn13from logic_actions import logic_actions_web14from logic_actions import logic_actions_utils15import os16current_path = os.path.dirname(os.path.abspath(__file__))17# Software version18version_file = os.path.join(current_path, "..", "version.ini")19# Workstations functions20workstations_file = os.path.join(current_path, "workstations", "common.ini")21exclude_elements = ["Fore", "Style", "__builtins__", "__cached__", "__doc__", "__file__", "__loader__", "__name__",22 "__package__", "__spec__", "Optional", "time", "os", "cv2", "time", "json", "random", "hashlib",23 "subprocess", "crypto"]24class Config:25 @staticmethod26 def get_version():27 return parse_value(version_file, "SI_simulator", "version")28 @staticmethod29 def get_camera_methods():30 return [f for f in dir(logic_actions_camera) if f not in exclude_elements]31 @staticmethod32 def get_dns_methods():33 return [f for f in dir(logic_actions_dns) if f not in exclude_elements]34 @staticmethod35 def get_elk_methods():36 return [f for f in dir(logic_actions_elk) if f not in exclude_elements]37 @staticmethod38 def get_filebeat_methods():39 return [f for f in dir(logic_actions_filebeat) if f not in exclude_elements]40 @staticmethod41 def get_ldap_methods():42 return [f for f in dir(logic_actions_ldap) if f not in exclude_elements]43 @staticmethod44 def get_mail_methods():45 return [f for f in dir(logic_actions_mail) if f not in exclude_elements]46 @staticmethod47 def get_proxy_methods():48 return [f for f in dir(logic_actions_proxy) if f not in exclude_elements]49 @staticmethod50 def get_rsyslog_methods():51 return [f for f in dir(logic_actions_rsyslog) if f not in exclude_elements]52 @staticmethod53 def get_samba_methods():54 return [f for f in dir(logic_actions_samba) if f not in exclude_elements]55 @staticmethod56 def get_security_methods():57 return [f for f in dir(logic_actions_security) if f not in exclude_elements]58 @staticmethod59 def get_utils_methods():60 return [f for f in dir(logic_actions_utils) if f not in exclude_elements]61 @staticmethod62 def get_vpn_methods():63 return [f for f in dir(logic_actions_vpn) if f not in exclude_elements]64 @staticmethod65 def get_web_methods():66 return [f for f in dir(logic_actions_web) if f not in exclude_elements]67 @staticmethod68 def get_workstations_methods():69 return parse_values_list(workstations_file, "FUNCTIONS", "common")70 @staticmethod71 def get_available_workstations():72 return parse_values_list(workstations_file, "SIMULATION", "workstations")73 @staticmethod74 def get_authorized_values(arg):75 values = []76 if arg in authorized_args.keys():77 values = authorized_args[arg]78 return values79def compare_d_lists(first_list, second_list):80 # Arguments are lists of dictionaries81 for base in first_list:82 for compared in second_list:83 if base["name"] == compared["name"]:84 base.update(compared)85 continue86 return first_list87# Switch88workstation_methods = {89 "camera": Config.get_camera_methods,90 "dns": Config.get_dns_methods,91 "elk": Config.get_elk_methods,92 "filebeat": Config.get_filebeat_methods, # TODO :add filebeat methods to common93 "ldap": Config.get_ldap_methods,94 "mail": Config.get_mail_methods,95 "proxy": Config.get_proxy_methods,96 "router": Config.get_workstations_methods,97 "rsyslog": Config.get_rsyslog_methods,98 "samba": Config.get_samba_methods,99 "security": Config.get_security_methods,100 "utils": Config.get_utils_methods,101 "vpn": Config.get_vpn_methods,102 "web": Config.get_web_methods,103 "workstation": Config.get_workstations_methods104}105authorized_args = {106 "install": ["module"],107 "execute_command": ["command", "execute_exit_code"],108 "add_nameserver": ["nameserver_ip"],109 "rsyslog_client": ["ip_log_server", "log_files"],110 "install_gnu_social_network": ["server_ip", "domain_name"],111 "download_file": [],112 "generate_root_ca": ["private_key_ca_certificate_name", "bits", "version", "serial", "C", "ST", "L", "O", "CN", "days_validity"],113 "generate_middle_certifications": ["ca_holder", "ca_name", "private_key_middle_certificate_name", "bits", "version", "serial", "C", "ST", "L", "O", "CN", "days_validity"],114 "generate_certificates": ["ca_holder", "ca_name", "middle_holder", "middle_name", "private_key_certificate_name", "bits", "version", "serial", "C", "ST", "L", "O", "CN", "days_validity", "dns"],115 "dns_installation": ["domain_name", "ip_resolution"],116 "dns_resolve_name": ["domain_name", "ip_resolution", "mail", "alias"],117 "ldap_create_domaine": ["root_password", "domaine_name", "domain", "organization", "ip_log_server"],118 "ldap_add_user": ["hostname", "username", "objectClass", "mail", "sn", "dn", "domain", "homeDirectory", "loginShell",119 "password", "uidNumber", "gidNumber"],120 "ldap_client_config": ["ldap_ip", "base", "uri", "ldap_admin"],121 "mail_installation": ["ldap_ip", "ldap_domain", "ldap_dn", "ldap_manager", "ldap_manager_password", "ldap_port", "domain_name", "users_mailbox"],122 "enable_ssl": ["cert_path", "key_path", "ca_dir", "cas_path"],123 "enable_ssl_imapd": ["cert_path", "key_path", "ca_dir", "cas_path"],124 "enable_ssl_postfix": ["cert_path", "key_path", "ca_dir", "cas_path"],125 "create_local_user": ["username", "password"],126 "configure_iptables": ["share_file_name", "comment", "private", "browseable", "writable", "valid_users", "users"],127 "install_samba": [],128 "add_share_file": [],129 "install_virtual_camera": ["video_url", "remote_video_path_file"],130 "install_motion": ["motion_port", "security"],131 "install_zoneminder": [],132 "install_elk": ["logstash", "elasticsearch", "kibana", "fqdn_host", "ip_fqdn", "admin_name", "admin_passwd"],133 "push_sim_user": [],...

Full Screen

Full Screen

schema.py

Source:schema.py Github

copy

Full Screen

1from marshmallow import fields, post_load, pre_dump2from marshmallow_sqlalchemy import SQLAlchemySchema3from api.models import Configurations4class GetConfigSchema(SQLAlchemySchema):5 ip = fields.IP(required=True)6 name = fields.Str(required=True)7class CreateConfigSchema(SQLAlchemySchema):8 class Meta:9 model = Configurations10 load_instance = True11 ip = fields.Str(required=True)12 name = fields.Str(required=True)13 block_iso = fields.Bool(required=True)14 exclude_elements = fields.List(fields.Str, required=True)15 @pre_dump16 def pre_dump(self, data, **kwargs):17 if data is not None and data.exclude_elements:18 data.exclude_elements = [19 element for element in data.exclude_elements.split(",")20 ]21 return data22 @post_load23 def post_load(self, data, **kwargs):24 if data is not None and data.exclude_elements:25 data.exclude_elements = ",".join(data.exclude_elements)...

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 toolium 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