On this page
General utility functions for io-operations, permissions and checking if a program is already running.
Submodules
wind_bearer_software.utils.csv_writer module
Contains utility functions for writing the measured data to a csv file.
- Authors:
Min Tai Yap
- wind_bearer_software.utils.csv_writer.csv_write(ws_name, flag_csv, flag_csv_df, folder_path, current_date, current_hour, current_time, battery_voltage, rpm, rain_mm, rain_ml, sht_temp, sht_rh, bmp_temp, bmp_pressure, bmp_altitude, angle_degrees, new_speed, SI1151_visible, SI1151_UV, SI1151_IR)[source]
Helper function to write a row of measurements to a csv file. Each hour, a new csv file is created, in which the measurements are recorded every 60 seconds. For each single day, a new folder is created. The location of the csv files is thus given by {folder_path}/{current_date}_data/{ws_name}_{current_data}_{current_hour}.csv. In practice, we disregard the first measurement after starting the weather station for data consistency. Note that we only do this for the first directory specified in parameter/user_path.txt
- Parameters:
ws_name – Prefix of the csv files, specified in parameter/parameters.txt
flag_csv – If this flag is set to 0, we additionally write the csv header to the csv file and set the flag to 1
flag_csv_df – This flag is set to 0 to ignore the first measurement after booting
folder_path – Path of the directory in which the data is collected
current_date – Current data
current_hour – Current hour
current_time – Timestamp to be written in the csv file
battery_voltage – Battery voltage in V
rpm – Wind speed in rpm measured by the anemometer
rain_mm – Rainfall measured in mm
rain_ml – Rainfall collected in the rain gauge in ml
sht_temp – Temperature measured by the SHT45 sensor in °C
sht_rh – Humidity measured by the SHT45 sensor in %
bmp_temp – Temperature measured by the BMP388 sensor in °C
bmp_pressure – Air pressure measured by the BMP388 sensor in hPa
bmp_altitude – Altitude measured by the BMP388 sensor in m
angle_degrees – Wind direction in °
new_speed – Wind speed measured in m/s
SI1151_visible – Visible light illuminance in lux measured by the SI1151 sensor
SI1151_UV – UV light illuminance in lux measured by the SI1151 sensor
SI1151_IR – IR light illuminance in lux measured by the SI1151 sensor
- Returns:
Tuple containing the updated csv_flag and the file path of the csv file
- wind_bearer_software.utils.csv_writer.format_value(value)[source]
Converts floating point value to a string cut-off at the second decimal.
- Parameters:
value – Floating point number to convert
- Returns:
If the input is a numerical value, string representation of the input cut-off at the second decimal place, otherwise returns the input
wind_bearer_software.utils.io_utils module
Contains helper functions to fetch the absolute path of the parameters, and to read and write JSON files.
- Authors:
Min Tai Yap
- wind_bearer_software.utils.io_utils.get_path()[source]
Fetches the absolute path of the working directory, as well as the path to the parameter and results directory
- Returns:
Absolute path to the current working directory, the parameter directory, and the results directory
- wind_bearer_software.utils.io_utils.read_dict(filepath)[source]
Reads the JSON file located at the given path :param filepath: Path to the JSON file :returns: Dictionary of the contents of the JSON file
- wind_bearer_software.utils.io_utils.read_parameter_dict(json_filename)[source]
Reads JSON parameter files from the parameter folder when the software is installed as a library
- Parameters:
json_filename – file name of the JSON file in parameter
- Returns:
Dictionary that contains contents of the JSON file
- wind_bearer_software.utils.io_utils.write_dict(filepath, data)[source]
Writes data to a JSON file in write mode
- Parameters:
filepath – Path of the JSON file to create / overwrite
data – Data to be written to the JSON file
wind_bearer_software.utils.permission module
Contains a helper function to set the GPIO permissions.
- Authors:
Min Tai Yap
- wind_bearer_software.utils.permission.set_gpio_permissions()[source]
Changes the ownership of the /dev/gpiomem to root:gpio and gives read and write access to the gpio group.
wind_bearer_software.utils.program_checker module
This module is used to prevent cron from running multiple instances of the main runner at the same time, and it also contains a helper function to terminate a program if the user is not aware of the command to do so.
- Authors:
Min Tai Yap
- wind_bearer_software.utils.program_checker.program_checker(program_name)[source]
Checks if an instance of program_name is already run. The usage of this method is to prevent cron from running multiple instances of the program in parallel. This has the advantage that, in case the program has crashed, it can be automatically restarted by cron at the times specified in the crontab_materials file. As it is meant to be called by the program itself, it won’t indicate that there are multiple instances of the same program running when there is only one program running, as this is the program that calls program_checker.
- Parameters:
program_name – Name of the program, e.g., “mr_V6”
- Returns:
False when there are multiple programs running, True when this is not the case, and a tuple of False and None in any error case
- wind_bearer_software.utils.program_checker.terminate_program(pid)[source]
Terminates the program with the given PID as a shorthand notation for the shell command or to be used in other modules.
- Parameters:
pid – PID of the process to be killed
- Returns:
True on successful termination, False else
