Skip to content

Weather Latest Function

get_grid(connection, parameters_dict)

A function to return the latest event values by querying databricks SQL Warehouse using a connection specified by the user.

This will return the raw weather forecast data for a grid.

The available connectors by RTDIP are Databricks SQL Connect, PYODBC SQL Connect, TURBODBC SQL Connect.

The available authentcation methods are Certificate Authentication, Client Secret Authentication or Default Authentication. See documentation.

This function requires the user to input a dictionary of parameters. (See Attributes table below)

Parameters:

Name Type Description Default
connection object

Connection chosen by the user (Databricks SQL Connect, PYODBC SQL Connect, TURBODBC SQL Connect)

required
parameters_dict dict

A dictionary of parameters (see Attributes table below)

required

Attributes:

Name Type Description
source optional str

Source of the data the full table name

forecast str

Any specific identifier for forecast

forecast_type(str) str

Type of forecast ie weather, solar, power, etc

region str

Region

data_security_level str

Level of data security

data_type str

Type of the data (float, integer, double, string)

max_lat float

Maximum latitude

max_lon float

Maximum longitude

min_lat float

Minimum latitude

min_lon float

Minimum longitude

measurement optional str

Measurement type

limit optional int

The number of rows to be returned

Returns:

Name Type Description
DataFrame DataFrame

A dataframe of event latest values.

Source code in src/sdk/python/rtdip_sdk/queries/weather/latest.py
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
def get_grid(connection: object, parameters_dict: dict) -> pd.DataFrame:
    """
    A function to return the latest event values by querying databricks SQL Warehouse using a connection specified by the user.

    This will return the raw weather forecast data for a grid.

    The available connectors by RTDIP are Databricks SQL Connect, PYODBC SQL Connect, TURBODBC SQL Connect.

    The available authentcation methods are Certificate Authentication, Client Secret Authentication or Default Authentication. See documentation.

    This function requires the user to input a dictionary of parameters. (See Attributes table below)

    Args:
        connection: Connection chosen by the user (Databricks SQL Connect, PYODBC SQL Connect, TURBODBC SQL Connect)
        parameters_dict: A dictionary of parameters (see Attributes table below)

    Attributes:
        source (optional str): Source of the data the full table name
        forecast (str): Any specific identifier for forecast
        forecast_type(str): Type of forecast ie weather, solar, power, etc
        region (str): Region
        data_security_level (str): Level of data security
        data_type (str): Type of the data (float, integer, double, string)
        max_lat (float): Maximum latitude
        max_lon (float): Maximum longitude
        min_lat (float): Minimum latitude
        min_lon (float): Minimum longitude
        measurement (optional str): Measurement type
        limit (optional int): The number of rows to be returned

    Returns:
        DataFrame: A dataframe of event latest values.
    """
    try:
        query = _query_builder(parameters_dict, "latest_grid")

        try:
            cursor = connection.cursor()
            cursor.execute(query)
            df = cursor.fetch_all()
            cursor.close()
            connection.close()
            return df
        except Exception as e:
            logging.exception("error returning dataframe")
            raise e

    except Exception as e:
        logging.exception("error returning latest function")
        raise e

get_point(connection, parameters_dict)

A function to return the latest event values by querying databricks SQL Warehouse using a connection specified by the user.

This will return the raw weather forecast data for a single point.

The available connectors by RTDIP are Databricks SQL Connect, PYODBC SQL Connect, TURBODBC SQL Connect.

The available authentcation methods are Certificate Authentication, Client Secret Authentication or Default Authentication. See documentation.

This function requires the user to input a dictionary of parameters. (See Attributes table below)

Parameters:

Name Type Description Default
connection object

Connection chosen by the user (Databricks SQL Connect, PYODBC SQL Connect, TURBODBC SQL Connect)

required
parameters_dict dict

A dictionary of parameters (see Attributes table below)

required

Attributes:

Name Type Description
source optional str

Source of the data the full table name

forecast str

