Read/Write Data¶
read_xlsx¶
- isopy.read_xlsx(filename, sheetname=None, has_keys=None, keys_in_first=None, comment_symbol='#', start_at='A1')[source]¶
Load data from an excel file.
- Parameters
filename (str, bytes, BytesIO) – Path for file to be opened. Also accepts file like objects.
sheetname (str, int, Optional) – To load data from a single sheet in the workbook pass either the name of the sheet or the position of the sheet. If nothing is specified all the data for all sheets in the workbook is returned.
has_keys (bool, None) – If True or keys_in_first is not None a dictionary will always be returned. If False an nexted list is always returned. If None it will return a nested list of all values in the first row and column can be converted to/is a float.
keys_in_first ({'c', 'r', None}) – Where the keys are found. Give ‘r’ if the keys are found in the first row and ‘c’ if the keys are in first column. If None it will analyse the data to determine where the keys are. If has_keys is not False an exception will be raised if it cant determine where the keys are.
comment_symbol (str, Default = '#') – Rows starting with this string will be ignored.
start_at (str, (int, int)) – Start scanning at this cell. Can either be a excel style cell reference or a (row, column) tuple of integers.
- Returns
data – A dictionary containing the data for a single sheet or a dictionary containing the data for multiple sheets in the workbook indexed by sheet name.
- Return type
write_xlsx¶
- isopy.write_xlsx(filename, *sheets, comments=None, keys_in_first='r', comment_symbol='#', keyfmt=None, start_at='A1', append=False, clear=True, **sheetnames)[source]¶
Save data to an excel file.
- Parameters
filename (str, BytesIO) – Path/name of the excel file to be created. Any existing file with the same path/name will be overwritten. Also accepts file like objects.
sheets (isopy_array_like, numpy_array_like) – Data given here will be saved as sheet1, sheet2 etc.
comments (str, Sequence[str], Optional) – Comments to be included at the top of the file
keys_in_first ({'c', 'r'}) – Only used if the input has keys. Give ‘r’ if the keys should be in the first row and ‘c’ if the keys should be in the first column.
comment_symbol (str, Default = '#') – This string will precede any comments at the beginning of the file
keyfmt – Specify the format used for the key string. See the
str()method of each key string for options.start_at (str, (int, int)) – The first cell where the data is written. Can either be a excel style cell reference or a (row, column) tuple of integers.
append (bool, Default = False) – If
Trueand filename exists it will append the data to this workbook. An exception is raised if filename is not a valid excel workbook.clear (bool, Default = True) – If
Trueany preexisting sheets are cleared before any new data is written to it.sheetnames (isopy_array, numpy_array) – Data given here will be saved in a sheet with sheetname name.
read_csv¶
- isopy.read_csv(filename, has_keys=None, keys_in_first=None, comment_symbol='#', encoding=None, dialect='excel')[source]¶
Load data from a csv file.
- Parameters
filename (str, bytes, StringIO, BytesIO) – Path for file to be opened. Alternatively a file like byte string can be supplied. Also accepts file like objects.
has_keys (bool, None) – If True or keys_in_first is not None a dictionary will always be returned. If False an nexted list is always returned. If None it will return a nested list of all values in the first row and column can be converted to/is a float.
keys_in_first ({'c', 'r', None}) – Where the keys are found. Give ‘r’ if the keys are found in the first row and ‘c’ if the keys are in first column. If None it will analyse the data to determine where the keys are. If has_keys is not False an exception will be raised if it cant determine where the keys are.
comment_symbol (str, Default = '#') – Rows starting with this string will be ignored.
encoding (str) – Encoding of the file. If None the encoding will be guessed from the file.
dialect – Dialect of the csv file. If None the dialect will be guessed from the file.
- Returns
data – Returns a dictionary for data with keys otherwise a list.
- Return type
write_csv¶
- isopy.write_csv(filename, data, comments=None, keys_in_first='r', comment_symbol='#', keyfmt=None, dialect='excel')[source]¶
Save data to a csv file.
- Parameters
filename (str, StringIO, BytesIO) – Path/name of the csv file to be created. Any existing file with the same path/name will be over written. Also accepts file like objects.
data (isopy_array_like, numpy_array_like) – Data to be saved in the array.
comments (str, Sequence[str], Optional) – Comments to be included at the top of the file
keys_in_first ({'c', 'r'}) – Only used if the input has keys. Give ‘r’ if the keys should be in the first row and ‘c’ if the keys should be in the first column.
comment_symbol (str, Default = '#') – This string will precede any comments at the beginning of the file.
keyfmt – Specify the format used for the key string. See the
str()method of each key string for options.dialect – The CSV dialect used to save the file. Default to ‘excel’ which is a ‘, ‘ seperated file.
- Return type
None
read_clipboard¶
- isopy.read_clipboard(has_keys=None, keys_in_first=None, comment_symbol='#', dialect=None)[source]¶
Load data from values in the clipboard.
- Parameters
comment_symbol (str, Default = '#') – Rows starting with this string will be ignored.
has_keys (bool, None) – If True or keys_in_first is not None a dictionary will always be returned. If False an nexted list is always returned. If None it will return a nested list of all values in the first row and column can be converted to/is a float.
keys_in_first ({'c', 'r', None}) – Where the keys are found. Give ‘r’ if the keys are found in the first row and ‘c’ if the keys are in first column. If None it will analyse the data to determine where the keys are. If has_keys is not False an exception will be raised if it cant determine where the keys are.
dialect – Dialect of the values in the clipboard. If None the dialect will be guessed from the values.
write_clipboard¶
- isopy.write_clipboard(data, comments=None, keys_in_first='r', comment_symbol='#', keyfmt=None, dialect='excel')[source]¶
Copies data to the clipboard
- Parameters
data (isopy_array_like, numpy_array_like) – Data to be copied.
comments (str, Sequence[str], Optional) – Comments to be included
keys_in_first ({'c', 'r'}) – Only used if the input has keys. Give ‘r’ if the keys should be in the first row and ‘c’ if the keys should be in the first column.
comment_symbol (str, Default = '#') – This string will precede any comments.
keyfmt – Specify the format used for the key string. See the
str()method of each key string for options.dialect – The CSV dialect used to copy the data to the clipboard. Default to ‘excel’ which is gives ‘, ‘ seperated data.
read_exp¶
- isopy.read_exp(filename, rename=None)[source]¶
Load data from a Neptune/Triton export file.
- Parameters
filename (str, bytes, StringIO, BytesIO) – Path for file to be opened. Alternatively a file like byte string or a file like object can be supplied.
rename (dict, Callable, Optional) – For renaming keys in the analysed data. Useful for cases when the key is the mass rather than the isotope measured. If a dictionary is passed then every key present in the dictionary will be replaced by the associated value. A callable can also be passed that takes the key in the file and returns the new key.
- Returns
neptune_data – An object containing the following attributes:
info - Dictionary containing the metadata included at the beginning of the file.
cycle - A list containing the cycle number for each measurement.
time - A list containing datetime objects for each measurement.
measurements - An dictionary containing an an isopy array with the values in for each line measured. Static measurements are always given as line
1.
To extract e.g only the isotope data from a measurement use
neptune_data.measurement[line].copy(flavour_eq='isotope').- Return type
NeptuneData