DataStore
index
DataStore.py

DataStore.py - stores readings in easy to access files
 
A separate file is used for each day's data, to keep memory load
reasonable. One day at a time is held in memory, and saved to disc
when another day needs to be accessed.
 
Data is accessed in a cross between dictionary and list behaviour.
The following are all valid:
# get value nearest 9:30 on Christmas day
data[data.nearest(datetime(2008, 12, 25, 9, 30))]
# get entire array, equivalent to data[:] or just data
data[datetime.min:datetime.max]
# get last 12 hours of data
data[datetime.utcnow() - timedelta(hours=12):]

 
Modules
       
csv
os
sys
time

 
Classes
       
core_store
daily_store
data_store
hourly_store
monthly_store
params

 
class core_store
     Methods defined here:
__del__(self)
__delitem__(self, i)
Delete the data item or items with index i.
 
i must be a datetime object or a slice.
If i is a single datetime then a value with that index must exist.
__getitem__(self, i)
Return the data item or items with index i.
 
i must be a datetime object or a slice.
If i is a single datetime then a value with that index must exist.
__init__(self, root_dir)
__setitem__(self, i, x)
Store a value x with index i.
 
i must be a datetime object.
If there is already a value with index i, it is overwritten.
after(self, idx)
Return datetime of oldest existing data record whose
datetime is >= idx.
 
Might not even be in the same year! If no such record exists,
return None.
before(self, idx)
Return datetime of newest existing data record whose
datetime is < idx.
 
Might not even be in the same year! If no such record exists,
return None.
nearest(self, idx)
Return datetime of record whose datetime is nearest idx.

 
class daily_store(core_store)
    Stores daily summary weather station data.
 
  Methods defined here:
__init__(self, root_dir)

Data and other attributes defined here:
conv = {'idx': <function safestrptime at 0x407284f0>, 'rain': <type 'float'>, 'start': <function safestrptime at 0x407284f0>, 'temp_out_ave': <type 'float'>, 'temp_out_max': <type 'float'>, 'temp_out_max_t': <function safestrptime at 0x407284f0>, 'temp_out_min': <type 'float'>, 'temp_out_min_t': <function safestrptime at 0x407284f0>, 'wind_ave': <type 'float'>, 'wind_dir': <type 'int'>, ...}
key_list = ['idx', 'start', 'temp_out_ave', 'temp_out_min', 'temp_out_min_t', 'temp_out_max', 'temp_out_max_t', 'wind_ave', 'wind_gust', 'wind_gust_t', 'wind_dir', 'rain']

Methods inherited from core_store:
__del__(self)
__delitem__(self, i)
Delete the data item or items with index i.
 
i must be a datetime object or a slice.
If i is a single datetime then a value with that index must exist.
__getitem__(self, i)
Return the data item or items with index i.
 
i must be a datetime object or a slice.
If i is a single datetime then a value with that index must exist.
__setitem__(self, i, x)
Store a value x with index i.
 
i must be a datetime object.
If there is already a value with index i, it is overwritten.
after(self, idx)
Return datetime of oldest existing data record whose
datetime is >= idx.
 
Might not even be in the same year! If no such record exists,
return None.
before(self, idx)
Return datetime of newest existing data record whose
datetime is < idx.
 
Might not even be in the same year! If no such record exists,
return None.
nearest(self, idx)
Return datetime of record whose datetime is nearest idx.

 
class data_store(core_store)
    Stores raw weather station data.
 
  Methods defined here:
__init__(self, root_dir)

Data and other attributes defined here:
conv = {'abs_pressure': <type 'float'>, 'delay': <type 'int'>, 'hum_in': <type 'int'>, 'hum_out': <type 'int'>, 'idx': <function safestrptime at 0x407284f0>, 'rain': <type 'float'>, 'status': <type 'int'>, 'temp_in': <type 'float'>, 'temp_out': <type 'float'>, 'wind_ave': <type 'float'>, ...}
key_list = ['idx', 'delay', 'hum_in', 'temp_in', 'hum_out', 'temp_out', 'abs_pressure', 'wind_ave', 'wind_gust', 'wind_dir', 'rain', 'status']

Methods inherited from core_store:
__del__(self)
__delitem__(self, i)
Delete the data item or items with index i.
 
i must be a datetime object or a slice.
If i is a single datetime then a value with that index must exist.
__getitem__(self, i)
Return the data item or items with index i.
 
i must be a datetime object or a slice.
If i is a single datetime then a value with that index must exist.
__setitem__(self, i, x)
Store a value x with index i.
 
