raspyre package

Submodules

raspyre.converter module

Raspyre Converter CSV Version: 0.1 Binary Version: 0.4

This tool converts Raspyre files between CSV format and binary format. If the input file is binary, the output will be CSV and vice versa. If the output file parameter is omitted, the input name will be used with a new file ending .csv or .bin The tool does support converting entire folders if the input file is a folder containing only valid measurement files.

exception raspyre.converter.RaspyreReaderException

Bases: Exception

raspyre.converter.convert_binary_to_csv(source, target)
raspyre.converter.convert_csv_to_binary(source, target)
raspyre.converter.main()

raspyre.helpers module

Some helper functions for frequent tasks:
write Records to file create Pandas Dataframe from Records (not jet tested) change the name of the wifi the Pi hosts (only if the pi is configured accordingly)
raspyre.helpers.changeWifiName(name, path='/home/pi/wifi.conf', reboot=False)

This function changes the SSID the Wifi created by the Pi uses. This SSID is in a config file. The default is the file wifi.conf in the home directory For the changes to take effect, the system has to be rebooted. This can be done with the reboot option.

raspyre.helpers.rec2DF(records)

Convert a list of Records into a Pandas DataFrame with column headers according to the attributes of the first object. NOT TESTED. Only works if all records have the same attribtues

raspyre.helpers.rec2File(file, records, append=True, header=True, delimiter=', ')

This function writes a list of Records into a file. You can choose whether to append or override the file if it allready exists and decide, if you want the attribute names asheader displayed. Also you can specify a column delimiter that defaults to “, “. The header is proceeded with a # sign to be marked as not data. The first column is the timestamp, after that the columns are ordered alphabetically

raspyre.record module

The Record object stores an arbitrary number of measured values. All records have the “time” attribute in common, that has the time of creation of the object in system time. Record objects can be sorted by this property. Element acces is done as in dictionarys.

class raspyre.record.Record(values=None)

Bases: object

add(key, value)
get(key)

raspyre.sensor module

class raspyre.sensor.Sensor

Bases: object

Base class for all concrete sensor implementations.

The derived classes have to call the base class constructor at the beginning of their own constructor. This is minimal interface the derived classes have to implement to comply with the frameworks requirements. Further expansion of the interface may be used to add functionality for special uses, but may not be used for the basic functionality.

Note

Each derived class must provide a class variable sensor_attributes that maps attribute strings to a datatype format character.

Example: A class for a sensor with attributes for 2 acceleration axes of type double and one temperature field of type integer would need to provide the sensor_attributes as follows:

sensor_attributes = { 'acceleration_1': 'd', 'acceleration_2': 'd', 'temperature': 'i' }
getAttributes()
getConfig()

Returns a dictionary of all configuration parameters the sensor has with their values.

getRecord(*args)

Returns a Record object containing the requested values. The Parameters to the function specify the attributes that will be measured.

sensor_attributes = {}
struct_fmt(attributes)

Returns a struct format string representing the datatypes of the attributes parameter.

Parameters:attributes (list of strings) – a list of a subset of the sensor’s sensor_attributes
Returns:a lift of format characters
Return type:list of characters
Example:
>>> from raspyre.sensors.mockup.mockup import Mockup
>>> sensor = Mockup(sps=100)
>>> sensor.struct_fmt(['y', 'x'])
['d', 'd']

See also

Format Strings

units(attributes)
updateConfig(**kwargs)

Pass a list of parameter names and values. The parameters of the sensor will be changed accordingly

raspyre.sensorbuilder module

This module provides the functions to create a sensor from a kwargs parameter.

raspyre.sensorbuilder.createSensor(sensor_type, **kwargs)

raspyre.storage module

This module provides the functionality to read and write data files. Supported for reading are all (including old) binary and csv formats, whereas for writing, we only support the newest binary and csv formats.

Also the functionality to resample data is included. Goal is to reduce the size of the stored data for longterm measurements. The following levels are available and can be derived from the file extension:

Level Interval Blocksize

rm01 sampling rate variable rm02 1 second 1 hour rm03 1 second 1 day rm04 1 minute 1 day rm05 1 minute 1 week rm06 1 minute 1 month rm07 1 hour 1 month

The filename consists of a descriptive name, the timestamp for the beginning of the file and the file extension that specifies the level of sampling. The file contains a timestamp as the first column followed by a number of value columns. The firs line of the file contains the name of the columns.

class raspyre.storage.BinReader(filename)

Bases: raspyre.storage.Reader

data()
parseHeader()
class raspyre.storage.CSVReader(filename)

Bases: raspyre.storage.Reader

data()

returns a generator for all the data rows in the csv file. :returns: tuple – the parsed values from the data row

parseHeader()

parses a CSV header, assuming all lines starting with #<space> currently supported versions: 0.1

exception raspyre.storage.RaspyreFileFormatException

Bases: Exception

class raspyre.storage.Reader(filename)

Bases: object

class raspyre.storage.Writer(filename, binary=True)

Bases: object

close()
writeHeader(header)
writeRow(row)
raspyre.storage.build_binary_header(date_float, metadata, fmt, units, column_names)
raspyre.storage.build_csv_header(date, metadata, fmt, units, column_names)

build csv header for the file writer version 0.2

raspyre.storage.cleanCSVLine(line)
cleans a CSV header line from leading # and whitespaces and
trailing
and whitespaces used for header parsing :param line:
string to be cleaned
raspyre.storage.getReader(filename)
raspyre.storage.process_files(in_folder, out_folder, level)

This function processes all the files in the in_folder such that it resamples them to the required sampling rate and stores them in the according blocksize in new files in the out_foler. It has the ability to see, which data has already been resampled, so that it can be called multiple times with the same arguments and only updates the new data.