def naget(): natype = request.args.get('natype') message = {} try: start_val, start_unit = si_format(float(NA[natype].linfreq( nabench[natype])[1]['START']), precision=1).split(" ") stop_val, stop_unit = si_format(float(NA[natype].linfreq( nabench[natype])[1]['STOP']), precision=1).split(" ") stop_conversion = si_parse("1%s" % stop_unit) / si_parse( "1%s" % start_unit) # equalizing both unit-range: message['start-frequency'] = "%s %sHz" % (start_val, start_unit ) # start-frequency message['stop-frequency'] = "%s %sHz" % ( float(stop_val) * stop_conversion, start_unit) # stop-frequency message['step-points'] = int(NA[natype].sweep( nabench[natype])[1]['POINTS']) - 1 # step-points in waveform message['power'] = "%.1f dBm" % float(NA[natype].power( nabench[natype])[1]['LEVEL']) # power (fixed unit) message['ifb'] = si_format( float(NA[natype].ifbw(nabench[natype])[1]['BANDWIDTH']), precision=0) + "Hz" # ifb (adjusted by si_prefix) message['s21'] = int('S21' in NA[natype].getrace(nabench[natype])) except: # raise message = dict(status='%s is not connected' % natype) return jsonify(message=message)
def nasetfreqrange(): natype = request.args.get('natype') freqrange = waveform(request.args.get('freqrange')) frequnit = request.args.get('frequnit').replace("Hz","") NA[natype].sweep(nabench[natype], action=['Set', 'ON', freqrange.count]) fstart, fstop = si_parse(str(freqrange.data[0])+frequnit), si_parse(str(freqrange.data[-1])+frequnit) NA[natype].sweep(nabench[natype], action=['Set', 'ON', freqrange.count]) NA[natype].linfreq(nabench[natype], action=['Set', fstart, fstop]) message = 'frequency: %s to %s' %(fstart, fstop) return jsonify(message=message)
def resistance(self, r): if type(r) is str: self._resistance = si_parse(r) else: if r < 0: raise ValueError('Invalid value provided for resistance') self._resistance = r
def unit_converter(unit_added_string: str) -> float: """ convert unit formatted strings to floating numbers without any units Arguments: :param unit_added_string: the unit added number we want to convert to be unit free Returns:: :return unit_in_float: the same number but in float without the units Raises:: :raise TypeError: if trying to parse an unknown unit type """ custom_unit_ratio = { "Ki": 1024, "Mi": 1024 * 1024, "Gi": 1024 * 1024 * 1024 } try: unit_in_float = float(si_parse(unit_added_string)) except AttributeError: if unit_added_string[-2:] in custom_unit_ratio: unit_in_float = float(unit_added_string[:-2]) * custom_unit_ratio[unit_added_string[-2:]] else: raise TypeError return unit_in_float
def nasetifb(): natype = request.args.get('natype') ifb = request.args.get('ifb') ifbunit = request.args.get('ifbunit').replace("Hz","") stat = NA[natype].ifbw(nabench[natype], action=['Set', si_parse(ifb + ifbunit)]) message = 'ifb: %s <%s>' %(stat[1], stat[0]) return jsonify(message=message)
async def change_frequency(self, frequency, params): try: print("FREQ", frequency) frequency = si_parse(_.replace(frequency, "Hz", "")) await self.put_frequency({"frequency": frequency}, params) await self.update_board_info() except Exception as e: print("Error setting frequency") print(e)
async def change_voltage(self, voltage, params): try: print("CHANGING :) VOLTAGE!!!") # Convert payload from si_unit string to number print("CALLING PSI PARSE:", voltage) voltage = si_parse(_.replace(voltage, "V", "")) print("ITS NOW: ", voltage) await self.put_voltage({"voltage": voltage}, {}) await self.update_board_info() except Exception as e: print("Error setting voltage") print(e)
def get_alloc_sizes(objdata): sizes = [] with open(objdata, 'r') as f: for line in f: line = line.strip() if line.startswith('<'): continue fields = re.split(' *\( *| *\) *| +', line) sz_w_sfx = fields[2] + fields[3] size = si_parse(sz_w_sfx[0:-1]) sizes.append(size) return sizes
def on_edited_dataframe_sync(cell_renderer, itr, new_value, column, df_py_dtypes, list_store, df_data): """ Handle the `'edited'` signal from a `Gtk.CellRenderer` to: * Update the corresponding entry in the list store. * Update the corresponding entry in the provided data frame instance. The callback can be connected to the cell renderer as follows: cell_renderer.connect('edited', on_edited_dataframe_sync, column, list_store, df_py_dtypes, df_data) where `column` is the `Gtk.TreeViewColumn` the cell renderer belongs to, and `df_py_dtypes` and `list_store` are the return values from calling `get_list_store` on the `df_data` data frame. Args: cell_renderer (Gtk.CellRenderer) iter (str) : Gtk TreeView iterator new_value (str) : New value resulting from edit operation. column (Gtk.TreeViewColumn) : Column containing edited cell. df_py_dtypes (pandas.DataFrame) : Data frame containing type information for columns in tree view (and `list_store`). list_store (Gtk.ListStore) : Model containing data bound to tree view. df_data (pandas.DataFrame) : Data frame containing data in `list_store`. Returns: None """ # Extract name of column (name of TreeView column must match data frame # column name). column_name = column.get_name() # Look up the list store column index and data type for column. i, dtype = df_py_dtypes.ix[column_name] # Update the list store with the new value. if dtype == float: value = si_parse(new_value) elif dtype == bool: value = not list_store[itr][i] if value == list_store[itr][i]: # Value has not changed. return False list_store[itr][i] = value # Update the data frame with the new value. df_data[column_name].values[int(itr)] = value return True
def on_edited_dataframe_sync(cell_renderer, iter, new_value, column, df_py_dtypes, list_store, df_data): ''' Handle the `'edited'` signal from a `gtk.CellRenderer` to: * Update the corresponding entry in the list store. * Update the corresponding entry in the provided data frame instance. The callback can be connected to the cell renderer as follows: cell_renderer.connect('edited', on_edited_dataframe_sync, column, list_store, df_py_dtypes, df_data) where `column` is the `gtk.TreeViewColumn` the cell renderer belongs to, and `df_py_dtypes` and `list_store` are the return values from calling `get_list_store` on the `df_data` data frame. Args: cell_renderer (gtk.CellRenderer) iter (str) : Gtk TreeView iterator new_value (str) : New value resulting from edit operation. column (gtk.TreeViewColumn) : Column containing edited cell. df_py_dtypes (pandas.DataFrame) : Data frame containing type information for columns in tree view (and `list_store`). list_store (gtk.ListStore) : Model containing data bound to tree view. df_data (pandas.DataFrame) : Data frame containing data in `list_store`. Returns: None ''' # Extract name of column (name of TreeView column must match data frame # column name). column_name = column.get_name() # Look up the list store column index and data type for column. i, dtype = df_py_dtypes.ix[column_name] # Update the list store with the new value. if dtype == float: value = si_parse(new_value) elif dtype == bool: value = not list_store[iter][i] if value == list_store[iter][i]: # Value has not changed. return False list_store[iter][i] = value # Update the data frame with the new value. df_data[column_name].values[int(iter)] = value return True
def process_query(self, query): # Try to infer and convert numerical shorthands to machine understandable format, e.g. 100M = 100*1,000,000 parsed_tokens = [] for token in word_tokenize(query): try: parsed_tokens.append(str(int(si_parse(token)))) except Exception as e: parsed_tokens.append(token) # Convert to lowercase query_lower = ' '.join(parsed_tokens).lower() return query_lower
def process_query(self, query): # Try to infer and convert numerical shorthands to machine understandable format, e.g. 100M = 100*1,000,000 parsed_tokens = [] for token in word_tokenize(query): try: parsed_tokens.append(str(int(si_parse(token)))) except Exception as e: parsed_tokens.append(token) # Clean sentence of non-alphanumerical characters query_processed = re.sub(r'[^A-Za-z0-9]+', ' ', ' '.join(parsed_tokens)) # Convert to lowercase query_lower = query_processed.lower() return query_lower