Modules

omdpb.cmd

Command line interface to the omdpb package.

omdpb.cmd.cmd_parser()[source]

Command line argument parser for the openmeteodata entry point.

Returns:
argparse.ArgumentParser

The specified argument parser.

omdpb.cmd.openmeteodata()[source]

Entry point for the omdpb package

omdpb.cmd.openmeteodata_io(argv)[source]

The openmeteodata command line tool.

Parameters:
args: list

output of sys.args[1:].

omdpb.open_meteo_data

Module to access the Open Meteo Data Api of the province of Bolzano

omdpb.open_meteo_data.sensor_code_lookup(station_code, sensor_code=None)[source]

Interactive sensor code (TYPE) selection.

If sensor_code is not specified, asks user for input. If sensor_code is specified, checks if it is valid.

Check the chapter ‘sensor acronyms’ in the documentation omdpb.pdf to find a list of the abbreviated sensor names and their meanings.

Parameters:
station_code : str

The station identifier.

sensor_code : str, list, -1, optional

The sensor identifier(s).

Returns:
list

Returns the selected or specified sensor_code if it is valid.

Raises:
TypeError

If station_code is not a str.

ValueError

If station_code is not a valid station identifier.

TypeError

If sensor_code is not a str, list or -1.

ValueError

If any sensor identifier in sensor_code is not valid.

TypeError

If any sensor identifier in sensor_code (list) is not a string.

AssertionError

If the response status (HTML) code is not 200.

urllib.error.HTTPError

If there is a problem with the connection (internal server error, bad request, …).

Examples

>>> sensor_code_lookup(station_code='83200MS')
    Asks the user to choose from the sensors of station '83200MS'.
>>> sensor_code_lookup(station_code='83200MS', sensor_code='LT')
    ['LT']
omdpb.open_meteo_data.sensor_data(url='http://daten.buergernetz.bz.it/services/meteo/v1/', station_code=None, sensor_code=None, date_from=None, date_to=None, save=False, sformat='csv', path='C:\\Users\\DFrisinghelli\\Documents\\', filename='omdpb')[source]

Get a time series of the specified sensor at the specified station.

If station_code and sensor_code are None, the user is asked to choose them interactively on the console. If date_from and date_to are None, a time series of the last 24h before the current datetime is returned. If date_from or date_to is None, a time series of the last 24h before (after) date_to (date_from) is returned. If both date_from and date_to are specified, a time series of the respective time period is returned.

Regarding sensor_code, you can either pass a single sensor code as a string or more sensor codes as a list of strings. If you pass -1 to sensor_code, automatically all sensors of the specified station are selected.

Allowed DATE_FORMATS = (‘%Y%m%d’, ‘%Y%m%d%H%M’)

Parameters:
url : str

The url of the API: ‘http://daten.buergernetz.bz.it/services/meteo/v1/

station_code : str, optional

The station identifier.

sensor_code : str, list, optional

The sensor identifier(s).

date_from : str, optional

The starting date.

date_to : str, optional

The ending date.

save : boolean, optional

Save time series to file.

sformat: str, optional

Output file format, either csv or json.

path : str, optional

Output file path, default is home/<user>/documents/. This should be an absolute path on your system.

filename : str, optional

Output file name, default is station_code.

Returns:
pandas.core.frame.DataFrame

A DataFrame containing a time series (timestamp, value) of the specified sensor.

Raises:
ValueError

If date_from or date_to is not of type str.

ValueError

If date_from or date_to is not one of the formats in DATE_FORMATS.

TypeError

If station_code is not a str.

ValueError

If station_code is not a valid station identifier.

TypeError

If sensor_code is not a str, list or -1.

ValueError

If any sensor identifier in sensor_code is not valid.

TypeError

If any sensor identifier in sensor_code (list) is not a string.

AssertionError

If the response status (HTML) code is not 200.

urllib.error.HTTPError

If there is a problem with the connection (internal server error, bad request, …).

Examples