Any specific identifier for forecast

forecast_type(str) str

Type of forecast ie weather, solar, power, etc

region str

Region

data_security_level str

Level of data security

data_type str

Type of the data (float, integer, double, string)

lat float

latitude

lon float

longitude

measurement optional str

Measurement type

limit optional int

The number of rows to be returned

Returns:

Name Type Description
DataFrame DataFrame

A dataframe of event latest values.

Source code in src/sdk/python/rtdip_sdk/queries/weather/latest.py
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
def get_point(connection: object, parameters_dict: dict) -> pd.DataFrame:
    """
    A function to return the latest event values by querying databricks SQL Warehouse using a connection specified by the user.

    This will return the raw weather forecast data for a single point.

    The available connectors by RTDIP are Databricks SQL Connect, PYODBC SQL Connect, TURBODBC SQL Connect.

    The available authentcation methods are Certificate Authentication, Client Secret Authentication or Default Authentication. See documentation.

    This function requires the user to input a dictionary of parameters. (See Attributes table below)

    Args:
        connection: Connection chosen by the user (Databricks SQL Connect, PYODBC SQL Connect, TURBODBC SQL Connect)
        parameters_dict: A dictionary of parameters (see Attributes table below)

    Attributes:
        source (optional str): Source of the data the full table name
        forecast (str): Any specific identifier for forecast
        forecast_type(str): Type of forecast ie weather, solar, power, etc
        region (str): Region
        data_security_level (str): Level of data security
        data_type (str): Type of the data (float, integer, double, string)
        lat (float): latitude
        lon (float): longitude
        measurement (optional str): Measurement type
        limit (optional int): The number of rows to be returned

    Returns:
        DataFrame: A dataframe of event latest values.
    """
    try:
        query = _query_builder(parameters_dict, "latest_point")

        try:
            cursor = connection.cursor()
            cursor.execute(query)
            df = cursor.fetch_all()
            cursor.close()
            connection.close()
            return df
        except Exception as e:
            logging.exception("error returning dataframe")
            raise e

    except Exception as e:
        logging.exception("error returning latest function")
        raise e

Example get_point

from rtdip_sdk.authentication.azure import DefaultAuth
from rtdip_sdk.queries.weather.latest import get_point
from rtdip_sdk.connectors import DatabricksSQLConnection

auth = DefaultAuth().authenticate()
token = auth.get_token("2ff814a6-3304-4ab8-85cb-cd0e6f879c1d/.default").token
connection = DatabricksSQLConnection("{server_hostname}", "{http_path}", token)

params = {
    "forecast": "mock_forecast",
    "forecast_type": "mock_weather",
    "region": "mock_region",
    "data_security_level": "mock_security",
    "data_type": "mock_data_type",
    "lat": 1.1,
    "lon": 1.1,
}

x = get_point(connection, params)

print(x)

Example get_grid

from rtdip_sdk.authentication.azure import DefaultAuth
from rtdip_sdk.queries.weather.latest import get_point
from rtdip_sdk.connectors import DatabricksSQLConnection

auth = DefaultAuth().authenticate()
token = auth.get_token("2ff814a6-3304-4ab8-85cb-cd0e6f879c1d/.default").token
connection = DatabricksSQLConnection("{server_hostname}", "{http_path}", token)

params = {
    "forecast": "mock_forecast",
    "forecast_type": "mock_weather",
    "region": "mock_region",
    "data_security_level": "mock_security",
    "data_type": "mock_data_type",
    "min_lat": 36,
    "max_lat": 38,
    "min_lon": -109.1,
    "max_lon": -107.1,
}

x = get_grid(connection, params)

print(x)

These examples are using DefaultAuth() and DatabricksSQLConnection() to authenticate and connect. You can find other ways to authenticate here. The alternative built in connection methods are either by PYODBCSQLConnection(), TURBODBCSQLConnection() or SparkConnection().

Note

server_hostname and http_path can be found on the SQL Warehouses Page.