i must be a datetime object.
If there is already a value with index i, it is overwritten.
after(self, idx)
Return datetime of oldest existing data record whose
datetime is >= idx.
 
Might not even be in the same year! If no such record exists,
return None.
before(self, idx)
Return datetime of newest existing data record whose
datetime is < idx.
 
Might not even be in the same year! If no such record exists,
return None.
nearest(self, idx)
Return datetime of record whose datetime is nearest idx.

 
class hourly_store(core_store)
    Stores hourly summary weather station data.
 
  Methods defined here:
__init__(self, root_dir)

Data and other attributes defined here:
conv = {'abs_pressure': <type 'float'>, 'hum_in': <type 'int'>, 'hum_out': <type 'int'>, 'idx': <function safestrptime at 0x407284f0>, 'pressure_trend': <type 'float'>, 'rain': <type 'float'>, 'rel_pressure': <type 'float'>, 'temp_in': <type 'float'>, 'temp_out': <type 'float'>, 'wind_ave': <type 'float'>, ...}
key_list = ['idx', 'hum_in', 'temp_in', 'hum_out', 'temp_out', 'abs_pressure', 'rel_pressure', 'pressure_trend', 'wind_ave', 'wind_gust', 'wind_dir', 'rain']

Methods inherited from core_store:
__del__(self)
__delitem__(self, i)
Delete the data item or items with index i.
 
i must be a datetime object or a slice.
If i is a single datetime then a value with that index must exist.
__getitem__(self, i)
Return the data item or items with index i.
 
i must be a datetime object or a slice.
If i is a single datetime then a value with that index must exist.
__setitem__(self, i, x)
Store a value x with index i.
 
i must be a datetime object.
If there is already a value with index i, it is overwritten.
after(self, idx)
Return datetime of oldest existing data record whose
datetime is >= idx.
 
Might not even be in the same year! If no such record exists,
return None.
before(self, idx)
Return datetime of newest existing data record whose
datetime is < idx.
 
Might not even be in the same year! If no such record exists,
return None.
nearest(self, idx)
Return datetime of record whose datetime is nearest idx.

 
class monthly_store(core_store)
    Stores monthly summary weather station data.
 
  Methods defined here:
__init__(self, root_dir)

Data and other attributes defined here:
conv = {'idx': <function safestrptime at 0x407284f0>, 'rain': <type 'float'>, 'start': <function safestrptime at 0x407284f0>, 'temp_out_ave': <type 'float'>, 'temp_out_max_ave': <type 'float'>, 'temp_out_max_hi': <type 'float'>, 'temp_out_max_hi_t': <function safestrptime at 0x407284f0>, 'temp_out_max_lo': <type 'float'>, 'temp_out_max_lo_t': <function safestrptime at 0x407284f0>, 'temp_out_min_ave': <type 'float'>, ...}
key_list = ['idx', 'start', 'temp_out_ave', 'temp_out_min_lo', 'temp_out_min_lo_t', 'temp_out_min_hi', 'temp_out_min_hi_t', 'temp_out_min_ave', 'temp_out_max_lo', 'temp_out_max_lo_t', 'temp_out_max_hi', 'temp_out_max_hi_t', 'temp_out_max_ave', 'rain']

Methods inherited from core_store:
__del__(self)
__delitem__(self, i)
Delete the data item or items with index i.
 
i must be a datetime object or a slice.
If i is a single datetime then a value with that index must exist.
__getitem__(self, i)
Return the data item or items with index i.
 
i must be a datetime object or a slice.
If i is a single datetime then a value with that index must exist.
__setitem__(self, i, x)
Store a value x with index i.
 
i must be a datetime object.
If there is already a value with index i, it is overwritten.
after(self, idx)
Return datetime of oldest existing data record whose
datetime is >= idx.
 
Might not even be in the same year! If no such record exists,
return None.
before(self, idx)
Return datetime of newest existing data record whose
datetime is < idx.
 
Might not even be in the same year! If no such record exists,
return None.
nearest(self, idx)
Return datetime of record whose datetime is nearest idx.

 
class params
     Methods defined here:
__del__(self)
__init__(self, root_dir)
Parameters are stored in a file "weather.ini" in root_dir.
get(self, section, option, default=None)
Get a parameter value and return a string.
 
If default is specified and section or option are not defined
in the weather.ini file, they are created and set to default,
which is then the return value.
set(self, section, option, value)
Set option in section to string value.

 
Functions
       
safestrptime(date_string, format=None)