# Helper Functions


# filterArrByKey()

Helper function to find all objects with the same key value in an array of objects

# Parameters

arr : list[object] - List of similar objects to filter from
key : str - Key to filter by
val : any - Key value to filter for

# Returns

list[objects]
List of objects where key of given object matches value provided in args

# reconnectInstructions()

Prints reconnection instructions for connected instruments to jupyter output.

# Parameters

inGui : bool, default=False
To check weather the functions is being used in Setup().

# getInstTypeCount()

Counts how many instruments of each kind are connected.

# Parameters

instruments : list[object] - List of all instruments, same as output of initInstruments().

# Returns

object
Object with key as type of instrument and value as the number of type connected.

# requiredInstrumentNotFound()

Prints information about the missing instrument's type (to be used before raising Warning)

# Parameters

instType: srt - Type of instrument which is required

# notEnoughReqInstType()

Prints information about insufficient instrument type for the current experiment (to be used before raising Warning).

# Parameters

instType : str - Type of instrument which is in insufficient quantity.
requiredEquipment : object - Required instruments object from [experiment].py (see Experiment Files for more information).
instruments : list[objects] - List of all instruments, same as output of initInstruments().
inGui : bool - To check weather the functions is being used in Setup().\

# showLiveReadings()

Prints information from a provided dictionary (liveReadings) where the key is the name of the reading and the value is the current reading. Can also be used to display live reading graphs (see examples for more detail).

When using in a for loop, the clear_output(wait=True) (opens new window) function can be used to clear the output before showing the next set of live readings. (See examples for more details)

# Parameters

liveReadings : object - Object with key as name of live reading (eg.: "Voltage") and value as the live reading (eg.: "20.0V") (See examples for more details)
g1 : object, optional - Object with key as matplotlib.pyplot.plot (opens new window) arguments and value for the given argument. Supported arguments below (See examples for more information).
g2 : object, optional - Like g1.
g3 : object, optional - Like g1.
g4 : object, optional - Like g1.

Supported matplotlib.pyplot.plot (opens new window) arguments:

  • title : str
  • xdata : list or numpy array
  • ydata : list or numpy array
  • xlim : tuple
  • ylim : tuple

# Examples

Displaying some example data
Code:

import HallPy_Teach as hpt
import numpy as np

someReadings = {
    'Hall Volt. (V)': 1.00,
    'Supply Curr. (mA)': 0.10,
    'Time Left (s)': 10
}
        
someGraph = {
    'title':'Some Graph 1',
    'xlim': (0,3.16*2),
    'ylim': (-1.1,1.1),
    'xdata': [1,2,3,4,5,6,7],
    'ydata': np.sin([1,2,3,4,5,6,7]),
    'xlabel': 'Radians',
    'ylabel': 'Sin(Radians)'
}

hpt.helper.showLiveReadings(liveReadings=someReadings, g1=someGraph)

Output: showLiveReadings Example

Example using clear_output(wait=True) (opens new window)
Code:

import HallPy_Teach as hpt
from IPython.display import clear_output
import time

someVar = 0
while True:
    
    someReadings = {
        'Changing Variable': 1.00 + someVar,
        'Time Passed (s)': someVar
    }
    
    # Clearing output with wait=True
    clear_output(wait=True)
    # Drawing new output to replace old output (works with graphs too)
    hpt.helper.showLiveReadings(liveReadings=someReadings)
    
    time.sleep(1)
    someVar += 1

Output:
Live Readings in action

# clearFileAndSaveData()

Uses the pickle (opens new window) library to save provided data to file in current directory. File will be saved with a .p extension.

If a file with the name same as the one provided in the fileNameWithoutExt argument already exists, the file will be overwritten.

# Parameters

data : any - Data to save.
fileNameWithoutExt : str - File name without extension.

# getDataFromFile()

Retrieves data from the provided file using pickle.load (opens new window).

# Parameters

fileNameWithExt : str - Name of file with extension.

# Returns

any - Returns any data within the file.

# Helper functions for instruments


See the full list of supported instruments in the constants.supportedInstruments documentation.

# setPSVolt()

Uses the PyVisa library (opens new window) and the instrument resource object (see individual instrument object in initInstruments()) to set the power supply voltage output.

Power supplies supported by HallPy_Teach can be found in the constants.supportedInstruments documentation

# Parameters

volt : int or float - Voltage value to set.
inst : object - Power supply PyVisa resource object (opens new window) (value of 'res' in the instrument object in initInstruments()).
channel : int, default=1 - Channel of the power supply which the voltage is to be set to (usually 1 or 2).
instSleepTime : float, default=0.1 - Time to sleep in seconds inorder to make sure voltage change is applied before moving further.

# setPSCurr()

Uses the PyVisa library (opens new window) and the instrument resource object (see individual instrument object in initInstruments()) to set the power supply current output.

Power supplies supported by HallPy_Teach can be found in the constants.supportedInstruments documentation

# Parameters

volt : int or float - Current value to set.
inst : object - Power supply PyVisa resource object (opens new window) (value of 'res' in the instrument object in initInstruments()).
channel : int, default=1 - Channel of the power supply which the current is to be set to (usually 1 or 2).
instSleepTime : float, default=0.1 - Time to sleep in seconds inorder to make sure current change is applied before moving further.

# getLCRCap()

Gets the capacitance reading from provided LCR meter.

LCR meters supported by HallPy_Teach can be found in the constants.supportedInstruments documentation

# Parameters

inst : object - LCR PyVisa resource object (opens new window) (value of 'res' in the instrument object in initInstruments()).

# Returns

float - Capacitance as float.

# getLCRCapLoss()

Gets the capacitance loss reading from provided LCR meter.

LCR meters supported by HallPy_Teach can be found in the constants.supportedInstruments documentation

# Parameters

inst : object - LCR PyVisa resource object (opens new window) (value of 'res' in the instrument object in initInstruments()).

# Returns

float - Capacitance loss as float.

Last Updated: Aug 13, 2022, 6:16 PM