Calibrate raw weather station data
This module allows adjustment of raw data from the weather station as part of the ‘processing’ step (see pywws.process). For example, if you have fitted a funnel to double your rain gauge’s collection area, you can write a calibration routine to double the rain value.
The default calibration generates the relative atmospheric pressure. Any user calibration you write must also do this.
Writing your calibration module¶
Firstly, decide where you want to keep your module. Like your text and
graph templates, it’s best to keep it separate from the pywws code, so
it isn’t affected by pywws upgrades. I suggest creating a
directory in the same place as your
You could start by copying one of the example calibration modules, or
you can create a plain text file in your
modules directory, e.g.
calib.py and copy the following text into it:
class Calib(object): def __init__(self, params, stored_data): self.pressure_offset = float(params.get('config', 'pressure offset')) def calib(self, raw): result = dict(raw) # calculate relative pressure result['rel_pressure'] = result['abs_pressure'] + self.pressure_offset return result
Calib class has two methods.
the constructor and is a good place to set any constants you need. It
is passed a reference to the raw data storage which can be useful for
advanced tasks such as spike removal.
a single set of ‘calibrated’ data from a single set of ‘raw’ data.
There are a few rules to follow when writing this method:
- Make sure you include the line
result = dict(raw), which copies all the raw data to your result value, at the start.
- Don’t modify any of the raw data.
- Make sure you set
- Don’t forget to
returnthe result at the end.
When you’ve finished writing your calibration module you can get pywws
to use it by putting its location in your
weather.ini file. It
goes in the
[paths] section, as shown in the example below:
[paths] work = /tmp/weather templates = /home/jim/weather/templates/ graph_templates = /home/jim/weather/graph_templates/ user_calib = /home/jim/weather/modules/usercalib
Note that the
user_calib value need not include the
.py at the
end of the file name.
||Calibration class that implements default or user calibration.|
||Default calibration class.|
Default calibration class.
This class sets the relative pressure, using a pressure offset originally read from the weather station. This is the bare minimum ‘calibration’ required.
Calibration class that implements default or user calibration.
Other pywws modules use this method to create a calibration object. The constructor creates either a default calibration object or a user calibration object, depending on the
user_calibvalue in the
[paths]section of the
paramsparameter. It then adopts the calibration object’s
calib()method as its own.
Comments or questions? Please subscribe to the pywws mailing list http://groups.google.com/group/pywws and let us know.