Classes

Classes to generalise common patterns with DSC data. Has some similarities to the database models on the web backend.

Jin Cheng, 17/01/17:
Wrote these classes partly using existing code from main.py.
Jin Cheng, 18/01/17:
Further simplification of the Run object.
class robotchem.classes.DataPoint(run, measured_at, temp_ref, temp_sample, heat_ref, heat_sample)[source]

Bases: object

An object based on the web backend database model DataPoint.

classmethod async_measure_raw(run, loop)[source]

Construct a new DataPoint object based a new, raw measurement.

Parameters:
  • run (classes.Run) – parent Run object.
  • loop (asyncio.BaseEventLoop) – main event loop.
  • delta_time (float) – time, in seconds, passed since last measurement (i.e. construction of previous instance of this class related to the Run)
Returns:

classes.DataPoint object.

jsonify()[source]

Pickle properties of this object into a JSON-ifiable dictionary. For communications with the web interface.

Return type:dict
Returns:dictionary representation of this object’s properties.
class robotchem.classes.Run(run_id, start_temp, target_temp, ramp_rate, max_ramp_rate, PID_ref, PID_sample, interval, min_upload_length, stabilization_duration, temp_tolerance)[source]

Bases: object

An object loosely based on the backend database model Run with additional hardware properties such as the PID object, the Analog-to-digital object, and the Network upload queue.

batch_setpoint(setpoint)[source]

Changes the set point for both PID objects related to the run’s sample and reference cells.

Parameters:setpoint (int) – temperature in Celsius.
check_stabilization(value, duration=None, tolerance=None)[source]

Check if the latest temperatures are within range of the value given. The measurements must be made within a specified amount of time ago and the temperature comparison tolerance is also customisable.

Parameters:
  • value (float | int) – value around which to determine if temperatures have stabilised
  • duration (float | int) – value with which to override this object’s stabilisation duration constraint, self.stabilization_duration
  • tolerance – value with which to override this object’s temperature tolerance, self.temp_tolerance
Type:

tolerance: float | int

Return type:

bool

Returns:

Whether stabilisation at the specified temperature has been achieved.

classmethod from_web_resp(json_data, temp_ref, temp_sample)[source]

Construct a Run object from a dictionary of returned values from the web status API page. PID objects are instantiated with initial temperature values supplied. The customisable parameters from the web API are also stored, and if none is given, defaults from settings will be used.

Parameters:
  • json_data – Returned JSON response.
  • temp_ref – Measured temperature at ref.
  • temp_sample – Measured temperature at sample
Returns:

A classes.Run object.

make_measurement(_loop)[source]

Make a new measurement asynchronously and store it to the series of measurements related to this run. All measurements are put into the network queue responsible for this run’s data.

Temperature measurements made are automatically fed into the hardware.PID objects related to this run. The main event loop is used to change the duty cycle on the respective heater PWM objects, RPi.GPIO.PWM.

Parameters:_loop (asyncio.BaseEventLoop) – The main event loop.
Return type:classes.DataPoint
Returns:The DataPoint object, containing all measurements made and measurement time.
queue_upload(_loop, override_threshold=None)[source]

An asynchronous function that uploads payloads by consuming from the network queue only when a specified amount of time has passed from time of last processing and when a specified number of items exist in the queue. The asynchronous process breaks otherwise.

Parameters:
  • _loop (asyncio.BaseEventLoop) – the main event loop
  • override_threshold (bool) – whether qsize and delta time constraints for batch uploading should be overrode
Return type:

bool

Returns:

if sample has been inserted and formal temp ramp can begin

Raises:

StopHeatingError – When this error is raised, any async function that calls it must give control back to the idle loop and stop heating. Raised if a ‘stop_flag’ field returns True from the web API response.

real_ramp_rate

Calculate the real temperature increment per main loop cycle, in degrees Celsius. The ramp_rate field is selected by the user on the web interface and the self.ramp_rate property stores the ramp rate in degrees Celsius per minute.

The output value is clamped between a maximum value (if too high, it can be dangerous) and a minimum (from experience, a too small increment can lead to a stagnating temperature).

Return type:float
Returns:Temperature increase per cycle, in degrees Celsius.