>>> sensor_data()
Asks the user to enter the desired ``station_code`` and ``sensor_code``.
Returns a time series of the last 24h before the current datetime.
>>> sensor_data(station_code='83200MS', date_from='20180903')
Asks the user to enter the desired ``sensor_code`` and returns a time
series of the last 24h after ``date_from``.
>>> sensor_data(station_code='83200MS', sensor_code='LT',
                date_to='20180903')
Returns a time series of the last 24h before ``date_to`` of sensor 'LT'
at station '83200MS'.
                           LT
DATE
2018-09-02T00:00:00CEST  15.3
2018-09-02T00:10:00CEST  15.2
2018-09-02T00:20:00CEST  15.1
2018-09-02T00:30:00CEST  15.0
2018-09-02T00:40:00CEST  15.2
>>> sensor_data(station_code='83200MS', sensor_code='LT',
                date_from='20180801', date_to='20180831')
Returns a time series of the specified time period of sensor 'LT'
at station '83200MS'.
                           LT
DATE
2018-08-01T00:00:00CEST  27.8
2018-08-01T00:10:00CEST  26.8
2018-08-01T00:20:00CEST  26.6
2018-08-01T00:30:00CEST  26.6
2018-08-01T00:40:00CEST  26.6
>>> sensor_data(station_code='83200MS', sensor_code='LT',
                date_from='20180801', date_to='20180831',
                save=True)
Saves the time series to the file: home/<user>/documents/83200MS.csv
omdpb.open_meteo_data.sensor_metadata(url='http://daten.buergernetz.bz.it/services/meteo/v1/', station_code=None, sensor_code=None)[source]

Lists all available sensors of a station.

If sensor_code is not specified, all sensors of the station with identifier station_code are listed. Otherwise, only the sensor(s) specified by sensor_code is returned.

Parameters:
url : str

The url of the API: ‘http://daten.buergernetz.bz.it/services/meteo/v1/

station_code : str, optional

The station identifier.

sensor_code : str, list, optional

The sensor identifier(s).

Returns:
pandas.core.frame.DataFrame

A DataFrame containing sensors of a station and their properties together with the last recorded values.

Raises:
TypeError

If station_code is not a str.

ValueError

If station_code is not a valid station identifier.

TypeError

If sensor_code is not a str or list.

ValueError

If any sensor identifier in sensor_code is not valid.

TypeError

If any sensor identifier in sensor_code (list) is not a string.

AssertionError

If the response status (HTML) code is not 200.

urllib.error.HTTPError

If there is a problem with the connection (internal server error, bad request, …).

Examples

>>> sensor_metadata()
    Asks the user to enter the desired ``station_code``.
>>> sensor_metadata(station_code='83200MS')
                      DATE                   DESC_D   ...     UNIT    VALUE
0  2018-09-03T15:00:00CEST           Lufttemperatur   ...       °C    22.90
1  2018-09-03T15:05:00CEST             Niederschlag   ...       mm     0.00
2  2018-09-03T15:00:00CEST             Windrichtung   ...       °    245.60
3  2018-09-03T15:00:00CEST      Windgeschwindigkeit   ...      m/s     0.87
4  2018-09-03T15:00:00CEST  Windgeschwindigkeit Böe   ...      m/s     3.20
5  2018-09-03T15:00:00CEST     relative Luftfeuchte   ...        %    49.80
6  2018-09-03T15:00:00CEST                Luftdruck   ...      hPa  1012.20
7  2018-09-03T15:00:00CEST          Globalstrahlung   ...     W/m²   611.60
>>> sensor_metadata(station_code='83200MS', sensor_code='LT')
                      DATE          DESC_D  ...  UNIT VALUE
0  2018-09-03T15:00:00CEST  Lufttemperatur  ...    °C  22.9
>>> sensor_metadata(station_code='83200MS', sensor_code=['LT', 'N'])
                      DATE          DESC_D  ...  UNIT VALUE
0  2018-09-06T09:50:00CEST  Lufttemperatur  ...    °C  19.7
1  2018-09-06T09:55:00CEST    Niederschlag  ...    mm   0.0
omdpb.open_meteo_data.station_code_lookup(station_code=None)[source]

