code
string
signature
string
docstring
string
loss_without_docstring
float64
loss_with_docstring
float64
factor
float64
if not bool(tax_id) ^ bool(tax_name): msg = 'Exactly one of tax_id and tax_name may be provided.' raise ValueError(msg) if tax_name: tax_id, primary_name, is_primary = self.primary_from_name(tax_name) else: primary_name = None #...
def lineage(self, tax_id=None, tax_name=None)
Public method for returning a lineage; includes tax_name and rank
4.439726
4.432248
1.001687
# TODO: shoud be able to do this inside a transaction if not source_name: raise ValueError('"source_name" may not be None or an empty string') sel = select([self.source.c.id], self.source.c.name == source_name).execute() result = sel.fetchone() if result: ...
def add_source(self, source_name, description=None)
Adds a row to table "source" if "name" does not exist. Returns (source_id, True) if a new row is created, (source_id, False) otherwise.
3.327351
2.809675
1.184248
if not (bool(source_id) ^ bool(source_name)): raise ValueError('exactly one of source_id or source_name is required') if source_id: try: source_id = int(source_id) except (ValueError, TypeError): raise ValueError( ...
def get_source(self, source_id=None, source_name=None)
Returns a dict with keys ['id', 'name', 'description'] or None if no match. The ``id`` field is guaranteed to be an int that exists in table source. Requires exactly one of ``source_id`` or ``source_name``. A new source corresponding to ``source_name`` is created if necessary.
2.263047
2.07993
1.08804
def _lower(n1, n2): return self.ranks.index(n1) < self.ranks.index(n2) if rank not in self.ranks: raise TaxonIntegrityError('rank "{}" is undefined'.format(rank)) parent_rank = self.rank(parent_id) # undefined ranks can be placed anywhere in a lineage ...
def verify_rank_integrity(self, tax_id, rank, parent_id, children)
Confirm that for each node the parent ranks and children ranks are coherent
3.254389
3.205714
1.015184
if ignored: log.info('some arguments were ignored: {} '.format(str(ignored))) children = children or [] self.verify_rank_integrity(tax_id, rank, parent_id, children) source_id, __ = self.add_source(source_name) assert isinstance(is_valid, bool) sta...
def add_node(self, tax_id, parent_id, rank, names, source_name, children=None, is_valid=True, execute=True, **ignored)
Add a node to the taxonomy. ``source_name`` is added to table "source" if necessary.
3.008952
3.05727
0.984196
assert isinstance(is_primary, bool) assert is_classified in {None, True, False} if ignored: log.info('some arguments were ignored: {} '.format(str(ignored))) source_id = self.get_source(source_id, source_name)['id'] statements = [] if is_primary:...
def add_name(self, tax_id, tax_name, source_name=None, source_id=None, name_class='synonym', is_primary=False, is_classified=None, execute=True, **ignored)
Add a record to the names table corresponding to ``tax_id``. Arguments are as follows: - tax_id (string, required) - tax_name (string, required) *one* of the following are required: - source_id (int or string coercable to int) - source_name (string) ``source_i...
2.567515
2.655636
0.966817
primary_names = [n['tax_name'] for n in names if n.get('is_primary')] if len(primary_names) > 1: raise ValueError( '`is_primary` may be True for no more than one name in `names`') statements = [] for namevals in names: if 'tax_id' in na...
def add_names(self, tax_id, names, execute=True)
Associate one or more names with ``tax_id``. ``names`` is a list of one or more dicts, with keys corresponding to the signature of ``self.add_name()`` (excluding ``execute``).
3.534782
3.428338
1.031048
if tax_id is None: return None parent_id, rank = self._node(tax_id) s = select([self.nodes.c.tax_id], and_(self.nodes.c.parent_id == parent_id, self.nodes.c.tax_id != tax_id, self.nodes.c.rank == rank)) ...
def sibling_of(self, tax_id)
Return None or a tax_id of a sibling of *tax_id*. If ``tax_id`` is None, then always returns None. Otherwise, returns None if there is no sibling.
2.743953
2.704902
1.014437
''' Return all tax_ids in node table ''' fetch = select([self.nodes.c.tax_id]).execute().fetchall() ids = [t[0] for t in fetch] return ids
def tax_ids(self)
Return all tax_ids in node table
6.724245
3.557796
1.890003
if tax_id is None: return None parent_id, rank = self._node(tax_id) s = select([self.nodes.c.tax_id], and_(self.nodes.c.parent_id == tax_id, or_(*[self.nodes.c.rank == r for r in self.ranks_below(rank)]...
def child_of(self, tax_id)
Return None or a tax id of a child of *tax_id*. If *tax_id* is None, then always returns None. Otherwise returns a child if one exists, else None. The child must have a proper rank below that of tax_id (i.e., genus, species, but not no_rank or below_below_kingdom).
3.510083
3.291975
1.066254
if tax_id is None: return None parent_id, rank = self._node(tax_id) if rank == 'species': return [tax_id] else: children = self.children_of(tax_id, 2) species_taxids = [] for t in children: species_taxid...
def nary_subtree(self, tax_id, n=2)
Return a list of species tax_ids under *tax_id* such that node under *tax_id* and above the species has two children.
2.801554
2.734218
1.024627
def decorator(func): @wraps(func) def wrapper(*args, **kwargs): def is_db_responsive(): try: sqlalchemy_bind.session.query('1').first_or_404() except: return False else: retur...
def validate_db(sqlalchemy_bind, is_enabled=ENABLE_DB)
Checks if a DB is authorized and responding before executing the function
2.696867
2.508055
1.075282
if mapping is None: mapping = {} templ = Template(template) return templ.substitute(mapping)
def substitute(template, mapping=None)
Render the template *template*. *mapping* is a :class:`dict` with values to add to the template.
2.853098
3.384417
0.84301
results = [] for name in glob.glob(os.path.join(path, '*')): results.append(name) if os.path.isdir(name): results.extend(dirtree(name)) return results
def dirtree(path)
Find recursively and return all files and directories from the path *path*.
2.093127
2.088319
1.002302
if context.config.app_settings_handler: app_settings_handler = import_object( context.config.app_settings_handler) settings = app_settings_handler(context) else: settings = {} apps = [] for interface in context.config.interfaces: urls = interface.urls ...
def get_tornado_apps(context, debug=False)
Create Tornado's application for all interfaces which are defined in the configuration. *context* is instance of the :class:`shelter.core.context.Context`. If *debug* is :const:`True`, server will be run in **DEBUG** mode. Return :class:`list` of the :class:`tornado.web.Application` instances.
3.123907
2.907508
1.074428
setproctitle.setproctitle("{:s}: {:s}".format( self.context.config.name, self.__class__.__name__)) self.logger.info( "Worker '%s' has been started with pid %d", self.__class__.__name__, os.getpid()) # Register SIGINT handler which will exit service p...
def run(self)
Child process. Repeatedly call :meth:`loop` method every :attribute:`interval` seconds.
4.144557
3.799224
1.090896
with open(fname, 'rU') as infile: infile = (line for line in infile if not line.startswith('#')) reader = list(csv.DictReader(infile)) rows = (d for d in reader if d['tax_id']) # for now, children are provided as a semicolon-delimited list # within a cell (yes, yuck). We need ...
def get_new_nodes(fname)
Return an iterator of dicts given a .csv-format file.
4.666676
4.395922
1.061592
with open(fname, 'rU') as f: for line in f: if line.strip() and not line.startswith('#'): yield line.split('#', 1)[0].strip()
def getlines(fname)
Returns iterator of whitespace-stripped lines in file, omitting blank lines, lines beginning with '#', and line contents following the first '#' character.
2.650857
2.279712
1.162803
s = ''.join(handle.readlines()) result = {} try_set_fields(result, r'(?P<program>RAxML version [0-9.]+)', s) try_set_fields(result, r'(?P<datatype>DNA|RNA|AA)', s) result['empirical_frequencies'] = ( result['datatype'] != 'AA' or re.search('empirical base frequencies', s, re.IGN...
def parse_raxml(handle)
Parse RAxML's summary output. *handle* should be an open file handle containing the RAxML output. It is parsed and a dictionary returned.
2.57992
2.58028
0.999861
names = OrderedDict() found_eof = False for line in fobj: line = line.strip() if line == '//': found_eof = True elif line.startswith('#') or not line.strip(): continue else: name, __ = line.split(None, 1) names[name] = No...
def parse_stockholm(fobj)
Return a list of names from an Stockholm-format sequence alignment file. ``fobj`` is an open file or another object representing a sequence of lines.
3.307767
3.020091
1.095254
with open(os.devnull) as dn: try: subprocess.check_call([rppr_name], stdout=dn, stderr=dn) except OSError as e: if e.errno == os.errno.ENOENT: return False else: raise except subprocess.CalledProcessError as e: ...
def has_rppr(rppr_name='rppr')
Check for rppr binary in path
2.720119
2.556864
1.06385
''' Add a standard set of database arguments for argparse ''' parser.add_argument( 'url', nargs='?', default='sqlite:///ncbi_taxonomy.db', type=sqlite_default(), help=('Database string URI or filename. If no database scheme ' 'specified \"sqlite:///...
def add_database_args(parser)
Add a standard set of database arguments for argparse
7.054004
6.222788
1.133576
''' Prepend default scheme if none is specified. This helps provides backwards compatibility with old versions of taxtastic where sqlite was the automatic default database. ''' def parse_url(url): # TODO: need separate option for a config file if url.endswith('.db') or url.endswi...
def sqlite_default()
Prepend default scheme if none is specified. This helps provides backwards compatibility with old versions of taxtastic where sqlite was the automatic default database.
5.68999
3.013024
1.888465
log.info('loading reference package') refpkg.Refpkg(args.refpkg, create=False).strip()
def action(args)
Strips non-current files and rollback information from a refpkg. *args* should be an argparse object with fields refpkg (giving the path to the refpkg to operate on).
38.065212
17.264826
2.204784
if not os.path.isdir(path): raise ValueError("'%s' is not a directory" % path) files_mask = os.path.join(path, "*.conf") return [f for f in sorted(glob.glob(files_mask)) if os.path.isfile(f)]
def get_conf_d_files(path)
Return alphabetical ordered :class:`list` of the *.conf* files placed in the path. *path* is a directory path. :: >>> get_conf_d_files('conf/conf.d/') ['conf/conf.d/10-base.conf', 'conf/conf.d/99-dev.conf']
2.29857
2.972438
0.773295
if not os.path.isfile(filename): raise ValueError("'%s' is not a file" % filename) conf_d_path = "%s.d" % filename if not os.path.exists(conf_d_path): return [filename] return [filename] + get_conf_d_files(conf_d_path)
def get_conf_files(filename)
Return :class:`list` of the all configuration files. *filename* is a path of the main configuration file. :: >>> get_conf_files('exampleapp.conf') ['exampleapp.conf', 'exampleapp.conf.d/10-database.conf']
2.7706
3.043616
0.910299
filename = filename or os.environ.get('SHELTER_CONFIG_FILENAME', '') if not filename: raise ImproperlyConfiguredError(_( "Configuration file is not defined. You must either " "set 'SHELTER_CONFIG_FILENAME' environment variable or " "'-f/--config-file' command lin...
def get_configparser(filename='')
Read main configuration file and all files from *conf.d* subdirectory and return parsed configuration as a **configparser.RawConfigParser** instance.
3.697288
3.522109
1.049737
try: return self.config_parser.get('application', 'name') except CONFIGPARSER_EXC: return super(IniConfig, self).name
def name(self)
Application name. It's used as a process name.
9.614746
8.114573
1.184874
if 'interfaces' not in self._cached_values: self._cached_values['interfaces'] = [] for name, interface in six.iteritems(self.settings.INTERFACES): interface_name = 'interface_%s' % name # Hostname:port + unix socket try: ...
def interfaces(self)
Interfaces as a :class:`list`of the :class:`shelter.core.config.Config.Interface` instances.
2.761042
2.675205
1.032086
try: filepath = tz_path(name) return open(filepath, 'rb') except TimezoneNotFound: # http://bugs.launchpad.net/bugs/383171 - we avoid using this # unless absolutely necessary to help when a broken version of # pkg_resources is installed. try: fro...
def tz_file(name)
Open a timezone file from the zoneinfo subdir for reading. :param name: The name of the timezone. :type name: str :rtype: file
4.628322
4.749579
0.97447
if not name: raise ValueError('Invalid timezone') name_parts = name.lstrip('/').split('/') for part in name_parts: if part == os.path.pardir or os.path.sep in part: raise ValueError('Bad path segment: %r' % part) filepath = os.path.join(_DIRECTORY, *name_parts) i...
def tz_path(name)
Return the path to a timezone file. :param name: The name of the timezone. :type name: str :rtype: str
3.611897
3.701154
0.975884
base_dir = _DIRECTORY zones = () for root, dirs, files in os.walk(base_dir): for basename in files: zone = os.path.join(root, basename) if os.path.isdir(zone): continue zone = os.path.relpath(zone, base_dir) with open(os.path.jo...
def get_timezones()
Get the supported timezones. The list will be cached unless you set the "fresh" attribute to True. :param fresh: Whether to get a fresh list or not :type fresh: bool :rtype: tuple
3.237659
3.725891
0.868962
point_value, points = get_points(key) if not ALLOW_NEGATIVE_TOTALS: total = points_awarded(target) if total + points < 0: reason = reason + "(floored from {0} to 0)".format(points) points = -total apv = AwardedPointValue(points=points, value=point_value, reason...
def award_points(target, key, reason="", source=None)
Awards target the point value for key. If key is an integer then it's a one off assignment and should be interpreted as the actual point value.
3.033003
3.058646
0.991616
lookup_params = {} if target is not None: if isinstance(target, get_user_model()): lookup_params["target_user"] = target else: lookup_params.update({ "target_content_type": ContentType.objects.get_for_model(target), "target_object_id...
def points_awarded(target=None, source=None, since=None)
Determine out how many points the given target has received.
1.853679
1.86726
0.992727
try: start_date = datetime.datetime.strptime(start_date, '%Y-%m-%d') end_date = datetime.datetime.strptime(end_date, '%Y-%m-%d') except ValueError: raise ValueError("Incorrect data format, should be yyyy-mm-dd") if (end_date - start_date).days > 366: raise ValueError("Th...
def __validate_dates(start_date, end_date)
Validate if a date string. Validate if a string is a date on yyyy-mm-dd format and it the period between them is less than a year.
1.799169
1.73398
1.037595
query = quote(query) url = 'https://query.yahooapis.com/v1/public/yql?q=' + query + \ '&format=json&env=store://datatables.org/alltableswithkeys' response = urlopen(url).read() return json.loads(response.decode('utf-8'))['query']['results']
def __yahoo_request(query)
Request Yahoo Finance information. Request information from YQL. `Check <http://goo.gl/8AROUD>`_ for more information on YQL.
1.911765
2.097017
0.911659
__validate_list(tickers_list) __validate_list(selected_columns) query = 'select {cols} from yahoo.finance.quotes where symbol in ({vals})' query = query.format( cols=', '.join(selected_columns), vals=', '.join('"{0}"'.format(s) for s in tickers_list) ) response = __yahoo_re...
def request_quotes(tickers_list, selected_columns=['*'])
Request Yahoo Finance recent quotes. Returns quotes information from YQL. The columns to be requested are listed at selected_columns. Check `here <http://goo.gl/8AROUD>`_ for more information on YQL. >>> request_quotes(['AAPL'], ['Name', 'PreviousClose']) { 'PreviousClose': '95.60', ...
3.223595
3.437938
0.937653
__validate_dates(start_date, end_date) cols = ['Date', 'Open', 'High', 'Low', 'Close', 'Volume', 'Adj_Close'] query = 'select {cols} from yahoo.finance.historicaldata ' + \ 'where symbol in ("{ticker}") and startDate = "{start_date}" ' + \ 'and endDate = "{end_date}"' query = query...
def request_historical(ticker, start_date, end_date)
Get stock's daily historical information. Returns a dictionary with Adj Close, Close, High, Low, Open and Volume, between the start_date and the end_date. Is start_date and end_date were not provided all the available information will be retrieved. Information provided by YQL platform. Check `here ...
2.724534
2.81562
0.96765
__validate_list(tickers_list) for ticker in tickers_list: file_name = os.path.join(output_folder, ticker + '.csv') with open(file_name, 'wb') as f: base_url = 'http://real-chart.finance.yahoo.com/table.csv?s=' try: urlopen(base_url + ticker) ...
def download_historical(tickers_list, output_folder)
Download historical data from Yahoo Finance. Downloads full historical data from Yahoo Finance as CSV. The following fields are available: Adj Close, Close, High, Low, Open and Volume. Files will be saved to output_folder as <ticker>.csv. :param tickers_list: List of tickers that will be returned. ...
2.838162
3.139013
0.904158
if not default_json_path: default_json_path = os.path.join( os.path.dirname(os.path.realpath(__file__)), "logging.json") path = default_json_path value = os.getenv(env_key, None) if value: path = value if os.path.exists(path): with open(path, 'rt') as f: ...
def setup_logging(default_json_path=None, default_level=None, env_key='LOG_CFG', custom_log_dir=None)
Setup logging configuration
2.396673
2.374428
1.009368
leading_text = elm.text and elm.text or '' result = [leading_text] for child in elm.getchildren(): # Encoding is set to utf-8 because otherwise `ó` would # become `&#243;` child_value = etree.tostring(child, encoding='utf-8') # Decode to a string for later regexp and wh...
def squash_xml_to_text(elm, remove_namespaces=False)
Squash the given XML element (as `elm`) to a text containing XML. The outer most element/tag will be removed, but inner elements will remain. If `remove_namespaces` is specified, XML namespace declarations will be removed from the text. :param elm: XML element :type elm: :class:`xml.etree.ElementTr...
5.221803
5.554337
0.940131
new_rundata = self.loader(file_name) new_rundata = self.inspect(new_rundata) return new_rundata
def load(self, file_name)
Load a raw data-file Args: file_name (path) Returns: loaded test
6.494293
6.838838
0.949619
delta = dt - OLE_TIME_ZERO delta_float = delta / datetime.timedelta(days=1) # trick from SO return delta_float
def datetime2ole(dt)
converts from datetime object to ole datetime float
10.207364
9.37714
1.088537
raw_limits = dict() raw_limits["current_hard"] = 0.0000000000001 raw_limits["current_soft"] = 0.00001 raw_limits["stable_current_hard"] = 2.0 raw_limits["stable_current_soft"] = 4.0 raw_limits["stable_voltage_hard"] = 2.0 raw_limits["stable_voltage_soft"]...
def get_raw_limits()
Include the settings for how to decide what kind of step you are examining here. The raw limits are 'epsilons' used to check if the current and/or voltage is stable (for example for galvanostatic steps, one would expect that the current is stable (constant) and non-zero). ...
2.254279
2.158266
1.044486
new_tests = [] if not os.path.isfile(file_name): self.logger.info("Missing file_\n %s" % file_name) return None filesize = os.path.getsize(file_name) hfilesize = humanize_bytes(filesize) txt = "Filesize: %i (%s)" % (filesize, hfilesize) ...
def loader(self, file_name, bad_steps=None, **kwargs)
Loads data from biologics .mpr files. Args: file_name (str): path to .res file. bad_steps (list of tuples): (c, s) tuples of steps s (in cycle c) to skip loading. Returns: new_tests (list of data objects)
4.730943
4.724785
1.001303
logging.info("dumping to csv") barn = kwargs["barn"] farms = kwargs["farms"] experiments = kwargs["experiments"] for experiment, farm in zip(experiments, farms): name = experiment.journal.name project = experiment.journal.project project_dir, batch_dir, raw_dir = \ ...
def csv_dumper(**kwargs)
dump data to csv
4.087183
4.072417
1.003626
logging.debug("trying to save stuff in memory") farms = kwargs["farms"] experiments = kwargs["experiments"] engine = kwargs["engine"] try: engine_name = engine.__name__ except AttributeError: engine_name = engine.__dict__.__name__ accepted_engines = ["summary_engine",]...
def ram_dumper(**kwargs)
Dump data to 'memory' for later usage.
6.48005
6.294638
1.029456
farms = kwargs["farms"] engine = kwargs["engine"] logging.info("dumping to screen") print(f"\n[Screen dumper] ({engine})") try: if len(farms) == 1: print(f"You have one farm with little pandas.") else: print(f"You have {len(farms)} farms with little pan...
def screen_dumper(**kwargs)
Dump data to screen.
5.440392
5.287858
1.028846
logging.debug(" - creating legends") mass, loading, label = info.loc[c, ["masses", "loadings", "labels"]] if use_index or not label: label = c.split("_") label = "_".join(label[1:]) if option == "clean": return label if option == "mass": label = f"{label} ...
def create_legend(info, c, option="clean", use_index=False)
creating more informative legends
3.341936
3.293898
1.014584
logging.debug(" - creating plot-options-dict (for bokeh)") # Current only works for bokeh if marker_types is None: marker_types = ["circle", "square", "triangle", "invertedtriangle", "diamond", "cross", "asterix"] if line_dash is None: line_dash = [0, ...
def create_plot_option_dicts(info, marker_types=None, colors=None, line_dash=None, size=None)
Create two dictionaries with plot-options. The first iterates colors (based on group-number), the second iterates through marker types. Returns: group_styles (dict), sub_group_styles (dict)
2.548249
2.324961
1.09604
logging.debug(f"Using {prms.Batch.backend} for plotting") experiments = kwargs["experiments"] farms = kwargs["farms"] barn = None logging.debug(" - summary_plot_engine") farms = _preparing_data_and_plotting( experiments=experiments, farms=farms ) return farms, ...
def summary_plotting_engine(**kwargs)
creates plots of summary data.
9.742916
9.721375
1.002216
logging.debug("start dumper::") dumper( experiments=self.experiments, farms=self.farms, barn=self.barn, engine=self.current_engine, ) logging.debug("::dumper ended")
def run_dumper(self, dumper)
run dumber (once pr. engine) Args: dumper: dumper to run (function or method). The dumper takes the attributes experiments, farms, and barn as input. It does not return anything. But can, if the dumper designer feels in a bad and nasty mood, modify the input objects ...
8.337768
4.166445
2.001171
''' Returns ------- pandas.DataFrame Table containing descriptor, and hardware ID of each available COM port, indexed by port (e.g., "COM4"). ''' return (pd.DataFrame(list(map(list, serial.tools.list_ports.comports())), columns=['port', 'descriptor', 'har...
def _comports()
Returns ------- pandas.DataFrame Table containing descriptor, and hardware ID of each available COM port, indexed by port (e.g., "COM4").
6.054658
2.195223
2.758106
''' Uses the Win32 registry to return a iterator of serial (COM) ports existing on this computer. See http://stackoverflow.com/questions/1205383/listing-serial-com-ports-on-windows ''' import six.moves.winreg as winreg reg_path = 'HARDWARE\\DEVICEMAP\\SERIALCOMM' try: key = win...
def _get_serial_ports_windows()
Uses the Win32 registry to return a iterator of serial (COM) ports existing on this computer. See http://stackoverflow.com/questions/1205383/listing-serial-com-ports-on-windows
3.361416
1.97118
1.705281
''' Using the specified baud-rate, attempt to connect to each available serial port. If the `test_connection()` method returns `True` for a port, update the `port` attribute and return the port. In the case where the `test_connection()` does not return `True` for any of...
def get_port(self, baud_rate)
Using the specified baud-rate, attempt to connect to each available serial port. If the `test_connection()` method returns `True` for a port, update the `port` attribute and return the port. In the case where the `test_connection()` does not return `True` for any of the evaluated ports...
4.209146
1.709402
2.462349
logging.debug("Reading config-file: %s" % name) try: with open(name, "r") as config_file: prm_dict = yaml.load(config_file) except yaml.YAMLError: raise yaml.YAMLErrorr else: return prm_dict
def _read(name)
read the yml file
3.908825
3.747701
1.042993
logging.info("cycles_engine:") logging.info("Not ready for production") # raise NotImplementedError experiments = kwargs["experiments"] farms = [] barn = "raw_dir" # Its a murder in the red barn - murder in the red barn for experiment in experiments: farms.append([]) ...
def cycles_engine(**kwargs)
engine to extract cycles
8.540155
8.351975
1.022531
logger.debug("cycles_engine") raise NotImplementedError experiments = kwargs["experiments"] farms = [] barn = "raw_dir" for experiment in experiments: farms.append([]) return farms, barn
def raw_data_engine(**kwargs)
engine to extract raw data
16.014477
15.696403
1.020264
logger.debug("summary_engine") # farms = kwargs["farms"] farms = [] experiments = kwargs["experiments"] for experiment in experiments: if experiment.selected_summaries is None: selected_summaries = [ "discharge_capacity", "charge_capacity", ...
def summary_engine(**kwargs)
engine to extract summary data
5.325634
5.333886
0.998453
if reader is None: reader = dbreader.Reader() logger.debug("No reader provided. Creating one myself.") info_dict = dict() info_dict["filenames"] = [reader.get_cell_name(srno) for srno in srnos] info_dict["masses"] = [reader.get_mass(srno) for srno in srnos] info_dict["total_ma...
def simple_db_engine(reader=None, srnos=None)
engine that gets values from the simple excel 'db
2.784487
2.904592
0.95865
''' Override ``set`` and ``clear`` methods on event to call specified callback function after performing default behaviour. Parameters ---------- ''' event.changed = changed_callback if not hasattr(event, '_set'): # `set`/`clear` methods have not been overridden on event yet. ...
def orify(event, changed_callback)
Override ``set`` and ``clear`` methods on event to call specified callback function after performing default behaviour. Parameters ----------
5.251477
2.950233
1.780021
''' Parameters ---------- events : list(threading.Event) List of events. Returns ------- threading.Event Event that is set when **at least one** of the events in :data:`events` is set. ''' or_event = threading.Event() def changed(): ''' S...
def OrEvent(*events)
Parameters ---------- events : list(threading.Event) List of events. Returns ------- threading.Event Event that is set when **at least one** of the events in :data:`events` is set.
3.897069
3.057079
1.274769
''' Send payload to serial device and wait for response. Parameters ---------- device : serial.Serial Serial instance. response_queue : Queue.Queue Queue to wait for response on. payload : str or bytes Payload to send. timeout_s : float, optional Maximum ...
def request(device, response_queue, payload, timeout_s=None, poll=POLL_QUEUES)
Send payload to serial device and wait for response. Parameters ---------- device : serial.Serial Serial instance. response_queue : Queue.Queue Queue to wait for response on. payload : str or bytes Payload to send. timeout_s : float, optional Maximum time to wait...
3.495172
1.691193
2.066689
self.port = transport.serial.port logger.debug('connection_made: `%s` `%s`', self.port, transport) self.transport = transport self.connected.set() self.disconnected.clear()
def connection_made(self, transport)
Called when reader thread is started
4.696286
4.418296
1.062918
if isinstance(exception, Exception): logger.debug('Connection to port `%s` lost: %s', self.port, exception) else: logger.debug('Connection to port `%s` closed', self.port) self.connected.clear() self.disconnected.set()
def connection_lost(self, exception)
\ Called when the serial port is closed or the reader loop terminated otherwise.
3.364336
3.059591
1.099603
''' Write to serial port. Waits for serial connection to be established before writing. Parameters ---------- data : str or bytes Data to write to serial port. timeout_s : float, optional Maximum number of seconds to wait for serial conne...
def write(self, data, timeout_s=None)
Write to serial port. Waits for serial connection to be established before writing. Parameters ---------- data : str or bytes Data to write to serial port. timeout_s : float, optional Maximum number of seconds to wait for serial connection to be ...
3.897392
1.896722
2.054804
''' Send Parameters ---------- device : serial.Serial Serial instance. response_queue : Queue.Queue Queue to wait for response on. payload : str or bytes Payload to send. timeout_s : float, optional Maximum ...
def request(self, response_queue, payload, timeout_s=None, poll=POLL_QUEUES)
Send Parameters ---------- device : serial.Serial Serial instance. response_queue : Queue.Queue Queue to wait for response on. payload : str or bytes Payload to send. timeout_s : float, optional Maximum time to wait (in sec...
5.091687
1.516527
3.357465
if fieldname == 'mode': return ('mode', np.uint8) elif fieldname in ("ox/red", "error", "control changes", "Ns changes", "counter inc."): return (fieldname, np.bool_) elif fieldname in ("time/s", "P/W", "(Q-Qo)/mA.h", "x", "control/V", "con...
def fieldname_to_dtype(fieldname)
Converts a column header from the MPT file into a tuple of canonical name and appropriate numpy dtype
5.039158
4.808889
1.047884
trans_table = maketrans(b',', b'.') return float(float_string.translate(trans_table))
def comma_converter(float_string)
Convert numbers to floats whether the decimal point is '.' or ',
5.651538
5.682425
0.994564
if isinstance(file_or_path, str): mpt_file = open(file_or_path, 'rb') else: mpt_file = file_or_path magic = next(mpt_file) if magic != b'EC-Lab ASCII FILE\r\n': raise ValueError("Bad first line for EC-Lab file: '%s'" % magic) nb_headers_match = re.match(b'Nb header li...
def MPTfile(file_or_path)
Opens .mpt files as numpy record arrays Checks for the correct headings, skips any comments and returns a numpy record array object and a list of comments
4.420104
4.173347
1.059127
if isinstance(file_or_path, str): mpt_file = open(file_or_path, 'r') else: mpt_file = file_or_path magic = next(mpt_file) if magic.rstrip() != 'EC-Lab ASCII FILE': raise ValueError("Bad first line for EC-Lab file: '%s'" % magic) nb_headers_match = re.match('Nb header ...
def MPTfileCSV(file_or_path)
Simple function to open MPT files as csv.DictReader objects Checks for the correct headings, skips any comments and returns a csv.DictReader object and a list of comments
3.565098
3.460323
1.030279
while True: module_magic = fileobj.read(len(b'MODULE')) if len(module_magic) == 0: # end of file raise StopIteration elif module_magic != b'MODULE': raise ValueError( "Found %r, expecting start of new VMP MODULE" % module_magic) hdr_byte...
def read_VMP_modules(fileobj, read_module_data=True)
Reads in module headers in the VMPmodule_hdr format. Yields a dict with the headers and offset for each module. N.B. the offset yielded is the offset to the start of the data i.e. after the end of the header. The data runs from (offset) to (offset+length)
2.88849
2.76699
1.043911
headers = dict() # - global column headings (specific for Arbin) headers["applications_path_txt"] = 'Applications_Path' headers["channel_index_txt"] = 'Channel_Index' headers["channel_number_txt"] = 'Channel_Number' headers["channel_type_txt"] = 'Channel_Type' ...
def get_headers_global()
Defines the so-called global column headings for Arbin .res-files
2.325017
2.18955
1.06187
# TODO: type checking if DEBUG_MODE: checked_rundata = [] for data in run_data: new_cols = data.dfdata.columns for col in self.headers_normal: if col not in new_cols: logging.debug(f"Missing col...
def inspect(self, run_data)
Inspect the file -> reports to log (debug)
4.523885
4.238635
1.067298
logger.debug("saving multi") with open(file_name, "w", newline='') as f: logger.debug(f"{file_name} opened") writer = csv.writer(f, delimiter=sep) try: writer.writerows(itertools.zip_longest(*data)) except Exception as e: logger.info(f"Exception encou...
def _save_multi(data, file_name, sep=";")
convenience function for storing data column-wise in a csv-file.
4.203194
4.095849
1.026208
from cellpy.utils.ica import dqdv list_of_cycles = cell_data.get_cycle_numbers() if last_cycle is not None: list_of_cycles = [c for c in list_of_cycles if c <= int(last_cycle)] logger.debug(f"only processing up to cycle {last_cycle}") logger.debug(f"you have {len(list_of_cycles...
def _extract_dqdv(cell_data, extract_func, last_cycle)
Simple wrapper around the cellpy.utils.ica.dqdv function.
3.257844
2.907577
1.120467
batch_name = batch_name batch_col = batch_col logger.debug(f"batch_name, batch_col: {batch_name}, {batch_col}") if reader is None: reader_obj = get_db_reader(reader_label) reader = reader_obj() srnos = reader.select_batch(batch_name, batch_col) logger.debug("srnos:" + str(...
def make_df_from_batch(batch_name, batch_col="b01", reader=None, reader_label=None)
Create a pandas DataFrame with the info needed for ``cellpy`` to load the runs. Args: batch_name (str): Name of the batch. batch_col (str): The column where the batch name is in the db. reader (method): the db-loader method. reader_label (str): the label for the db-loader (if db...
2.981219
3.041009
0.980339
out_data_dir = prms.Paths["outdatadir"] project_dir = os.path.join(out_data_dir, project_name) batch_dir = os.path.join(project_dir, batch_name) raw_dir = os.path.join(batch_dir, "raw_data") # create folders if not os.path.isdir(project_dir): os.mkdir(project_dir) if not os.pat...
def create_folder_structure(project_name, batch_name)
This function creates a folder structure for the batch project. The folder structure consists of main working folder ``project_name` located in the ``outdatadir`` (as defined in the cellpy configuration file) with a sub-folder named ``batch_name``. It also creates a folder inside the ``batch_name`` fol...
2.310587
1.749324
1.320846
if not frames: logger.info("Could save summaries - no summaries to save!") logger.info("You have no frames - aborting") return None if not keys: logger.info("Could save summaries - no summaries to save!") logger.info("You have no keys - aborting") return None...
def save_summaries(frames, keys, selected_summaries, batch_dir, batch_name)
Writes the summaries to csv-files Args: frames: list of ``cellpy`` summary DataFrames keys: list of indexes (typically run-names) for the different runs selected_summaries: list defining which summary data to save batch_dir: directory to save to batch_name: the batch name (w...
3.457001
3.301373
1.04714
selected_summaries_dict = create_selected_summaries_dict(selected_summaries) value = selected_summaries_dict[key] return summary_df.iloc[:, summary_df.columns.get_level_values(1) == value]
def pick_summary_data(key, summary_df, selected_summaries)
picks the selected pandas.DataFrame
2.887296
2.886495
1.000278
logger.debug("trying to plot summary data") if plot_style is None: logger.debug("no plot_style given, using default") plot_style = DEFAULT_PLOT_STYLE else: logger.debug("plot_style given") list_of_lines = list() for datacol in df.columns: group = info_df.get_v...
def plot_summary_data(ax, df, info_df, color_list, symbol_list, is_charge=False, plot_style=None)
creates a plot of the selected df-data in the given axes. Typical usage: standard_fig, (ce_ax, cap_ax, ir_ax) = plt.subplots(nrows=3, ncols=1, sharex=True) list_of_lines, plot_style = plot_summary_data(ce_ax, ce_df, ...
2.59047
2.451043
1.056885
logger.debug("exporting dqdv") filename = cell_data.dataset.loaded_from no_merged_sets = "" firstname, extension = os.path.splitext(filename) firstname += no_merged_sets if savedir: firstname = os.path.join(savedir, os.path.basename(firstname)) logger.debug(f"savedir is true...
def export_dqdv(cell_data, savedir, sep, last_cycle=None)
Exports dQ/dV data from a CellpyData instance. Args: cell_data: CellpyData instance savedir: path to the folder where the files should be saved sep: separator for the .csv-files. last_cycle: only export up to this cycle (if not None)
3.089112
3.05875
1.009926
# set up cellpy logger default_log_level = kwargs.pop("default_log_level", None) import cellpy.log as log log.setup_logging(custom_log_dir=prms.Paths["filelogdir"], default_level=default_log_level) b = Batch(*args, **kwargs) return b
def init(*args, **kwargs)
Returns an initialized instance of the Batch class
6.812766
6.322292
1.077578
print("In debugging") json_file = r"C:\Scripting\Processing\Cell" \ r"data\outdata\SiBEC\cellpy_batch_bec_exp02.json" b = init(default_log_level="DEBUG") b.load_info_df(json_file) print(b.info_df.head()) # setting some variables b.export_raw = False b.export_cycles...
def debugging()
This one I use for debugging...
9.775172
9.72611
1.005044
logger.debug("running create_info_df") # initializing the reader reader = self.reader() self.info_df = make_df_from_batch(self.name, batch_col=self.batch_col, reader=reader) logger.debug(str(self.info_df.head(5)))
def create_info_df(self)
Creates a DataFrame with info about the runs (loaded from the DB)
5.693308
5.452822
1.044103
logger.debug("running save_info_df") info_df = self.info_df top_level_dict = {'info_df': info_df, 'metadata': self._prm_packer()} # packing prms jason_string = json.dumps(top_level_dict, default=lambda info_df: json.loads( ...
def save_info_df(self)
Saves the DataFrame with info about the runs to a JSON file
5.023884
4.800201
1.046599
if file_name is None: file_name = self.info_file with open(file_name, 'r') as infile: top_level_dict = json.load(infile) new_info_df_dict = top_level_dict['info_df'] new_info_df = pd.DataFrame(new_info_df_dict) self.info_df = new_info_df ...
def load_info_df(self, file_name=None)
Loads a DataFrame with all the needed info about the run (JSON file)
3.10202
3.080471
1.006995
self.info_file, directories = create_folder_structure(self.project, self.name) self.project_dir, self.batch_dir, self.raw_dir = directories logger.debug("create folders:" + str(directories))
def create_folder_structure(self)
Creates a folder structure based on the project and batch name. Project - Batch-name - Raw-data-dir The info_df JSON-file will be stored in the Project folder. The summary-files will be saved in the Batch-name folder. The raw data (including exported cycles and ica-data) will be saved ...
7.872791
5.645789
1.394454
sep = prms.Reader["sep"] if self.use_cellpy_stat_file is None: use_cellpy_stat_file = prms.Reader.use_cellpy_stat_file else: use_cellpy_stat_file = self.use_cellpy_stat_file logger.debug(f"b.load_and_save_raw: " f"use_cellpy_stat_file...
def load_and_save_raw(self, parent_level="CellpyData")
Loads the cellpy or raw-data file(s) and saves to csv
3.169027
3.08047
1.028748
self.summary_df = save_summaries(self.frames, self.keys, self.selected_summaries, self.batch_dir, self.name) logger.debug("made and saved summaries")
def make_summaries(self)
Make and save summary csv files, each containing values from all cells
10.032148
8.659361
1.158532
if not figure_type: figure_type = self.default_figure_type if not figure_type in self.default_figure_types: logger.debug("unknown figure type selected") figure_type = self.default_figure_type color_list, symbol_list = self._create_colors_markers_li...
def plot_summaries(self, show=False, save=True, figure_type=None)
Plot summary graphs. Args: show: shows the figure if True. save: saves the figure if True. figure_type: optional, figure type to create.
2.967981
3.075691
0.96498
logging.info("[estblishing links]") logging.debug("checking and establishing link to data") cell_data_frames = dict() counter = 0 errors = [] try: for indx, row in self.journal.pages.iterrows(): counter += 1 l_txt = "s...
def link(self)
Ensure that an appropriate link to the cellpy-files exists for each cell. The experiment will then contain a CellpyData object for each cell (in the cell_data_frames attribute) with only the step-table stored. Remark that running update persists the summary frames instead (or e...
5.478053
4.612666
1.187611
prm_dir = get_package_prm_dir() if not init_filename: init_filename = DEFAULT_FILENAME src = os.path.join(prm_dir, init_filename) return src
def get_default_config_file_path(init_filename=None)
gets the path to the default config-file
3.887202
3.665866
1.060377
user_dir = get_user_dir() dst_file = os.path.join(user_dir, init_filename) return user_dir, dst_file
def get_user_dir_and_dst(init_filename)
gets the name of the user directory and full prm filepath
1.951708
1.86002
1.049294
click.echo("[cellpy] (setup)") # generate variables init_filename = create_custom_init_filename() userdir, dst_file = get_user_dir_and_dst(init_filename) if testuser: if not root_dir: root_dir = os.getcwd() click.echo(f"[cellpy] (setup) DEV-MODE testuser: {testus...
def setup(interactive, not_relative, dry_run, reset, root_dir, testuser)
This will help you to setup cellpy.
3.378734
3.275656
1.031468
for f in repo.get_contents(gdirpath): if f.type == "dir": for sf in repo.get_contents(f.path): yield sf else: yield f
def _parse_g_dir(repo, gdirpath)
parses a repo directory two-levels deep
3.116143
3.06847
1.015537
# infoname = '/CellpyData/info' # dataname = '/CellpyData/dfdata' # summaryname = '/CellpyData/dfsummary' # fidname = '/CellpyData/fidtable' # stepname = '/CellpyData/step_table' root = '/CellpyData' table_path = '/'.join([root, table_name]) logging.debug(f"look_up_and_get({cellp...
def look_up_and_get(cellpy_file_name, table_name)
Extracts table from cellpy hdf5-file.
3.699271
3.582183
1.032686
_groups = [] for g in groups: try: if not float(g) > 0: _groups.append(1000) else: _groups.append(int(g)) except TypeError as e: logging.info("Error in reading group number (check your db)") logging.debug(g) ...
def fix_groups(groups)
Takes care of strange group numbers.
3.352087
3.329778
1.0067
headers_summary = cellpy.parameters.internal_settings.get_headers_summary() selected_summaries = dict() for h in summaries_list: selected_summaries[h] = headers_summary[h] return selected_summaries
def create_selected_summaries_dict(summaries_list)
Creates a dictionary with summary column headers. Examples: >>> summaries_to_output = ["discharge_capacity", "charge_capacity"] >>> summaries_to_output_dict = create_selected_summaries_dict( >>> summaries_to_output >>> ) >>> print(summaries_to_output_dict) {'disch...
5.358166
5.077538
1.055268
selected_summaries_dict = create_selected_summaries_dict(selected_summaries) frames = [] keys = [] for key in summary_frames: keys.append(key) if summary_frames[key].empty: logging.debug("Empty summary_frame encountered") frames.append(summary_frames[key]) ...
def join_summaries(summary_frames, selected_summaries, keep_old_header=False)
parse the summaries and combine based on column (selected_summaries)
2.795867
2.758943
1.013383