repo
stringlengths
7
55
path
stringlengths
4
127
func_name
stringlengths
1
88
original_string
stringlengths
75
19.8k
language
stringclasses
1 value
code
stringlengths
75
19.8k
code_tokens
listlengths
20
707
docstring
stringlengths
3
17.3k
docstring_tokens
listlengths
3
222
sha
stringlengths
40
40
url
stringlengths
87
242
partition
stringclasses
1 value
idx
int64
0
252k
pinax/pinax-points
pinax/points/models.py
points_awarded
def points_awarded(target=None, source=None, since=None): """ Determine out how many points the given target has received. """ 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": target.pk, }) if source is not None: if isinstance(source, get_user_model()): lookup_params["source_user"] = source else: lookup_params.update({ "source_content_type": ContentType.objects.get_for_model(source), "source_object_id": source.pk, }) if since is None: if target is not None and source is None: try: return TargetStat.objects.get(**lookup_params).points except TargetStat.DoesNotExist: return 0 else: return AwardedPointValue.points_awarded(**lookup_params) else: lookup_params["timestamp__gte"] = since return AwardedPointValue.points_awarded(**lookup_params)
python
def points_awarded(target=None, source=None, since=None): """ Determine out how many points the given target has received. """ 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": target.pk, }) if source is not None: if isinstance(source, get_user_model()): lookup_params["source_user"] = source else: lookup_params.update({ "source_content_type": ContentType.objects.get_for_model(source), "source_object_id": source.pk, }) if since is None: if target is not None and source is None: try: return TargetStat.objects.get(**lookup_params).points except TargetStat.DoesNotExist: return 0 else: return AwardedPointValue.points_awarded(**lookup_params) else: lookup_params["timestamp__gte"] = since return AwardedPointValue.points_awarded(**lookup_params)
[ "def", "points_awarded", "(", "target", "=", "None", ",", "source", "=", "None", ",", "since", "=", "None", ")", ":", "lookup_params", "=", "{", "}", "if", "target", "is", "not", "None", ":", "if", "isinstance", "(", "target", ",", "get_user_model", "(...
Determine out how many points the given target has received.
[ "Determine", "out", "how", "many", "points", "the", "given", "target", "has", "received", "." ]
c8490f847d0572943029ff4718d67094c04fadc9
https://github.com/pinax/pinax-points/blob/c8490f847d0572943029ff4718d67094c04fadc9/pinax/points/models.py#L228-L262
train
41,100
condereis/realtime-stock
rtstock/utils.py
__validate_dates
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. """ 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("The difference between start and end date " + "should be less than or equal to 366 days.") if (end_date - start_date).days < 0: raise ValueError("End date cannot be before start date.")
python
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. """ 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("The difference between start and end date " + "should be less than or equal to 366 days.") if (end_date - start_date).days < 0: raise ValueError("End date cannot be before start date.")
[ "def", "__validate_dates", "(", "start_date", ",", "end_date", ")", ":", "try", ":", "start_date", "=", "datetime", ".", "datetime", ".", "strptime", "(", "start_date", ",", "'%Y-%m-%d'", ")", "end_date", "=", "datetime", ".", "datetime", ".", "strptime", "(...
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.
[ "Validate", "if", "a", "date", "string", "." ]
5b3110d0bc2fd3e8354ab2edb5cfe6cafd6f2a94
https://github.com/condereis/realtime-stock/blob/5b3110d0bc2fd3e8354ab2edb5cfe6cafd6f2a94/rtstock/utils.py#L33-L48
train
41,101
condereis/realtime-stock
rtstock/utils.py
__yahoo_request
def __yahoo_request(query): """Request Yahoo Finance information. Request information from YQL. `Check <http://goo.gl/8AROUD>`_ for more information on YQL. """ 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']
python
def __yahoo_request(query): """Request Yahoo Finance information. Request information from YQL. `Check <http://goo.gl/8AROUD>`_ for more information on YQL. """ 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", ")", ":", "query", "=", "quote", "(", "query", ")", "url", "=", "'https://query.yahooapis.com/v1/public/yql?q='", "+", "query", "+", "'&format=json&env=store://datatables.org/alltableswithkeys'", "response", "=", "urlopen", "(", "...
Request Yahoo Finance information. Request information from YQL. `Check <http://goo.gl/8AROUD>`_ for more information on YQL.
[ "Request", "Yahoo", "Finance", "information", "." ]
5b3110d0bc2fd3e8354ab2edb5cfe6cafd6f2a94
https://github.com/condereis/realtime-stock/blob/5b3110d0bc2fd3e8354ab2edb5cfe6cafd6f2a94/rtstock/utils.py#L51-L63
train
41,102
condereis/realtime-stock
rtstock/utils.py
request_quotes
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', 'Name': 'Apple Inc.' } :param table: Table name. :type table: string :param tickers_list: List of tickers that will be returned. :type tickers_list: list of strings :param selected_columns: List of columns to be returned, defaults to ['*'] :type selected_columns: list of strings, optional :returns: Requested quotes. :rtype: json :raises: TypeError, TypeError """ __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_request(query) if not response: raise RequestError('Unable to process the request. Check if the ' + 'columns selected are valid.') if not type(response['quote']) is list: return [response['quote']] return response['quote']
python
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', 'Name': 'Apple Inc.' } :param table: Table name. :type table: string :param tickers_list: List of tickers that will be returned. :type tickers_list: list of strings :param selected_columns: List of columns to be returned, defaults to ['*'] :type selected_columns: list of strings, optional :returns: Requested quotes. :rtype: json :raises: TypeError, TypeError """ __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_request(query) if not response: raise RequestError('Unable to process the request. Check if the ' + 'columns selected are valid.') if not type(response['quote']) is list: return [response['quote']] return response['quote']
[ "def", "request_quotes", "(", "tickers_list", ",", "selected_columns", "=", "[", "'*'", "]", ")", ":", "__validate_list", "(", "tickers_list", ")", "__validate_list", "(", "selected_columns", ")", "query", "=", "'select {cols} from yahoo.finance.quotes where symbol in ({v...
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', 'Name': 'Apple Inc.' } :param table: Table name. :type table: string :param tickers_list: List of tickers that will be returned. :type tickers_list: list of strings :param selected_columns: List of columns to be returned, defaults to ['*'] :type selected_columns: list of strings, optional :returns: Requested quotes. :rtype: json :raises: TypeError, TypeError
[ "Request", "Yahoo", "Finance", "recent", "quotes", "." ]
5b3110d0bc2fd3e8354ab2edb5cfe6cafd6f2a94
https://github.com/condereis/realtime-stock/blob/5b3110d0bc2fd3e8354ab2edb5cfe6cafd6f2a94/rtstock/utils.py#L66-L105
train
41,103
condereis/realtime-stock
rtstock/utils.py
request_historical
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 <http://goo.gl/8AROUD>`_ for more information on YQL. .. warning:: Request limited to a period not greater than 366 days. Use download_historical() to download the full historical data. >>> request_historical('AAPL', '2016-03-01', '2016-03-02') [ { 'Close': '100.75', 'Low': '99.639999', 'High': '100.889999', 'Adj_Close': '100.140301', 'Date': '2016-03-02', 'Open': '100.510002', 'Volume': '33169600' }, { 'Close': '100.529999', 'Low': '97.419998', 'High': '100.769997', 'Adj_Close': '99.921631', 'Date': '2016-03-01', 'Open': '97.650002', 'Volume': '50407100' } ] :param start_date: Start date :type start_date: string on the format of "yyyy-mm-dd" :param end_date: End date :type end_date: string on the format of "yyyy-mm-dd" :returns: Daily historical information. :rtype: list of dictionaries """ __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.format( cols=', '.join(cols), ticker=ticker, start_date=start_date, end_date=end_date ) response = __yahoo_request(query) if not response: raise RequestError('Unable to process the request. Check if the ' + 'stock ticker used is a valid one.') if not type(response['quote']) is list: return [response['quote']] return response['quote']
python
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 <http://goo.gl/8AROUD>`_ for more information on YQL. .. warning:: Request limited to a period not greater than 366 days. Use download_historical() to download the full historical data. >>> request_historical('AAPL', '2016-03-01', '2016-03-02') [ { 'Close': '100.75', 'Low': '99.639999', 'High': '100.889999', 'Adj_Close': '100.140301', 'Date': '2016-03-02', 'Open': '100.510002', 'Volume': '33169600' }, { 'Close': '100.529999', 'Low': '97.419998', 'High': '100.769997', 'Adj_Close': '99.921631', 'Date': '2016-03-01', 'Open': '97.650002', 'Volume': '50407100' } ] :param start_date: Start date :type start_date: string on the format of "yyyy-mm-dd" :param end_date: End date :type end_date: string on the format of "yyyy-mm-dd" :returns: Daily historical information. :rtype: list of dictionaries """ __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.format( cols=', '.join(cols), ticker=ticker, start_date=start_date, end_date=end_date ) response = __yahoo_request(query) if not response: raise RequestError('Unable to process the request. Check if the ' + 'stock ticker used is a valid one.') if not type(response['quote']) is list: return [response['quote']] return response['quote']
[ "def", "request_historical", "(", "ticker", ",", "start_date", ",", "end_date", ")", ":", "__validate_dates", "(", "start_date", ",", "end_date", ")", "cols", "=", "[", "'Date'", ",", "'Open'", ",", "'High'", ",", "'Low'", ",", "'Close'", ",", "'Volume'", ...
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 <http://goo.gl/8AROUD>`_ for more information on YQL. .. warning:: Request limited to a period not greater than 366 days. Use download_historical() to download the full historical data. >>> request_historical('AAPL', '2016-03-01', '2016-03-02') [ { 'Close': '100.75', 'Low': '99.639999', 'High': '100.889999', 'Adj_Close': '100.140301', 'Date': '2016-03-02', 'Open': '100.510002', 'Volume': '33169600' }, { 'Close': '100.529999', 'Low': '97.419998', 'High': '100.769997', 'Adj_Close': '99.921631', 'Date': '2016-03-01', 'Open': '97.650002', 'Volume': '50407100' } ] :param start_date: Start date :type start_date: string on the format of "yyyy-mm-dd" :param end_date: End date :type end_date: string on the format of "yyyy-mm-dd" :returns: Daily historical information. :rtype: list of dictionaries
[ "Get", "stock", "s", "daily", "historical", "information", "." ]
5b3110d0bc2fd3e8354ab2edb5cfe6cafd6f2a94
https://github.com/condereis/realtime-stock/blob/5b3110d0bc2fd3e8354ab2edb5cfe6cafd6f2a94/rtstock/utils.py#L108-L170
train
41,104
condereis/realtime-stock
rtstock/utils.py
download_historical
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. :type tickers_list: list of strings :param output_folder: Output folder path :type output_folder: string """ __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) urlretrieve(base_url + ticker, f.name) except: os.remove(file_name) raise RequestError('Unable to process the request. Check if ' + ticker + ' is a valid stock ticker')
python
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. :type tickers_list: list of strings :param output_folder: Output folder path :type output_folder: string """ __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) urlretrieve(base_url + ticker, f.name) except: os.remove(file_name) raise RequestError('Unable to process the request. Check if ' + ticker + ' is a valid stock ticker')
[ "def", "download_historical", "(", "tickers_list", ",", "output_folder", ")", ":", "__validate_list", "(", "tickers_list", ")", "for", "ticker", "in", "tickers_list", ":", "file_name", "=", "os", ".", "path", ".", "join", "(", "output_folder", ",", "ticker", "...
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. :type tickers_list: list of strings :param output_folder: Output folder path :type output_folder: string
[ "Download", "historical", "data", "from", "Yahoo", "Finance", "." ]
5b3110d0bc2fd3e8354ab2edb5cfe6cafd6f2a94
https://github.com/condereis/realtime-stock/blob/5b3110d0bc2fd3e8354ab2edb5cfe6cafd6f2a94/rtstock/utils.py#L173-L196
train
41,105
jepegit/cellpy
cellpy/readers/instruments/custom.py
CustomLoader.load
def load(self, file_name): """Load a raw data-file Args: file_name (path) Returns: loaded test """ new_rundata = self.loader(file_name) new_rundata = self.inspect(new_rundata) return new_rundata
python
def load(self, file_name): """Load a raw data-file Args: file_name (path) Returns: loaded test """ new_rundata = self.loader(file_name) new_rundata = self.inspect(new_rundata) return new_rundata
[ "def", "load", "(", "self", ",", "file_name", ")", ":", "new_rundata", "=", "self", ".", "loader", "(", "file_name", ")", "new_rundata", "=", "self", ".", "inspect", "(", "new_rundata", ")", "return", "new_rundata" ]
Load a raw data-file Args: file_name (path) Returns: loaded test
[ "Load", "a", "raw", "data", "-", "file" ]
9f4a84cdd11f72cfa02cda8c2d7b5174abbb7370
https://github.com/jepegit/cellpy/blob/9f4a84cdd11f72cfa02cda8c2d7b5174abbb7370/cellpy/readers/instruments/custom.py#L344-L356
train
41,106
jepegit/cellpy
cellpy/readers/instruments/biologics_mpr.py
datetime2ole
def datetime2ole(dt): """converts from datetime object to ole datetime float""" delta = dt - OLE_TIME_ZERO delta_float = delta / datetime.timedelta(days=1) # trick from SO return delta_float
python
def datetime2ole(dt): """converts from datetime object to ole datetime float""" delta = dt - OLE_TIME_ZERO delta_float = delta / datetime.timedelta(days=1) # trick from SO return delta_float
[ "def", "datetime2ole", "(", "dt", ")", ":", "delta", "=", "dt", "-", "OLE_TIME_ZERO", "delta_float", "=", "delta", "/", "datetime", ".", "timedelta", "(", "days", "=", "1", ")", "# trick from SO", "return", "delta_float" ]
converts from datetime object to ole datetime float
[ "converts", "from", "datetime", "object", "to", "ole", "datetime", "float" ]
9f4a84cdd11f72cfa02cda8c2d7b5174abbb7370
https://github.com/jepegit/cellpy/blob/9f4a84cdd11f72cfa02cda8c2d7b5174abbb7370/cellpy/readers/instruments/biologics_mpr.py#L33-L37
train
41,107
jepegit/cellpy
cellpy/readers/instruments/biologics_mpr.py
MprLoader.loader
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) """ 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) self.logger.debug(txt) # creating temporary file and connection temp_dir = tempfile.gettempdir() temp_filename = os.path.join(temp_dir, os.path.basename(file_name)) shutil.copy2(file_name, temp_dir) self.logger.debug("tmp file: %s" % temp_filename) self.logger.debug("HERE WE LOAD THE DATA") data = DataSet() fid = FileID(file_name) # div parameters and information (probably load this last) test_no = 1 data.test_no = test_no data.loaded_from = file_name # some overall prms data.channel_index = None data.channel_number = None data.creator = None data.item_ID = None data.schedule_file_name = None data.start_datetime = None data.test_ID = None data.test_name = None data.raw_data_files.append(fid) # --------- read raw-data (normal-data) ------------------------- self.logger.debug("reading raw-data") self.mpr_data = None self.mpr_log = None self.mpr_settings = None self._load_mpr_data(temp_filename, bad_steps) length_of_test = self.mpr_data.shape[0] self.logger.debug(f"length of test: {length_of_test}") self.logger.debug("renaming columns") self._rename_headers() # --------- stats-data (summary-data) ------------------------- summary_df = self._create_summary_data() if summary_df.empty: txt = "\nCould not find any summary (stats-file)!" txt += " (summary_df.empty = True)" txt += "\n -> issue make_summary(use_cellpy_stat_file=False)" warnings.warn(txt) data.dfsummary = summary_df data.dfdata = self.mpr_data data.raw_data_files_length.append(length_of_test) new_tests.append(data) self._clean_up(temp_filename) return new_tests
python
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) """ 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) self.logger.debug(txt) # creating temporary file and connection temp_dir = tempfile.gettempdir() temp_filename = os.path.join(temp_dir, os.path.basename(file_name)) shutil.copy2(file_name, temp_dir) self.logger.debug("tmp file: %s" % temp_filename) self.logger.debug("HERE WE LOAD THE DATA") data = DataSet() fid = FileID(file_name) # div parameters and information (probably load this last) test_no = 1 data.test_no = test_no data.loaded_from = file_name # some overall prms data.channel_index = None data.channel_number = None data.creator = None data.item_ID = None data.schedule_file_name = None data.start_datetime = None data.test_ID = None data.test_name = None data.raw_data_files.append(fid) # --------- read raw-data (normal-data) ------------------------- self.logger.debug("reading raw-data") self.mpr_data = None self.mpr_log = None self.mpr_settings = None self._load_mpr_data(temp_filename, bad_steps) length_of_test = self.mpr_data.shape[0] self.logger.debug(f"length of test: {length_of_test}") self.logger.debug("renaming columns") self._rename_headers() # --------- stats-data (summary-data) ------------------------- summary_df = self._create_summary_data() if summary_df.empty: txt = "\nCould not find any summary (stats-file)!" txt += " (summary_df.empty = True)" txt += "\n -> issue make_summary(use_cellpy_stat_file=False)" warnings.warn(txt) data.dfsummary = summary_df data.dfdata = self.mpr_data data.raw_data_files_length.append(length_of_test) new_tests.append(data) self._clean_up(temp_filename) return new_tests
[ "def", "loader", "(", "self", ",", "file_name", ",", "bad_steps", "=", "None", ",", "*", "*", "kwargs", ")", ":", "new_tests", "=", "[", "]", "if", "not", "os", ".", "path", ".", "isfile", "(", "file_name", ")", ":", "self", ".", "logger", ".", "...
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)
[ "Loads", "data", "from", "biologics", ".", "mpr", "files", "." ]
9f4a84cdd11f72cfa02cda8c2d7b5174abbb7370
https://github.com/jepegit/cellpy/blob/9f4a84cdd11f72cfa02cda8c2d7b5174abbb7370/cellpy/readers/instruments/biologics_mpr.py#L164-L240
train
41,108
jepegit/cellpy
cellpy/utils/batch_tools/dumpers.py
csv_dumper
def csv_dumper(**kwargs): """dump data to csv""" 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 = \ experiment.journal.paginate() if batch_dir is None: logging.info("have to generate folder-name on the fly") out_data_dir, project_dir, batch_dir, raw_dir = \ generate_folder_names(name, project) if barn == "batch_dir": out_dir = batch_dir elif barn == "project_dir": out_dir = project_dir elif barn == "raw_dir": out_dir = raw_dir else: out_dir = barn for animal in farm: file_name = os.path.join( out_dir, "summary_%s_%s.csv" % ( animal.name, name ) ) logging.info(f"> {file_name}") animal.to_csv(file_name, sep=prms.Reader.sep)
python
def csv_dumper(**kwargs): """dump data to csv""" 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 = \ experiment.journal.paginate() if batch_dir is None: logging.info("have to generate folder-name on the fly") out_data_dir, project_dir, batch_dir, raw_dir = \ generate_folder_names(name, project) if barn == "batch_dir": out_dir = batch_dir elif barn == "project_dir": out_dir = project_dir elif barn == "raw_dir": out_dir = raw_dir else: out_dir = barn for animal in farm: file_name = os.path.join( out_dir, "summary_%s_%s.csv" % ( animal.name, name ) ) logging.info(f"> {file_name}") animal.to_csv(file_name, sep=prms.Reader.sep)
[ "def", "csv_dumper", "(", "*", "*", "kwargs", ")", ":", "logging", ".", "info", "(", "\"dumping to csv\"", ")", "barn", "=", "kwargs", "[", "\"barn\"", "]", "farms", "=", "kwargs", "[", "\"farms\"", "]", "experiments", "=", "kwargs", "[", "\"experiments\""...
dump data to csv
[ "dump", "data", "to", "csv" ]
9f4a84cdd11f72cfa02cda8c2d7b5174abbb7370
https://github.com/jepegit/cellpy/blob/9f4a84cdd11f72cfa02cda8c2d7b5174abbb7370/cellpy/utils/batch_tools/dumpers.py#L8-L41
train
41,109
jepegit/cellpy
cellpy/utils/batch_tools/dumpers.py
ram_dumper
def ram_dumper(**kwargs): """Dump data to 'memory' for later usage.""" 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",] if engine_name in accepted_engines: logging.debug("found the engine that I will try to dump from: " f"{engine_name}") for experiment, farm in zip(experiments, farms): name = experiment.journal.name project = experiment.journal.project experiment.memory_dumped[engine_name] = farm logging.debug(f"farm put into memory_dumped ({project}::{name})")
python
def ram_dumper(**kwargs): """Dump data to 'memory' for later usage.""" 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",] if engine_name in accepted_engines: logging.debug("found the engine that I will try to dump from: " f"{engine_name}") for experiment, farm in zip(experiments, farms): name = experiment.journal.name project = experiment.journal.project experiment.memory_dumped[engine_name] = farm logging.debug(f"farm put into memory_dumped ({project}::{name})")
[ "def", "ram_dumper", "(", "*", "*", "kwargs", ")", ":", "logging", ".", "debug", "(", "\"trying to save stuff in memory\"", ")", "farms", "=", "kwargs", "[", "\"farms\"", "]", "experiments", "=", "kwargs", "[", "\"experiments\"", "]", "engine", "=", "kwargs", ...
Dump data to 'memory' for later usage.
[ "Dump", "data", "to", "memory", "for", "later", "usage", "." ]
9f4a84cdd11f72cfa02cda8c2d7b5174abbb7370
https://github.com/jepegit/cellpy/blob/9f4a84cdd11f72cfa02cda8c2d7b5174abbb7370/cellpy/utils/batch_tools/dumpers.py#L54-L75
train
41,110
jepegit/cellpy
cellpy/utils/batch_tools/dumpers.py
screen_dumper
def screen_dumper(**kwargs): """Dump data to screen.""" 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 pandas.") except TypeError: print(" - your farm has burned to the ground.") else: for number, farm in enumerate(farms): print(f"[#{number+1}]You have {len(farm)} " f"little pandas in this farm.") for animal in farm: print(80*"=") try: print(animal.name) except AttributeError: print("no-name") print(80*"-") print(animal.head(5)) print()
python
def screen_dumper(**kwargs): """Dump data to screen.""" 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 pandas.") except TypeError: print(" - your farm has burned to the ground.") else: for number, farm in enumerate(farms): print(f"[#{number+1}]You have {len(farm)} " f"little pandas in this farm.") for animal in farm: print(80*"=") try: print(animal.name) except AttributeError: print("no-name") print(80*"-") print(animal.head(5)) print()
[ "def", "screen_dumper", "(", "*", "*", "kwargs", ")", ":", "farms", "=", "kwargs", "[", "\"farms\"", "]", "engine", "=", "kwargs", "[", "\"engine\"", "]", "logging", ".", "info", "(", "\"dumping to screen\"", ")", "print", "(", "f\"\\n[Screen dumper] ({engine}...
Dump data to screen.
[ "Dump", "data", "to", "screen", "." ]
9f4a84cdd11f72cfa02cda8c2d7b5174abbb7370
https://github.com/jepegit/cellpy/blob/9f4a84cdd11f72cfa02cda8c2d7b5174abbb7370/cellpy/utils/batch_tools/dumpers.py#L78-L105
train
41,111
jepegit/cellpy
cellpy/utils/batch_tools/batch_plotters.py
create_legend
def create_legend(info, c, option="clean", use_index=False): """creating more informative legends""" 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} ({mass:.2f} mg)" elif option == "loading": label = f"{label} ({loading:.2f} mg/cm2)" elif option == "all": label = f"{label} ({mass:.2f} mg) ({loading:.2f} mg/cm2)" return label
python
def create_legend(info, c, option="clean", use_index=False): """creating more informative legends""" 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} ({mass:.2f} mg)" elif option == "loading": label = f"{label} ({loading:.2f} mg/cm2)" elif option == "all": label = f"{label} ({mass:.2f} mg) ({loading:.2f} mg/cm2)" return label
[ "def", "create_legend", "(", "info", ",", "c", ",", "option", "=", "\"clean\"", ",", "use_index", "=", "False", ")", ":", "logging", ".", "debug", "(", "\" - creating legends\"", ")", "mass", ",", "loading", ",", "label", "=", "info", ".", "loc", "[",...
creating more informative legends
[ "creating", "more", "informative", "legends" ]
9f4a84cdd11f72cfa02cda8c2d7b5174abbb7370
https://github.com/jepegit/cellpy/blob/9f4a84cdd11f72cfa02cda8c2d7b5174abbb7370/cellpy/utils/batch_tools/batch_plotters.py#L34-L54
train
41,112
jepegit/cellpy
cellpy/utils/batch_tools/batch_plotters.py
create_plot_option_dicts
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) """ 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, 0] if size is None: size = 10 groups = info.groups.unique() number_of_groups = len(groups) if colors is None: if number_of_groups < 4: # print("using 3") colors = bokeh.palettes.brewer['YlGnBu'][3] else: # print(f"using {min(9, number_of_groups)}") colors = bokeh.palettes.brewer['YlGnBu'][min(9, number_of_groups)] sub_groups = info.sub_groups.unique() marker_it = itertools.cycle(marker_types) colors_it = itertools.cycle(colors) group_styles = dict() sub_group_styles = dict() for j in groups: color = next(colors_it) marker_options = { "line_color": color, "fill_color": color, } line_options = { "line_color": color, } group_styles[j] = { "marker": marker_options, "line": line_options, } for j in sub_groups: marker_type = next(marker_it) marker_options = { "marker": marker_type, "size": size, } line_options = { "line_dash": line_dash, } sub_group_styles[j] = { "marker": marker_options, "line": line_options, } return group_styles, sub_group_styles
python
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) """ 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, 0] if size is None: size = 10 groups = info.groups.unique() number_of_groups = len(groups) if colors is None: if number_of_groups < 4: # print("using 3") colors = bokeh.palettes.brewer['YlGnBu'][3] else: # print(f"using {min(9, number_of_groups)}") colors = bokeh.palettes.brewer['YlGnBu'][min(9, number_of_groups)] sub_groups = info.sub_groups.unique() marker_it = itertools.cycle(marker_types) colors_it = itertools.cycle(colors) group_styles = dict() sub_group_styles = dict() for j in groups: color = next(colors_it) marker_options = { "line_color": color, "fill_color": color, } line_options = { "line_color": color, } group_styles[j] = { "marker": marker_options, "line": line_options, } for j in sub_groups: marker_type = next(marker_it) marker_options = { "marker": marker_type, "size": size, } line_options = { "line_dash": line_dash, } sub_group_styles[j] = { "marker": marker_options, "line": line_options, } return group_styles, sub_group_styles
[ "def", "create_plot_option_dicts", "(", "info", ",", "marker_types", "=", "None", ",", "colors", "=", "None", ",", "line_dash", "=", "None", ",", "size", "=", "None", ")", ":", "logging", ".", "debug", "(", "\" - creating plot-options-dict (for bokeh)\"", ")"...
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)
[ "Create", "two", "dictionaries", "with", "plot", "-", "options", "." ]
9f4a84cdd11f72cfa02cda8c2d7b5174abbb7370
https://github.com/jepegit/cellpy/blob/9f4a84cdd11f72cfa02cda8c2d7b5174abbb7370/cellpy/utils/batch_tools/batch_plotters.py#L63-L134
train
41,113
jepegit/cellpy
cellpy/utils/batch_tools/batch_plotters.py
summary_plotting_engine
def summary_plotting_engine(**kwargs): """creates plots of summary data.""" 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, barn
python
def summary_plotting_engine(**kwargs): """creates plots of summary data.""" 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, barn
[ "def", "summary_plotting_engine", "(", "*", "*", "kwargs", ")", ":", "logging", ".", "debug", "(", "f\"Using {prms.Batch.backend} for plotting\"", ")", "experiments", "=", "kwargs", "[", "\"experiments\"", "]", "farms", "=", "kwargs", "[", "\"farms\"", "]", "barn"...
creates plots of summary data.
[ "creates", "plots", "of", "summary", "data", "." ]
9f4a84cdd11f72cfa02cda8c2d7b5174abbb7370
https://github.com/jepegit/cellpy/blob/9f4a84cdd11f72cfa02cda8c2d7b5174abbb7370/cellpy/utils/batch_tools/batch_plotters.py#L316-L330
train
41,114
jepegit/cellpy
dev_utils/make_example_custom_file_configfile.py
_read
def _read(name): """read the yml file""" 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
python
def _read(name): """read the yml file""" 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", ")", ":", "logging", ".", "debug", "(", "\"Reading config-file: %s\"", "%", "name", ")", "try", ":", "with", "open", "(", "name", ",", "\"r\"", ")", "as", "config_file", ":", "prm_dict", "=", "yaml", ".", "load", "(", "conf...
read the yml file
[ "read", "the", "yml", "file" ]
9f4a84cdd11f72cfa02cda8c2d7b5174abbb7370
https://github.com/jepegit/cellpy/blob/9f4a84cdd11f72cfa02cda8c2d7b5174abbb7370/dev_utils/make_example_custom_file_configfile.py#L16-L25
train
41,115
jepegit/cellpy
cellpy/utils/batch_tools/engines.py
cycles_engine
def cycles_engine(**kwargs): """engine to extract cycles""" 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([]) if experiment.all_in_memory: logging.debug("all in memory") for key in experiment.cell_data_frames: logging.debug(f"extracting cycles from {key}") else: logging.debug("dont have it in memory - need to lookup in the files") for key in experiment.cell_data_frames: logging.debug(f"looking up cellpyfile for {key}") return farms, barn
python
def cycles_engine(**kwargs): """engine to extract cycles""" 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([]) if experiment.all_in_memory: logging.debug("all in memory") for key in experiment.cell_data_frames: logging.debug(f"extracting cycles from {key}") else: logging.debug("dont have it in memory - need to lookup in the files") for key in experiment.cell_data_frames: logging.debug(f"looking up cellpyfile for {key}") return farms, barn
[ "def", "cycles_engine", "(", "*", "*", "kwargs", ")", ":", "logging", ".", "info", "(", "\"cycles_engine:\"", ")", "logging", ".", "info", "(", "\"Not ready for production\"", ")", "# raise NotImplementedError", "experiments", "=", "kwargs", "[", "\"experiments\"", ...
engine to extract cycles
[ "engine", "to", "extract", "cycles" ]
9f4a84cdd11f72cfa02cda8c2d7b5174abbb7370
https://github.com/jepegit/cellpy/blob/9f4a84cdd11f72cfa02cda8c2d7b5174abbb7370/cellpy/utils/batch_tools/engines.py#L11-L33
train
41,116
jepegit/cellpy
cellpy/utils/batch_tools/engines.py
raw_data_engine
def raw_data_engine(**kwargs): """engine to extract raw data""" logger.debug("cycles_engine") raise NotImplementedError experiments = kwargs["experiments"] farms = [] barn = "raw_dir" for experiment in experiments: farms.append([]) return farms, barn
python
def raw_data_engine(**kwargs): """engine to extract raw data""" 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", ")", ":", "logger", ".", "debug", "(", "\"cycles_engine\"", ")", "raise", "NotImplementedError", "experiments", "=", "kwargs", "[", "\"experiments\"", "]", "farms", "=", "[", "]", "barn", "=", "\"raw_dir\"", ...
engine to extract raw data
[ "engine", "to", "extract", "raw", "data" ]
9f4a84cdd11f72cfa02cda8c2d7b5174abbb7370
https://github.com/jepegit/cellpy/blob/9f4a84cdd11f72cfa02cda8c2d7b5174abbb7370/cellpy/utils/batch_tools/engines.py#L36-L48
train
41,117
jepegit/cellpy
cellpy/utils/batch_tools/engines.py
summary_engine
def summary_engine(**kwargs): """engine to extract summary data""" 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", "coulombic_efficiency", "cumulated_coulombic_efficiency", "ir_discharge", "ir_charge", "end_voltage_discharge", "end_voltage_charge", ] else: selected_summaries = experiment.selected_summaries farm = helper.join_summaries( experiment.summary_frames, selected_summaries ) farms.append(farm) barn = "batch_dir" return farms, barn
python
def summary_engine(**kwargs): """engine to extract summary data""" 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", "coulombic_efficiency", "cumulated_coulombic_efficiency", "ir_discharge", "ir_charge", "end_voltage_discharge", "end_voltage_charge", ] else: selected_summaries = experiment.selected_summaries farm = helper.join_summaries( experiment.summary_frames, selected_summaries ) farms.append(farm) barn = "batch_dir" return farms, barn
[ "def", "summary_engine", "(", "*", "*", "kwargs", ")", ":", "logger", ".", "debug", "(", "\"summary_engine\"", ")", "# farms = kwargs[\"farms\"]", "farms", "=", "[", "]", "experiments", "=", "kwargs", "[", "\"experiments\"", "]", "for", "experiment", "in", "ex...
engine to extract summary data
[ "engine", "to", "extract", "summary", "data" ]
9f4a84cdd11f72cfa02cda8c2d7b5174abbb7370
https://github.com/jepegit/cellpy/blob/9f4a84cdd11f72cfa02cda8c2d7b5174abbb7370/cellpy/utils/batch_tools/engines.py#L51-L77
train
41,118
jepegit/cellpy
cellpy/utils/batch_tools/engines.py
simple_db_engine
def simple_db_engine(reader=None, srnos=None): """engine that gets values from the simple excel 'db'""" 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_masses"] = [reader.get_total_mass(srno) for srno in srnos] info_dict["loadings"] = [reader.get_loading(srno) for srno in srnos] info_dict["fixed"] = [reader.inspect_hd5f_fixed(srno) for srno in srnos] info_dict["labels"] = [reader.get_label(srno) for srno in srnos] info_dict["cell_type"] = [reader.get_cell_type(srno) for srno in srnos] info_dict["raw_file_names"] = [] info_dict["cellpy_file_names"] = [] logger.debug("created info-dict") for key in list(info_dict.keys()): logger.debug("%s: %s" % (key, str(info_dict[key]))) _groups = [reader.get_group(srno) for srno in srnos] logger.debug(">\ngroups: %s" % str(_groups)) groups = helper.fix_groups(_groups) info_dict["groups"] = groups my_timer_start = time.time() filename_cache = [] info_dict = helper.find_files(info_dict, filename_cache) my_timer_end = time.time() if (my_timer_end - my_timer_start) > 5.0: logger.info( "The function _find_files was very slow. " "Save your info_df so you don't have to run it again!" ) info_df = pd.DataFrame(info_dict) info_df = info_df.sort_values(["groups", "filenames"]) info_df = helper.make_unique_groups(info_df) info_df["labels"] = info_df["filenames"].apply(helper.create_labels) info_df.set_index("filenames", inplace=True) return info_df
python
def simple_db_engine(reader=None, srnos=None): """engine that gets values from the simple excel 'db'""" 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_masses"] = [reader.get_total_mass(srno) for srno in srnos] info_dict["loadings"] = [reader.get_loading(srno) for srno in srnos] info_dict["fixed"] = [reader.inspect_hd5f_fixed(srno) for srno in srnos] info_dict["labels"] = [reader.get_label(srno) for srno in srnos] info_dict["cell_type"] = [reader.get_cell_type(srno) for srno in srnos] info_dict["raw_file_names"] = [] info_dict["cellpy_file_names"] = [] logger.debug("created info-dict") for key in list(info_dict.keys()): logger.debug("%s: %s" % (key, str(info_dict[key]))) _groups = [reader.get_group(srno) for srno in srnos] logger.debug(">\ngroups: %s" % str(_groups)) groups = helper.fix_groups(_groups) info_dict["groups"] = groups my_timer_start = time.time() filename_cache = [] info_dict = helper.find_files(info_dict, filename_cache) my_timer_end = time.time() if (my_timer_end - my_timer_start) > 5.0: logger.info( "The function _find_files was very slow. " "Save your info_df so you don't have to run it again!" ) info_df = pd.DataFrame(info_dict) info_df = info_df.sort_values(["groups", "filenames"]) info_df = helper.make_unique_groups(info_df) info_df["labels"] = info_df["filenames"].apply(helper.create_labels) info_df.set_index("filenames", inplace=True) return info_df
[ "def", "simple_db_engine", "(", "reader", "=", "None", ",", "srnos", "=", "None", ")", ":", "if", "reader", "is", "None", ":", "reader", "=", "dbreader", ".", "Reader", "(", ")", "logger", ".", "debug", "(", "\"No reader provided. Creating one myself.\"", ")...
engine that gets values from the simple excel 'db
[ "engine", "that", "gets", "values", "from", "the", "simple", "excel", "db" ]
9f4a84cdd11f72cfa02cda8c2d7b5174abbb7370
https://github.com/jepegit/cellpy/blob/9f4a84cdd11f72cfa02cda8c2d7b5174abbb7370/cellpy/utils/batch_tools/engines.py#L87-L131
train
41,119
sci-bots/serial-device
serial_device/or_event.py
orify
def orify(event, changed_callback): ''' 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. # Override methods to call `changed_callback` after performing default # action. event._set = event.set event._clear = event.clear event.set = lambda: or_set(event) event.clear = lambda: or_clear(event)
python
def orify(event, changed_callback): ''' 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. # Override methods to call `changed_callback` after performing default # action. event._set = event.set event._clear = event.clear event.set = lambda: or_set(event) event.clear = lambda: or_clear(event)
[ "def", "orify", "(", "event", ",", "changed_callback", ")", ":", "event", ".", "changed", "=", "changed_callback", "if", "not", "hasattr", "(", "event", ",", "'_set'", ")", ":", "# `set`/`clear` methods have not been overridden on event yet.", "# Override methods to cal...
Override ``set`` and ``clear`` methods on event to call specified callback function after performing default behaviour. Parameters ----------
[ "Override", "set", "and", "clear", "methods", "on", "event", "to", "call", "specified", "callback", "function", "after", "performing", "default", "behaviour", "." ]
5de1c3fc447ae829b57d80073ec6ac4fba3283c6
https://github.com/sci-bots/serial-device/blob/5de1c3fc447ae829b57d80073ec6ac4fba3283c6/serial_device/or_event.py#L19-L36
train
41,120
sci-bots/serial-device
serial_device/threaded.py
request
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 (in seconds) for response. By default, block until response is ready. poll : bool, optional If ``True``, poll response queue in a busy loop until response is ready (or timeout occurs). Polling is much more processor intensive, but (at least on Windows) results in faster response processing. On Windows, polling is enabled by default. ''' device.write(payload) if poll: # Polling enabled. Wait for response in busy loop. start = dt.datetime.now() while not response_queue.qsize(): if (dt.datetime.now() - start).total_seconds() > timeout_s: raise queue.Empty('No response received.') return response_queue.get() else: # Polling disabled. Use blocking `Queue.get()` method to wait for # response. return response_queue.get(timeout=timeout_s)
python
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 (in seconds) for response. By default, block until response is ready. poll : bool, optional If ``True``, poll response queue in a busy loop until response is ready (or timeout occurs). Polling is much more processor intensive, but (at least on Windows) results in faster response processing. On Windows, polling is enabled by default. ''' device.write(payload) if poll: # Polling enabled. Wait for response in busy loop. start = dt.datetime.now() while not response_queue.qsize(): if (dt.datetime.now() - start).total_seconds() > timeout_s: raise queue.Empty('No response received.') return response_queue.get() else: # Polling disabled. Use blocking `Queue.get()` method to wait for # response. return response_queue.get(timeout=timeout_s)
[ "def", "request", "(", "device", ",", "response_queue", ",", "payload", ",", "timeout_s", "=", "None", ",", "poll", "=", "POLL_QUEUES", ")", ":", "device", ".", "write", "(", "payload", ")", "if", "poll", ":", "# Polling enabled. Wait for response in busy loop....
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 (in seconds) for response. By default, block until response is ready. poll : bool, optional If ``True``, poll response queue in a busy loop until response is ready (or timeout occurs). Polling is much more processor intensive, but (at least on Windows) results in faster response processing. On Windows, polling is enabled by default.
[ "Send", "payload", "to", "serial", "device", "and", "wait", "for", "response", "." ]
5de1c3fc447ae829b57d80073ec6ac4fba3283c6
https://github.com/sci-bots/serial-device/blob/5de1c3fc447ae829b57d80073ec6ac4fba3283c6/serial_device/threaded.py#L237-L272
train
41,121
sci-bots/serial-device
serial_device/threaded.py
EventProtocol.connection_made
def connection_made(self, transport): """Called when reader thread is started""" self.port = transport.serial.port logger.debug('connection_made: `%s` `%s`', self.port, transport) self.transport = transport self.connected.set() self.disconnected.clear()
python
def connection_made(self, transport): """Called when reader thread is started""" 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", ")", ":", "self", ".", "port", "=", "transport", ".", "serial", ".", "port", "logger", ".", "debug", "(", "'connection_made: `%s` `%s`'", ",", "self", ".", "port", ",", "transport", ")", "self", ".",...
Called when reader thread is started
[ "Called", "when", "reader", "thread", "is", "started" ]
5de1c3fc447ae829b57d80073ec6ac4fba3283c6
https://github.com/sci-bots/serial-device/blob/5de1c3fc447ae829b57d80073ec6ac4fba3283c6/serial_device/threaded.py#L28-L34
train
41,122
sci-bots/serial-device
serial_device/threaded.py
EventProtocol.connection_lost
def connection_lost(self, exception): """\ Called when the serial port is closed or the reader loop terminated otherwise. """ 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()
python
def connection_lost(self, exception): """\ Called when the serial port is closed or the reader loop terminated otherwise. """ 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", ")", ":", "if", "isinstance", "(", "exception", ",", "Exception", ")", ":", "logger", ".", "debug", "(", "'Connection to port `%s` lost: %s'", ",", "self", ".", "port", ",", "exception", ")", "else", "...
\ Called when the serial port is closed or the reader loop terminated otherwise.
[ "\\", "Called", "when", "the", "serial", "port", "is", "closed", "or", "the", "reader", "loop", "terminated", "otherwise", "." ]
5de1c3fc447ae829b57d80073ec6ac4fba3283c6
https://github.com/sci-bots/serial-device/blob/5de1c3fc447ae829b57d80073ec6ac4fba3283c6/serial_device/threaded.py#L40-L51
train
41,123
sci-bots/serial-device
serial_device/threaded.py
KeepAliveReader.write
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 established. By default, block until serial connection is ready. ''' self.connected.wait(timeout_s) self.protocol.transport.write(data)
python
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 established. By default, block until serial connection is ready. ''' self.connected.wait(timeout_s) self.protocol.transport.write(data)
[ "def", "write", "(", "self", ",", "data", ",", "timeout_s", "=", "None", ")", ":", "self", ".", "connected", ".", "wait", "(", "timeout_s", ")", "self", ".", "protocol", ".", "transport", ".", "write", "(", "data", ")" ]
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 established. By default, block until serial connection is ready.
[ "Write", "to", "serial", "port", "." ]
5de1c3fc447ae829b57d80073ec6ac4fba3283c6
https://github.com/sci-bots/serial-device/blob/5de1c3fc447ae829b57d80073ec6ac4fba3283c6/serial_device/threaded.py#L167-L184
train
41,124
jepegit/cellpy
dev_utils/BioLogic_.py
fieldname_to_dtype
def fieldname_to_dtype(fieldname): """Converts a column header from the MPT file into a tuple of canonical name and appropriate numpy dtype""" 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", "control/V/mA", "(Q-Qo)/C", "dQ/C", "freq/Hz", "|Ewe|/V", "|I|/A", "Phase(Z)/deg", "|Z|/Ohm", "Re(Z)/Ohm", "-Im(Z)/Ohm"): return (fieldname, np.float_) elif fieldname in ("cycle number", "I Range", "Ns", "half cycle"): return (fieldname, np.int_) elif fieldname in ("dq/mA.h", "dQ/mA.h"): return ("dQ/mA.h", np.float_) elif fieldname in ("I/mA", "<I>/mA"): return ("I/mA", np.float_) elif fieldname in ("Ewe/V", "<Ewe>/V"): return ("Ewe/V", np.float_) else: raise ValueError("Invalid column header: %s" % fieldname)
python
def fieldname_to_dtype(fieldname): """Converts a column header from the MPT file into a tuple of canonical name and appropriate numpy dtype""" 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", "control/V/mA", "(Q-Qo)/C", "dQ/C", "freq/Hz", "|Ewe|/V", "|I|/A", "Phase(Z)/deg", "|Z|/Ohm", "Re(Z)/Ohm", "-Im(Z)/Ohm"): return (fieldname, np.float_) elif fieldname in ("cycle number", "I Range", "Ns", "half cycle"): return (fieldname, np.int_) elif fieldname in ("dq/mA.h", "dQ/mA.h"): return ("dQ/mA.h", np.float_) elif fieldname in ("I/mA", "<I>/mA"): return ("I/mA", np.float_) elif fieldname in ("Ewe/V", "<Ewe>/V"): return ("Ewe/V", np.float_) else: raise ValueError("Invalid column header: %s" % fieldname)
[ "def", "fieldname_to_dtype", "(", "fieldname", ")", ":", "if", "fieldname", "==", "'mode'", ":", "return", "(", "'mode'", ",", "np", ".", "uint8", ")", "elif", "fieldname", "in", "(", "\"ox/red\"", ",", "\"error\"", ",", "\"control changes\"", ",", "\"Ns cha...
Converts a column header from the MPT file into a tuple of canonical name and appropriate numpy dtype
[ "Converts", "a", "column", "header", "from", "the", "MPT", "file", "into", "a", "tuple", "of", "canonical", "name", "and", "appropriate", "numpy", "dtype" ]
9f4a84cdd11f72cfa02cda8c2d7b5174abbb7370
https://github.com/jepegit/cellpy/blob/9f4a84cdd11f72cfa02cda8c2d7b5174abbb7370/dev_utils/BioLogic_.py#L26-L49
train
41,125
jepegit/cellpy
dev_utils/BioLogic_.py
comma_converter
def comma_converter(float_string): """Convert numbers to floats whether the decimal point is '.' or ','""" trans_table = maketrans(b',', b'.') return float(float_string.translate(trans_table))
python
def comma_converter(float_string): """Convert numbers to floats whether the decimal point is '.' or ','""" trans_table = maketrans(b',', b'.') return float(float_string.translate(trans_table))
[ "def", "comma_converter", "(", "float_string", ")", ":", "trans_table", "=", "maketrans", "(", "b','", ",", "b'.'", ")", "return", "float", "(", "float_string", ".", "translate", "(", "trans_table", ")", ")" ]
Convert numbers to floats whether the decimal point is '.' or ',
[ "Convert", "numbers", "to", "floats", "whether", "the", "decimal", "point", "is", ".", "or" ]
9f4a84cdd11f72cfa02cda8c2d7b5174abbb7370
https://github.com/jepegit/cellpy/blob/9f4a84cdd11f72cfa02cda8c2d7b5174abbb7370/dev_utils/BioLogic_.py#L52-L55
train
41,126
jepegit/cellpy
dev_utils/BioLogic_.py
MPTfile
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 """ 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 lines : (\d+)\s*$', next(mpt_file)) nb_headers = int(nb_headers_match.group(1)) if nb_headers < 3: raise ValueError("Too few header lines: %d" % nb_headers) ## The 'magic number' line, the 'Nb headers' line and the column headers ## make three lines. Every additional line is a comment line. comments = [next(mpt_file) for i in range(nb_headers - 3)] fieldnames = str3(next(mpt_file)).strip().split('\t') record_type = np.dtype(list(map(fieldname_to_dtype, fieldnames))) ## Must be able to parse files where commas are used for decimal points converter_dict = dict(((i, comma_converter) for i in range(len(fieldnames)))) mpt_array = np.loadtxt(mpt_file, dtype=record_type, converters=converter_dict) return mpt_array, comments
python
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 """ 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 lines : (\d+)\s*$', next(mpt_file)) nb_headers = int(nb_headers_match.group(1)) if nb_headers < 3: raise ValueError("Too few header lines: %d" % nb_headers) ## The 'magic number' line, the 'Nb headers' line and the column headers ## make three lines. Every additional line is a comment line. comments = [next(mpt_file) for i in range(nb_headers - 3)] fieldnames = str3(next(mpt_file)).strip().split('\t') record_type = np.dtype(list(map(fieldname_to_dtype, fieldnames))) ## Must be able to parse files where commas are used for decimal points converter_dict = dict(((i, comma_converter) for i in range(len(fieldnames)))) mpt_array = np.loadtxt(mpt_file, dtype=record_type, converters=converter_dict) return mpt_array, comments
[ "def", "MPTfile", "(", "file_or_path", ")", ":", "if", "isinstance", "(", "file_or_path", ",", "str", ")", ":", "mpt_file", "=", "open", "(", "file_or_path", ",", "'rb'", ")", "else", ":", "mpt_file", "=", "file_or_path", "magic", "=", "next", "(", "mpt_...
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
[ "Opens", ".", "mpt", "files", "as", "numpy", "record", "arrays" ]
9f4a84cdd11f72cfa02cda8c2d7b5174abbb7370
https://github.com/jepegit/cellpy/blob/9f4a84cdd11f72cfa02cda8c2d7b5174abbb7370/dev_utils/BioLogic_.py#L58-L92
train
41,127
jepegit/cellpy
dev_utils/BioLogic_.py
MPTfileCSV
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 """ 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 lines : (\d+)\s*$', next(mpt_file)) nb_headers = int(nb_headers_match.group(1)) if nb_headers < 3: raise ValueError("Too few header lines: %d" % nb_headers) ## The 'magic number' line, the 'Nb headers' line and the column headers ## make three lines. Every additional line is a comment line. comments = [next(mpt_file) for i in range(nb_headers - 3)] mpt_csv = csv.DictReader(mpt_file, dialect='excel-tab') expected_fieldnames = ( ["mode", "ox/red", "error", "control changes", "Ns changes", "counter inc.", "time/s", "control/V/mA", "Ewe/V", "dq/mA.h", "P/W", "<I>/mA", "(Q-Qo)/mA.h", "x"], ['mode', 'ox/red', 'error', 'control changes', 'Ns changes', 'counter inc.', 'time/s', 'control/V', 'Ewe/V', 'dq/mA.h', '<I>/mA', '(Q-Qo)/mA.h', 'x'], ["mode", "ox/red", "error", "control changes", "Ns changes", "counter inc.", "time/s", "control/V", "Ewe/V", "I/mA", "dQ/mA.h", "P/W"], ["mode", "ox/red", "error", "control changes", "Ns changes", "counter inc.", "time/s", "control/V", "Ewe/V", "<I>/mA", "dQ/mA.h", "P/W"]) if mpt_csv.fieldnames not in expected_fieldnames: raise ValueError("Unrecognised headers for MPT file format") return mpt_csv, comments
python
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 """ 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 lines : (\d+)\s*$', next(mpt_file)) nb_headers = int(nb_headers_match.group(1)) if nb_headers < 3: raise ValueError("Too few header lines: %d" % nb_headers) ## The 'magic number' line, the 'Nb headers' line and the column headers ## make three lines. Every additional line is a comment line. comments = [next(mpt_file) for i in range(nb_headers - 3)] mpt_csv = csv.DictReader(mpt_file, dialect='excel-tab') expected_fieldnames = ( ["mode", "ox/red", "error", "control changes", "Ns changes", "counter inc.", "time/s", "control/V/mA", "Ewe/V", "dq/mA.h", "P/W", "<I>/mA", "(Q-Qo)/mA.h", "x"], ['mode', 'ox/red', 'error', 'control changes', 'Ns changes', 'counter inc.', 'time/s', 'control/V', 'Ewe/V', 'dq/mA.h', '<I>/mA', '(Q-Qo)/mA.h', 'x'], ["mode", "ox/red", "error", "control changes", "Ns changes", "counter inc.", "time/s", "control/V", "Ewe/V", "I/mA", "dQ/mA.h", "P/W"], ["mode", "ox/red", "error", "control changes", "Ns changes", "counter inc.", "time/s", "control/V", "Ewe/V", "<I>/mA", "dQ/mA.h", "P/W"]) if mpt_csv.fieldnames not in expected_fieldnames: raise ValueError("Unrecognised headers for MPT file format") return mpt_csv, comments
[ "def", "MPTfileCSV", "(", "file_or_path", ")", ":", "if", "isinstance", "(", "file_or_path", ",", "str", ")", ":", "mpt_file", "=", "open", "(", "file_or_path", ",", "'r'", ")", "else", ":", "mpt_file", "=", "file_or_path", "magic", "=", "next", "(", "mp...
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
[ "Simple", "function", "to", "open", "MPT", "files", "as", "csv", ".", "DictReader", "objects" ]
9f4a84cdd11f72cfa02cda8c2d7b5174abbb7370
https://github.com/jepegit/cellpy/blob/9f4a84cdd11f72cfa02cda8c2d7b5174abbb7370/dev_utils/BioLogic_.py#L95-L138
train
41,128
jepegit/cellpy
cellpy/readers/instruments/arbin.py
ArbinLoader.get_headers_global
def get_headers_global(): """Defines the so-called global column headings for Arbin .res-files""" 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' headers["comments_txt"] = 'Comments' headers["creator_txt"] = 'Creator' headers["daq_index_txt"] = 'DAQ_Index' headers["item_id_txt"] = 'Item_ID' headers["log_aux_data_flag_txt"] = 'Log_Aux_Data_Flag' headers["log_chanstat_data_flag_txt"] = 'Log_ChanStat_Data_Flag' headers["log_event_data_flag_txt"] = 'Log_Event_Data_Flag' headers["log_smart_battery_data_flag_txt"] = 'Log_Smart_Battery_Data_Flag' headers["mapped_aux_conc_cnumber_txt"] = 'Mapped_Aux_Conc_CNumber' headers["mapped_aux_di_cnumber_txt"] = 'Mapped_Aux_DI_CNumber' headers["mapped_aux_do_cnumber_txt"] = 'Mapped_Aux_DO_CNumber' headers["mapped_aux_flow_rate_cnumber_txt"] = 'Mapped_Aux_Flow_Rate_CNumber' headers["mapped_aux_ph_number_txt"] = 'Mapped_Aux_PH_Number' headers["mapped_aux_pressure_number_txt"] = 'Mapped_Aux_Pressure_Number' headers["mapped_aux_temperature_number_txt"] = 'Mapped_Aux_Temperature_Number' headers["mapped_aux_voltage_number_txt"] = 'Mapped_Aux_Voltage_Number' headers["schedule_file_name_txt"] = 'Schedule_File_Name' # KEEP FOR CELLPY FILE FORMAT headers["start_datetime_txt"] = 'Start_DateTime' headers["test_id_txt"] = 'Test_ID' # KEEP FOR CELLPY FILE FORMAT headers["test_name_txt"] = 'Test_Name' # KEEP FOR CELLPY FILE FORMAT return headers
python
def get_headers_global(): """Defines the so-called global column headings for Arbin .res-files""" 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' headers["comments_txt"] = 'Comments' headers["creator_txt"] = 'Creator' headers["daq_index_txt"] = 'DAQ_Index' headers["item_id_txt"] = 'Item_ID' headers["log_aux_data_flag_txt"] = 'Log_Aux_Data_Flag' headers["log_chanstat_data_flag_txt"] = 'Log_ChanStat_Data_Flag' headers["log_event_data_flag_txt"] = 'Log_Event_Data_Flag' headers["log_smart_battery_data_flag_txt"] = 'Log_Smart_Battery_Data_Flag' headers["mapped_aux_conc_cnumber_txt"] = 'Mapped_Aux_Conc_CNumber' headers["mapped_aux_di_cnumber_txt"] = 'Mapped_Aux_DI_CNumber' headers["mapped_aux_do_cnumber_txt"] = 'Mapped_Aux_DO_CNumber' headers["mapped_aux_flow_rate_cnumber_txt"] = 'Mapped_Aux_Flow_Rate_CNumber' headers["mapped_aux_ph_number_txt"] = 'Mapped_Aux_PH_Number' headers["mapped_aux_pressure_number_txt"] = 'Mapped_Aux_Pressure_Number' headers["mapped_aux_temperature_number_txt"] = 'Mapped_Aux_Temperature_Number' headers["mapped_aux_voltage_number_txt"] = 'Mapped_Aux_Voltage_Number' headers["schedule_file_name_txt"] = 'Schedule_File_Name' # KEEP FOR CELLPY FILE FORMAT headers["start_datetime_txt"] = 'Start_DateTime' headers["test_id_txt"] = 'Test_ID' # KEEP FOR CELLPY FILE FORMAT headers["test_name_txt"] = 'Test_Name' # KEEP FOR CELLPY FILE FORMAT return headers
[ "def", "get_headers_global", "(", ")", ":", "headers", "=", "dict", "(", ")", "# - global column headings (specific for Arbin)", "headers", "[", "\"applications_path_txt\"", "]", "=", "'Applications_Path'", "headers", "[", "\"channel_index_txt\"", "]", "=", "'Channel_Inde...
Defines the so-called global column headings for Arbin .res-files
[ "Defines", "the", "so", "-", "called", "global", "column", "headings", "for", "Arbin", ".", "res", "-", "files" ]
9f4a84cdd11f72cfa02cda8c2d7b5174abbb7370
https://github.com/jepegit/cellpy/blob/9f4a84cdd11f72cfa02cda8c2d7b5174abbb7370/cellpy/readers/instruments/arbin.py#L124-L152
train
41,129
jepegit/cellpy
cellpy/utils/batch_old.py
_save_multi
def _save_multi(data, file_name, sep=";"): """convenience function for storing data column-wise in a csv-file.""" 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 encountered in batch._save_multi: {e}") raise ExportFailed logger.debug("wrote rows using itertools in _save_multi")
python
def _save_multi(data, file_name, sep=";"): """convenience function for storing data column-wise in a csv-file.""" 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 encountered in batch._save_multi: {e}") raise ExportFailed logger.debug("wrote rows using itertools in _save_multi")
[ "def", "_save_multi", "(", "data", ",", "file_name", ",", "sep", "=", "\";\"", ")", ":", "logger", ".", "debug", "(", "\"saving multi\"", ")", "with", "open", "(", "file_name", ",", "\"w\"", ",", "newline", "=", "''", ")", "as", "f", ":", "logger", "...
convenience function for storing data column-wise in a csv-file.
[ "convenience", "function", "for", "storing", "data", "column", "-", "wise", "in", "a", "csv", "-", "file", "." ]
9f4a84cdd11f72cfa02cda8c2d7b5174abbb7370
https://github.com/jepegit/cellpy/blob/9f4a84cdd11f72cfa02cda8c2d7b5174abbb7370/cellpy/utils/batch_old.py#L152-L163
train
41,130
jepegit/cellpy
cellpy/utils/batch_old.py
_extract_dqdv
def _extract_dqdv(cell_data, extract_func, last_cycle): """Simple wrapper around the cellpy.utils.ica.dqdv function.""" 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)} cycles to process") out_data = [] for cycle in list_of_cycles: try: c, v = extract_func(cycle) v, dq = dqdv(v, c) v = v.tolist() dq = dq.tolist() except NullData as e: v = list() dq = list() logger.info(" Ups! Could not process this (cycle %i)" % cycle) logger.info(" %s" % e) header_x = "dQ cycle_no %i" % cycle header_y = "voltage cycle_no %i" % cycle dq.insert(0, header_x) v.insert(0, header_y) out_data.append(v) out_data.append(dq) return out_data
python
def _extract_dqdv(cell_data, extract_func, last_cycle): """Simple wrapper around the cellpy.utils.ica.dqdv function.""" 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)} cycles to process") out_data = [] for cycle in list_of_cycles: try: c, v = extract_func(cycle) v, dq = dqdv(v, c) v = v.tolist() dq = dq.tolist() except NullData as e: v = list() dq = list() logger.info(" Ups! Could not process this (cycle %i)" % cycle) logger.info(" %s" % e) header_x = "dQ cycle_no %i" % cycle header_y = "voltage cycle_no %i" % cycle dq.insert(0, header_x) v.insert(0, header_y) out_data.append(v) out_data.append(dq) return out_data
[ "def", "_extract_dqdv", "(", "cell_data", ",", "extract_func", ",", "last_cycle", ")", ":", "from", "cellpy", ".", "utils", ".", "ica", "import", "dqdv", "list_of_cycles", "=", "cell_data", ".", "get_cycle_numbers", "(", ")", "if", "last_cycle", "is", "not", ...
Simple wrapper around the cellpy.utils.ica.dqdv function.
[ "Simple", "wrapper", "around", "the", "cellpy", ".", "utils", ".", "ica", ".", "dqdv", "function", "." ]
9f4a84cdd11f72cfa02cda8c2d7b5174abbb7370
https://github.com/jepegit/cellpy/blob/9f4a84cdd11f72cfa02cda8c2d7b5174abbb7370/cellpy/utils/batch_old.py#L197-L226
train
41,131
jepegit/cellpy
cellpy/utils/batch_old.py
make_df_from_batch
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-loader method is not given) Returns: info_df (pandas DataFrame) """ 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(srnos)) info_dict = _create_info_dict(reader, srnos) info_df = pd.DataFrame(info_dict) info_df = info_df.sort_values(["groups", "filenames"]) info_df = _make_unique_groups(info_df) info_df["labels"] = info_df["filenames"].apply(create_labels) info_df.set_index("filenames", inplace=True) return info_df
python
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-loader method is not given) Returns: info_df (pandas DataFrame) """ 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(srnos)) info_dict = _create_info_dict(reader, srnos) info_df = pd.DataFrame(info_dict) info_df = info_df.sort_values(["groups", "filenames"]) info_df = _make_unique_groups(info_df) info_df["labels"] = info_df["filenames"].apply(create_labels) info_df.set_index("filenames", inplace=True) return info_df
[ "def", "make_df_from_batch", "(", "batch_name", ",", "batch_col", "=", "\"b01\"", ",", "reader", "=", "None", ",", "reader_label", "=", "None", ")", ":", "batch_name", "=", "batch_name", "batch_col", "=", "batch_col", "logger", ".", "debug", "(", "f\"batch_nam...
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-loader method is not given) Returns: info_df (pandas DataFrame)
[ "Create", "a", "pandas", "DataFrame", "with", "the", "info", "needed", "for", "cellpy", "to", "load", "the", "runs", "." ]
9f4a84cdd11f72cfa02cda8c2d7b5174abbb7370
https://github.com/jepegit/cellpy/blob/9f4a84cdd11f72cfa02cda8c2d7b5174abbb7370/cellpy/utils/batch_old.py#L887-L917
train
41,132
jepegit/cellpy
cellpy/utils/batch_old.py
create_folder_structure
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`` folder for storing the raw data. If the folders does not exist, they will be made. The function also returns the name of the info-df. Args: project_name: name of the project batch_name: name of the batch Returns: (info_file, (project_dir, batch_dir, raw_dir)) """ 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.path.isdir(batch_dir): os.mkdir(batch_dir) if not os.path.isdir(raw_dir): os.mkdir(raw_dir) # create file-name for the info_df (json) info_file = "cellpy_batch_%s.json" % batch_name info_file = os.path.join(project_dir, info_file) return info_file, (project_dir, batch_dir, raw_dir)
python
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`` folder for storing the raw data. If the folders does not exist, they will be made. The function also returns the name of the info-df. Args: project_name: name of the project batch_name: name of the batch Returns: (info_file, (project_dir, batch_dir, raw_dir)) """ 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.path.isdir(batch_dir): os.mkdir(batch_dir) if not os.path.isdir(raw_dir): os.mkdir(raw_dir) # create file-name for the info_df (json) info_file = "cellpy_batch_%s.json" % batch_name info_file = os.path.join(project_dir, info_file) return info_file, (project_dir, batch_dir, raw_dir)
[ "def", "create_folder_structure", "(", "project_name", ",", "batch_name", ")", ":", "out_data_dir", "=", "prms", ".", "Paths", "[", "\"outdatadir\"", "]", "project_dir", "=", "os", ".", "path", ".", "join", "(", "out_data_dir", ",", "project_name", ")", "batch...
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`` folder for storing the raw data. If the folders does not exist, they will be made. The function also returns the name of the info-df. Args: project_name: name of the project batch_name: name of the batch Returns: (info_file, (project_dir, batch_dir, raw_dir))
[ "This", "function", "creates", "a", "folder", "structure", "for", "the", "batch", "project", "." ]
9f4a84cdd11f72cfa02cda8c2d7b5174abbb7370
https://github.com/jepegit/cellpy/blob/9f4a84cdd11f72cfa02cda8c2d7b5174abbb7370/cellpy/utils/batch_old.py#L920-L953
train
41,133
jepegit/cellpy
cellpy/utils/batch_old.py
save_summaries
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 (will be used for making the file-name(s)) Returns: a pandas DataFrame with your selected summaries. """ 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 selected_summaries_dict = create_selected_summaries_dict(selected_summaries) summary_df = pd.concat(frames, keys=keys, axis=1) # saving the selected summaries for key, value in selected_summaries_dict.items(): _summary_file_name = os.path.join(batch_dir, "summary_%s_%s.csv" % ( key, batch_name)) _summary_df = summary_df.iloc[:, summary_df.columns.get_level_values(1) == value] # include function to tweak headers here (need to learn MultiIndex) _header = _summary_df.columns _summary_df.to_csv(_summary_file_name, sep=";") logger.info( "saved summary (%s) to:\n %s" % (key, _summary_file_name)) logger.info("finished saving summaries") return summary_df
python
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 (will be used for making the file-name(s)) Returns: a pandas DataFrame with your selected summaries. """ 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 selected_summaries_dict = create_selected_summaries_dict(selected_summaries) summary_df = pd.concat(frames, keys=keys, axis=1) # saving the selected summaries for key, value in selected_summaries_dict.items(): _summary_file_name = os.path.join(batch_dir, "summary_%s_%s.csv" % ( key, batch_name)) _summary_df = summary_df.iloc[:, summary_df.columns.get_level_values(1) == value] # include function to tweak headers here (need to learn MultiIndex) _header = _summary_df.columns _summary_df.to_csv(_summary_file_name, sep=";") logger.info( "saved summary (%s) to:\n %s" % (key, _summary_file_name)) logger.info("finished saving summaries") return summary_df
[ "def", "save_summaries", "(", "frames", ",", "keys", ",", "selected_summaries", ",", "batch_dir", ",", "batch_name", ")", ":", "if", "not", "frames", ":", "logger", ".", "info", "(", "\"Could save summaries - no summaries to save!\"", ")", "logger", ".", "info", ...
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 (will be used for making the file-name(s)) Returns: a pandas DataFrame with your selected summaries.
[ "Writes", "the", "summaries", "to", "csv", "-", "files" ]
9f4a84cdd11f72cfa02cda8c2d7b5174abbb7370
https://github.com/jepegit/cellpy/blob/9f4a84cdd11f72cfa02cda8c2d7b5174abbb7370/cellpy/utils/batch_old.py#L1110-L1146
train
41,134
jepegit/cellpy
cellpy/utils/batch_old.py
pick_summary_data
def pick_summary_data(key, summary_df, selected_summaries): """picks the selected pandas.DataFrame""" 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]
python
def pick_summary_data(key, summary_df, selected_summaries): """picks the selected pandas.DataFrame""" 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", ")", ":", "selected_summaries_dict", "=", "create_selected_summaries_dict", "(", "selected_summaries", ")", "value", "=", "selected_summaries_dict", "[", "key", "]", "return", "summary...
picks the selected pandas.DataFrame
[ "picks", "the", "selected", "pandas", ".", "DataFrame" ]
9f4a84cdd11f72cfa02cda8c2d7b5174abbb7370
https://github.com/jepegit/cellpy/blob/9f4a84cdd11f72cfa02cda8c2d7b5174abbb7370/cellpy/utils/batch_old.py#L1149-L1154
train
41,135
jepegit/cellpy
cellpy/utils/batch_old.py
plot_summary_data
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, info_df=info_df, color_list=color_list, symbol_list=symbol_list, is_charge=False, plot_style=plot_style) the ce_df is a pandas.DataFrame with ce-values for all your selected cells. the color_list and the symbol_list are both list with colors and symbols to use when plotting to ensure that if you have several subplots (axes), then the lines and symbols match up for each given cell. Args: ax: the matplotlib axes to plot on df: DataFrame with the data to plot info_df: DataFrame with info for the data color_list: List of colors to use symbol_list: List of symbols to use is_charge: plots open symbols if True plot_style: selected style of the plot Returns: list of the matplotlib lines (convenient to have if you are adding a custom legend) the plot style (dictionary with matplotlib plotstyles) """ 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_value(datacol[0], "groups") sub_group = info_df.get_value(datacol[0], "sub_groups") color = color_list[group - 1] marker = symbol_list[sub_group - 1] plot_style["marker"] = marker plot_style["markeredgecolor"] = color plot_style["color"] = color plot_style["markerfacecolor"] = 'none' logger.debug("selecting color for group: " + str(color)) if not is_charge: plot_style["markerfacecolor"] = color lines = ax.plot(df[datacol], **plot_style) list_of_lines.extend(lines) return list_of_lines, plot_style
python
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, info_df=info_df, color_list=color_list, symbol_list=symbol_list, is_charge=False, plot_style=plot_style) the ce_df is a pandas.DataFrame with ce-values for all your selected cells. the color_list and the symbol_list are both list with colors and symbols to use when plotting to ensure that if you have several subplots (axes), then the lines and symbols match up for each given cell. Args: ax: the matplotlib axes to plot on df: DataFrame with the data to plot info_df: DataFrame with info for the data color_list: List of colors to use symbol_list: List of symbols to use is_charge: plots open symbols if True plot_style: selected style of the plot Returns: list of the matplotlib lines (convenient to have if you are adding a custom legend) the plot style (dictionary with matplotlib plotstyles) """ 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_value(datacol[0], "groups") sub_group = info_df.get_value(datacol[0], "sub_groups") color = color_list[group - 1] marker = symbol_list[sub_group - 1] plot_style["marker"] = marker plot_style["markeredgecolor"] = color plot_style["color"] = color plot_style["markerfacecolor"] = 'none' logger.debug("selecting color for group: " + str(color)) if not is_charge: plot_style["markerfacecolor"] = color lines = ax.plot(df[datacol], **plot_style) list_of_lines.extend(lines) return list_of_lines, plot_style
[ "def", "plot_summary_data", "(", "ax", ",", "df", ",", "info_df", ",", "color_list", ",", "symbol_list", ",", "is_charge", "=", "False", ",", "plot_style", "=", "None", ")", ":", "logger", ".", "debug", "(", "\"trying to plot summary data\"", ")", "if", "plo...
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, info_df=info_df, color_list=color_list, symbol_list=symbol_list, is_charge=False, plot_style=plot_style) the ce_df is a pandas.DataFrame with ce-values for all your selected cells. the color_list and the symbol_list are both list with colors and symbols to use when plotting to ensure that if you have several subplots (axes), then the lines and symbols match up for each given cell. Args: ax: the matplotlib axes to plot on df: DataFrame with the data to plot info_df: DataFrame with info for the data color_list: List of colors to use symbol_list: List of symbols to use is_charge: plots open symbols if True plot_style: selected style of the plot Returns: list of the matplotlib lines (convenient to have if you are adding a custom legend) the plot style (dictionary with matplotlib plotstyles)
[ "creates", "a", "plot", "of", "the", "selected", "df", "-", "data", "in", "the", "given", "axes", "." ]
9f4a84cdd11f72cfa02cda8c2d7b5174abbb7370
https://github.com/jepegit/cellpy/blob/9f4a84cdd11f72cfa02cda8c2d7b5174abbb7370/cellpy/utils/batch_old.py#L1157-L1215
train
41,136
jepegit/cellpy
cellpy/utils/batch_old.py
init
def init(*args, **kwargs): """Returns an initialized instance of the Batch class""" # 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
python
def init(*args, **kwargs): """Returns an initialized instance of the Batch class""" # 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", ")", ":", "# set up cellpy logger", "default_log_level", "=", "kwargs", ".", "pop", "(", "\"default_log_level\"", ",", "None", ")", "import", "cellpy", ".", "log", "as", "log", "log", ".", "setup_lo...
Returns an initialized instance of the Batch class
[ "Returns", "an", "initialized", "instance", "of", "the", "Batch", "class" ]
9f4a84cdd11f72cfa02cda8c2d7b5174abbb7370
https://github.com/jepegit/cellpy/blob/9f4a84cdd11f72cfa02cda8c2d7b5174abbb7370/cellpy/utils/batch_old.py#L1415-L1423
train
41,137
jepegit/cellpy
cellpy/utils/batch_old.py
debugging
def debugging(): """This one I use for debugging...""" 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 = False b.export_ica = False b.save_cellpy_file = True b.force_raw_file = False b.force_cellpy_file = True b.load_and_save_raw(parent_level="cellpydata")
python
def debugging(): """This one I use for debugging...""" 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 = False b.export_ica = False b.save_cellpy_file = True b.force_raw_file = False b.force_cellpy_file = True b.load_and_save_raw(parent_level="cellpydata")
[ "def", "debugging", "(", ")", ":", "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", ".", "lo...
This one I use for debugging...
[ "This", "one", "I", "use", "for", "debugging", "..." ]
9f4a84cdd11f72cfa02cda8c2d7b5174abbb7370
https://github.com/jepegit/cellpy/blob/9f4a84cdd11f72cfa02cda8c2d7b5174abbb7370/cellpy/utils/batch_old.py#L1437-L1455
train
41,138
jepegit/cellpy
cellpy/utils/batch_old.py
Batch.save_info_df
def save_info_df(self): """Saves the DataFrame with info about the runs to a JSON file""" 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( info_df.to_json())) with open(self.info_file, 'w') as outfile: outfile.write(jason_string) logger.info("Saved file to {}".format(self.info_file))
python
def save_info_df(self): """Saves the DataFrame with info about the runs to a JSON file""" 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( info_df.to_json())) with open(self.info_file, 'w') as outfile: outfile.write(jason_string) logger.info("Saved file to {}".format(self.info_file))
[ "def", "save_info_df", "(", "self", ")", ":", "logger", ".", "debug", "(", "\"running save_info_df\"", ")", "info_df", "=", "self", ".", "info_df", "top_level_dict", "=", "{", "'info_df'", ":", "info_df", ",", "'metadata'", ":", "self", ".", "_prm_packer", "...
Saves the DataFrame with info about the runs to a JSON file
[ "Saves", "the", "DataFrame", "with", "info", "about", "the", "runs", "to", "a", "JSON", "file" ]
9f4a84cdd11f72cfa02cda8c2d7b5174abbb7370
https://github.com/jepegit/cellpy/blob/9f4a84cdd11f72cfa02cda8c2d7b5174abbb7370/cellpy/utils/batch_old.py#L451-L465
train
41,139
jepegit/cellpy
cellpy/utils/batch_old.py
Batch.create_folder_structure
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 to the Raw-data-dir. """ 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))
python
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 to the Raw-data-dir. """ 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", ")", ":", "self", ".", "info_file", ",", "directories", "=", "create_folder_structure", "(", "self", ".", "project", ",", "self", ".", "name", ")", "self", ".", "project_dir", ",", "self", ".", "batch_dir", ",",...
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 to the Raw-data-dir.
[ "Creates", "a", "folder", "structure", "based", "on", "the", "project", "and", "batch", "name", "." ]
9f4a84cdd11f72cfa02cda8c2d7b5174abbb7370
https://github.com/jepegit/cellpy/blob/9f4a84cdd11f72cfa02cda8c2d7b5174abbb7370/cellpy/utils/batch_old.py#L486-L500
train
41,140
jepegit/cellpy
cellpy/utils/batch_old.py
Batch.make_summaries
def make_summaries(self): """Make and save summary csv files, each containing values from all cells""" self.summary_df = save_summaries(self.frames, self.keys, self.selected_summaries, self.batch_dir, self.name) logger.debug("made and saved summaries")
python
def make_summaries(self): """Make and save summary csv files, each containing values from all cells""" 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", ")", ":", "self", ".", "summary_df", "=", "save_summaries", "(", "self", ".", "frames", ",", "self", ".", "keys", ",", "self", ".", "selected_summaries", ",", "self", ".", "batch_dir", ",", "self", ".", "name", ")", ...
Make and save summary csv files, each containing values from all cells
[ "Make", "and", "save", "summary", "csv", "files", "each", "containing", "values", "from", "all", "cells" ]
9f4a84cdd11f72cfa02cda8c2d7b5174abbb7370
https://github.com/jepegit/cellpy/blob/9f4a84cdd11f72cfa02cda8c2d7b5174abbb7370/cellpy/utils/batch_old.py#L528-L534
train
41,141
jepegit/cellpy
cellpy/utils/batch_old.py
Batch.plot_summaries
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. """ 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_list() summary_df = self.summary_df selected_summaries = self.selected_summaries batch_dir = self.batch_dir batch_name = self.name fig, ax = plot_summary_figure(self.info_df, summary_df, color_list, symbol_list, selected_summaries, batch_dir, batch_name, show=show, save=save, figure_type=figure_type) self.figure[figure_type] = fig self.axes[figure_type] = ax
python
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. """ 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_list() summary_df = self.summary_df selected_summaries = self.selected_summaries batch_dir = self.batch_dir batch_name = self.name fig, ax = plot_summary_figure(self.info_df, summary_df, color_list, symbol_list, selected_summaries, batch_dir, batch_name, show=show, save=save, figure_type=figure_type) self.figure[figure_type] = fig self.axes[figure_type] = ax
[ "def", "plot_summaries", "(", "self", ",", "show", "=", "False", ",", "save", "=", "True", ",", "figure_type", "=", "None", ")", ":", "if", "not", "figure_type", ":", "figure_type", "=", "self", ".", "default_figure_type", "if", "not", "figure_type", "in",...
Plot summary graphs. Args: show: shows the figure if True. save: saves the figure if True. figure_type: optional, figure type to create.
[ "Plot", "summary", "graphs", "." ]
9f4a84cdd11f72cfa02cda8c2d7b5174abbb7370
https://github.com/jepegit/cellpy/blob/9f4a84cdd11f72cfa02cda8c2d7b5174abbb7370/cellpy/utils/batch_old.py#L813-L839
train
41,142
jepegit/cellpy
cellpy/utils/batch_tools/batch_experiments.py
CyclingExperiment.link
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 everything in case you specify all_in_memory=True). This might be considered "a strange and unexpected behaviour". Sorry for that (but the authors of this package is also a bit strange...). """ 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 = "starting to process file # %i (index=%s)" % (counter, indx) logging.debug(l_txt) logging.info(f"linking cellpy-file: {row.cellpy_file_names}") if not os.path.isfile(row.cellpy_file_names): logging.error("File does not exist") raise IOError cell_data_frames[indx] = cellreader.CellpyData(initialize=True) step_table = helper.look_up_and_get( row.cellpy_file_names, "step_table" ) cell_data_frames[indx].dataset.step_table = step_table self.cell_data_frames = cell_data_frames except IOError as e: logging.warning(e) e_txt = "links not established - try update" logging.warning(e_txt) errors.append(e_txt) self.errors["link"] = errors
python
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 everything in case you specify all_in_memory=True). This might be considered "a strange and unexpected behaviour". Sorry for that (but the authors of this package is also a bit strange...). """ 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 = "starting to process file # %i (index=%s)" % (counter, indx) logging.debug(l_txt) logging.info(f"linking cellpy-file: {row.cellpy_file_names}") if not os.path.isfile(row.cellpy_file_names): logging.error("File does not exist") raise IOError cell_data_frames[indx] = cellreader.CellpyData(initialize=True) step_table = helper.look_up_and_get( row.cellpy_file_names, "step_table" ) cell_data_frames[indx].dataset.step_table = step_table self.cell_data_frames = cell_data_frames except IOError as e: logging.warning(e) e_txt = "links not established - try update" logging.warning(e_txt) errors.append(e_txt) self.errors["link"] = errors
[ "def", "link", "(", "self", ")", ":", "logging", ".", "info", "(", "\"[estblishing links]\"", ")", "logging", ".", "debug", "(", "\"checking and establishing link to data\"", ")", "cell_data_frames", "=", "dict", "(", ")", "counter", "=", "0", "errors", "=", "...
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 everything in case you specify all_in_memory=True). This might be considered "a strange and unexpected behaviour". Sorry for that (but the authors of this package is also a bit strange...).
[ "Ensure", "that", "an", "appropriate", "link", "to", "the", "cellpy", "-", "files", "exists", "for", "each", "cell", "." ]
9f4a84cdd11f72cfa02cda8c2d7b5174abbb7370
https://github.com/jepegit/cellpy/blob/9f4a84cdd11f72cfa02cda8c2d7b5174abbb7370/cellpy/utils/batch_tools/batch_experiments.py#L268-L315
train
41,143
jepegit/cellpy
cellpy/cli.py
get_default_config_file_path
def get_default_config_file_path(init_filename=None): """gets the path to the default config-file""" prm_dir = get_package_prm_dir() if not init_filename: init_filename = DEFAULT_FILENAME src = os.path.join(prm_dir, init_filename) return src
python
def get_default_config_file_path(init_filename=None): """gets the path to the default config-file""" 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", ")", ":", "prm_dir", "=", "get_package_prm_dir", "(", ")", "if", "not", "init_filename", ":", "init_filename", "=", "DEFAULT_FILENAME", "src", "=", "os", ".", "path", ".", "join", "(", "...
gets the path to the default config-file
[ "gets", "the", "path", "to", "the", "default", "config", "-", "file" ]
9f4a84cdd11f72cfa02cda8c2d7b5174abbb7370
https://github.com/jepegit/cellpy/blob/9f4a84cdd11f72cfa02cda8c2d7b5174abbb7370/cellpy/cli.py#L35-L41
train
41,144
jepegit/cellpy
cellpy/cli.py
get_user_dir_and_dst
def get_user_dir_and_dst(init_filename): """gets the name of the user directory and full prm filepath""" user_dir = get_user_dir() dst_file = os.path.join(user_dir, init_filename) return user_dir, dst_file
python
def get_user_dir_and_dst(init_filename): """gets the name of the user directory and full prm filepath""" 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", ")", ":", "user_dir", "=", "get_user_dir", "(", ")", "dst_file", "=", "os", ".", "path", ".", "join", "(", "user_dir", ",", "init_filename", ")", "return", "user_dir", ",", "dst_file" ]
gets the name of the user directory and full prm filepath
[ "gets", "the", "name", "of", "the", "user", "directory", "and", "full", "prm", "filepath" ]
9f4a84cdd11f72cfa02cda8c2d7b5174abbb7370
https://github.com/jepegit/cellpy/blob/9f4a84cdd11f72cfa02cda8c2d7b5174abbb7370/cellpy/cli.py#L44-L48
train
41,145
jepegit/cellpy
cellpy/cli.py
setup
def setup(interactive, not_relative, dry_run, reset, root_dir, testuser): """This will help you to setup cellpy.""" 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: {testuser}") init_filename = create_custom_init_filename(testuser) userdir = root_dir dst_file = get_dst_file(userdir, init_filename) click.echo(f"[cellpy] (setup) DEV-MODE userdir: {userdir}") click.echo(f"[cellpy] (setup) DEV-MODE dst_file: {dst_file}") if not pathlib.Path(dst_file).is_file(): reset = True if interactive: click.echo(" interactive mode ".center(80, "-")) _update_paths(root_dir, not not_relative, dry_run=dry_run, reset=reset) _write_config_file( userdir, dst_file, init_filename, dry_run, ) _check() else: _write_config_file(userdir, dst_file, init_filename, dry_run) _check()
python
def setup(interactive, not_relative, dry_run, reset, root_dir, testuser): """This will help you to setup cellpy.""" 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: {testuser}") init_filename = create_custom_init_filename(testuser) userdir = root_dir dst_file = get_dst_file(userdir, init_filename) click.echo(f"[cellpy] (setup) DEV-MODE userdir: {userdir}") click.echo(f"[cellpy] (setup) DEV-MODE dst_file: {dst_file}") if not pathlib.Path(dst_file).is_file(): reset = True if interactive: click.echo(" interactive mode ".center(80, "-")) _update_paths(root_dir, not not_relative, dry_run=dry_run, reset=reset) _write_config_file( userdir, dst_file, init_filename, dry_run, ) _check() else: _write_config_file(userdir, dst_file, init_filename, dry_run) _check()
[ "def", "setup", "(", "interactive", ",", "not_relative", ",", "dry_run", ",", "reset", ",", "root_dir", ",", "testuser", ")", ":", "click", ".", "echo", "(", "\"[cellpy] (setup)\"", ")", "# generate variables", "init_filename", "=", "create_custom_init_filename", ...
This will help you to setup cellpy.
[ "This", "will", "help", "you", "to", "setup", "cellpy", "." ]
9f4a84cdd11f72cfa02cda8c2d7b5174abbb7370
https://github.com/jepegit/cellpy/blob/9f4a84cdd11f72cfa02cda8c2d7b5174abbb7370/cellpy/cli.py#L131-L165
train
41,146
jepegit/cellpy
cellpy/cli.py
_parse_g_dir
def _parse_g_dir(repo, gdirpath): """parses a repo directory two-levels deep""" for f in repo.get_contents(gdirpath): if f.type == "dir": for sf in repo.get_contents(f.path): yield sf else: yield f
python
def _parse_g_dir(repo, gdirpath): """parses a repo directory two-levels deep""" 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", ")", ":", "for", "f", "in", "repo", ".", "get_contents", "(", "gdirpath", ")", ":", "if", "f", ".", "type", "==", "\"dir\"", ":", "for", "sf", "in", "repo", ".", "get_contents", "(", "f", ".", "p...
parses a repo directory two-levels deep
[ "parses", "a", "repo", "directory", "two", "-", "levels", "deep" ]
9f4a84cdd11f72cfa02cda8c2d7b5174abbb7370
https://github.com/jepegit/cellpy/blob/9f4a84cdd11f72cfa02cda8c2d7b5174abbb7370/cellpy/cli.py#L716-L723
train
41,147
jepegit/cellpy
cellpy/utils/batch_tools/batch_helpers.py
look_up_and_get
def look_up_and_get(cellpy_file_name, table_name): """Extracts table from cellpy hdf5-file.""" # 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({cellpy_file_name}, {table_name}") store = pd.HDFStore(cellpy_file_name) table = store.select(table_path) store.close() return table
python
def look_up_and_get(cellpy_file_name, table_name): """Extracts table from cellpy hdf5-file.""" # 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({cellpy_file_name}, {table_name}") store = pd.HDFStore(cellpy_file_name) table = store.select(table_path) store.close() return table
[ "def", "look_up_and_get", "(", "cellpy_file_name", ",", "table_name", ")", ":", "# infoname = '/CellpyData/info'", "# dataname = '/CellpyData/dfdata'", "# summaryname = '/CellpyData/dfsummary'", "# fidname = '/CellpyData/fidtable'", "# stepname = '/CellpyData/step_table'", "root", "=", ...
Extracts table from cellpy hdf5-file.
[ "Extracts", "table", "from", "cellpy", "hdf5", "-", "file", "." ]
9f4a84cdd11f72cfa02cda8c2d7b5174abbb7370
https://github.com/jepegit/cellpy/blob/9f4a84cdd11f72cfa02cda8c2d7b5174abbb7370/cellpy/utils/batch_tools/batch_helpers.py#L17-L33
train
41,148
jepegit/cellpy
cellpy/utils/batch_tools/batch_helpers.py
fix_groups
def fix_groups(groups): """Takes care of strange group numbers.""" _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) logging.debug(e) _groups.append(1000) return _groups
python
def fix_groups(groups): """Takes care of strange group numbers.""" _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) logging.debug(e) _groups.append(1000) return _groups
[ "def", "fix_groups", "(", "groups", ")", ":", "_groups", "=", "[", "]", "for", "g", "in", "groups", ":", "try", ":", "if", "not", "float", "(", "g", ")", ">", "0", ":", "_groups", ".", "append", "(", "1000", ")", "else", ":", "_groups", ".", "a...
Takes care of strange group numbers.
[ "Takes", "care", "of", "strange", "group", "numbers", "." ]
9f4a84cdd11f72cfa02cda8c2d7b5174abbb7370
https://github.com/jepegit/cellpy/blob/9f4a84cdd11f72cfa02cda8c2d7b5174abbb7370/cellpy/utils/batch_tools/batch_helpers.py#L88-L102
train
41,149
jepegit/cellpy
cellpy/utils/batch_tools/batch_helpers.py
create_selected_summaries_dict
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) {'discharge_capacity': "Discharge_Capacity(mAh/g)", 'charge_capacity': "Charge_Capacity(mAh/g)} Args: summaries_list: list containing cellpy summary column id names Returns: dictionary of the form {cellpy id name: cellpy summary header name,} """ 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
python
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) {'discharge_capacity': "Discharge_Capacity(mAh/g)", 'charge_capacity': "Charge_Capacity(mAh/g)} Args: summaries_list: list containing cellpy summary column id names Returns: dictionary of the form {cellpy id name: cellpy summary header name,} """ 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", ")", ":", "headers_summary", "=", "cellpy", ".", "parameters", ".", "internal_settings", ".", "get_headers_summary", "(", ")", "selected_summaries", "=", "dict", "(", ")", "for", "h", "in", "summaries_l...
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) {'discharge_capacity': "Discharge_Capacity(mAh/g)", 'charge_capacity': "Charge_Capacity(mAh/g)} Args: summaries_list: list containing cellpy summary column id names Returns: dictionary of the form {cellpy id name: cellpy summary header name,}
[ "Creates", "a", "dictionary", "with", "summary", "column", "headers", "." ]
9f4a84cdd11f72cfa02cda8c2d7b5174abbb7370
https://github.com/jepegit/cellpy/blob/9f4a84cdd11f72cfa02cda8c2d7b5174abbb7370/cellpy/utils/batch_tools/batch_helpers.py#L148-L171
train
41,150
jepegit/cellpy
cellpy/utils/batch_tools/batch_helpers.py
generate_folder_names
def generate_folder_names(name, project): """Creates sensible folder names.""" out_data_dir = prms.Paths.outdatadir project_dir = os.path.join(out_data_dir, project) batch_dir = os.path.join(project_dir, name) raw_dir = os.path.join(batch_dir, "raw_data") return out_data_dir, project_dir, batch_dir, raw_dir
python
def generate_folder_names(name, project): """Creates sensible folder names.""" out_data_dir = prms.Paths.outdatadir project_dir = os.path.join(out_data_dir, project) batch_dir = os.path.join(project_dir, name) raw_dir = os.path.join(batch_dir, "raw_data") return out_data_dir, project_dir, batch_dir, raw_dir
[ "def", "generate_folder_names", "(", "name", ",", "project", ")", ":", "out_data_dir", "=", "prms", ".", "Paths", ".", "outdatadir", "project_dir", "=", "os", ".", "path", ".", "join", "(", "out_data_dir", ",", "project", ")", "batch_dir", "=", "os", ".", ...
Creates sensible folder names.
[ "Creates", "sensible", "folder", "names", "." ]
9f4a84cdd11f72cfa02cda8c2d7b5174abbb7370
https://github.com/jepegit/cellpy/blob/9f4a84cdd11f72cfa02cda8c2d7b5174abbb7370/cellpy/utils/batch_tools/batch_helpers.py#L215-L222
train
41,151
jepegit/cellpy
cellpy/readers/cellreader.py
_interpolate_df_col
def _interpolate_df_col(df, x=None, y=None, new_x=None, dx=10.0, number_of_points=None, direction=1, **kwargs): """Interpolate a column based on another column. Args: df: DataFrame with the (cycle) data. x: Column name for the x-value (defaults to the step-time column). y: Column name for the y-value (defaults to the voltage column). new_x (numpy array or None): Interpolate using these new x-values instead of generating x-values based on dx or number_of_points. dx: step-value (defaults to 10.0) number_of_points: number of points for interpolated values (use instead of dx and overrides dx if given). direction (-1,1): if direction is negetive, then invert the x-values before interpolating. **kwargs: arguments passed to scipy.interpolate.interp1d Returns: DataFrame with interpolated y-values based on given or generated x-values. """ if x is None: x = df.columns[0] if y is None: y = df.columns[1] xs = df[x].values ys = df[y].values if direction > 0: x_min = xs.min() x_max = xs.max() else: x_max = xs.min() x_min = xs.max() dx = -dx bounds_error = kwargs.pop("bounds_error", False) f = interpolate.interp1d(xs, ys, bounds_error=bounds_error, **kwargs) if new_x is None: if number_of_points: new_x = np.linspace(x_min, x_max, number_of_points) else: new_x = np.arange(x_min, x_max, dx) new_y = f(new_x) new_df = pd.DataFrame( {x: new_x, y: new_y} ) return new_df
python
def _interpolate_df_col(df, x=None, y=None, new_x=None, dx=10.0, number_of_points=None, direction=1, **kwargs): """Interpolate a column based on another column. Args: df: DataFrame with the (cycle) data. x: Column name for the x-value (defaults to the step-time column). y: Column name for the y-value (defaults to the voltage column). new_x (numpy array or None): Interpolate using these new x-values instead of generating x-values based on dx or number_of_points. dx: step-value (defaults to 10.0) number_of_points: number of points for interpolated values (use instead of dx and overrides dx if given). direction (-1,1): if direction is negetive, then invert the x-values before interpolating. **kwargs: arguments passed to scipy.interpolate.interp1d Returns: DataFrame with interpolated y-values based on given or generated x-values. """ if x is None: x = df.columns[0] if y is None: y = df.columns[1] xs = df[x].values ys = df[y].values if direction > 0: x_min = xs.min() x_max = xs.max() else: x_max = xs.min() x_min = xs.max() dx = -dx bounds_error = kwargs.pop("bounds_error", False) f = interpolate.interp1d(xs, ys, bounds_error=bounds_error, **kwargs) if new_x is None: if number_of_points: new_x = np.linspace(x_min, x_max, number_of_points) else: new_x = np.arange(x_min, x_max, dx) new_y = f(new_x) new_df = pd.DataFrame( {x: new_x, y: new_y} ) return new_df
[ "def", "_interpolate_df_col", "(", "df", ",", "x", "=", "None", ",", "y", "=", "None", ",", "new_x", "=", "None", ",", "dx", "=", "10.0", ",", "number_of_points", "=", "None", ",", "direction", "=", "1", ",", "*", "*", "kwargs", ")", ":", "if", "...
Interpolate a column based on another column. Args: df: DataFrame with the (cycle) data. x: Column name for the x-value (defaults to the step-time column). y: Column name for the y-value (defaults to the voltage column). new_x (numpy array or None): Interpolate using these new x-values instead of generating x-values based on dx or number_of_points. dx: step-value (defaults to 10.0) number_of_points: number of points for interpolated values (use instead of dx and overrides dx if given). direction (-1,1): if direction is negetive, then invert the x-values before interpolating. **kwargs: arguments passed to scipy.interpolate.interp1d Returns: DataFrame with interpolated y-values based on given or generated x-values.
[ "Interpolate", "a", "column", "based", "on", "another", "column", "." ]
9f4a84cdd11f72cfa02cda8c2d7b5174abbb7370
https://github.com/jepegit/cellpy/blob/9f4a84cdd11f72cfa02cda8c2d7b5174abbb7370/cellpy/readers/cellreader.py#L4070-L4122
train
41,152
jepegit/cellpy
cellpy/readers/cellreader.py
_collect_capacity_curves
def _collect_capacity_curves(data, direction="charge"): """Create a list of pandas.DataFrames, one for each charge step. The DataFrames are named by its cycle number. Input: CellpyData Returns: list of pandas.DataFrames minimum voltage value, maximum voltage value""" minimum_v_value = np.Inf maximum_v_value = -np.Inf charge_list = [] cycles = data.get_cycle_numbers() for cycle in cycles: try: if direction == "charge": q, v = data.get_ccap(cycle) else: q, v = data.get_dcap(cycle) except NullData as e: logging.warning(e) break else: d = pd.DataFrame({"q": q, "v": v}) # d.name = f"{cycle}" d.name = cycle charge_list.append(d) v_min = v.min() v_max = v.max() if v_min < minimum_v_value: minimum_v_value = v_min if v_max > maximum_v_value: maximum_v_value = v_max return charge_list, cycles, minimum_v_value, maximum_v_value
python
def _collect_capacity_curves(data, direction="charge"): """Create a list of pandas.DataFrames, one for each charge step. The DataFrames are named by its cycle number. Input: CellpyData Returns: list of pandas.DataFrames minimum voltage value, maximum voltage value""" minimum_v_value = np.Inf maximum_v_value = -np.Inf charge_list = [] cycles = data.get_cycle_numbers() for cycle in cycles: try: if direction == "charge": q, v = data.get_ccap(cycle) else: q, v = data.get_dcap(cycle) except NullData as e: logging.warning(e) break else: d = pd.DataFrame({"q": q, "v": v}) # d.name = f"{cycle}" d.name = cycle charge_list.append(d) v_min = v.min() v_max = v.max() if v_min < minimum_v_value: minimum_v_value = v_min if v_max > maximum_v_value: maximum_v_value = v_max return charge_list, cycles, minimum_v_value, maximum_v_value
[ "def", "_collect_capacity_curves", "(", "data", ",", "direction", "=", "\"charge\"", ")", ":", "minimum_v_value", "=", "np", ".", "Inf", "maximum_v_value", "=", "-", "np", ".", "Inf", "charge_list", "=", "[", "]", "cycles", "=", "data", ".", "get_cycle_numbe...
Create a list of pandas.DataFrames, one for each charge step. The DataFrames are named by its cycle number. Input: CellpyData Returns: list of pandas.DataFrames minimum voltage value, maximum voltage value
[ "Create", "a", "list", "of", "pandas", ".", "DataFrames", "one", "for", "each", "charge", "step", "." ]
9f4a84cdd11f72cfa02cda8c2d7b5174abbb7370
https://github.com/jepegit/cellpy/blob/9f4a84cdd11f72cfa02cda8c2d7b5174abbb7370/cellpy/readers/cellreader.py#L4125-L4161
train
41,153
jepegit/cellpy
cellpy/readers/cellreader.py
cell
def cell(filename=None, mass=None, instrument=None, logging_mode="INFO", cycle_mode=None, auto_summary=True): """Create a CellpyData object""" from cellpy import log log.setup_logging(default_level=logging_mode) cellpy_instance = setup_cellpy_instance() if instrument is not None: cellpy_instance.set_instrument(instrument=instrument) if cycle_mode is not None: cellpy_instance.cycle_mode = cycle_mode if filename is not None: filename = Path(filename) if filename.suffix in [".h5", ".hdf5", ".cellpy", ".cpy"]: logging.info(f"Loading cellpy-file: {filename}") cellpy_instance.load(filename) else: logging.info(f"Loading raw-file: {filename}") cellpy_instance.from_raw(filename) if mass is not None: logging.info("Setting mass") cellpy_instance.set_mass(mass) if auto_summary: logging.info("Creating step table") cellpy_instance.make_step_table() logging.info("Creating summary data") cellpy_instance.make_summary() logging.info("Created CellpyData object") return cellpy_instance
python
def cell(filename=None, mass=None, instrument=None, logging_mode="INFO", cycle_mode=None, auto_summary=True): """Create a CellpyData object""" from cellpy import log log.setup_logging(default_level=logging_mode) cellpy_instance = setup_cellpy_instance() if instrument is not None: cellpy_instance.set_instrument(instrument=instrument) if cycle_mode is not None: cellpy_instance.cycle_mode = cycle_mode if filename is not None: filename = Path(filename) if filename.suffix in [".h5", ".hdf5", ".cellpy", ".cpy"]: logging.info(f"Loading cellpy-file: {filename}") cellpy_instance.load(filename) else: logging.info(f"Loading raw-file: {filename}") cellpy_instance.from_raw(filename) if mass is not None: logging.info("Setting mass") cellpy_instance.set_mass(mass) if auto_summary: logging.info("Creating step table") cellpy_instance.make_step_table() logging.info("Creating summary data") cellpy_instance.make_summary() logging.info("Created CellpyData object") return cellpy_instance
[ "def", "cell", "(", "filename", "=", "None", ",", "mass", "=", "None", ",", "instrument", "=", "None", ",", "logging_mode", "=", "\"INFO\"", ",", "cycle_mode", "=", "None", ",", "auto_summary", "=", "True", ")", ":", "from", "cellpy", "import", "log", ...
Create a CellpyData object
[ "Create", "a", "CellpyData", "object" ]
9f4a84cdd11f72cfa02cda8c2d7b5174abbb7370
https://github.com/jepegit/cellpy/blob/9f4a84cdd11f72cfa02cda8c2d7b5174abbb7370/cellpy/readers/cellreader.py#L4164-L4198
train
41,154
jepegit/cellpy
cellpy/readers/cellreader.py
load_and_save_resfile
def load_and_save_resfile(filename, outfile=None, outdir=None, mass=1.00): """Load a raw data file and save it as cellpy-file. Args: mass (float): active material mass [mg]. outdir (path): optional, path to directory for saving the hdf5-file. outfile (str): optional, name of hdf5-file. filename (str): name of the resfile. Returns: out_file_name (str): name of saved file. """ d = CellpyData() if not outdir: outdir = prms.Paths["cellpydatadir"] if not outfile: outfile = os.path.basename(filename).split(".")[0] + ".h5" outfile = os.path.join(outdir, outfile) print("filename:", filename) print("outfile:", outfile) print("outdir:", outdir) print("mass:", mass, "mg") d.from_raw(filename) d.set_mass(mass) d.make_step_table() d.make_summary() d.save(filename=outfile) d.to_csv(datadir=outdir, cycles=True, raw=True, summary=True) return outfile
python
def load_and_save_resfile(filename, outfile=None, outdir=None, mass=1.00): """Load a raw data file and save it as cellpy-file. Args: mass (float): active material mass [mg]. outdir (path): optional, path to directory for saving the hdf5-file. outfile (str): optional, name of hdf5-file. filename (str): name of the resfile. Returns: out_file_name (str): name of saved file. """ d = CellpyData() if not outdir: outdir = prms.Paths["cellpydatadir"] if not outfile: outfile = os.path.basename(filename).split(".")[0] + ".h5" outfile = os.path.join(outdir, outfile) print("filename:", filename) print("outfile:", outfile) print("outdir:", outdir) print("mass:", mass, "mg") d.from_raw(filename) d.set_mass(mass) d.make_step_table() d.make_summary() d.save(filename=outfile) d.to_csv(datadir=outdir, cycles=True, raw=True, summary=True) return outfile
[ "def", "load_and_save_resfile", "(", "filename", ",", "outfile", "=", "None", ",", "outdir", "=", "None", ",", "mass", "=", "1.00", ")", ":", "d", "=", "CellpyData", "(", ")", "if", "not", "outdir", ":", "outdir", "=", "prms", ".", "Paths", "[", "\"c...
Load a raw data file and save it as cellpy-file. Args: mass (float): active material mass [mg]. outdir (path): optional, path to directory for saving the hdf5-file. outfile (str): optional, name of hdf5-file. filename (str): name of the resfile. Returns: out_file_name (str): name of saved file.
[ "Load", "a", "raw", "data", "file", "and", "save", "it", "as", "cellpy", "-", "file", "." ]
9f4a84cdd11f72cfa02cda8c2d7b5174abbb7370
https://github.com/jepegit/cellpy/blob/9f4a84cdd11f72cfa02cda8c2d7b5174abbb7370/cellpy/readers/cellreader.py#L4293-L4325
train
41,155
jepegit/cellpy
cellpy/readers/cellreader.py
load_and_print_resfile
def load_and_print_resfile(filename, info_dict=None): """Load a raw data file and print information. Args: filename (str): name of the resfile. info_dict (dict): Returns: info (str): string describing something. """ # self.test_no = None # self.mass = 1.0 # mass of (active) material (in mg) # self.no_cycles = 0.0 # self.charge_steps = None # not in use at the moment # self.discharge_steps = None # not in use at the moment # self.ir_steps = None # dict # not in use at the moment # self.ocv_steps = None # dict # not in use at the moment # self.nom_cap = 3579 # mAh/g (used for finding c-rates) # self.mass_given = False # self.c_mode = True # self.starts_with = "discharge" # self.material = "noname" # self.merged = False # self.file_errors = None # not in use at the moment # self.loaded_from = None # name of the .res file it is loaded from # (can be list if merged) # self.raw_data_files = [] # self.raw_data_files_length = [] # # self.parent_filename = None # name of the .res file it is loaded from # (basename) (can be list if merded) # # self.parent_filename = if listtype, for file in etc,,, # os.path.basename(self.loaded_from) # self.channel_index = None # self.channel_number = None # self.creator = None # self.item_ID = None # self.schedule_file_name = None # self.start_datetime = None # self.test_ID = None # self.name = None # NEXT: include nom_cap, tot_mass and parameters table in save/load hdf5 if info_dict is None: info_dict = dict() info_dict["mass"] = 1.23 # mg info_dict["nom_cap"] = 3600 # mAh/g (active material) info_dict["tot_mass"] = 2.33 # mAh/g (total mass of material) d = CellpyData() print("filename:", filename) print("info_dict in:", end=' ') print(info_dict) d.from_raw(filename) d.set_mass(info_dict["mass"]) d.make_step_table() d.make_summary() for test in d.datasets: print("newtest") print(test) return info_dict
python
def load_and_print_resfile(filename, info_dict=None): """Load a raw data file and print information. Args: filename (str): name of the resfile. info_dict (dict): Returns: info (str): string describing something. """ # self.test_no = None # self.mass = 1.0 # mass of (active) material (in mg) # self.no_cycles = 0.0 # self.charge_steps = None # not in use at the moment # self.discharge_steps = None # not in use at the moment # self.ir_steps = None # dict # not in use at the moment # self.ocv_steps = None # dict # not in use at the moment # self.nom_cap = 3579 # mAh/g (used for finding c-rates) # self.mass_given = False # self.c_mode = True # self.starts_with = "discharge" # self.material = "noname" # self.merged = False # self.file_errors = None # not in use at the moment # self.loaded_from = None # name of the .res file it is loaded from # (can be list if merged) # self.raw_data_files = [] # self.raw_data_files_length = [] # # self.parent_filename = None # name of the .res file it is loaded from # (basename) (can be list if merded) # # self.parent_filename = if listtype, for file in etc,,, # os.path.basename(self.loaded_from) # self.channel_index = None # self.channel_number = None # self.creator = None # self.item_ID = None # self.schedule_file_name = None # self.start_datetime = None # self.test_ID = None # self.name = None # NEXT: include nom_cap, tot_mass and parameters table in save/load hdf5 if info_dict is None: info_dict = dict() info_dict["mass"] = 1.23 # mg info_dict["nom_cap"] = 3600 # mAh/g (active material) info_dict["tot_mass"] = 2.33 # mAh/g (total mass of material) d = CellpyData() print("filename:", filename) print("info_dict in:", end=' ') print(info_dict) d.from_raw(filename) d.set_mass(info_dict["mass"]) d.make_step_table() d.make_summary() for test in d.datasets: print("newtest") print(test) return info_dict
[ "def", "load_and_print_resfile", "(", "filename", ",", "info_dict", "=", "None", ")", ":", "# self.test_no = None", "# self.mass = 1.0 # mass of (active) material (in mg)", "# self.no_cycles = 0.0", "# self.charge_steps = None # not in use at the moment", "# self.discharge_steps = None...
Load a raw data file and print information. Args: filename (str): name of the resfile. info_dict (dict): Returns: info (str): string describing something.
[ "Load", "a", "raw", "data", "file", "and", "print", "information", "." ]
9f4a84cdd11f72cfa02cda8c2d7b5174abbb7370
https://github.com/jepegit/cellpy/blob/9f4a84cdd11f72cfa02cda8c2d7b5174abbb7370/cellpy/readers/cellreader.py#L4328-L4392
train
41,156
jepegit/cellpy
cellpy/readers/cellreader.py
CellpyData.set_raw_datadir
def set_raw_datadir(self, directory=None): """Set the directory containing .res-files. Used for setting directory for looking for res-files.@ A valid directory name is required. Args: directory (str): path to res-directory Example: >>> d = CellpyData() >>> directory = "MyData/Arbindata" >>> d.set_raw_datadir(directory) """ if directory is None: self.logger.info("no directory name given") return if not os.path.isdir(directory): self.logger.info(directory) self.logger.info("directory does not exist") return self.raw_datadir = directory
python
def set_raw_datadir(self, directory=None): """Set the directory containing .res-files. Used for setting directory for looking for res-files.@ A valid directory name is required. Args: directory (str): path to res-directory Example: >>> d = CellpyData() >>> directory = "MyData/Arbindata" >>> d.set_raw_datadir(directory) """ if directory is None: self.logger.info("no directory name given") return if not os.path.isdir(directory): self.logger.info(directory) self.logger.info("directory does not exist") return self.raw_datadir = directory
[ "def", "set_raw_datadir", "(", "self", ",", "directory", "=", "None", ")", ":", "if", "directory", "is", "None", ":", "self", ".", "logger", ".", "info", "(", "\"no directory name given\"", ")", "return", "if", "not", "os", ".", "path", ".", "isdir", "("...
Set the directory containing .res-files. Used for setting directory for looking for res-files.@ A valid directory name is required. Args: directory (str): path to res-directory Example: >>> d = CellpyData() >>> directory = "MyData/Arbindata" >>> d.set_raw_datadir(directory)
[ "Set", "the", "directory", "containing", ".", "res", "-", "files", "." ]
9f4a84cdd11f72cfa02cda8c2d7b5174abbb7370
https://github.com/jepegit/cellpy/blob/9f4a84cdd11f72cfa02cda8c2d7b5174abbb7370/cellpy/readers/cellreader.py#L342-L365
train
41,157
jepegit/cellpy
cellpy/readers/cellreader.py
CellpyData.set_cellpy_datadir
def set_cellpy_datadir(self, directory=None): """Set the directory containing .hdf5-files. Used for setting directory for looking for hdf5-files. A valid directory name is required. Args: directory (str): path to hdf5-directory Example: >>> d = CellpyData() >>> directory = "MyData/HDF5" >>> d.set_raw_datadir(directory) """ if directory is None: self.logger.info("no directory name given") return if not os.path.isdir(directory): self.logger.info("directory does not exist") return self.cellpy_datadir = directory
python
def set_cellpy_datadir(self, directory=None): """Set the directory containing .hdf5-files. Used for setting directory for looking for hdf5-files. A valid directory name is required. Args: directory (str): path to hdf5-directory Example: >>> d = CellpyData() >>> directory = "MyData/HDF5" >>> d.set_raw_datadir(directory) """ if directory is None: self.logger.info("no directory name given") return if not os.path.isdir(directory): self.logger.info("directory does not exist") return self.cellpy_datadir = directory
[ "def", "set_cellpy_datadir", "(", "self", ",", "directory", "=", "None", ")", ":", "if", "directory", "is", "None", ":", "self", ".", "logger", ".", "info", "(", "\"no directory name given\"", ")", "return", "if", "not", "os", ".", "path", ".", "isdir", ...
Set the directory containing .hdf5-files. Used for setting directory for looking for hdf5-files. A valid directory name is required. Args: directory (str): path to hdf5-directory Example: >>> d = CellpyData() >>> directory = "MyData/HDF5" >>> d.set_raw_datadir(directory)
[ "Set", "the", "directory", "containing", ".", "hdf5", "-", "files", "." ]
9f4a84cdd11f72cfa02cda8c2d7b5174abbb7370
https://github.com/jepegit/cellpy/blob/9f4a84cdd11f72cfa02cda8c2d7b5174abbb7370/cellpy/readers/cellreader.py#L367-L389
train
41,158
jepegit/cellpy
cellpy/readers/cellreader.py
CellpyData._check_raw
def _check_raw(self, file_names, abort_on_missing=False): """Get the file-ids for the res_files.""" strip_file_names = True check_on = self.filestatuschecker if not self._is_listtype(file_names): file_names = [file_names, ] ids = dict() for f in file_names: self.logger.debug(f"checking res file {f}") fid = FileID(f) # self.logger.debug(fid) if fid.name is None: warnings.warn(f"file does not exist: {f}") if abort_on_missing: sys.exit(-1) else: if strip_file_names: name = os.path.basename(f) else: name = f if check_on == "size": ids[name] = int(fid.size) elif check_on == "modified": ids[name] = int(fid.last_modified) else: ids[name] = int(fid.last_accessed) return ids
python
def _check_raw(self, file_names, abort_on_missing=False): """Get the file-ids for the res_files.""" strip_file_names = True check_on = self.filestatuschecker if not self._is_listtype(file_names): file_names = [file_names, ] ids = dict() for f in file_names: self.logger.debug(f"checking res file {f}") fid = FileID(f) # self.logger.debug(fid) if fid.name is None: warnings.warn(f"file does not exist: {f}") if abort_on_missing: sys.exit(-1) else: if strip_file_names: name = os.path.basename(f) else: name = f if check_on == "size": ids[name] = int(fid.size) elif check_on == "modified": ids[name] = int(fid.last_modified) else: ids[name] = int(fid.last_accessed) return ids
[ "def", "_check_raw", "(", "self", ",", "file_names", ",", "abort_on_missing", "=", "False", ")", ":", "strip_file_names", "=", "True", "check_on", "=", "self", ".", "filestatuschecker", "if", "not", "self", ".", "_is_listtype", "(", "file_names", ")", ":", "...
Get the file-ids for the res_files.
[ "Get", "the", "file", "-", "ids", "for", "the", "res_files", "." ]
9f4a84cdd11f72cfa02cda8c2d7b5174abbb7370
https://github.com/jepegit/cellpy/blob/9f4a84cdd11f72cfa02cda8c2d7b5174abbb7370/cellpy/readers/cellreader.py#L430-L458
train
41,159
jepegit/cellpy
cellpy/readers/cellreader.py
CellpyData._check_cellpy_file
def _check_cellpy_file(self, filename): """Get the file-ids for the cellpy_file.""" strip_filenames = True check_on = self.filestatuschecker self.logger.debug("checking cellpy-file") self.logger.debug(filename) if not os.path.isfile(filename): self.logger.debug("cellpy-file does not exist") return None try: store = pd.HDFStore(filename) except Exception as e: self.logger.debug(f"could not open cellpy-file ({e})") return None try: fidtable = store.select("CellpyData/fidtable") except KeyError: self.logger.warning("no fidtable -" " you should update your hdf5-file") fidtable = None finally: store.close() if fidtable is not None: raw_data_files, raw_data_files_length = \ self._convert2fid_list(fidtable) txt = "contains %i res-files" % (len(raw_data_files)) self.logger.debug(txt) ids = dict() for fid in raw_data_files: full_name = fid.full_name size = fid.size mod = fid.last_modified self.logger.debug(f"fileID information for: {full_name}") self.logger.debug(f" modified: {mod}") self.logger.debug(f" size: {size}") if strip_filenames: name = os.path.basename(full_name) else: name = full_name if check_on == "size": ids[name] = int(fid.size) elif check_on == "modified": ids[name] = int(fid.last_modified) else: ids[name] = int(fid.last_accessed) return ids else: return None
python
def _check_cellpy_file(self, filename): """Get the file-ids for the cellpy_file.""" strip_filenames = True check_on = self.filestatuschecker self.logger.debug("checking cellpy-file") self.logger.debug(filename) if not os.path.isfile(filename): self.logger.debug("cellpy-file does not exist") return None try: store = pd.HDFStore(filename) except Exception as e: self.logger.debug(f"could not open cellpy-file ({e})") return None try: fidtable = store.select("CellpyData/fidtable") except KeyError: self.logger.warning("no fidtable -" " you should update your hdf5-file") fidtable = None finally: store.close() if fidtable is not None: raw_data_files, raw_data_files_length = \ self._convert2fid_list(fidtable) txt = "contains %i res-files" % (len(raw_data_files)) self.logger.debug(txt) ids = dict() for fid in raw_data_files: full_name = fid.full_name size = fid.size mod = fid.last_modified self.logger.debug(f"fileID information for: {full_name}") self.logger.debug(f" modified: {mod}") self.logger.debug(f" size: {size}") if strip_filenames: name = os.path.basename(full_name) else: name = full_name if check_on == "size": ids[name] = int(fid.size) elif check_on == "modified": ids[name] = int(fid.last_modified) else: ids[name] = int(fid.last_accessed) return ids else: return None
[ "def", "_check_cellpy_file", "(", "self", ",", "filename", ")", ":", "strip_filenames", "=", "True", "check_on", "=", "self", ".", "filestatuschecker", "self", ".", "logger", ".", "debug", "(", "\"checking cellpy-file\"", ")", "self", ".", "logger", ".", "debu...
Get the file-ids for the cellpy_file.
[ "Get", "the", "file", "-", "ids", "for", "the", "cellpy_file", "." ]
9f4a84cdd11f72cfa02cda8c2d7b5174abbb7370
https://github.com/jepegit/cellpy/blob/9f4a84cdd11f72cfa02cda8c2d7b5174abbb7370/cellpy/readers/cellreader.py#L460-L509
train
41,160
jepegit/cellpy
cellpy/readers/cellreader.py
CellpyData.loadcell
def loadcell(self, raw_files, cellpy_file=None, mass=None, summary_on_raw=False, summary_ir=True, summary_ocv=False, summary_end_v=True, only_summary=False, only_first=False, force_raw=False, use_cellpy_stat_file=None): """Loads data for given cells. Args: raw_files (list): name of res-files cellpy_file (path): name of cellpy-file mass (float): mass of electrode or active material summary_on_raw (bool): use raw-file for summary summary_ir (bool): summarize ir summary_ocv (bool): summarize ocv steps summary_end_v (bool): summarize end voltage only_summary (bool): get only the summary of the runs only_first (bool): only use the first file fitting search criteria force_raw (bool): only use raw-files use_cellpy_stat_file (bool): use stat file if creating summary from raw Example: >>> srnos = my_dbreader.select_batch("testing_new_solvent") >>> cell_datas = [] >>> for srno in srnos: >>> ... my_run_name = my_dbreader.get_cell_name(srno) >>> ... mass = my_dbreader.get_mass(srno) >>> ... rawfiles, cellpyfiles = \ >>> ... filefinder.search_for_files(my_run_name) >>> ... cell_data = cellreader.CellpyData() >>> ... cell_data.loadcell(raw_files=rawfiles, >>> ... cellpy_file=cellpyfiles) >>> ... cell_data.set_mass(mass) >>> ... if not cell_data.summary_exists: >>> ... cell_data.make_summary() # etc. etc. >>> ... cell_datas.append(cell_data) >>> """ # This is a part of a dramatic API change. It will not be possible to # load more than one set of datasets (i.e. one single cellpy-file or # several raw-files that will be automatically merged) self.logger.info("started loadcell") if cellpy_file is None: similar = False elif force_raw: similar = False else: similar = self.check_file_ids(raw_files, cellpy_file) self.logger.debug("checked if the files were similar") if only_summary: self.load_only_summary = True else: self.load_only_summary = False if not similar: self.logger.info("cellpy file(s) needs updating - loading raw") self.logger.debug(raw_files) self.from_raw(raw_files) self.logger.debug("loaded files") # Check if the run was loaded ([] if empty) if self.status_datasets: if mass: self.set_mass(mass) if summary_on_raw: self.make_summary(all_tests=False, find_ocv=summary_ocv, find_ir=summary_ir, find_end_voltage=summary_end_v, use_cellpy_stat_file=use_cellpy_stat_file) else: self.logger.warning("Empty run!") else: self.load(cellpy_file) return self
python
def loadcell(self, raw_files, cellpy_file=None, mass=None, summary_on_raw=False, summary_ir=True, summary_ocv=False, summary_end_v=True, only_summary=False, only_first=False, force_raw=False, use_cellpy_stat_file=None): """Loads data for given cells. Args: raw_files (list): name of res-files cellpy_file (path): name of cellpy-file mass (float): mass of electrode or active material summary_on_raw (bool): use raw-file for summary summary_ir (bool): summarize ir summary_ocv (bool): summarize ocv steps summary_end_v (bool): summarize end voltage only_summary (bool): get only the summary of the runs only_first (bool): only use the first file fitting search criteria force_raw (bool): only use raw-files use_cellpy_stat_file (bool): use stat file if creating summary from raw Example: >>> srnos = my_dbreader.select_batch("testing_new_solvent") >>> cell_datas = [] >>> for srno in srnos: >>> ... my_run_name = my_dbreader.get_cell_name(srno) >>> ... mass = my_dbreader.get_mass(srno) >>> ... rawfiles, cellpyfiles = \ >>> ... filefinder.search_for_files(my_run_name) >>> ... cell_data = cellreader.CellpyData() >>> ... cell_data.loadcell(raw_files=rawfiles, >>> ... cellpy_file=cellpyfiles) >>> ... cell_data.set_mass(mass) >>> ... if not cell_data.summary_exists: >>> ... cell_data.make_summary() # etc. etc. >>> ... cell_datas.append(cell_data) >>> """ # This is a part of a dramatic API change. It will not be possible to # load more than one set of datasets (i.e. one single cellpy-file or # several raw-files that will be automatically merged) self.logger.info("started loadcell") if cellpy_file is None: similar = False elif force_raw: similar = False else: similar = self.check_file_ids(raw_files, cellpy_file) self.logger.debug("checked if the files were similar") if only_summary: self.load_only_summary = True else: self.load_only_summary = False if not similar: self.logger.info("cellpy file(s) needs updating - loading raw") self.logger.debug(raw_files) self.from_raw(raw_files) self.logger.debug("loaded files") # Check if the run was loaded ([] if empty) if self.status_datasets: if mass: self.set_mass(mass) if summary_on_raw: self.make_summary(all_tests=False, find_ocv=summary_ocv, find_ir=summary_ir, find_end_voltage=summary_end_v, use_cellpy_stat_file=use_cellpy_stat_file) else: self.logger.warning("Empty run!") else: self.load(cellpy_file) return self
[ "def", "loadcell", "(", "self", ",", "raw_files", ",", "cellpy_file", "=", "None", ",", "mass", "=", "None", ",", "summary_on_raw", "=", "False", ",", "summary_ir", "=", "True", ",", "summary_ocv", "=", "False", ",", "summary_end_v", "=", "True", ",", "o...
Loads data for given cells. Args: raw_files (list): name of res-files cellpy_file (path): name of cellpy-file mass (float): mass of electrode or active material summary_on_raw (bool): use raw-file for summary summary_ir (bool): summarize ir summary_ocv (bool): summarize ocv steps summary_end_v (bool): summarize end voltage only_summary (bool): get only the summary of the runs only_first (bool): only use the first file fitting search criteria force_raw (bool): only use raw-files use_cellpy_stat_file (bool): use stat file if creating summary from raw Example: >>> srnos = my_dbreader.select_batch("testing_new_solvent") >>> cell_datas = [] >>> for srno in srnos: >>> ... my_run_name = my_dbreader.get_cell_name(srno) >>> ... mass = my_dbreader.get_mass(srno) >>> ... rawfiles, cellpyfiles = \ >>> ... filefinder.search_for_files(my_run_name) >>> ... cell_data = cellreader.CellpyData() >>> ... cell_data.loadcell(raw_files=rawfiles, >>> ... cellpy_file=cellpyfiles) >>> ... cell_data.set_mass(mass) >>> ... if not cell_data.summary_exists: >>> ... cell_data.make_summary() # etc. etc. >>> ... cell_datas.append(cell_data) >>>
[ "Loads", "data", "for", "given", "cells", "." ]
9f4a84cdd11f72cfa02cda8c2d7b5174abbb7370
https://github.com/jepegit/cellpy/blob/9f4a84cdd11f72cfa02cda8c2d7b5174abbb7370/cellpy/readers/cellreader.py#L525-L602
train
41,161
jepegit/cellpy
cellpy/readers/cellreader.py
CellpyData.from_raw
def from_raw(self, file_names=None, **kwargs): """Load a raw data-file. Args: file_names (list of raw-file names): uses CellpyData.file_names if None. If the list contains more than one file name, then the runs will be merged together. """ # This function only loads one test at a time (but could contain several # files). The function from_res() also implements loading several # datasets (using list of lists as input). if file_names: self.file_names = file_names if not isinstance(file_names, (list, tuple)): self.file_names = [file_names, ] # file_type = self.tester raw_file_loader = self.loader set_number = 0 test = None counter = 0 self.logger.debug("start iterating through file(s)") for f in self.file_names: self.logger.debug("loading raw file:") self.logger.debug(f"{f}") new_tests = raw_file_loader(f, **kwargs) if new_tests: if test is not None: self.logger.debug("continuing reading files...") _test = self._append(test[set_number], new_tests[set_number]) if not _test: self.logger.warning(f"EMPTY TEST: {f}") continue test[set_number] = _test self.logger.debug("added this test - started merging") for j in range(len(new_tests[set_number].raw_data_files)): raw_data_file = new_tests[set_number].raw_data_files[j] file_size = new_tests[set_number].raw_data_files_length[j] test[set_number].raw_data_files.append(raw_data_file) test[set_number].raw_data_files_length.append(file_size) counter += 1 if counter > 10: self.logger.debug("ERROR? Too many files to merge") raise ValueError("Too many files to merge - " "could be a p2-p3 zip thing") else: self.logger.debug("getting data from first file") if new_tests[set_number].no_data: self.logger.debug("NO DATA") else: test = new_tests else: self.logger.debug("NOTHING LOADED") self.logger.debug("finished loading the raw-files") test_exists = False if test: if test[0].no_data: self.logging.debug("the first dataset (or only dataset) loaded from the raw data file is empty") else: test_exists = True if test_exists: if not prms.Reader.sorted_data: self.logger.debug("sorting data") test[set_number] = self._sort_data(test[set_number]) self.datasets.append(test[set_number]) else: self.logger.warning("No new datasets added!") self.number_of_datasets = len(self.datasets) self.status_datasets = self._validate_datasets() self._invent_a_name() return self
python
def from_raw(self, file_names=None, **kwargs): """Load a raw data-file. Args: file_names (list of raw-file names): uses CellpyData.file_names if None. If the list contains more than one file name, then the runs will be merged together. """ # This function only loads one test at a time (but could contain several # files). The function from_res() also implements loading several # datasets (using list of lists as input). if file_names: self.file_names = file_names if not isinstance(file_names, (list, tuple)): self.file_names = [file_names, ] # file_type = self.tester raw_file_loader = self.loader set_number = 0 test = None counter = 0 self.logger.debug("start iterating through file(s)") for f in self.file_names: self.logger.debug("loading raw file:") self.logger.debug(f"{f}") new_tests = raw_file_loader(f, **kwargs) if new_tests: if test is not None: self.logger.debug("continuing reading files...") _test = self._append(test[set_number], new_tests[set_number]) if not _test: self.logger.warning(f"EMPTY TEST: {f}") continue test[set_number] = _test self.logger.debug("added this test - started merging") for j in range(len(new_tests[set_number].raw_data_files)): raw_data_file = new_tests[set_number].raw_data_files[j] file_size = new_tests[set_number].raw_data_files_length[j] test[set_number].raw_data_files.append(raw_data_file) test[set_number].raw_data_files_length.append(file_size) counter += 1 if counter > 10: self.logger.debug("ERROR? Too many files to merge") raise ValueError("Too many files to merge - " "could be a p2-p3 zip thing") else: self.logger.debug("getting data from first file") if new_tests[set_number].no_data: self.logger.debug("NO DATA") else: test = new_tests else: self.logger.debug("NOTHING LOADED") self.logger.debug("finished loading the raw-files") test_exists = False if test: if test[0].no_data: self.logging.debug("the first dataset (or only dataset) loaded from the raw data file is empty") else: test_exists = True if test_exists: if not prms.Reader.sorted_data: self.logger.debug("sorting data") test[set_number] = self._sort_data(test[set_number]) self.datasets.append(test[set_number]) else: self.logger.warning("No new datasets added!") self.number_of_datasets = len(self.datasets) self.status_datasets = self._validate_datasets() self._invent_a_name() return self
[ "def", "from_raw", "(", "self", ",", "file_names", "=", "None", ",", "*", "*", "kwargs", ")", ":", "# This function only loads one test at a time (but could contain several", "# files). The function from_res() also implements loading several", "# datasets (using list of lists as inpu...
Load a raw data-file. Args: file_names (list of raw-file names): uses CellpyData.file_names if None. If the list contains more than one file name, then the runs will be merged together.
[ "Load", "a", "raw", "data", "-", "file", "." ]
9f4a84cdd11f72cfa02cda8c2d7b5174abbb7370
https://github.com/jepegit/cellpy/blob/9f4a84cdd11f72cfa02cda8c2d7b5174abbb7370/cellpy/readers/cellreader.py#L604-L680
train
41,162
jepegit/cellpy
cellpy/readers/cellreader.py
CellpyData.check
def check(self): """Returns False if no datasets exists or if one or more of the datasets are empty""" if len(self.status_datasets) == 0: return False if all(self.status_datasets): return True return False
python
def check(self): """Returns False if no datasets exists or if one or more of the datasets are empty""" if len(self.status_datasets) == 0: return False if all(self.status_datasets): return True return False
[ "def", "check", "(", "self", ")", ":", "if", "len", "(", "self", ".", "status_datasets", ")", "==", "0", ":", "return", "False", "if", "all", "(", "self", ".", "status_datasets", ")", ":", "return", "True", "return", "False" ]
Returns False if no datasets exists or if one or more of the datasets are empty
[ "Returns", "False", "if", "no", "datasets", "exists", "or", "if", "one", "or", "more", "of", "the", "datasets", "are", "empty" ]
9f4a84cdd11f72cfa02cda8c2d7b5174abbb7370
https://github.com/jepegit/cellpy/blob/9f4a84cdd11f72cfa02cda8c2d7b5174abbb7370/cellpy/readers/cellreader.py#L712-L720
train
41,163
jepegit/cellpy
cellpy/readers/cellreader.py
CellpyData.load
def load(self, cellpy_file, parent_level="CellpyData"): """Loads a cellpy file. Args: cellpy_file (path, str): Full path to the cellpy file. parent_level (str, optional): Parent level """ try: self.logger.debug("loading cellpy-file (hdf5):") self.logger.debug(cellpy_file) new_datasets = self._load_hdf5(cellpy_file, parent_level) self.logger.debug("cellpy-file loaded") except AttributeError: new_datasets = [] self.logger.warning("This cellpy-file version is not supported by" "current reader (try to update cellpy).") if new_datasets: for dataset in new_datasets: self.datasets.append(dataset) else: # raise LoadError self.logger.warning("Could not load") self.logger.warning(str(cellpy_file)) self.number_of_datasets = len(self.datasets) self.status_datasets = self._validate_datasets() self._invent_a_name(cellpy_file) return self
python
def load(self, cellpy_file, parent_level="CellpyData"): """Loads a cellpy file. Args: cellpy_file (path, str): Full path to the cellpy file. parent_level (str, optional): Parent level """ try: self.logger.debug("loading cellpy-file (hdf5):") self.logger.debug(cellpy_file) new_datasets = self._load_hdf5(cellpy_file, parent_level) self.logger.debug("cellpy-file loaded") except AttributeError: new_datasets = [] self.logger.warning("This cellpy-file version is not supported by" "current reader (try to update cellpy).") if new_datasets: for dataset in new_datasets: self.datasets.append(dataset) else: # raise LoadError self.logger.warning("Could not load") self.logger.warning(str(cellpy_file)) self.number_of_datasets = len(self.datasets) self.status_datasets = self._validate_datasets() self._invent_a_name(cellpy_file) return self
[ "def", "load", "(", "self", ",", "cellpy_file", ",", "parent_level", "=", "\"CellpyData\"", ")", ":", "try", ":", "self", ".", "logger", ".", "debug", "(", "\"loading cellpy-file (hdf5):\"", ")", "self", ".", "logger", ".", "debug", "(", "cellpy_file", ")", ...
Loads a cellpy file. Args: cellpy_file (path, str): Full path to the cellpy file. parent_level (str, optional): Parent level
[ "Loads", "a", "cellpy", "file", "." ]
9f4a84cdd11f72cfa02cda8c2d7b5174abbb7370
https://github.com/jepegit/cellpy/blob/9f4a84cdd11f72cfa02cda8c2d7b5174abbb7370/cellpy/readers/cellreader.py#L749-L779
train
41,164
jepegit/cellpy
cellpy/readers/cellreader.py
CellpyData._load_hdf5
def _load_hdf5(self, filename, parent_level="CellpyData"): """Load a cellpy-file. Args: filename (str): Name of the cellpy file. parent_level (str) (optional): name of the parent level (defaults to "CellpyData") Returns: loaded datasets (DataSet-object) """ if not os.path.isfile(filename): self.logger.info(f"file does not exist: {filename}") raise IOError store = pd.HDFStore(filename) # required_keys = ['dfdata', 'dfsummary', 'fidtable', 'info'] required_keys = ['dfdata', 'dfsummary', 'info'] required_keys = ["/" + parent_level + "/" + _ for _ in required_keys] for key in required_keys: if key not in store.keys(): self.logger.info(f"This hdf-file is not good enough - " f"at least one key is missing: {key}") raise Exception(f"OH MY GOD! At least one crucial key" f"is missing {key}!") self.logger.debug(f"Keys in current hdf5-file: {store.keys()}") data = DataSet() if parent_level != "CellpyData": self.logger.debug("Using non-default parent label for the " "hdf-store: {}".format(parent_level)) # checking file version infotable = store.select(parent_level + "/info") try: data.cellpy_file_version = \ self._extract_from_dict(infotable, "cellpy_file_version") except Exception as e: data.cellpy_file_version = 0 warnings.warn(f"Unhandled exception raised: {e}") if data.cellpy_file_version < MINIMUM_CELLPY_FILE_VERSION: raise WrongFileVersion if data.cellpy_file_version > CELLPY_FILE_VERSION: raise WrongFileVersion data.dfsummary = store.select(parent_level + "/dfsummary") data.dfdata = store.select(parent_level + "/dfdata") try: data.step_table = store.select(parent_level + "/step_table") except Exception as e: self.logging.debug("could not get step_table from cellpy-file") data.step_table = pd.DataFrame() warnings.warn(f"Unhandled exception raised: {e}") try: fidtable = store.select( parent_level + "/fidtable") # remark! changed spelling from # lower letter to camel-case! fidtable_selected = True except Exception as e: self.logging.debug("could not get fid-table from cellpy-file") fidtable = [] warnings.warn("no fidtable - you should update your hdf5-file") fidtable_selected = False self.logger.debug(" h5") # this does not yet allow multiple sets newtests = [] # but this is ready when that time comes # The infotable stores "meta-data". The follwing statements loads the # content of infotable and updates div. DataSet attributes. # Maybe better use it as dict? data = self._load_infotable(data, infotable, filename) if fidtable_selected: data.raw_data_files, data.raw_data_files_length = \ self._convert2fid_list(fidtable) else: data.raw_data_files = None data.raw_data_files_length = None newtests.append(data) store.close() # self.datasets.append(data) return newtests
python
def _load_hdf5(self, filename, parent_level="CellpyData"): """Load a cellpy-file. Args: filename (str): Name of the cellpy file. parent_level (str) (optional): name of the parent level (defaults to "CellpyData") Returns: loaded datasets (DataSet-object) """ if not os.path.isfile(filename): self.logger.info(f"file does not exist: {filename}") raise IOError store = pd.HDFStore(filename) # required_keys = ['dfdata', 'dfsummary', 'fidtable', 'info'] required_keys = ['dfdata', 'dfsummary', 'info'] required_keys = ["/" + parent_level + "/" + _ for _ in required_keys] for key in required_keys: if key not in store.keys(): self.logger.info(f"This hdf-file is not good enough - " f"at least one key is missing: {key}") raise Exception(f"OH MY GOD! At least one crucial key" f"is missing {key}!") self.logger.debug(f"Keys in current hdf5-file: {store.keys()}") data = DataSet() if parent_level != "CellpyData": self.logger.debug("Using non-default parent label for the " "hdf-store: {}".format(parent_level)) # checking file version infotable = store.select(parent_level + "/info") try: data.cellpy_file_version = \ self._extract_from_dict(infotable, "cellpy_file_version") except Exception as e: data.cellpy_file_version = 0 warnings.warn(f"Unhandled exception raised: {e}") if data.cellpy_file_version < MINIMUM_CELLPY_FILE_VERSION: raise WrongFileVersion if data.cellpy_file_version > CELLPY_FILE_VERSION: raise WrongFileVersion data.dfsummary = store.select(parent_level + "/dfsummary") data.dfdata = store.select(parent_level + "/dfdata") try: data.step_table = store.select(parent_level + "/step_table") except Exception as e: self.logging.debug("could not get step_table from cellpy-file") data.step_table = pd.DataFrame() warnings.warn(f"Unhandled exception raised: {e}") try: fidtable = store.select( parent_level + "/fidtable") # remark! changed spelling from # lower letter to camel-case! fidtable_selected = True except Exception as e: self.logging.debug("could not get fid-table from cellpy-file") fidtable = [] warnings.warn("no fidtable - you should update your hdf5-file") fidtable_selected = False self.logger.debug(" h5") # this does not yet allow multiple sets newtests = [] # but this is ready when that time comes # The infotable stores "meta-data". The follwing statements loads the # content of infotable and updates div. DataSet attributes. # Maybe better use it as dict? data = self._load_infotable(data, infotable, filename) if fidtable_selected: data.raw_data_files, data.raw_data_files_length = \ self._convert2fid_list(fidtable) else: data.raw_data_files = None data.raw_data_files_length = None newtests.append(data) store.close() # self.datasets.append(data) return newtests
[ "def", "_load_hdf5", "(", "self", ",", "filename", ",", "parent_level", "=", "\"CellpyData\"", ")", ":", "if", "not", "os", ".", "path", ".", "isfile", "(", "filename", ")", ":", "self", ".", "logger", ".", "info", "(", "f\"file does not exist: {filename}\""...
Load a cellpy-file. Args: filename (str): Name of the cellpy file. parent_level (str) (optional): name of the parent level (defaults to "CellpyData") Returns: loaded datasets (DataSet-object)
[ "Load", "a", "cellpy", "-", "file", "." ]
9f4a84cdd11f72cfa02cda8c2d7b5174abbb7370
https://github.com/jepegit/cellpy/blob/9f4a84cdd11f72cfa02cda8c2d7b5174abbb7370/cellpy/readers/cellreader.py#L781-L872
train
41,165
jepegit/cellpy
cellpy/readers/cellreader.py
CellpyData.merge
def merge(self, datasets=None, separate_datasets=False): """This function merges datasets into one set.""" self.logger.info("merging") if separate_datasets: warnings.warn("The option seperate_datasets=True is" "not implemented yet. Performing merging, but" "neglecting the option.") else: if datasets is None: datasets = list(range(len(self.datasets))) first = True for dataset_number in datasets: if first: dataset = self.datasets[dataset_number] first = False else: dataset = self._append(dataset, self.datasets[dataset_number]) for raw_data_file, file_size in zip(self.datasets[dataset_number].raw_data_files, self.datasets[dataset_number].raw_data_files_length): dataset.raw_data_files.append(raw_data_file) dataset.raw_data_files_length.append(file_size) self.datasets = [dataset] self.number_of_datasets = 1 return self
python
def merge(self, datasets=None, separate_datasets=False): """This function merges datasets into one set.""" self.logger.info("merging") if separate_datasets: warnings.warn("The option seperate_datasets=True is" "not implemented yet. Performing merging, but" "neglecting the option.") else: if datasets is None: datasets = list(range(len(self.datasets))) first = True for dataset_number in datasets: if first: dataset = self.datasets[dataset_number] first = False else: dataset = self._append(dataset, self.datasets[dataset_number]) for raw_data_file, file_size in zip(self.datasets[dataset_number].raw_data_files, self.datasets[dataset_number].raw_data_files_length): dataset.raw_data_files.append(raw_data_file) dataset.raw_data_files_length.append(file_size) self.datasets = [dataset] self.number_of_datasets = 1 return self
[ "def", "merge", "(", "self", ",", "datasets", "=", "None", ",", "separate_datasets", "=", "False", ")", ":", "self", ".", "logger", ".", "info", "(", "\"merging\"", ")", "if", "separate_datasets", ":", "warnings", ".", "warn", "(", "\"The option seperate_dat...
This function merges datasets into one set.
[ "This", "function", "merges", "datasets", "into", "one", "set", "." ]
9f4a84cdd11f72cfa02cda8c2d7b5174abbb7370
https://github.com/jepegit/cellpy/blob/9f4a84cdd11f72cfa02cda8c2d7b5174abbb7370/cellpy/readers/cellreader.py#L1018-L1041
train
41,166
jepegit/cellpy
cellpy/readers/cellreader.py
CellpyData.print_step_table
def print_step_table(self, dataset_number=None): """Print the step table.""" dataset_number = self._validate_dataset_number(dataset_number) if dataset_number is None: self._report_empty_dataset() return st = self.datasets[dataset_number].step_table print(st)
python
def print_step_table(self, dataset_number=None): """Print the step table.""" dataset_number = self._validate_dataset_number(dataset_number) if dataset_number is None: self._report_empty_dataset() return st = self.datasets[dataset_number].step_table print(st)
[ "def", "print_step_table", "(", "self", ",", "dataset_number", "=", "None", ")", ":", "dataset_number", "=", "self", ".", "_validate_dataset_number", "(", "dataset_number", ")", "if", "dataset_number", "is", "None", ":", "self", ".", "_report_empty_dataset", "(", ...
Print the step table.
[ "Print", "the", "step", "table", "." ]
9f4a84cdd11f72cfa02cda8c2d7b5174abbb7370
https://github.com/jepegit/cellpy/blob/9f4a84cdd11f72cfa02cda8c2d7b5174abbb7370/cellpy/readers/cellreader.py#L1248-L1255
train
41,167
jepegit/cellpy
cellpy/readers/cellreader.py
CellpyData.load_step_specifications
def load_step_specifications(self, file_name, short=False, dataset_number=None): """ Load a table that contains step-type definitions. This function loads a file containing a specification for each step or for each (cycle_number, step_number) combinations if short==False. The step_cycle specifications that are allowed are stored in the variable cellreader.list_of_step_types. """ dataset_number = self._validate_dataset_number(dataset_number) if dataset_number is None: self._report_empty_dataset() return # if short: # # the table only consists of steps (not cycle,step pairs) assuming # # that the step numbers uniquely defines step type (this is true # # for arbin at least). # raise NotImplementedError step_specs = pd.read_csv(file_name, sep=prms.Reader.sep) if "step" not in step_specs.columns: self.logger.info("step col is missing") raise IOError if "type" not in step_specs.columns: self.logger.info("type col is missing") raise IOError if not short and "cycle" not in step_specs.columns: self.logger.info("cycle col is missing") raise IOError self.make_step_table(custom_step_definition=True, step_specifications=step_specs, short=short)
python
def load_step_specifications(self, file_name, short=False, dataset_number=None): """ Load a table that contains step-type definitions. This function loads a file containing a specification for each step or for each (cycle_number, step_number) combinations if short==False. The step_cycle specifications that are allowed are stored in the variable cellreader.list_of_step_types. """ dataset_number = self._validate_dataset_number(dataset_number) if dataset_number is None: self._report_empty_dataset() return # if short: # # the table only consists of steps (not cycle,step pairs) assuming # # that the step numbers uniquely defines step type (this is true # # for arbin at least). # raise NotImplementedError step_specs = pd.read_csv(file_name, sep=prms.Reader.sep) if "step" not in step_specs.columns: self.logger.info("step col is missing") raise IOError if "type" not in step_specs.columns: self.logger.info("type col is missing") raise IOError if not short and "cycle" not in step_specs.columns: self.logger.info("cycle col is missing") raise IOError self.make_step_table(custom_step_definition=True, step_specifications=step_specs, short=short)
[ "def", "load_step_specifications", "(", "self", ",", "file_name", ",", "short", "=", "False", ",", "dataset_number", "=", "None", ")", ":", "dataset_number", "=", "self", ".", "_validate_dataset_number", "(", "dataset_number", ")", "if", "dataset_number", "is", ...
Load a table that contains step-type definitions. This function loads a file containing a specification for each step or for each (cycle_number, step_number) combinations if short==False. The step_cycle specifications that are allowed are stored in the variable cellreader.list_of_step_types.
[ "Load", "a", "table", "that", "contains", "step", "-", "type", "definitions", "." ]
9f4a84cdd11f72cfa02cda8c2d7b5174abbb7370
https://github.com/jepegit/cellpy/blob/9f4a84cdd11f72cfa02cda8c2d7b5174abbb7370/cellpy/readers/cellreader.py#L1396-L1432
train
41,168
jepegit/cellpy
cellpy/readers/cellreader.py
CellpyData.sget_voltage
def sget_voltage(self, cycle, step, set_number=None): """Returns voltage for cycle, step. Convinience function; same as issuing dfdata[(dfdata[cycle_index_header] == cycle) & (dfdata[step_index_header] == step)][voltage_header] Args: cycle: cycle number step: step number set_number: the dataset number (automatic selection if None) Returns: pandas.Series or None if empty """ time_00 = time.time() set_number = self._validate_dataset_number(set_number) if set_number is None: self._report_empty_dataset() return cycle_index_header = self.headers_normal.cycle_index_txt voltage_header = self.headers_normal.voltage_txt step_index_header = self.headers_normal.step_index_txt test = self.datasets[set_number].dfdata if isinstance(step, (list, tuple)): warnings.warn(f"The varialbe step is a list." f"Should be an integer." f"{step}") step = step[0] c = test[(test[cycle_index_header] == cycle) & (test[step_index_header] == step)] self.logger.debug(f"(dt: {(time.time() - time_00):4.2f}s)") if not self.is_empty(c): v = c[voltage_header] return v else: return None
python
def sget_voltage(self, cycle, step, set_number=None): """Returns voltage for cycle, step. Convinience function; same as issuing dfdata[(dfdata[cycle_index_header] == cycle) & (dfdata[step_index_header] == step)][voltage_header] Args: cycle: cycle number step: step number set_number: the dataset number (automatic selection if None) Returns: pandas.Series or None if empty """ time_00 = time.time() set_number = self._validate_dataset_number(set_number) if set_number is None: self._report_empty_dataset() return cycle_index_header = self.headers_normal.cycle_index_txt voltage_header = self.headers_normal.voltage_txt step_index_header = self.headers_normal.step_index_txt test = self.datasets[set_number].dfdata if isinstance(step, (list, tuple)): warnings.warn(f"The varialbe step is a list." f"Should be an integer." f"{step}") step = step[0] c = test[(test[cycle_index_header] == cycle) & (test[step_index_header] == step)] self.logger.debug(f"(dt: {(time.time() - time_00):4.2f}s)") if not self.is_empty(c): v = c[voltage_header] return v else: return None
[ "def", "sget_voltage", "(", "self", ",", "cycle", ",", "step", ",", "set_number", "=", "None", ")", ":", "time_00", "=", "time", ".", "time", "(", ")", "set_number", "=", "self", ".", "_validate_dataset_number", "(", "set_number", ")", "if", "set_number", ...
Returns voltage for cycle, step. Convinience function; same as issuing dfdata[(dfdata[cycle_index_header] == cycle) & (dfdata[step_index_header] == step)][voltage_header] Args: cycle: cycle number step: step number set_number: the dataset number (automatic selection if None) Returns: pandas.Series or None if empty
[ "Returns", "voltage", "for", "cycle", "step", "." ]
9f4a84cdd11f72cfa02cda8c2d7b5174abbb7370
https://github.com/jepegit/cellpy/blob/9f4a84cdd11f72cfa02cda8c2d7b5174abbb7370/cellpy/readers/cellreader.py#L2288-L2328
train
41,169
jepegit/cellpy
cellpy/readers/cellreader.py
CellpyData.sget_steptime
def sget_steptime(self, cycle, step, dataset_number=None): """Returns step time for cycle, step. Convinience function; same as issuing dfdata[(dfdata[cycle_index_header] == cycle) & (dfdata[step_index_header] == step)][step_time_header] Args: cycle: cycle number step: step number dataset_number: the dataset number (automatic selection if None) Returns: pandas.Series or None if empty """ dataset_number = self._validate_dataset_number(dataset_number) if dataset_number is None: self._report_empty_dataset() return cycle_index_header = self.headers_normal.cycle_index_txt step_time_header = self.headers_normal.step_time_txt step_index_header = self.headers_normal.step_index_txt test = self.datasets[dataset_number].dfdata if isinstance(step, (list, tuple)): warnings.warn(f"The varialbe step is a list." f"Should be an integer." f"{step}") step = step[0] c = test.loc[ (test[cycle_index_header] == cycle) & (test[step_index_header] == step), : ] if not self.is_empty(c): t = c[step_time_header] return t else: return None
python
def sget_steptime(self, cycle, step, dataset_number=None): """Returns step time for cycle, step. Convinience function; same as issuing dfdata[(dfdata[cycle_index_header] == cycle) & (dfdata[step_index_header] == step)][step_time_header] Args: cycle: cycle number step: step number dataset_number: the dataset number (automatic selection if None) Returns: pandas.Series or None if empty """ dataset_number = self._validate_dataset_number(dataset_number) if dataset_number is None: self._report_empty_dataset() return cycle_index_header = self.headers_normal.cycle_index_txt step_time_header = self.headers_normal.step_time_txt step_index_header = self.headers_normal.step_index_txt test = self.datasets[dataset_number].dfdata if isinstance(step, (list, tuple)): warnings.warn(f"The varialbe step is a list." f"Should be an integer." f"{step}") step = step[0] c = test.loc[ (test[cycle_index_header] == cycle) & (test[step_index_header] == step), : ] if not self.is_empty(c): t = c[step_time_header] return t else: return None
[ "def", "sget_steptime", "(", "self", ",", "cycle", ",", "step", ",", "dataset_number", "=", "None", ")", ":", "dataset_number", "=", "self", ".", "_validate_dataset_number", "(", "dataset_number", ")", "if", "dataset_number", "is", "None", ":", "self", ".", ...
Returns step time for cycle, step. Convinience function; same as issuing dfdata[(dfdata[cycle_index_header] == cycle) & (dfdata[step_index_header] == step)][step_time_header] Args: cycle: cycle number step: step number dataset_number: the dataset number (automatic selection if None) Returns: pandas.Series or None if empty
[ "Returns", "step", "time", "for", "cycle", "step", "." ]
9f4a84cdd11f72cfa02cda8c2d7b5174abbb7370
https://github.com/jepegit/cellpy/blob/9f4a84cdd11f72cfa02cda8c2d7b5174abbb7370/cellpy/readers/cellreader.py#L2420-L2460
train
41,170
jepegit/cellpy
cellpy/readers/cellreader.py
CellpyData.sget_timestamp
def sget_timestamp(self, cycle, step, dataset_number=None): """Returns timestamp for cycle, step. Convinience function; same as issuing dfdata[(dfdata[cycle_index_header] == cycle) & (dfdata[step_index_header] == step)][timestamp_header] Args: cycle: cycle number step: step number dataset_number: the dataset number (automatic selection if None) Returns: pandas.Series """ dataset_number = self._validate_dataset_number(dataset_number) if dataset_number is None: self._report_empty_dataset() return cycle_index_header = self.headers_normal.cycle_index_txt timestamp_header = self.headers_normal.test_time_txt step_index_header = self.headers_normal.step_index_txt test = self.datasets[dataset_number].dfdata if isinstance(step, (list, tuple)): warnings.warn(f"The varialbe step is a list." f"Should be an integer." f"{step}") step = step[0] c = test[(test[cycle_index_header] == cycle) & (test[step_index_header] == step)] if not self.is_empty(c): t = c[timestamp_header] return t else: return pd.Series()
python
def sget_timestamp(self, cycle, step, dataset_number=None): """Returns timestamp for cycle, step. Convinience function; same as issuing dfdata[(dfdata[cycle_index_header] == cycle) & (dfdata[step_index_header] == step)][timestamp_header] Args: cycle: cycle number step: step number dataset_number: the dataset number (automatic selection if None) Returns: pandas.Series """ dataset_number = self._validate_dataset_number(dataset_number) if dataset_number is None: self._report_empty_dataset() return cycle_index_header = self.headers_normal.cycle_index_txt timestamp_header = self.headers_normal.test_time_txt step_index_header = self.headers_normal.step_index_txt test = self.datasets[dataset_number].dfdata if isinstance(step, (list, tuple)): warnings.warn(f"The varialbe step is a list." f"Should be an integer." f"{step}") step = step[0] c = test[(test[cycle_index_header] == cycle) & (test[step_index_header] == step)] if not self.is_empty(c): t = c[timestamp_header] return t else: return pd.Series()
[ "def", "sget_timestamp", "(", "self", ",", "cycle", ",", "step", ",", "dataset_number", "=", "None", ")", ":", "dataset_number", "=", "self", ".", "_validate_dataset_number", "(", "dataset_number", ")", "if", "dataset_number", "is", "None", ":", "self", ".", ...
Returns timestamp for cycle, step. Convinience function; same as issuing dfdata[(dfdata[cycle_index_header] == cycle) & (dfdata[step_index_header] == step)][timestamp_header] Args: cycle: cycle number step: step number dataset_number: the dataset number (automatic selection if None) Returns: pandas.Series
[ "Returns", "timestamp", "for", "cycle", "step", "." ]
9f4a84cdd11f72cfa02cda8c2d7b5174abbb7370
https://github.com/jepegit/cellpy/blob/9f4a84cdd11f72cfa02cda8c2d7b5174abbb7370/cellpy/readers/cellreader.py#L2462-L2499
train
41,171
jepegit/cellpy
cellpy/readers/cellreader.py
CellpyData.get_ocv
def get_ocv(self, cycles=None, direction="up", remove_first=False, interpolated=False, dx=None, number_of_points=None): """get the open curcuit voltage relaxation curves. Args: cycles (list of ints or None): the cycles to extract from (selects all if not given). direction ("up", "down", or "both"): extract only relaxations that is performed during discharge for "up" (because then the voltage relaxes upwards) etc. remove_first: remove the first relaxation curve (typically, the first curve is from the initial rest period between assembling the cell to the actual testing/cycling starts) interpolated (bool): set to True if you want the data to be interpolated (e.g. for creating smaller files) dx (float): the step used when interpolating. number_of_points (int): number of points to use (over-rides dx) for interpolation (i.e. the length of the interpolated data). Returns: A pandas.DataFrame with cycle-number, step-number, step-time, and voltage columns. """ if cycles is None: cycles = self.get_cycle_numbers() else: if not isinstance(cycles, (list, tuple)): cycles = [cycles, ] else: remove_first = False ocv_rlx_id = "ocvrlx" if direction == "up": ocv_rlx_id += "_up" elif direction == "down": ocv_rlx_id += "_down" step_table = self.dataset.step_table dfdata = self.dataset.dfdata ocv_steps = step_table.loc[ step_table["cycle"].isin(cycles), : ] ocv_steps = ocv_steps.loc[ ocv_steps.type.str.startswith(ocv_rlx_id), : ] if remove_first: ocv_steps = ocv_steps.iloc[1:, :] step_time_label = self.headers_normal.step_time_txt voltage_label = self.headers_normal.voltage_txt cycle_label = self.headers_normal.cycle_index_txt step_label = self.headers_normal.step_index_txt selected_df = dfdata.where( dfdata[cycle_label].isin(ocv_steps.cycle) & dfdata[step_label].isin(ocv_steps.step) ).dropna() selected_df = selected_df.loc[ :, [cycle_label, step_label, step_time_label, voltage_label] ] if interpolated: if dx is None and number_of_points is None: dx = prms.Reader.time_interpolation_step new_dfs = list() groupby_list = [cycle_label, step_label] for name, group in selected_df.groupby(groupby_list): new_group = _interpolate_df_col( group, x=step_time_label, y=voltage_label, dx=dx, number_of_points=number_of_points, ) for i, j in zip(groupby_list, name): new_group[i] = j new_dfs.append(new_group) selected_df = pd.concat(new_dfs) return selected_df
python
def get_ocv(self, cycles=None, direction="up", remove_first=False, interpolated=False, dx=None, number_of_points=None): """get the open curcuit voltage relaxation curves. Args: cycles (list of ints or None): the cycles to extract from (selects all if not given). direction ("up", "down", or "both"): extract only relaxations that is performed during discharge for "up" (because then the voltage relaxes upwards) etc. remove_first: remove the first relaxation curve (typically, the first curve is from the initial rest period between assembling the cell to the actual testing/cycling starts) interpolated (bool): set to True if you want the data to be interpolated (e.g. for creating smaller files) dx (float): the step used when interpolating. number_of_points (int): number of points to use (over-rides dx) for interpolation (i.e. the length of the interpolated data). Returns: A pandas.DataFrame with cycle-number, step-number, step-time, and voltage columns. """ if cycles is None: cycles = self.get_cycle_numbers() else: if not isinstance(cycles, (list, tuple)): cycles = [cycles, ] else: remove_first = False ocv_rlx_id = "ocvrlx" if direction == "up": ocv_rlx_id += "_up" elif direction == "down": ocv_rlx_id += "_down" step_table = self.dataset.step_table dfdata = self.dataset.dfdata ocv_steps = step_table.loc[ step_table["cycle"].isin(cycles), : ] ocv_steps = ocv_steps.loc[ ocv_steps.type.str.startswith(ocv_rlx_id), : ] if remove_first: ocv_steps = ocv_steps.iloc[1:, :] step_time_label = self.headers_normal.step_time_txt voltage_label = self.headers_normal.voltage_txt cycle_label = self.headers_normal.cycle_index_txt step_label = self.headers_normal.step_index_txt selected_df = dfdata.where( dfdata[cycle_label].isin(ocv_steps.cycle) & dfdata[step_label].isin(ocv_steps.step) ).dropna() selected_df = selected_df.loc[ :, [cycle_label, step_label, step_time_label, voltage_label] ] if interpolated: if dx is None and number_of_points is None: dx = prms.Reader.time_interpolation_step new_dfs = list() groupby_list = [cycle_label, step_label] for name, group in selected_df.groupby(groupby_list): new_group = _interpolate_df_col( group, x=step_time_label, y=voltage_label, dx=dx, number_of_points=number_of_points, ) for i, j in zip(groupby_list, name): new_group[i] = j new_dfs.append(new_group) selected_df = pd.concat(new_dfs) return selected_df
[ "def", "get_ocv", "(", "self", ",", "cycles", "=", "None", ",", "direction", "=", "\"up\"", ",", "remove_first", "=", "False", ",", "interpolated", "=", "False", ",", "dx", "=", "None", ",", "number_of_points", "=", "None", ")", ":", "if", "cycles", "i...
get the open curcuit voltage relaxation curves. Args: cycles (list of ints or None): the cycles to extract from (selects all if not given). direction ("up", "down", or "both"): extract only relaxations that is performed during discharge for "up" (because then the voltage relaxes upwards) etc. remove_first: remove the first relaxation curve (typically, the first curve is from the initial rest period between assembling the cell to the actual testing/cycling starts) interpolated (bool): set to True if you want the data to be interpolated (e.g. for creating smaller files) dx (float): the step used when interpolating. number_of_points (int): number of points to use (over-rides dx) for interpolation (i.e. the length of the interpolated data). Returns: A pandas.DataFrame with cycle-number, step-number, step-time, and voltage columns.
[ "get", "the", "open", "curcuit", "voltage", "relaxation", "curves", "." ]
9f4a84cdd11f72cfa02cda8c2d7b5174abbb7370
https://github.com/jepegit/cellpy/blob/9f4a84cdd11f72cfa02cda8c2d7b5174abbb7370/cellpy/readers/cellreader.py#L2837-L2928
train
41,172
jepegit/cellpy
cellpy/readers/cellreader.py
CellpyData.get_number_of_cycles
def get_number_of_cycles(self, dataset_number=None, steptable=None): """Get the number of cycles in the test.""" if steptable is None: dataset_number = self._validate_dataset_number(dataset_number) if dataset_number is None: self._report_empty_dataset() return d = self.datasets[dataset_number].dfdata no_cycles = np.amax(d[self.headers_normal.cycle_index_txt]) else: no_cycles = np.amax(steptable[self.headers_step_table.cycle]) return no_cycles
python
def get_number_of_cycles(self, dataset_number=None, steptable=None): """Get the number of cycles in the test.""" if steptable is None: dataset_number = self._validate_dataset_number(dataset_number) if dataset_number is None: self._report_empty_dataset() return d = self.datasets[dataset_number].dfdata no_cycles = np.amax(d[self.headers_normal.cycle_index_txt]) else: no_cycles = np.amax(steptable[self.headers_step_table.cycle]) return no_cycles
[ "def", "get_number_of_cycles", "(", "self", ",", "dataset_number", "=", "None", ",", "steptable", "=", "None", ")", ":", "if", "steptable", "is", "None", ":", "dataset_number", "=", "self", ".", "_validate_dataset_number", "(", "dataset_number", ")", "if", "da...
Get the number of cycles in the test.
[ "Get", "the", "number", "of", "cycles", "in", "the", "test", "." ]
9f4a84cdd11f72cfa02cda8c2d7b5174abbb7370
https://github.com/jepegit/cellpy/blob/9f4a84cdd11f72cfa02cda8c2d7b5174abbb7370/cellpy/readers/cellreader.py#L3054-L3065
train
41,173
jepegit/cellpy
cellpy/readers/cellreader.py
CellpyData.get_cycle_numbers
def get_cycle_numbers(self, dataset_number=None, steptable=None): """Get a list containing all the cycle numbers in the test.""" if steptable is None: dataset_number = self._validate_dataset_number(dataset_number) if dataset_number is None: self._report_empty_dataset() return d = self.datasets[dataset_number].dfdata cycles = np.unique(d[self.headers_normal.cycle_index_txt]) else: cycles = np.unique(steptable[self.headers_step_table.cycle]) return cycles
python
def get_cycle_numbers(self, dataset_number=None, steptable=None): """Get a list containing all the cycle numbers in the test.""" if steptable is None: dataset_number = self._validate_dataset_number(dataset_number) if dataset_number is None: self._report_empty_dataset() return d = self.datasets[dataset_number].dfdata cycles = np.unique(d[self.headers_normal.cycle_index_txt]) else: cycles = np.unique(steptable[self.headers_step_table.cycle]) return cycles
[ "def", "get_cycle_numbers", "(", "self", ",", "dataset_number", "=", "None", ",", "steptable", "=", "None", ")", ":", "if", "steptable", "is", "None", ":", "dataset_number", "=", "self", ".", "_validate_dataset_number", "(", "dataset_number", ")", "if", "datas...
Get a list containing all the cycle numbers in the test.
[ "Get", "a", "list", "containing", "all", "the", "cycle", "numbers", "in", "the", "test", "." ]
9f4a84cdd11f72cfa02cda8c2d7b5174abbb7370
https://github.com/jepegit/cellpy/blob/9f4a84cdd11f72cfa02cda8c2d7b5174abbb7370/cellpy/readers/cellreader.py#L3067-L3078
train
41,174
jepegit/cellpy
cellpy/readers/cellreader.py
CellpyData.get_converter_to_specific
def get_converter_to_specific(self, dataset=None, mass=None, to_unit=None, from_unit=None): """get the convertion values Args: dataset: DataSet object mass: mass of electrode (for example active material in mg) to_unit: (float) unit of input, f.ex. if unit of charge is mAh and unit of mass is g, then to_unit for charge/mass will be 0.001 / 1.0 = 0.001 from_unit: float) unit of output, f.ex. if unit of charge is mAh and unit of mass is g, then to_unit for charge/mass will be 1.0 / 0.001 = 1000.0 Returns: multiplier (float) from_unit/to_unit * mass """ if not dataset: dataset_number = self._validate_dataset_number(None) if dataset_number is None: self._report_empty_dataset() return dataset = self.datasets[dataset_number] if not mass: mass = dataset.mass if not to_unit: to_unit_cap = self.cellpy_units["charge"] to_unit_mass = self.cellpy_units["specific"] to_unit = to_unit_cap / to_unit_mass if not from_unit: from_unit_cap = self.raw_units["charge"] from_unit_mass = self.raw_units["mass"] from_unit = from_unit_cap / from_unit_mass return from_unit / to_unit / mass
python
def get_converter_to_specific(self, dataset=None, mass=None, to_unit=None, from_unit=None): """get the convertion values Args: dataset: DataSet object mass: mass of electrode (for example active material in mg) to_unit: (float) unit of input, f.ex. if unit of charge is mAh and unit of mass is g, then to_unit for charge/mass will be 0.001 / 1.0 = 0.001 from_unit: float) unit of output, f.ex. if unit of charge is mAh and unit of mass is g, then to_unit for charge/mass will be 1.0 / 0.001 = 1000.0 Returns: multiplier (float) from_unit/to_unit * mass """ if not dataset: dataset_number = self._validate_dataset_number(None) if dataset_number is None: self._report_empty_dataset() return dataset = self.datasets[dataset_number] if not mass: mass = dataset.mass if not to_unit: to_unit_cap = self.cellpy_units["charge"] to_unit_mass = self.cellpy_units["specific"] to_unit = to_unit_cap / to_unit_mass if not from_unit: from_unit_cap = self.raw_units["charge"] from_unit_mass = self.raw_units["mass"] from_unit = from_unit_cap / from_unit_mass return from_unit / to_unit / mass
[ "def", "get_converter_to_specific", "(", "self", ",", "dataset", "=", "None", ",", "mass", "=", "None", ",", "to_unit", "=", "None", ",", "from_unit", "=", "None", ")", ":", "if", "not", "dataset", ":", "dataset_number", "=", "self", ".", "_validate_datase...
get the convertion values Args: dataset: DataSet object mass: mass of electrode (for example active material in mg) to_unit: (float) unit of input, f.ex. if unit of charge is mAh and unit of mass is g, then to_unit for charge/mass will be 0.001 / 1.0 = 0.001 from_unit: float) unit of output, f.ex. if unit of charge is mAh and unit of mass is g, then to_unit for charge/mass will be 1.0 / 0.001 = 1000.0 Returns: multiplier (float) from_unit/to_unit * mass
[ "get", "the", "convertion", "values" ]
9f4a84cdd11f72cfa02cda8c2d7b5174abbb7370
https://github.com/jepegit/cellpy/blob/9f4a84cdd11f72cfa02cda8c2d7b5174abbb7370/cellpy/readers/cellreader.py#L3084-L3122
train
41,175
jepegit/cellpy
cellpy/readers/cellreader.py
CellpyData.set_col_first
def set_col_first(df, col_names): """set selected columns first in a pandas.DataFrame. This function sets cols with names given in col_names (a list) first in the DataFrame. The last col in col_name will come first (processed last) """ column_headings = df.columns column_headings = column_headings.tolist() try: for col_name in col_names: i = column_headings.index(col_name) column_headings.pop(column_headings.index(col_name)) column_headings.insert(0, col_name) finally: df = df.reindex(columns=column_headings) return df
python
def set_col_first(df, col_names): """set selected columns first in a pandas.DataFrame. This function sets cols with names given in col_names (a list) first in the DataFrame. The last col in col_name will come first (processed last) """ column_headings = df.columns column_headings = column_headings.tolist() try: for col_name in col_names: i = column_headings.index(col_name) column_headings.pop(column_headings.index(col_name)) column_headings.insert(0, col_name) finally: df = df.reindex(columns=column_headings) return df
[ "def", "set_col_first", "(", "df", ",", "col_names", ")", ":", "column_headings", "=", "df", ".", "columns", "column_headings", "=", "column_headings", ".", "tolist", "(", ")", "try", ":", "for", "col_name", "in", "col_names", ":", "i", "=", "column_headings...
set selected columns first in a pandas.DataFrame. This function sets cols with names given in col_names (a list) first in the DataFrame. The last col in col_name will come first (processed last)
[ "set", "selected", "columns", "first", "in", "a", "pandas", ".", "DataFrame", "." ]
9f4a84cdd11f72cfa02cda8c2d7b5174abbb7370
https://github.com/jepegit/cellpy/blob/9f4a84cdd11f72cfa02cda8c2d7b5174abbb7370/cellpy/readers/cellreader.py#L3207-L3224
train
41,176
jepegit/cellpy
cellpy/readers/cellreader.py
CellpyData.get_summary
def get_summary(self, dataset_number=None, use_dfsummary_made=False): """Retrieve summary returned as a pandas DataFrame.""" dataset_number = self._validate_dataset_number(dataset_number) if dataset_number is None: self._report_empty_dataset() return None test = self.get_dataset(dataset_number) # This is a bit convoluted; in the old days, we used an attribute # called dfsummary_made, # that was set to True when the summary was made successfully. # It is most likely never # used anymore. And will most probably be deleted. if use_dfsummary_made: dfsummary_made = test.dfsummary_made else: dfsummary_made = True if not dfsummary_made: warnings.warn("Summary is not made yet") return None else: self.logger.info("returning datasets[test_no].dfsummary") return test.dfsummary
python
def get_summary(self, dataset_number=None, use_dfsummary_made=False): """Retrieve summary returned as a pandas DataFrame.""" dataset_number = self._validate_dataset_number(dataset_number) if dataset_number is None: self._report_empty_dataset() return None test = self.get_dataset(dataset_number) # This is a bit convoluted; in the old days, we used an attribute # called dfsummary_made, # that was set to True when the summary was made successfully. # It is most likely never # used anymore. And will most probably be deleted. if use_dfsummary_made: dfsummary_made = test.dfsummary_made else: dfsummary_made = True if not dfsummary_made: warnings.warn("Summary is not made yet") return None else: self.logger.info("returning datasets[test_no].dfsummary") return test.dfsummary
[ "def", "get_summary", "(", "self", ",", "dataset_number", "=", "None", ",", "use_dfsummary_made", "=", "False", ")", ":", "dataset_number", "=", "self", ".", "_validate_dataset_number", "(", "dataset_number", ")", "if", "dataset_number", "is", "None", ":", "self...
Retrieve summary returned as a pandas DataFrame.
[ "Retrieve", "summary", "returned", "as", "a", "pandas", "DataFrame", "." ]
9f4a84cdd11f72cfa02cda8c2d7b5174abbb7370
https://github.com/jepegit/cellpy/blob/9f4a84cdd11f72cfa02cda8c2d7b5174abbb7370/cellpy/readers/cellreader.py#L3271-L3295
train
41,177
jepegit/cellpy
cellpy/readers/cellreader.py
CellpyData.make_summary
def make_summary(self, find_ocv=False, find_ir=False, find_end_voltage=False, use_cellpy_stat_file=None, all_tests=True, dataset_number=0, ensure_step_table=True, convert_date=False): """Convenience function that makes a summary of the cycling data.""" # first - check if we need some "instrument-specific" prms if self.tester == "arbin": convert_date = True if ensure_step_table is None: ensure_step_table = self.ensure_step_table # Cycle_Index Test_Time(s) Test_Time(h) Date_Time Current(A) # Current(mA) Voltage(V) Charge_Capacity(Ah) Discharge_Capacity(Ah) # Charge_Energy(Wh) Discharge_Energy(Wh) Internal_Resistance(Ohm) # AC_Impedance(Ohm) ACI_Phase_Angle(Deg) Charge_Time(s) # DisCharge_Time(s) Vmax_On_Cycle(V) Coulombic_Efficiency if use_cellpy_stat_file is None: use_cellpy_stat_file = prms.Reader.use_cellpy_stat_file self.logger.debug("using use_cellpy_stat_file from prms") self.logger.debug(f"use_cellpy_stat_file: {use_cellpy_stat_file}") if all_tests is True: for j in range(len(self.datasets)): txt = "creating summary for file " test = self.datasets[j] if not self._is_not_empty_dataset(test): self.logger.info("empty test %i" % j) return if isinstance(test.loaded_from, (list, tuple)): for f in test.loaded_from: txt += f txt += "\n" else: txt += str(test.loaded_from) if not test.mass_given: txt += " mass for test %i is not given" % j txt += " setting it to %f mg" % test.mass self.logger.debug(txt) self._make_summary(j, find_ocv=find_ocv, find_ir=find_ir, find_end_voltage=find_end_voltage, use_cellpy_stat_file=use_cellpy_stat_file, ensure_step_table=ensure_step_table, convert_date=convert_date, ) else: self.logger.debug("creating summary for only one test") dataset_number = self._validate_dataset_number(dataset_number) if dataset_number is None: self._report_empty_dataset() return self._make_summary(dataset_number, find_ocv=find_ocv, find_ir=find_ir, find_end_voltage=find_end_voltage, use_cellpy_stat_file=use_cellpy_stat_file, ensure_step_table=ensure_step_table, convert_date=convert_date, ) return self
python
def make_summary(self, find_ocv=False, find_ir=False, find_end_voltage=False, use_cellpy_stat_file=None, all_tests=True, dataset_number=0, ensure_step_table=True, convert_date=False): """Convenience function that makes a summary of the cycling data.""" # first - check if we need some "instrument-specific" prms if self.tester == "arbin": convert_date = True if ensure_step_table is None: ensure_step_table = self.ensure_step_table # Cycle_Index Test_Time(s) Test_Time(h) Date_Time Current(A) # Current(mA) Voltage(V) Charge_Capacity(Ah) Discharge_Capacity(Ah) # Charge_Energy(Wh) Discharge_Energy(Wh) Internal_Resistance(Ohm) # AC_Impedance(Ohm) ACI_Phase_Angle(Deg) Charge_Time(s) # DisCharge_Time(s) Vmax_On_Cycle(V) Coulombic_Efficiency if use_cellpy_stat_file is None: use_cellpy_stat_file = prms.Reader.use_cellpy_stat_file self.logger.debug("using use_cellpy_stat_file from prms") self.logger.debug(f"use_cellpy_stat_file: {use_cellpy_stat_file}") if all_tests is True: for j in range(len(self.datasets)): txt = "creating summary for file " test = self.datasets[j] if not self._is_not_empty_dataset(test): self.logger.info("empty test %i" % j) return if isinstance(test.loaded_from, (list, tuple)): for f in test.loaded_from: txt += f txt += "\n" else: txt += str(test.loaded_from) if not test.mass_given: txt += " mass for test %i is not given" % j txt += " setting it to %f mg" % test.mass self.logger.debug(txt) self._make_summary(j, find_ocv=find_ocv, find_ir=find_ir, find_end_voltage=find_end_voltage, use_cellpy_stat_file=use_cellpy_stat_file, ensure_step_table=ensure_step_table, convert_date=convert_date, ) else: self.logger.debug("creating summary for only one test") dataset_number = self._validate_dataset_number(dataset_number) if dataset_number is None: self._report_empty_dataset() return self._make_summary(dataset_number, find_ocv=find_ocv, find_ir=find_ir, find_end_voltage=find_end_voltage, use_cellpy_stat_file=use_cellpy_stat_file, ensure_step_table=ensure_step_table, convert_date=convert_date, ) return self
[ "def", "make_summary", "(", "self", ",", "find_ocv", "=", "False", ",", "find_ir", "=", "False", ",", "find_end_voltage", "=", "False", ",", "use_cellpy_stat_file", "=", "None", ",", "all_tests", "=", "True", ",", "dataset_number", "=", "0", ",", "ensure_ste...
Convenience function that makes a summary of the cycling data.
[ "Convenience", "function", "that", "makes", "a", "summary", "of", "the", "cycling", "data", "." ]
9f4a84cdd11f72cfa02cda8c2d7b5174abbb7370
https://github.com/jepegit/cellpy/blob/9f4a84cdd11f72cfa02cda8c2d7b5174abbb7370/cellpy/readers/cellreader.py#L3421-L3485
train
41,178
openstax/cnx-epub
cnxepub/scripts/single_html/main.py
single_html
def single_html(epub_file_path, html_out=sys.stdout, mathjax_version=None, numchapters=None, includes=None): """Generate complete book HTML.""" epub = cnxepub.EPUB.from_file(epub_file_path) if len(epub) != 1: raise Exception('Expecting an epub with one book') package = epub[0] binder = cnxepub.adapt_package(package) partcount.update({}.fromkeys(parts, 0)) partcount['book'] += 1 html = cnxepub.SingleHTMLFormatter(binder, includes=includes) # Truncate binder to the first N chapters where N = numchapters. logger.debug('Full binder: {}'.format(cnxepub.model_to_tree(binder))) if numchapters is not None: apply_numchapters(html.get_node_type, binder, numchapters) logger.debug('Truncated Binder: {}'.format( cnxepub.model_to_tree(binder))) # Add mathjax to the page. if mathjax_version: etree.SubElement( html.head, 'script', src=MATHJAX_URL.format(mathjax_version=mathjax_version)) print(str(html), file=html_out) if hasattr(html_out, 'name'): # html_out is a file, close after writing html_out.close()
python
def single_html(epub_file_path, html_out=sys.stdout, mathjax_version=None, numchapters=None, includes=None): """Generate complete book HTML.""" epub = cnxepub.EPUB.from_file(epub_file_path) if len(epub) != 1: raise Exception('Expecting an epub with one book') package = epub[0] binder = cnxepub.adapt_package(package) partcount.update({}.fromkeys(parts, 0)) partcount['book'] += 1 html = cnxepub.SingleHTMLFormatter(binder, includes=includes) # Truncate binder to the first N chapters where N = numchapters. logger.debug('Full binder: {}'.format(cnxepub.model_to_tree(binder))) if numchapters is not None: apply_numchapters(html.get_node_type, binder, numchapters) logger.debug('Truncated Binder: {}'.format( cnxepub.model_to_tree(binder))) # Add mathjax to the page. if mathjax_version: etree.SubElement( html.head, 'script', src=MATHJAX_URL.format(mathjax_version=mathjax_version)) print(str(html), file=html_out) if hasattr(html_out, 'name'): # html_out is a file, close after writing html_out.close()
[ "def", "single_html", "(", "epub_file_path", ",", "html_out", "=", "sys", ".", "stdout", ",", "mathjax_version", "=", "None", ",", "numchapters", "=", "None", ",", "includes", "=", "None", ")", ":", "epub", "=", "cnxepub", ".", "EPUB", ".", "from_file", ...
Generate complete book HTML.
[ "Generate", "complete", "book", "HTML", "." ]
f648a309eff551b0a68a115a98ddf7858149a2ea
https://github.com/openstax/cnx-epub/blob/f648a309eff551b0a68a115a98ddf7858149a2ea/cnxepub/scripts/single_html/main.py#L34-L65
train
41,179
jepegit/cellpy
cellpy/parameters/prmreader.py
_pack_prms
def _pack_prms(): """if you introduce new 'save-able' parameter dictionaries, then you have to include them here""" config_dict = { "Paths": prms.Paths.to_dict(), "FileNames": prms.FileNames.to_dict(), "Db": prms.Db.to_dict(), "DbCols": prms.DbCols.to_dict(), "DataSet": prms.DataSet.to_dict(), "Reader": prms.Reader.to_dict(), "Instruments": prms.Instruments.to_dict(), # "excel_db_cols": prms.excel_db_cols.to_dict(), # "excel_db_filename_cols": prms.excel_db_filename_cols.to_dict(), "Batch": prms.Batch.to_dict(), } return config_dict
python
def _pack_prms(): """if you introduce new 'save-able' parameter dictionaries, then you have to include them here""" config_dict = { "Paths": prms.Paths.to_dict(), "FileNames": prms.FileNames.to_dict(), "Db": prms.Db.to_dict(), "DbCols": prms.DbCols.to_dict(), "DataSet": prms.DataSet.to_dict(), "Reader": prms.Reader.to_dict(), "Instruments": prms.Instruments.to_dict(), # "excel_db_cols": prms.excel_db_cols.to_dict(), # "excel_db_filename_cols": prms.excel_db_filename_cols.to_dict(), "Batch": prms.Batch.to_dict(), } return config_dict
[ "def", "_pack_prms", "(", ")", ":", "config_dict", "=", "{", "\"Paths\"", ":", "prms", ".", "Paths", ".", "to_dict", "(", ")", ",", "\"FileNames\"", ":", "prms", ".", "FileNames", ".", "to_dict", "(", ")", ",", "\"Db\"", ":", "prms", ".", "Db", ".", ...
if you introduce new 'save-able' parameter dictionaries, then you have to include them here
[ "if", "you", "introduce", "new", "save", "-", "able", "parameter", "dictionaries", "then", "you", "have", "to", "include", "them", "here" ]
9f4a84cdd11f72cfa02cda8c2d7b5174abbb7370
https://github.com/jepegit/cellpy/blob/9f4a84cdd11f72cfa02cda8c2d7b5174abbb7370/cellpy/parameters/prmreader.py#L56-L72
train
41,180
jepegit/cellpy
cellpy/parameters/prmreader.py
_read_prm_file
def _read_prm_file(prm_filename): """read the prm file""" logger.debug("Reading config-file: %s" % prm_filename) try: with open(prm_filename, "r") as config_file: prm_dict = yaml.load(config_file) except yaml.YAMLError: raise ConfigFileNotRead else: _update_prms(prm_dict)
python
def _read_prm_file(prm_filename): """read the prm file""" logger.debug("Reading config-file: %s" % prm_filename) try: with open(prm_filename, "r") as config_file: prm_dict = yaml.load(config_file) except yaml.YAMLError: raise ConfigFileNotRead else: _update_prms(prm_dict)
[ "def", "_read_prm_file", "(", "prm_filename", ")", ":", "logger", ".", "debug", "(", "\"Reading config-file: %s\"", "%", "prm_filename", ")", "try", ":", "with", "open", "(", "prm_filename", ",", "\"r\"", ")", "as", "config_file", ":", "prm_dict", "=", "yaml",...
read the prm file
[ "read", "the", "prm", "file" ]
9f4a84cdd11f72cfa02cda8c2d7b5174abbb7370
https://github.com/jepegit/cellpy/blob/9f4a84cdd11f72cfa02cda8c2d7b5174abbb7370/cellpy/parameters/prmreader.py#L75-L84
train
41,181
jepegit/cellpy
cellpy/parameters/prmreader.py
_get_prm_file
def _get_prm_file(file_name=None, search_order=None): """returns name of the prm file""" if file_name is not None: if os.path.isfile(file_name): return file_name else: logger.info("Could not find the prm-file") default_name = prms._prm_default_name prm_globtxt = prms._prm_globtxt script_dir = os.path.abspath(os.path.dirname(__file__)) search_path = dict() search_path["curdir"] = os.path.abspath(os.path.dirname(sys.argv[0])) search_path["filedir"] = script_dir search_path["userdir"] = os.path.expanduser("~") if search_order is None: search_order = ["userdir", ] # ["curdir","filedir", "userdir",] else: search_order = search_order # The default name for the prm file is at the moment in the script-dir,@ # while default searching is in the userdir (yes, I know): prm_default = os.path.join(script_dir, default_name) # -searching----------------------- search_dict = OrderedDict() for key in search_order: search_dict[key] = [None, None] prm_directory = search_path[key] default_file = os.path.join(prm_directory, default_name) if os.path.isfile(default_file): # noinspection PyTypeChecker search_dict[key][0] = default_file prm_globtxt_full = os.path.join(prm_directory, prm_globtxt) user_files = glob.glob(prm_globtxt_full) for f in user_files: if os.path.basename(f) != os.path.basename(default_file): search_dict[key][1] = f break # -selecting---------------------- prm_file = None for key, file_list in search_dict.items(): if file_list[-1]: prm_file = file_list[-1] break else: if not prm_file: prm_file = file_list[0] if prm_file: prm_filename = prm_file else: prm_filename = prm_default return prm_filename
python
def _get_prm_file(file_name=None, search_order=None): """returns name of the prm file""" if file_name is not None: if os.path.isfile(file_name): return file_name else: logger.info("Could not find the prm-file") default_name = prms._prm_default_name prm_globtxt = prms._prm_globtxt script_dir = os.path.abspath(os.path.dirname(__file__)) search_path = dict() search_path["curdir"] = os.path.abspath(os.path.dirname(sys.argv[0])) search_path["filedir"] = script_dir search_path["userdir"] = os.path.expanduser("~") if search_order is None: search_order = ["userdir", ] # ["curdir","filedir", "userdir",] else: search_order = search_order # The default name for the prm file is at the moment in the script-dir,@ # while default searching is in the userdir (yes, I know): prm_default = os.path.join(script_dir, default_name) # -searching----------------------- search_dict = OrderedDict() for key in search_order: search_dict[key] = [None, None] prm_directory = search_path[key] default_file = os.path.join(prm_directory, default_name) if os.path.isfile(default_file): # noinspection PyTypeChecker search_dict[key][0] = default_file prm_globtxt_full = os.path.join(prm_directory, prm_globtxt) user_files = glob.glob(prm_globtxt_full) for f in user_files: if os.path.basename(f) != os.path.basename(default_file): search_dict[key][1] = f break # -selecting---------------------- prm_file = None for key, file_list in search_dict.items(): if file_list[-1]: prm_file = file_list[-1] break else: if not prm_file: prm_file = file_list[0] if prm_file: prm_filename = prm_file else: prm_filename = prm_default return prm_filename
[ "def", "_get_prm_file", "(", "file_name", "=", "None", ",", "search_order", "=", "None", ")", ":", "if", "file_name", "is", "not", "None", ":", "if", "os", ".", "path", ".", "isfile", "(", "file_name", ")", ":", "return", "file_name", "else", ":", "log...
returns name of the prm file
[ "returns", "name", "of", "the", "prm", "file" ]
9f4a84cdd11f72cfa02cda8c2d7b5174abbb7370
https://github.com/jepegit/cellpy/blob/9f4a84cdd11f72cfa02cda8c2d7b5174abbb7370/cellpy/parameters/prmreader.py#L93-L156
train
41,182
jepegit/cellpy
cellpy/parameters/prmreader.py
info
def info(): """this function will show only the 'box'-type attributes and their content in the cellpy.prms module""" print("convenience function for listing prms") print(type(prms)) print(prms.__name__) print(f"prm file: {_get_prm_file()}") for key in prms.__dict__: if isinstance(prms.__dict__[key], box.Box): print() print(80 * "=") print(f"prms.{key}:") print(80 * "-") for subkey in prms.__dict__[key]: print( f"prms.{key}.{subkey} = ", f"{prms.__dict__[key][subkey]}" ) print(80 * "=")
python
def info(): """this function will show only the 'box'-type attributes and their content in the cellpy.prms module""" print("convenience function for listing prms") print(type(prms)) print(prms.__name__) print(f"prm file: {_get_prm_file()}") for key in prms.__dict__: if isinstance(prms.__dict__[key], box.Box): print() print(80 * "=") print(f"prms.{key}:") print(80 * "-") for subkey in prms.__dict__[key]: print( f"prms.{key}.{subkey} = ", f"{prms.__dict__[key][subkey]}" ) print(80 * "=")
[ "def", "info", "(", ")", ":", "print", "(", "\"convenience function for listing prms\"", ")", "print", "(", "type", "(", "prms", ")", ")", "print", "(", "prms", ".", "__name__", ")", "print", "(", "f\"prm file: {_get_prm_file()}\"", ")", "for", "key", "in", ...
this function will show only the 'box'-type attributes and their content in the cellpy.prms module
[ "this", "function", "will", "show", "only", "the", "box", "-", "type", "attributes", "and", "their", "content", "in", "the", "cellpy", ".", "prms", "module" ]
9f4a84cdd11f72cfa02cda8c2d7b5174abbb7370
https://github.com/jepegit/cellpy/blob/9f4a84cdd11f72cfa02cda8c2d7b5174abbb7370/cellpy/parameters/prmreader.py#L165-L184
train
41,183
openstax/cnx-epub
cnxepub/formatters.py
_replace_tex_math
def _replace_tex_math(node, mml_url, mc_client=None, retry=0): """call mml-api service to replace TeX math in body of node with mathml""" math = node.attrib['data-math'] or node.text if math is None: return None eq = {} if mc_client: math_key = hashlib.md5(math.encode('utf-8')).hexdigest() eq = json.loads(mc_client.get(math_key) or '{}') if not eq: res = requests.post(mml_url, {'math': math.encode('utf-8'), 'mathType': 'TeX', 'mml': 'true'}) if res: # Non-error response from requests eq = res.json() if mc_client: mc_client.set(math_key, res.text) if 'components' in eq and len(eq['components']) > 0: for component in eq['components']: if component['format'] == 'mml': mml = etree.fromstring(component['source']) if node.tag.endswith('span'): mml.set('display', 'inline') elif node.tag.endswith('div'): mml.set('display', 'block') mml.tail = node.tail return mml else: logger.warning('Retrying math TeX conversion: ' '{}'.format(json.dumps(eq, indent=4))) retry += 1 if retry < 2: return _replace_tex_math(node, mml_url, mc_client, retry) return None
python
def _replace_tex_math(node, mml_url, mc_client=None, retry=0): """call mml-api service to replace TeX math in body of node with mathml""" math = node.attrib['data-math'] or node.text if math is None: return None eq = {} if mc_client: math_key = hashlib.md5(math.encode('utf-8')).hexdigest() eq = json.loads(mc_client.get(math_key) or '{}') if not eq: res = requests.post(mml_url, {'math': math.encode('utf-8'), 'mathType': 'TeX', 'mml': 'true'}) if res: # Non-error response from requests eq = res.json() if mc_client: mc_client.set(math_key, res.text) if 'components' in eq and len(eq['components']) > 0: for component in eq['components']: if component['format'] == 'mml': mml = etree.fromstring(component['source']) if node.tag.endswith('span'): mml.set('display', 'inline') elif node.tag.endswith('div'): mml.set('display', 'block') mml.tail = node.tail return mml else: logger.warning('Retrying math TeX conversion: ' '{}'.format(json.dumps(eq, indent=4))) retry += 1 if retry < 2: return _replace_tex_math(node, mml_url, mc_client, retry) return None
[ "def", "_replace_tex_math", "(", "node", ",", "mml_url", ",", "mc_client", "=", "None", ",", "retry", "=", "0", ")", ":", "math", "=", "node", ".", "attrib", "[", "'data-math'", "]", "or", "node", ".", "text", "if", "math", "is", "None", ":", "return...
call mml-api service to replace TeX math in body of node with mathml
[ "call", "mml", "-", "api", "service", "to", "replace", "TeX", "math", "in", "body", "of", "node", "with", "mathml" ]
f648a309eff551b0a68a115a98ddf7858149a2ea
https://github.com/openstax/cnx-epub/blob/f648a309eff551b0a68a115a98ddf7858149a2ea/cnxepub/formatters.py#L336-L374
train
41,184
openstax/cnx-epub
cnxepub/formatters.py
exercise_callback_factory
def exercise_callback_factory(match, url_template, mc_client=None, token=None, mml_url=None): """Create a callback function to replace an exercise by fetching from a server.""" def _replace_exercises(elem): item_code = elem.get('href')[len(match):] url = url_template.format(itemCode=item_code) exercise = {} if mc_client: mc_key = item_code + (token or '') exercise = json.loads(mc_client.get(mc_key) or '{}') if not exercise: if token: headers = {'Authorization': 'Bearer {}'.format(token)} res = requests.get(url, headers=headers) else: res = requests.get(url) if res: # grab the json exercise, run it through Jinja2 template, # replace element w/ it exercise = res.json() if mc_client: mc_client.set(mc_key, res.text) if exercise['total_count'] == 0: logger.warning('MISSING EXERCISE: {}'.format(url)) XHTML = '{{{}}}'.format(HTML_DOCUMENT_NAMESPACES['xhtml']) missing = etree.Element(XHTML + 'div', {'class': 'missing-exercise'}, nsmap=HTML_DOCUMENT_NAMESPACES) missing.text = 'MISSING EXERCISE: tag:{}'.format(item_code) nodes = [missing] else: html = EXERCISE_TEMPLATE.render(data=exercise) try: nodes = etree.fromstring('<div>{}</div>'.format(html)) except etree.XMLSyntaxError: # Probably HTML nodes = etree.HTML(html)[0] # body node if mml_url: for node in nodes.xpath('//*[@data-math]'): mathml = _replace_tex_math(node, mml_url, mc_client) if mathml is not None: mparent = node.getparent() mparent.replace(node, mathml) else: mathtext = node.get('data-math') or node.text or '' logger.warning('BAD TEX CONVERSION: "%s" URL: %s' % (mathtext.encode('utf-8'), url)) parent = elem.getparent() if etree.QName(parent.tag).localname == 'p': elem = parent parent = elem.getparent() parent.remove(elem) # Special case - assumes single wrapper elem for child in nodes: parent.append(child) xpath = '//xhtml:a[contains(@href, "{}")]'.format(match) return (xpath, _replace_exercises)
python
def exercise_callback_factory(match, url_template, mc_client=None, token=None, mml_url=None): """Create a callback function to replace an exercise by fetching from a server.""" def _replace_exercises(elem): item_code = elem.get('href')[len(match):] url = url_template.format(itemCode=item_code) exercise = {} if mc_client: mc_key = item_code + (token or '') exercise = json.loads(mc_client.get(mc_key) or '{}') if not exercise: if token: headers = {'Authorization': 'Bearer {}'.format(token)} res = requests.get(url, headers=headers) else: res = requests.get(url) if res: # grab the json exercise, run it through Jinja2 template, # replace element w/ it exercise = res.json() if mc_client: mc_client.set(mc_key, res.text) if exercise['total_count'] == 0: logger.warning('MISSING EXERCISE: {}'.format(url)) XHTML = '{{{}}}'.format(HTML_DOCUMENT_NAMESPACES['xhtml']) missing = etree.Element(XHTML + 'div', {'class': 'missing-exercise'}, nsmap=HTML_DOCUMENT_NAMESPACES) missing.text = 'MISSING EXERCISE: tag:{}'.format(item_code) nodes = [missing] else: html = EXERCISE_TEMPLATE.render(data=exercise) try: nodes = etree.fromstring('<div>{}</div>'.format(html)) except etree.XMLSyntaxError: # Probably HTML nodes = etree.HTML(html)[0] # body node if mml_url: for node in nodes.xpath('//*[@data-math]'): mathml = _replace_tex_math(node, mml_url, mc_client) if mathml is not None: mparent = node.getparent() mparent.replace(node, mathml) else: mathtext = node.get('data-math') or node.text or '' logger.warning('BAD TEX CONVERSION: "%s" URL: %s' % (mathtext.encode('utf-8'), url)) parent = elem.getparent() if etree.QName(parent.tag).localname == 'p': elem = parent parent = elem.getparent() parent.remove(elem) # Special case - assumes single wrapper elem for child in nodes: parent.append(child) xpath = '//xhtml:a[contains(@href, "{}")]'.format(match) return (xpath, _replace_exercises)
[ "def", "exercise_callback_factory", "(", "match", ",", "url_template", ",", "mc_client", "=", "None", ",", "token", "=", "None", ",", "mml_url", "=", "None", ")", ":", "def", "_replace_exercises", "(", "elem", ")", ":", "item_code", "=", "elem", ".", "get"...
Create a callback function to replace an exercise by fetching from a server.
[ "Create", "a", "callback", "function", "to", "replace", "an", "exercise", "by", "fetching", "from", "a", "server", "." ]
f648a309eff551b0a68a115a98ddf7858149a2ea
https://github.com/openstax/cnx-epub/blob/f648a309eff551b0a68a115a98ddf7858149a2ea/cnxepub/formatters.py#L377-L440
train
41,185
openstax/cnx-epub
cnxepub/formatters.py
html_listify
def html_listify(tree, root_xl_element, extensions, list_type='ol'): """Convert a node tree into an xhtml nested list-of-lists. This will create 'li' elements under the root_xl_element, additional sublists of the type passed as list_type. The contents of each li depends on the extensions dictonary: the keys of this dictionary are the ids of tree elements that are repesented by files in the epub, with associated filename extensions as the value. Those nodes will be rendered as links to the reassembled filename: i.e. id='abc-2345-54e4' {'abc-2345-54e4': 'xhtml'} -> abc-2345-54e4.xhtml Other nodes will render as spans. If the node has id or short id values, the associated li will be populated with cnx-archive-uri and cnx-archive-shortid attributes, respectively""" for node in tree: li_elm = etree.SubElement(root_xl_element, 'li') if node['id'] not in extensions: # no extension, no associated file span_elm = lxml.html.fragment_fromstring( node['title'], create_parent='span') li_elm.append(span_elm) else: a_elm = lxml.html.fragment_fromstring( node['title'], create_parent='a') a_elm.set('href', ''.join([node['id'], extensions[node['id']]])) li_elm.append(a_elm) if node['id'] is not None and node['id'] != 'subcol': li_elm.set('cnx-archive-uri', node['id']) if node['shortId'] is not None: li_elm.set('cnx-archive-shortid', node['shortId']) if 'contents' in node: elm = etree.SubElement(li_elm, list_type) html_listify(node['contents'], elm, extensions)
python
def html_listify(tree, root_xl_element, extensions, list_type='ol'): """Convert a node tree into an xhtml nested list-of-lists. This will create 'li' elements under the root_xl_element, additional sublists of the type passed as list_type. The contents of each li depends on the extensions dictonary: the keys of this dictionary are the ids of tree elements that are repesented by files in the epub, with associated filename extensions as the value. Those nodes will be rendered as links to the reassembled filename: i.e. id='abc-2345-54e4' {'abc-2345-54e4': 'xhtml'} -> abc-2345-54e4.xhtml Other nodes will render as spans. If the node has id or short id values, the associated li will be populated with cnx-archive-uri and cnx-archive-shortid attributes, respectively""" for node in tree: li_elm = etree.SubElement(root_xl_element, 'li') if node['id'] not in extensions: # no extension, no associated file span_elm = lxml.html.fragment_fromstring( node['title'], create_parent='span') li_elm.append(span_elm) else: a_elm = lxml.html.fragment_fromstring( node['title'], create_parent='a') a_elm.set('href', ''.join([node['id'], extensions[node['id']]])) li_elm.append(a_elm) if node['id'] is not None and node['id'] != 'subcol': li_elm.set('cnx-archive-uri', node['id']) if node['shortId'] is not None: li_elm.set('cnx-archive-shortid', node['shortId']) if 'contents' in node: elm = etree.SubElement(li_elm, list_type) html_listify(node['contents'], elm, extensions)
[ "def", "html_listify", "(", "tree", ",", "root_xl_element", ",", "extensions", ",", "list_type", "=", "'ol'", ")", ":", "for", "node", "in", "tree", ":", "li_elm", "=", "etree", ".", "SubElement", "(", "root_xl_element", ",", "'li'", ")", "if", "node", "...
Convert a node tree into an xhtml nested list-of-lists. This will create 'li' elements under the root_xl_element, additional sublists of the type passed as list_type. The contents of each li depends on the extensions dictonary: the keys of this dictionary are the ids of tree elements that are repesented by files in the epub, with associated filename extensions as the value. Those nodes will be rendered as links to the reassembled filename: i.e. id='abc-2345-54e4' {'abc-2345-54e4': 'xhtml'} -> abc-2345-54e4.xhtml Other nodes will render as spans. If the node has id or short id values, the associated li will be populated with cnx-archive-uri and cnx-archive-shortid attributes, respectively
[ "Convert", "a", "node", "tree", "into", "an", "xhtml", "nested", "list", "-", "of", "-", "lists", "." ]
f648a309eff551b0a68a115a98ddf7858149a2ea
https://github.com/openstax/cnx-epub/blob/f648a309eff551b0a68a115a98ddf7858149a2ea/cnxepub/formatters.py#L806-L836
train
41,186
openstax/cnx-epub
cnxepub/formatters.py
HTMLFormatter._generate_ids
def _generate_ids(self, document, content): """Generate unique ids for html elements in page content so that it's possible to link to them. """ existing_ids = content.xpath('//*/@id') elements = [ 'p', 'dl', 'dt', 'dd', 'table', 'div', 'section', 'figure', 'blockquote', 'q', 'code', 'pre', 'object', 'img', 'audio', 'video', ] elements_xpath = '|'.join(['.//{}|.//xhtml:{}'.format(elem, elem) for elem in elements]) data_types = [ 'equation', 'list', 'exercise', 'rule', 'example', 'note', 'footnote-number', 'footnote-ref', 'problem', 'solution', 'media', 'proof', 'statement', 'commentary' ] data_types_xpath = '|'.join(['.//*[@data-type="{}"]'.format(data_type) for data_type in data_types]) xpath = '|'.join([elements_xpath, data_types_xpath]) mapping = {} # old id -> new id for node in content.xpath(xpath, namespaces=HTML_DOCUMENT_NAMESPACES): old_id = node.attrib.get('id') document_id = document.id.replace('_', '') if old_id: new_id = 'auto_{}_{}'.format(document_id, old_id) else: random_number = random.randint(0, 100000) new_id = 'auto_{}_{}'.format(document_id, random_number) while new_id in existing_ids: random_number = random.randint(0, 100000) new_id = 'auto_{}_{}'.format(document_id, random_number) node.attrib['id'] = new_id if old_id: mapping[old_id] = new_id existing_ids.append(new_id) for a in content.xpath('//a[@href]|//xhtml:a[@href]', namespaces=HTML_DOCUMENT_NAMESPACES): href = a.attrib['href'] if href.startswith('#') and href[1:] in mapping: a.attrib['href'] = '#{}'.format(mapping[href[1:]])
python
def _generate_ids(self, document, content): """Generate unique ids for html elements in page content so that it's possible to link to them. """ existing_ids = content.xpath('//*/@id') elements = [ 'p', 'dl', 'dt', 'dd', 'table', 'div', 'section', 'figure', 'blockquote', 'q', 'code', 'pre', 'object', 'img', 'audio', 'video', ] elements_xpath = '|'.join(['.//{}|.//xhtml:{}'.format(elem, elem) for elem in elements]) data_types = [ 'equation', 'list', 'exercise', 'rule', 'example', 'note', 'footnote-number', 'footnote-ref', 'problem', 'solution', 'media', 'proof', 'statement', 'commentary' ] data_types_xpath = '|'.join(['.//*[@data-type="{}"]'.format(data_type) for data_type in data_types]) xpath = '|'.join([elements_xpath, data_types_xpath]) mapping = {} # old id -> new id for node in content.xpath(xpath, namespaces=HTML_DOCUMENT_NAMESPACES): old_id = node.attrib.get('id') document_id = document.id.replace('_', '') if old_id: new_id = 'auto_{}_{}'.format(document_id, old_id) else: random_number = random.randint(0, 100000) new_id = 'auto_{}_{}'.format(document_id, random_number) while new_id in existing_ids: random_number = random.randint(0, 100000) new_id = 'auto_{}_{}'.format(document_id, random_number) node.attrib['id'] = new_id if old_id: mapping[old_id] = new_id existing_ids.append(new_id) for a in content.xpath('//a[@href]|//xhtml:a[@href]', namespaces=HTML_DOCUMENT_NAMESPACES): href = a.attrib['href'] if href.startswith('#') and href[1:] in mapping: a.attrib['href'] = '#{}'.format(mapping[href[1:]])
[ "def", "_generate_ids", "(", "self", ",", "document", ",", "content", ")", ":", "existing_ids", "=", "content", ".", "xpath", "(", "'//*/@id'", ")", "elements", "=", "[", "'p'", ",", "'dl'", ",", "'dt'", ",", "'dd'", ",", "'table'", ",", "'div'", ",", ...
Generate unique ids for html elements in page content so that it's possible to link to them.
[ "Generate", "unique", "ids", "for", "html", "elements", "in", "page", "content", "so", "that", "it", "s", "possible", "to", "link", "to", "them", "." ]
f648a309eff551b0a68a115a98ddf7858149a2ea
https://github.com/openstax/cnx-epub/blob/f648a309eff551b0a68a115a98ddf7858149a2ea/cnxepub/formatters.py#L98-L143
train
41,187
openstax/cnx-epub
cnxepub/epub.py
Package.to_file
def to_file(package, directory): """Write the package to the given ``directory``. Returns the OPF filename. """ opf_filepath = os.path.join(directory, package.name) # Create the directory structure for name in ('contents', 'resources',): path = os.path.join(directory, name) if not os.path.exists(path): os.mkdir(path) # Write the items to the filesystem locations = {} # Used when rendering for item in package: if item.media_type == 'application/xhtml+xml': base = os.path.join(directory, 'contents') else: base = os.path.join(directory, 'resources') filename = item.name filepath = os.path.join(base, filename) locations[item] = os.path.relpath(filepath, directory) with open(filepath, 'wb') as item_file: item_file.write(item.data.read()) # Write the OPF template = jinja2.Template(OPF_TEMPLATE, trim_blocks=True, lstrip_blocks=True) with open(opf_filepath, 'wb') as opf_file: opf = template.render(package=package, locations=locations) if not isinstance(opf, bytes): opf = opf.encode('utf-8') opf_file.write(opf) return opf_filepath
python
def to_file(package, directory): """Write the package to the given ``directory``. Returns the OPF filename. """ opf_filepath = os.path.join(directory, package.name) # Create the directory structure for name in ('contents', 'resources',): path = os.path.join(directory, name) if not os.path.exists(path): os.mkdir(path) # Write the items to the filesystem locations = {} # Used when rendering for item in package: if item.media_type == 'application/xhtml+xml': base = os.path.join(directory, 'contents') else: base = os.path.join(directory, 'resources') filename = item.name filepath = os.path.join(base, filename) locations[item] = os.path.relpath(filepath, directory) with open(filepath, 'wb') as item_file: item_file.write(item.data.read()) # Write the OPF template = jinja2.Template(OPF_TEMPLATE, trim_blocks=True, lstrip_blocks=True) with open(opf_filepath, 'wb') as opf_file: opf = template.render(package=package, locations=locations) if not isinstance(opf, bytes): opf = opf.encode('utf-8') opf_file.write(opf) return opf_filepath
[ "def", "to_file", "(", "package", ",", "directory", ")", ":", "opf_filepath", "=", "os", ".", "path", ".", "join", "(", "directory", ",", "package", ".", "name", ")", "# Create the directory structure", "for", "name", "in", "(", "'contents'", ",", "'resource...
Write the package to the given ``directory``. Returns the OPF filename.
[ "Write", "the", "package", "to", "the", "given", "directory", ".", "Returns", "the", "OPF", "filename", "." ]
f648a309eff551b0a68a115a98ddf7858149a2ea
https://github.com/openstax/cnx-epub/blob/f648a309eff551b0a68a115a98ddf7858149a2ea/cnxepub/epub.py#L379-L413
train
41,188
jepegit/cellpy
cellpy/utils/batch_tools/batch_journals.py
LabJournal.from_file
def from_file(self, file_name=None): """Loads a DataFrame with all the needed info about the experiment""" file_name = self._check_file_name(file_name) with open(file_name, 'r') as infile: top_level_dict = json.load(infile) pages_dict = top_level_dict['info_df'] pages = pd.DataFrame(pages_dict) self.pages = pages self.file_name = file_name self._prm_packer(top_level_dict['metadata']) self.generate_folder_names() self.paginate()
python
def from_file(self, file_name=None): """Loads a DataFrame with all the needed info about the experiment""" file_name = self._check_file_name(file_name) with open(file_name, 'r') as infile: top_level_dict = json.load(infile) pages_dict = top_level_dict['info_df'] pages = pd.DataFrame(pages_dict) self.pages = pages self.file_name = file_name self._prm_packer(top_level_dict['metadata']) self.generate_folder_names() self.paginate()
[ "def", "from_file", "(", "self", ",", "file_name", "=", "None", ")", ":", "file_name", "=", "self", ".", "_check_file_name", "(", "file_name", ")", "with", "open", "(", "file_name", ",", "'r'", ")", "as", "infile", ":", "top_level_dict", "=", "json", "."...
Loads a DataFrame with all the needed info about the experiment
[ "Loads", "a", "DataFrame", "with", "all", "the", "needed", "info", "about", "the", "experiment" ]
9f4a84cdd11f72cfa02cda8c2d7b5174abbb7370
https://github.com/jepegit/cellpy/blob/9f4a84cdd11f72cfa02cda8c2d7b5174abbb7370/cellpy/utils/batch_tools/batch_journals.py#L47-L61
train
41,189
jepegit/cellpy
cellpy/utils/batch_tools/batch_journals.py
LabJournal.to_file
def to_file(self, file_name=None): """Saves a DataFrame with all the needed info about the experiment""" file_name = self._check_file_name(file_name) pages = self.pages top_level_dict = { 'info_df': pages, 'metadata': self._prm_packer() } jason_string = json.dumps( top_level_dict, default=lambda info_df: json.loads( info_df.to_json() ) ) self.paginate() with open(file_name, 'w') as outfile: outfile.write(jason_string) self.file_name = file_name logging.info("Saved file to {}".format(file_name))
python
def to_file(self, file_name=None): """Saves a DataFrame with all the needed info about the experiment""" file_name = self._check_file_name(file_name) pages = self.pages top_level_dict = { 'info_df': pages, 'metadata': self._prm_packer() } jason_string = json.dumps( top_level_dict, default=lambda info_df: json.loads( info_df.to_json() ) ) self.paginate() with open(file_name, 'w') as outfile: outfile.write(jason_string) self.file_name = file_name logging.info("Saved file to {}".format(file_name))
[ "def", "to_file", "(", "self", ",", "file_name", "=", "None", ")", ":", "file_name", "=", "self", ".", "_check_file_name", "(", "file_name", ")", "pages", "=", "self", ".", "pages", "top_level_dict", "=", "{", "'info_df'", ":", "pages", ",", "'metadata'", ...
Saves a DataFrame with all the needed info about the experiment
[ "Saves", "a", "DataFrame", "with", "all", "the", "needed", "info", "about", "the", "experiment" ]
9f4a84cdd11f72cfa02cda8c2d7b5174abbb7370
https://github.com/jepegit/cellpy/blob/9f4a84cdd11f72cfa02cda8c2d7b5174abbb7370/cellpy/utils/batch_tools/batch_journals.py#L63-L87
train
41,190
jepegit/cellpy
cellpy/utils/batch_tools/batch_journals.py
LabJournal.generate_folder_names
def generate_folder_names(self): """Set appropriate folder names.""" self.project_dir = os.path.join(prms.Paths.outdatadir, self.project) self.batch_dir = os.path.join(self.project_dir, self.name) self.raw_dir = os.path.join(self.batch_dir, "raw_data")
python
def generate_folder_names(self): """Set appropriate folder names.""" self.project_dir = os.path.join(prms.Paths.outdatadir, self.project) self.batch_dir = os.path.join(self.project_dir, self.name) self.raw_dir = os.path.join(self.batch_dir, "raw_data")
[ "def", "generate_folder_names", "(", "self", ")", ":", "self", ".", "project_dir", "=", "os", ".", "path", ".", "join", "(", "prms", ".", "Paths", ".", "outdatadir", ",", "self", ".", "project", ")", "self", ".", "batch_dir", "=", "os", ".", "path", ...
Set appropriate folder names.
[ "Set", "appropriate", "folder", "names", "." ]
9f4a84cdd11f72cfa02cda8c2d7b5174abbb7370
https://github.com/jepegit/cellpy/blob/9f4a84cdd11f72cfa02cda8c2d7b5174abbb7370/cellpy/utils/batch_tools/batch_journals.py#L89-L93
train
41,191
jepegit/cellpy
cellpy/utils/batch_tools/batch_journals.py
LabJournal.paginate
def paginate(self): """Make folders where we would like to put results etc.""" project_dir = self.project_dir raw_dir = self.raw_dir batch_dir = self.batch_dir if project_dir is None: raise UnderDefined("no project directory defined") if raw_dir is None: raise UnderDefined("no raw directory defined") if batch_dir is None: raise UnderDefined("no batcb directory defined") # create the folders if not os.path.isdir(project_dir): os.mkdir(project_dir) logging.info(f"created folder {project_dir}") if not os.path.isdir(batch_dir): os.mkdir(batch_dir) logging.info(f"created folder {batch_dir}") if not os.path.isdir(raw_dir): os.mkdir(raw_dir) logging.info(f"created folder {raw_dir}") return project_dir, batch_dir, raw_dir
python
def paginate(self): """Make folders where we would like to put results etc.""" project_dir = self.project_dir raw_dir = self.raw_dir batch_dir = self.batch_dir if project_dir is None: raise UnderDefined("no project directory defined") if raw_dir is None: raise UnderDefined("no raw directory defined") if batch_dir is None: raise UnderDefined("no batcb directory defined") # create the folders if not os.path.isdir(project_dir): os.mkdir(project_dir) logging.info(f"created folder {project_dir}") if not os.path.isdir(batch_dir): os.mkdir(batch_dir) logging.info(f"created folder {batch_dir}") if not os.path.isdir(raw_dir): os.mkdir(raw_dir) logging.info(f"created folder {raw_dir}") return project_dir, batch_dir, raw_dir
[ "def", "paginate", "(", "self", ")", ":", "project_dir", "=", "self", ".", "project_dir", "raw_dir", "=", "self", ".", "raw_dir", "batch_dir", "=", "self", ".", "batch_dir", "if", "project_dir", "is", "None", ":", "raise", "UnderDefined", "(", "\"no project ...
Make folders where we would like to put results etc.
[ "Make", "folders", "where", "we", "would", "like", "to", "put", "results", "etc", "." ]
9f4a84cdd11f72cfa02cda8c2d7b5174abbb7370
https://github.com/jepegit/cellpy/blob/9f4a84cdd11f72cfa02cda8c2d7b5174abbb7370/cellpy/utils/batch_tools/batch_journals.py#L95-L120
train
41,192
jepegit/cellpy
cellpy/utils/batch_tools/batch_journals.py
LabJournal.generate_file_name
def generate_file_name(self): """generate a suitable file name for the experiment""" if not self.project: raise UnderDefined("project name not given") out_data_dir = prms.Paths.outdatadir project_dir = os.path.join(out_data_dir, self.project) file_name = "cellpy_batch_%s.json" % self.name self.file_name = os.path.join(project_dir, file_name)
python
def generate_file_name(self): """generate a suitable file name for the experiment""" if not self.project: raise UnderDefined("project name not given") out_data_dir = prms.Paths.outdatadir project_dir = os.path.join(out_data_dir, self.project) file_name = "cellpy_batch_%s.json" % self.name self.file_name = os.path.join(project_dir, file_name)
[ "def", "generate_file_name", "(", "self", ")", ":", "if", "not", "self", ".", "project", ":", "raise", "UnderDefined", "(", "\"project name not given\"", ")", "out_data_dir", "=", "prms", ".", "Paths", ".", "outdatadir", "project_dir", "=", "os", ".", "path", ...
generate a suitable file name for the experiment
[ "generate", "a", "suitable", "file", "name", "for", "the", "experiment" ]
9f4a84cdd11f72cfa02cda8c2d7b5174abbb7370
https://github.com/jepegit/cellpy/blob/9f4a84cdd11f72cfa02cda8c2d7b5174abbb7370/cellpy/utils/batch_tools/batch_journals.py#L122-L130
train
41,193
jepegit/cellpy
cellpy/utils/batch_tools/batch_core.py
Doer.info
def info(self): """Delivers some info to you about the class.""" print("Sorry, but I don't have much to share.") print("This is me:") print(self) print("And these are the experiments assigned to me:") print(self.experiments)
python
def info(self): """Delivers some info to you about the class.""" print("Sorry, but I don't have much to share.") print("This is me:") print(self) print("And these are the experiments assigned to me:") print(self.experiments)
[ "def", "info", "(", "self", ")", ":", "print", "(", "\"Sorry, but I don't have much to share.\"", ")", "print", "(", "\"This is me:\"", ")", "print", "(", "self", ")", "print", "(", "\"And these are the experiments assigned to me:\"", ")", "print", "(", "self", ".",...
Delivers some info to you about the class.
[ "Delivers", "some", "info", "to", "you", "about", "the", "class", "." ]
9f4a84cdd11f72cfa02cda8c2d7b5174abbb7370
https://github.com/jepegit/cellpy/blob/9f4a84cdd11f72cfa02cda8c2d7b5174abbb7370/cellpy/utils/batch_tools/batch_core.py#L46-L53
train
41,194
jepegit/cellpy
cellpy/utils/batch_tools/batch_core.py
Doer.assign
def assign(self, experiment): """Assign an experiment.""" self.experiments.append(experiment) self.farms.append(empty_farm)
python
def assign(self, experiment): """Assign an experiment.""" self.experiments.append(experiment) self.farms.append(empty_farm)
[ "def", "assign", "(", "self", ",", "experiment", ")", ":", "self", ".", "experiments", ".", "append", "(", "experiment", ")", "self", ".", "farms", ".", "append", "(", "empty_farm", ")" ]
Assign an experiment.
[ "Assign", "an", "experiment", "." ]
9f4a84cdd11f72cfa02cda8c2d7b5174abbb7370
https://github.com/jepegit/cellpy/blob/9f4a84cdd11f72cfa02cda8c2d7b5174abbb7370/cellpy/utils/batch_tools/batch_core.py#L55-L59
train
41,195
openstax/cnx-epub
cnxepub/models.py
flatten_model
def flatten_model(model): """Flatten a model to a list of models. This is used to flatten a ``Binder``'ish model down to a list of contained models. """ yield model if isinstance(model, (TranslucentBinder, Binder,)): for m in model: # yield from flatten_model(m) for x in flatten_model(m): yield x
python
def flatten_model(model): """Flatten a model to a list of models. This is used to flatten a ``Binder``'ish model down to a list of contained models. """ yield model if isinstance(model, (TranslucentBinder, Binder,)): for m in model: # yield from flatten_model(m) for x in flatten_model(m): yield x
[ "def", "flatten_model", "(", "model", ")", ":", "yield", "model", "if", "isinstance", "(", "model", ",", "(", "TranslucentBinder", ",", "Binder", ",", ")", ")", ":", "for", "m", "in", "model", ":", "# yield from flatten_model(m)", "for", "x", "in", "flatte...
Flatten a model to a list of models. This is used to flatten a ``Binder``'ish model down to a list of contained models.
[ "Flatten", "a", "model", "to", "a", "list", "of", "models", ".", "This", "is", "used", "to", "flatten", "a", "Binder", "ish", "model", "down", "to", "a", "list", "of", "contained", "models", "." ]
f648a309eff551b0a68a115a98ddf7858149a2ea
https://github.com/openstax/cnx-epub/blob/f648a309eff551b0a68a115a98ddf7858149a2ea/cnxepub/models.py#L146-L156
train
41,196
openstax/cnx-epub
cnxepub/models.py
_discover_uri_type
def _discover_uri_type(uri): """Given a ``uri``, determine if it is internal or external.""" parsed_uri = urlparse(uri) if not parsed_uri.netloc: if parsed_uri.scheme == 'data': type_ = INLINE_REFERENCE_TYPE else: type_ = INTERNAL_REFERENCE_TYPE else: type_ = EXTERNAL_REFERENCE_TYPE return type_
python
def _discover_uri_type(uri): """Given a ``uri``, determine if it is internal or external.""" parsed_uri = urlparse(uri) if not parsed_uri.netloc: if parsed_uri.scheme == 'data': type_ = INLINE_REFERENCE_TYPE else: type_ = INTERNAL_REFERENCE_TYPE else: type_ = EXTERNAL_REFERENCE_TYPE return type_
[ "def", "_discover_uri_type", "(", "uri", ")", ":", "parsed_uri", "=", "urlparse", "(", "uri", ")", "if", "not", "parsed_uri", ".", "netloc", ":", "if", "parsed_uri", ".", "scheme", "==", "'data'", ":", "type_", "=", "INLINE_REFERENCE_TYPE", "else", ":", "t...
Given a ``uri``, determine if it is internal or external.
[ "Given", "a", "uri", "determine", "if", "it", "is", "internal", "or", "external", "." ]
f648a309eff551b0a68a115a98ddf7858149a2ea
https://github.com/openstax/cnx-epub/blob/f648a309eff551b0a68a115a98ddf7858149a2ea/cnxepub/models.py#L191-L201
train
41,197
openstax/cnx-epub
cnxepub/models.py
_parse_references
def _parse_references(xml): """Parse the references to ``Reference`` instances.""" references = [] ref_finder = HTMLReferenceFinder(xml) for elm, uri_attr in ref_finder: type_ = _discover_uri_type(elm.get(uri_attr)) references.append(Reference(elm, type_, uri_attr)) return references
python
def _parse_references(xml): """Parse the references to ``Reference`` instances.""" references = [] ref_finder = HTMLReferenceFinder(xml) for elm, uri_attr in ref_finder: type_ = _discover_uri_type(elm.get(uri_attr)) references.append(Reference(elm, type_, uri_attr)) return references
[ "def", "_parse_references", "(", "xml", ")", ":", "references", "=", "[", "]", "ref_finder", "=", "HTMLReferenceFinder", "(", "xml", ")", "for", "elm", ",", "uri_attr", "in", "ref_finder", ":", "type_", "=", "_discover_uri_type", "(", "elm", ".", "get", "(...
Parse the references to ``Reference`` instances.
[ "Parse", "the", "references", "to", "Reference", "instances", "." ]
f648a309eff551b0a68a115a98ddf7858149a2ea
https://github.com/openstax/cnx-epub/blob/f648a309eff551b0a68a115a98ddf7858149a2ea/cnxepub/models.py#L204-L211
train
41,198
openstax/cnx-epub
cnxepub/models.py
Reference._set_uri_from_bound_model
def _set_uri_from_bound_model(self): """Using the bound model, set the uri.""" value = self._uri_template.format(self._bound_model.id) self.elm.set(self._uri_attr, value)
python
def _set_uri_from_bound_model(self): """Using the bound model, set the uri.""" value = self._uri_template.format(self._bound_model.id) self.elm.set(self._uri_attr, value)
[ "def", "_set_uri_from_bound_model", "(", "self", ")", ":", "value", "=", "self", ".", "_uri_template", ".", "format", "(", "self", ".", "_bound_model", ".", "id", ")", "self", ".", "elm", ".", "set", "(", "self", ".", "_uri_attr", ",", "value", ")" ]
Using the bound model, set the uri.
[ "Using", "the", "bound", "model", "set", "the", "uri", "." ]
f648a309eff551b0a68a115a98ddf7858149a2ea
https://github.com/openstax/cnx-epub/blob/f648a309eff551b0a68a115a98ddf7858149a2ea/cnxepub/models.py#L258-L261
train
41,199