def get_SNR(): fs, signal = scipy.io.wavfile.read( "/home/jonas/CLionProjects/soundLocalizer/dataset/background_test.wav", "wb", ) fs, signal2 = scipy.io.wavfile.read( "/home/jonas/CLionProjects/soundLocalizer/dataset/signal.wav", "wb", ) power_noise = get_power(signal[:, 0]) power_signal = get_power(signal2[:, 0]) SNR = 10 * np.log10((power_signal - power_noise) / power_noise) print(f'SNR is {SNR}')
def get_command_template(self): """ In case the user wants to customize the power management commands, we source the code for each command from /etc/cobbler and run them through Cheetah. """ if self.system.power_type in [ "", "none" ]: utils.die(self.logger,"Power management is not enabled for this system") result = utils.get_power(self.system.power_type) if not result: utils.die(self.logger, "Invalid power management type for this system (%s, %s)" % (self.system.power_type, self.system.name)) return result
def tianbiao_my(person, n): base_row_index = n * 6 r = 0 + base_row_index set_value(r, 2, person['成员姓名']) set_value(r, 5, person['性别']) set_value(r, 8, '汉') set_value(r, 10, get_birth_day(person['身份证号码'])) set_font_size(r, 10, 9) set_value(r, 12, person['文化程度']) r = 1 + base_row_index set_value(r, 2, str(person['身份证号码'])) set_value(r, 8, person['兵役状况']) # 兵役情况 # set_value(r, 10, phone_numbers[person['成员姓名']]) set_value(r, 10, person['联系电话']) set_value(r, 12, person['与户主关系']) r = 2 + base_row_index set_value( r, 2, get_power(person[[ '土地(共有)使用权', '保留型土地使用权', '承包经营权', '集体资产管理权', '集体收益分配权' ]])) set_value(r, 7, get_state(person['存在状态'])) set_align(r, 2, WD_ALIGN_PARAGRAPH.JUSTIFY) set_align(r, 7, WD_ALIGN_PARAGRAPH.LEFT) r = 3 + base_row_index # set_value(r, 7, get_state(person['存在状态'])) set_value(r, 10, person['现住地址']) r = 4 + base_row_index # set_value(r, 2, get_power(person[['土地(共有)使用权', '保留型土地使用权', '承包经营权', '集体资产管理权', '集体收益分配权']])) set_value(r, 10, str(person['户籍号'])) r = 5 + base_row_index set_value(r, 2, person['婚姻状况']) # 婚姻状况
def power(self, desired_state): """ state is either "on" or "off". Rebooting is implemented at the api.py level. The user and password need not be supplied. If not supplied they will be taken from the environment, COBBLER_POWER_USER and COBBLER_POWER_PASS. If provided, these will override any other data and be used instead. Users interested in maximum security should take that route. """ power_command = utils.get_power(self.system.power_type) if not power_command: utils.die(self.logger, "no power type set for system") meta = utils.blender(self.api, False, self.system) meta["power_mode"] = desired_state # allow command line overrides of the username/password if self.force_user is not None: meta["power_user"] = self.force_user if self.force_pass is not None: meta["power_pass"] = self.force_pass self.logger.info("cobbler power configuration is:") self.logger.info(" type : %s" % self.system.power_type) self.logger.info(" address: %s" % self.system.power_address) self.logger.info(" user : %s" % self.system.power_user) self.logger.info(" id : %s" % self.system.power_id) # if no username/password data, check the environment if meta.get("power_user", "") == "": meta["power_user"] = os.environ.get("COBBLER_POWER_USER", "") if meta.get("power_pass", "") == "": meta["power_pass"] = os.environ.get("COBBLER_POWER_PASS", "") template = utils.get_power_template(self.system.power_type) tmp = templar.Templar(self.api._config) template_data = tmp.render(template, meta, None, self.system) # Try the power command 5 times before giving up. # Some power switches are flakey for x in range(0, 5): output, rc = utils.subprocess_sp(self.logger, power_command, shell=False, input=template_data) if rc == 0: # If the desired state is actually a query for the status # return different information than command return code if desired_state == 'status': match = re.match('^(Status:|.+power\s=)\s(on|off)$', output, re.IGNORECASE | re.MULTILINE) if match: power_status = match.groups()[1] if power_status.lower() == 'on': return True else: return False utils.die(self.logger, "command succeeded (rc=%s), but output ('%s') was not understood" % (rc, output)) return None break else: time.sleep(2) if not rc == 0: utils.die(self.logger, "command failed (rc=%s), please validate the physical setup and cobbler config" % rc) return rc
def power(self, desired_state): """ state is either "on" or "off". Rebooting is implemented at the api.py level. The user and password need not be supplied. If not supplied they will be taken from the environment, COBBLER_POWER_USER and COBBLER_POWER_PASS. If provided, these will override any other data and be used instead. Users interested in maximum security should take that route. """ power_command = utils.get_power(self.system.power_type) if not power_command: utils.die(self.logger, "no power type set for system") meta = utils.blender(self.api, False, self.system) meta["power_mode"] = desired_state # allow command line overrides of the username/password if self.force_user is not None: meta["power_user"] = self.force_user if self.force_pass is not None: meta["power_pass"] = self.force_pass self.logger.info("cobbler power configuration is:") self.logger.info(" type : %s" % self.system.power_type) self.logger.info(" address: %s" % self.system.power_address) self.logger.info(" user : %s" % self.system.power_user) self.logger.info(" id : %s" % self.system.power_id) # if no username/password data, check the environment if meta.get("power_user", "") == "": meta["power_user"] = os.environ.get("COBBLER_POWER_USER", "") if meta.get("power_pass", "") == "": meta["power_pass"] = os.environ.get("COBBLER_POWER_PASS", "") template = utils.get_power_template(self.system.power_type) tmp = templar.Templar(self.api._collection_mgr) template_data = tmp.render(template, meta, None, self.system) # Try the power command 5 times before giving up. # Some power switches are flakey for x in range(0, 5): output, rc = utils.subprocess_sp(self.logger, power_command, shell=False, input=template_data) if rc == 0: # If the desired state is actually a query for the status # return different information than command return code if desired_state == 'status': match = re.match('^(Status:|.+power\s=)\s(on|off)$', output, re.IGNORECASE | re.MULTILINE) if match: power_status = match.groups()[1] if power_status.lower() == 'on': return True else: return False error_msg = "command succeeded (rc=%s), but output ('%s') was not understood" % (rc, output) utils.die(self.logger, error_msg) raise CX(error_msg) return None else: time.sleep(2) if not rc == 0: error_msg = "command failed (rc=%s), please validate the physical setup and cobbler config" % rc utils.die(self.logger, error_msg) raise CX(error_msg)
if xx['name'] == 'position_lat': pos_lat = xx['value'] if xx['name'] == 'position_long': pos_long = xx['value'] if xx['name'] == 'altitude': h = xx['value'] if xx['name'] == 'speed': v = xx['value'] if xx['name'] == 'timestamp': t = xx['value'] if xx['name'] == 'distance': cur_dist = xx['value'] if xx['name'] == 'heart_rate': hr = xx['value'] cd = utils.get_cadence(x) pw = utils.get_power(x) if hr is not None and t is not None: th = t hrs.append(hr) cds.append(cd) pws.append(pw) ths.append(th) if v is not None: tv = t if h is not None and t is not None: if v is not None: vs.append(3.6 * v)