Interactive station code (SCODE) selection.

If station_code is not specified, the user is asked to enter the desired station on the console. If station_code is specified, checks if it is valid.

Parameters:
station_code : str, optional

The station identifier.

Returns:
str

Returns the selected or specified station_code if it is valid.

Raises:
TypeError

If station_code is not a str.

ValueError

If station_code is not a valid station identifier.

AssertionError

If the response status (HTML) code is not 200.

urllib.error.HTTPError

If there is a problem with the connection (internal server error, bad request, …).

Examples

>>> station_code_lookup()
    Asks the user to enter the desired ``station_code`` on the console.
>>> station_code_lookup('83200MS')
    '83200MS'
omdpb.open_meteo_data.station_metadata(url='http://daten.buergernetz.bz.it/services/meteo/v1/')[source]

Lists all available stations and their properties.

Parameters:
url : str

The url of the API: ‘http://daten.buergernetz.bz.it/services/meteo/v1/

Returns:
pandas.core.frame.DataFrame

A DataFrame containing all stations and their properties.

Raises:
AssertionError

If the response status (HTML) code is not 200.

urllib.error.HTTPError

If there is a problem with the connection (internal server error, bad request, …).

Examples

>>> station_metadata()
         ALT        LAT  ...                             coordinates   type
0     210.00  46.243333  ...    [669803.015640121, 5123442.04315501]  Point
1     873.99  46.621876  ...    [626295.144332811, 5164467.60475602]  Point
2    2152.00  46.841700  ...    [744723.350800056, 5192575.70046406]  Point
3    2260.00  46.615600  ...    [688387.444866793, 5165389.11604176]  Point
4    2747.00  46.856100  ...     [743964.273827689, 5194147.3777763]  Point
5    2926.00  46.776700  ...    [613580.465752357, 5181424.77411351]  Point

omdpb.utils

Utility functions for the omdpb package.

omdpb.utils.check_date_format(date)[source]

Checks ìf the format of ``date`` is one of the formats in DATE_FORMATS.

Allowed DATE_FORMATS = (‘%Y%m%d’, ‘%Y%m%d%H%M’)

Parameters:
date : str

A string containing a date.

Returns:
NoneType

If date is one of the formats in DATE_FORMATS, the function passes without raising an error.

Raises:
ValueError

If date is not of type str.

ValueError

If date is not one of the formats in DATE_FORMATS.

Examples

>>> check_date_format('20180903')
>>> check_date_format('2018-01-01')
    ValueError('Incorrect date format,
               should be one of ('%Y%m%d', '%Y%m%d%H%M')')
omdpb.utils.check_dependencies(package_names, ret=False)[source]

Check if a package can be imported, if not throw a warning.

Parameters:
package_names : list

A list containing the packages’ names (str) to be imported.

Returns:
NoneType

If all packages can be imported.

list

If ret is True; list of all packages that could not be found.

omdpb.utils.http_get_api(request)[source]

Makes a HTML GET request to the url ``request``.

The content of the HTML GET request has to be either json or csv.

Parameters:
request : str

A string containing a url.

Returns:
pandas.core.frame.DataFrame

Returns a DataFrame containing the parsed request content.

Raises:
urllib.error.HTTPError

If there is a problem with the connection (internal server error, bad request, …).

AssertionError

If the response status (HTML) code is not 200.

Examples

>>> http_get_api(API_URL + 'stations')
         ALT        LAT  ...                             coordinates   type
0     210.00  46.243333  ...    [669803.015640121, 5123442.04315501]  Point
1     873.99  46.621876  ...    [626295.144332811, 5164467.60475602]  Point
2    2152.00  46.841700  ...    [744723.350800056, 5192575.70046406]  Point
3    2260.00  46.615600  ...    [688387.444866793, 5165389.11604176]  Point
4    2747.00  46.856100  ...     [743964.273827689, 5194147.3777763]  Point
5    2926.00  46.776700  ...    [613580.465752357, 5181424.77411351]  Point