Skip to content

Weather Query Builder

WeatherQueryBuilder

A builder for developing RTDIP forecast queries using any delta table

Source code in src/sdk/python/rtdip_sdk/queries/weather/weather_query_builder.py
 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
 70
 71
 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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
class WeatherQueryBuilder:
    """
    A builder for developing RTDIP forecast queries using any delta table

    """

    parameters: dict
    connection: ConnectionInterface
    close_connection: bool
    data_source: str
    tagname_column: str
    timestamp_column: str
    status_column: str
    value_column: str

    def connect(self, connection: ConnectionInterface):
        """
        Specifies the connection to be used for the query

        Args:
            connection: Connection chosen by the user (Databricks SQL Connect, PYODBC SQL Connect, TURBODBC SQL Connect)
        """
        self.connection = connection
        return self

    def source(
        self,
        source: str,
        tagname_column: str = "TagName",
        timestamp_column: str = "EventTime",
        forecast_run_timestamp_column: str = "EnqueuedTime",
        status_column: Union[str, None] = "Status",
        value_column: str = "Value",
    ):
        """
        Specifies the source of the query

        Args:
            source (str): Source of the query can be a Unity Catalog table, Hive metastore table or path
            tagname_column (optional str): The column name in the source that contains the tagnames or series
            timestamp_column (optional str): The timestamp column name in the source
            forecast_run_timestamp_column (optional str): The forecast run timestamp column name in the source
            status_column (optional str): The status column name in the source indicating `Good` or `Bad`. If this is not available, specify `None`
            value_column (optional str): The value column name in the source which is normally a float or string value for the time series event
        """
        self.data_source = "`.`".join(source.split("."))
        self.tagname_column = tagname_column
        self.timestamp_column = timestamp_column
        self.forecast_run_timestamp_column = forecast_run_timestamp_column
        self.status_column = status_column
        self.value_column = value_column
        return self

    def raw_point(
        self,
        start_date: str,
        end_date: str,
        forecast_run_start_date: str,
        forecast_run_end_date: str,
        lat: float,
        lon: float,
        limit: int = None,
        measurement: str = None,
    ) -> DataFrame:
        """
        A function to return back raw data for a point.

        **Example:**
        ```python
        from rtdip_sdk.queries.weather.weather_query_builder import (
            WeatherQueryBuilder,
        )
        from rtdip_sdk.authentication.azure import DefaultAuth
        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)

        data = (
                WeatherQueryBuilder()
                .connect(connection)
                .source("example.forecast.table")
                .raw_point(
                    start_date="2021-01-01",
                    end_date="2021-01-02",
                    forecast_run_start_date="2021-01-01",
                    forecast_run_end_date="2021-01-02",
                    lat=0.1,
                    lon=0.1,
                )
            )

        print(data)
        ```

        Args:
            start_date (str): Start date (Either a date in the format YY-MM-DD or a datetime in the format YYY-MM-DDTHH:MM:SS or specify the timezone offset in the format YYYY-MM-DDTHH:MM:SS+zz:zz)
            end_date (str): End date (Either a date in the format YY-MM-DD or a datetime in the format YYY-MM-DDTHH:MM:SS or specify the timezone offset in the format YYYY-MM-DDTHH:MM:SS+zz:zz)
            forecast_run_start_date (str): Start date of the forecast run (Either a date in the format YY-MM-DD or a datetime in the format YYY-MM-DDTHH:MM:SS or specify the timezone offset in the format YYYY-MM-DDTHH:MM:SS+zz:zz)
            forecast_run_end_date (str): End date of the forecast run (Either a date in the format YY-MM-DD or a datetime in the format YYY-MM-DDTHH:MM:SS or specify the timezone offset in the format YYYY-MM-DDTHH:MM:SS+zz:zz)
            lat (float): latitude
            lon (float): longitude
            limit (optional int): The number of rows to be returned
            measurement (optional str): Measurement type

        Returns:
            DataFrame: A dataframe of raw timeseries data.
        """
        raw_parameters = {
            "source": self.data_source,
            "start_date": start_date,
            "end_date": end_date,
            "forecast_run_start_date": forecast_run_start_date,
            "forecast_run_end_date": forecast_run_end_date,
            "timestamp_column": self.timestamp_column,
            "forecast_run_timestamp_column": self.forecast_run_timestamp_column,
            "lat": lat,
            "lon": lon,
            "limit": limit,
            "measurement": measurement,
            "supress_warning": True,
        }

        return raw.get_point(self.connection, raw_parameters)

    def latest_point(
        self,
        lat: float,
        lon: float,
        limit: int = None,
        measurement: str = None,
    ) -> DataFrame:
        """
        A function to return back the latest data for a point.

        **Example:**
        ```python
        from rtdip_sdk.queries.weather.weather_query_builder import (
            WeatherQueryBuilder,
        )
        from rtdip_sdk.authentication.azure import DefaultAuth
        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)

        data = (
                WeatherQueryBuilder()
                .connect(connection)
                .source("example.forecast.table")
                .latest_point(
                    lat=0.1,
                    lon=0.1,
                    )
                )

        print(data)
        ```

        Args:
            lat (float): latitude
            lon (float): longitude
            limit (optional int): The number of rows to be returned
            measurement (optional str): Measurement type

        Returns:
            DataFrame: A dataframe of raw timeseries data.
        """
        raw_parameters = {
            "source": self.data_source,
            "lat": lat,
            "lon": lon,
            "limit": limit,
            "measurement": measurement,
            "supress_warning": True,
        }

        return latest.get_point(self.connection, raw_parameters)

    def raw_grid(  # NOSONAR
        self,  # NOSONAR
        start_date: str,
        end_date: str,
        forecast_run_start_date: str,
        forecast_run_end_date: str,
        min_lat: float,
        min_lon: float,
        max_lat: float,
        max_lon: float,
        limit: int = None,  # NOSONAR
        measurement: str = None,
    ) -> DataFrame:
        """
        A function to return back raw data for a grid.

        **Example:**
        ```python
        from rtdip_sdk.queries.weather.weather_query_builder import (
            WeatherQueryBuilder,
        )
        from rtdip_sdk.authentication.azure import DefaultAuth
        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)

        data = (
                WeatherQueryBuilder()
                .connect(connection)
                .source("example.forecast.table")
                .raw_grid(
                    start_date="2021-01-01",
                    end_date="2021-01-02",
                    forecast_run_start_date="2021-01-01",
                    forecast_run_end_date="2021-01-02",
                    min_lat=0.1,
                    max_lat=0.1,
                    min_lon=0.1,
                    max_lon=0.1,
                )
            )

        print(data)
        ```

        Args:
            start_date (str): Start date (Either a date in the format YY-MM-DD or a datetime in the format YYY-MM-DDTHH:MM:SS or specify the timezone offset in the format YYYY-MM-DDTHH:MM:SS+zz:zz)
            end_date (str): End date (Either a date in the format YY-MM-DD or a datetime in the format YYY-MM-DDTHH:MM:SS or specify the timezone offset in the format YYYY-MM-DDTHH:MM:SS+zz:zz)
            forecast_run_start_date (str): Start date of the forecast run (Either a date in the format YY-MM-DD or a datetime in the format YYY-MM-DDTHH:MM:SS or specify the timezone offset in the format YYYY-MM-DDTHH:MM:SS+zz:zz)
            forecast_run_end_date (str): End date of the forecast run (Either a date in the format YY-MM-DD or a datetime in the format YYY-MM-DDTHH:MM:SS or specify the timezone offset in the format YYYY-MM-DDTHH:MM:SS+zz:zz)
            min_lat (float): Min latitude
            min_lon (float): Min longitude
            max_lat (float): Max latitude
            max_lon (float): Max longitude
            limit (optional int): The number of rows to be returned
            measurement (optional str): Measurement type

        Returns:
            DataFrame: A dataframe of raw timeseries data.
        """
        raw_parameters = {
            "source": self.data_source,
            "start_date": start_date,
            "end_date": end_date,
            "forecast_run_start_date": forecast_run_start_date,
            "forecast_run_end_date": forecast_run_end_date,
            "timestamp_column": self.timestamp_column,
            "forecast_run_timestamp_column": self.forecast_run_timestamp_column,
            "min_lat": min_lat,
            "min_lon": min_lon,
            "max_lat": max_lat,
            "max_lon": max_lon,
            "limit": limit,
            "measurement": measurement,
            "supress_warning": True,
        }

        return raw.get_grid(self.connection, raw_parameters)

    def latest_grid(
        self,
        min_lat: float,
        min_lon: float,
        max_lat: float,
        max_lon: float,
        limit: int = None,
        measurement: str = None,
    ) -> DataFrame:
        """
        A function to return back the latest data for a grid.

        **Example:**
        ```python
        from rtdip_sdk.queries.weather.weather_query_builder import (
            WeatherQueryBuilder,
        )
        from rtdip_sdk.authentication.azure import DefaultAuth
        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)

        data = (
                WeatherQueryBuilder()
                .connect(connection)
                .source("example.forecast.table")
                .latest_grid(
                    min_lat=0.1,
                    max_lat=0.1,
                    min_lon=0.1,
                    max_lon=0.1,
                )
            )

        print(data)
        ```

        Args:
            min_lat (float): Min latitude
            min_lon (float): Min longitude
            max_lat (float): Max latitude
            max_lon (float): Max longitude
            limit (optional int): The number of rows to be returned
            measurement (optional str): Measurement type

        Returns:
            DataFrame: A dataframe of raw timeseries data.
        """
        raw_parameters = {
            "source": self.data_source,
            "min_lat": min_lat,
            "min_lon": min_lon,
            "max_lat": max_lat,
            "max_lon": max_lon,
            "limit": limit,
            "measurement": measurement,
            "supress_warning": True,
        }

        return latest.get_grid(self.connection, raw_parameters)

connect(connection)

Specifies the connection to be used for the query

Parameters:

Name Type Description Default
connection ConnectionInterface

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

required
Source code in src/sdk/python/rtdip_sdk/queries/weather/weather_query_builder.py
39
40
41
42
43
44
45
46
47
def connect(self, connection: ConnectionInterface):
    """
    Specifies the connection to be used for the query

    Args:
        connection: Connection chosen by the user (Databricks SQL Connect, PYODBC SQL Connect, TURBODBC SQL Connect)
    """
    self.connection = connection
    return self

source(source, tagname_column='TagName', timestamp_column='EventTime', forecast_run_timestamp_column='EnqueuedTime', status_column='Status', value_column='Value')

Specifies the source of the query

Parameters:

Name Type Description Default
source str

Source of the query can be a Unity Catalog table, Hive metastore table or path

required
tagname_column optional str

The column name in the source that contains the tagnames or series

'TagName'
timestamp_column optional str

The timestamp column name in the source

'EventTime'
forecast_run_timestamp_column optional str

The forecast run timestamp column name in the source

'EnqueuedTime'
status_column optional str

The status column name in the source indicating Good or Bad. If this is not available, specify None

'Status'
value_column optional str

The value column name in the source which is normally a float or string value for the time series event

'Value'
Source code in src/sdk/python/rtdip_sdk/queries/weather/weather_query_builder.py
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
def source(
    self,
    source: str,
    tagname_column: str = "TagName",
    timestamp_column: str = "EventTime",
    forecast_run_timestamp_column: str = "EnqueuedTime",
    status_column: Union[str, None] = "Status",
    value_column: str = "Value",
):
    """
    Specifies the source of the query

    Args:
        source (str): Source of the query can be a Unity Catalog table, Hive metastore table or path
        tagname_column (optional str): The column name in the source that contains the tagnames or series
        timestamp_column (optional str): The timestamp column name in the source
        forecast_run_timestamp_column (optional str): The forecast run timestamp column name in the source
        status_column (optional str): The status column name in the source indicating `Good` or `Bad`. If this is not available, specify `None`
        value_column (optional str): The value column name in the source which is normally a float or string value for the time series event
    """
    self.data_source = "`.`".join(source.split("."))
    self.tagname_column = tagname_column
    self.timestamp_column = timestamp_column
    self.forecast_run_timestamp_column = forecast_run_timestamp_column
    self.status_column = status_column
    self.value_column = value_column
    return self

raw_point(start_date, end_date, forecast_run_start_date, forecast_run_end_date, lat, lon, limit=None, measurement=None)

A function to return back raw data for a point.

Example:

from rtdip_sdk.queries.weather.weather_query_builder import (
    WeatherQueryBuilder,
)
from rtdip_sdk.authentication.azure import DefaultAuth
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)

data = (
        WeatherQueryBuilder()
        .connect(connection)
        .source("example.forecast.table")
        .raw_point(
            start_date="2021-01-01",
            end_date="2021-01-02",
            forecast_run_start_date="2021-01-01",
            forecast_run_end_date="2021-01-02",
            lat=0.1,
            lon=0.1,
        )
    )

print(data)

Parameters:

Name Type Description Default
start_date str

Start date (Either a date in the format YY-MM-DD or a datetime in the format YYY-MM-DDTHH:MM:SS or specify the timezone offset in the format YYYY-MM-DDTHH:MM:SS+zz:zz)

required
end_date str

End date (Either a date in the format YY-MM-DD or a datetime in the format YYY-MM-DDTHH:MM:SS or specify the timezone offset in the format YYYY-MM-DDTHH:MM:SS+zz:zz)

required
forecast_run_start_date str

Start date of the forecast run (Either a date in the format YY-MM-DD or a datetime in the format YYY-MM-DDTHH:MM:SS or specify the timezone offset in the format YYYY-MM-DDTHH:MM:SS+zz:zz)

required
forecast_run_end_date str

End date of the forecast run (Either a date in the format YY-MM-DD or a datetime in the format YYY-MM-DDTHH:MM:SS or specify the timezone offset in the format YYYY-MM-DDTHH:MM:SS+zz:zz)

required
lat float

latitude

required
lon float

longitude

required
limit optional int

The number of rows to be returned

None
measurement optional str

Measurement type

None

Returns:

Name Type Description
DataFrame DataFrame

A dataframe of raw timeseries data.

Source code in src/sdk/python/rtdip_sdk/queries/weather/weather_query_builder.py
 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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
def raw_point(
    self,
    start_date: str,
    end_date: str,
    forecast_run_start_date: str,
    forecast_run_end_date: str,
    lat: float,
    lon: float,
    limit: int = None,
    measurement: str = None,
) -> DataFrame:
    """
    A function to return back raw data for a point.

    **Example:**
    ```python
    from rtdip_sdk.queries.weather.weather_query_builder import (
        WeatherQueryBuilder,
    )
    from rtdip_sdk.authentication.azure import DefaultAuth
    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)

    data = (
            WeatherQueryBuilder()
            .connect(connection)
            .source("example.forecast.table")
            .raw_point(
                start_date="2021-01-01",
                end_date="2021-01-02",
                forecast_run_start_date="2021-01-01",
                forecast_run_end_date="2021-01-02",
                lat=0.1,
                lon=0.1,
            )
        )

    print(data)
    ```

    Args:
        start_date (str): Start date (Either a date in the format YY-MM-DD or a datetime in the format YYY-MM-DDTHH:MM:SS or specify the timezone offset in the format YYYY-MM-DDTHH:MM:SS+zz:zz)
        end_date (str): End date (Either a date in the format YY-MM-DD or a datetime in the format YYY-MM-DDTHH:MM:SS or specify the timezone offset in the format YYYY-MM-DDTHH:MM:SS+zz:zz)
        forecast_run_start_date (str): Start date of the forecast run (Either a date in the format YY-MM-DD or a datetime in the format YYY-MM-DDTHH:MM:SS or specify the timezone offset in the format YYYY-MM-DDTHH:MM:SS+zz:zz)
        forecast_run_end_date (str): End date of the forecast run (Either a date in the format YY-MM-DD or a datetime in the format YYY-MM-DDTHH:MM:SS or specify the timezone offset in the format YYYY-MM-DDTHH:MM:SS+zz:zz)
        lat (float): latitude
        lon (float): longitude
        limit (optional int): The number of rows to be returned
        measurement (optional str): Measurement type

    Returns:
        DataFrame: A dataframe of raw timeseries data.
    """
    raw_parameters = {
        "source": self.data_source,
        "start_date": start_date,
        "end_date": end_date,
        "forecast_run_start_date": forecast_run_start_date,
        "forecast_run_end_date": forecast_run_end_date,
        "timestamp_column": self.timestamp_column,
        "forecast_run_timestamp_column": self.forecast_run_timestamp_column,
        "lat": lat,
        "lon": lon,
        "limit": limit,
        "measurement": measurement,
        "supress_warning": True,
    }

    return raw.get_point(self.connection, raw_parameters)

latest_point(lat, lon, limit=None, measurement=None)

A function to return back the latest data for a point.

Example:

from rtdip_sdk.queries.weather.weather_query_builder import (
    WeatherQueryBuilder,
)
from rtdip_sdk.authentication.azure import DefaultAuth
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)

data = (
        WeatherQueryBuilder()
        .connect(connection)
        .source("example.forecast.table")
        .latest_point(
            lat=0.1,
            lon=0.1,
            )
        )

print(data)

Parameters:

Name Type Description Default
lat float

latitude

required
lon float

longitude

required
limit optional int

The number of rows to be returned

None
measurement optional str

Measurement type

None

Returns:

Name Type Description
DataFrame DataFrame

A dataframe of raw timeseries data.

Source code in src/sdk/python/rtdip_sdk/queries/weather/weather_query_builder.py
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
def latest_point(
    self,
    lat: float,
    lon: float,
    limit: int = None,
    measurement: str = None,
) -> DataFrame:
    """
    A function to return back the latest data for a point.

    **Example:**
    ```python
    from rtdip_sdk.queries.weather.weather_query_builder import (
        WeatherQueryBuilder,
    )
    from rtdip_sdk.authentication.azure import DefaultAuth
    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)

    data = (
            WeatherQueryBuilder()
            .connect(connection)
            .source("example.forecast.table")
            .latest_point(
                lat=0.1,
                lon=0.1,
                )
            )

    print(data)
    ```

    Args:
        lat (float): latitude
        lon (float): longitude
        limit (optional int): The number of rows to be returned
        measurement (optional str): Measurement type

    Returns:
        DataFrame: A dataframe of raw timeseries data.
    """
    raw_parameters = {
        "source": self.data_source,
        "lat": lat,
        "lon": lon,
        "limit": limit,
        "measurement": measurement,
        "supress_warning": True,
    }

    return latest.get_point(self.connection, raw_parameters)

raw_grid(start_date, end_date, forecast_run_start_date, forecast_run_end_date, min_lat, min_lon, max_lat, max_lon, limit=None, measurement=None)

A function to return back raw data for a grid.

Example:

from rtdip_sdk.queries.weather.weather_query_builder import (
    WeatherQueryBuilder,
)
from rtdip_sdk.authentication.azure import DefaultAuth
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)

data = (
        WeatherQueryBuilder()
        .connect(connection)
        .source("example.forecast.table")
        .raw_grid(
            start_date="2021-01-01",
            end_date="2021-01-02",
            forecast_run_start_date="2021-01-01",
            forecast_run_end_date="2021-01-02",
            min_lat=0.1,
            max_lat=0.1,
            min_lon=0.1,
            max_lon=0.1,
        )
    )

print(data)

Parameters:

Name Type Description Default
start_date str

Start date (Either a date in the format YY-MM-DD or a datetime in the format YYY-MM-DDTHH:MM:SS or specify the timezone offset in the format YYYY-MM-DDTHH:MM:SS+zz:zz)

required
end_date str

End date (Either a date in the format YY-MM-DD or a datetime in the format YYY-MM-DDTHH:MM:SS or specify the timezone offset in the format YYYY-MM-DDTHH:MM:SS+zz:zz)

required
forecast_run_start_date str

Start date of the forecast run (Either a date in the format YY-MM-DD or a datetime in the format YYY-MM-DDTHH:MM:SS or specify the timezone offset in the format YYYY-MM-DDTHH:MM:SS+zz:zz)

required
forecast_run_end_date str

End date of the forecast run (Either a date in the format YY-MM-DD or a datetime in the format YYY-MM-DDTHH:MM:SS or specify the timezone offset in the format YYYY-MM-DDTHH:MM:SS+zz:zz)

required
min_lat float

Min latitude

required
min_lon float

Min longitude

required
max_lat float

Max latitude

required
max_lon float

Max longitude

required
limit optional int

The number of rows to be returned

None
measurement optional str

Measurement type

None

Returns:

Name Type Description
DataFrame DataFrame

A dataframe of raw timeseries data.

Source code in src/sdk/python/rtdip_sdk/queries/weather/weather_query_builder.py
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
def raw_grid(  # NOSONAR
    self,  # NOSONAR
    start_date: str,
    end_date: str,
    forecast_run_start_date: str,
    forecast_run_end_date: str,
    min_lat: float,
    min_lon: float,
    max_lat: float,
    max_lon: float,
    limit: int = None,  # NOSONAR
    measurement: str = None,
) -> DataFrame:
    """
    A function to return back raw data for a grid.

    **Example:**
    ```python
    from rtdip_sdk.queries.weather.weather_query_builder import (
        WeatherQueryBuilder,
    )
    from rtdip_sdk.authentication.azure import DefaultAuth
    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)

    data = (
            WeatherQueryBuilder()
            .connect(connection)
            .source("example.forecast.table")
            .raw_grid(
                start_date="2021-01-01",
                end_date="2021-01-02",
                forecast_run_start_date="2021-01-01",
                forecast_run_end_date="2021-01-02",
                min_lat=0.1,
                max_lat=0.1,
                min_lon=0.1,
                max_lon=0.1,
            )
        )

    print(data)
    ```

    Args:
        start_date (str): Start date (Either a date in the format YY-MM-DD or a datetime in the format YYY-MM-DDTHH:MM:SS or specify the timezone offset in the format YYYY-MM-DDTHH:MM:SS+zz:zz)
        end_date (str): End date (Either a date in the format YY-MM-DD or a datetime in the format YYY-MM-DDTHH:MM:SS or specify the timezone offset in the format YYYY-MM-DDTHH:MM:SS+zz:zz)
        forecast_run_start_date (str): Start date of the forecast run (Either a date in the format YY-MM-DD or a datetime in the format YYY-MM-DDTHH:MM:SS or specify the timezone offset in the format YYYY-MM-DDTHH:MM:SS+zz:zz)
        forecast_run_end_date (str): End date of the forecast run (Either a date in the format YY-MM-DD or a datetime in the format YYY-MM-DDTHH:MM:SS or specify the timezone offset in the format YYYY-MM-DDTHH:MM:SS+zz:zz)
        min_lat (float): Min latitude
        min_lon (float): Min longitude
        max_lat (float): Max latitude
        max_lon (float): Max longitude
        limit (optional int): The number of rows to be returned
        measurement (optional str): Measurement type

    Returns:
        DataFrame: A dataframe of raw timeseries data.
    """
    raw_parameters = {
        "source": self.data_source,
        "start_date": start_date,
        "end_date": end_date,
        "forecast_run_start_date": forecast_run_start_date,
        "forecast_run_end_date": forecast_run_end_date,
        "timestamp_column": self.timestamp_column,
        "forecast_run_timestamp_column": self.forecast_run_timestamp_column,
        "min_lat": min_lat,
        "min_lon": min_lon,
        "max_lat": max_lat,
        "max_lon": max_lon,
        "limit": limit,
        "measurement": measurement,
        "supress_warning": True,
    }

    return raw.get_grid(self.connection, raw_parameters)

latest_grid(min_lat, min_lon, max_lat, max_lon, limit=None, measurement=None)

A function to return back the latest data for a grid.

Example:

from rtdip_sdk.queries.weather.weather_query_builder import (
    WeatherQueryBuilder,
)
from rtdip_sdk.authentication.azure import DefaultAuth
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)

data = (
        WeatherQueryBuilder()
        .connect(connection)
        .source("example.forecast.table")
        .latest_grid(
            min_lat=0.1,
            max_lat=0.1,
            min_lon=0.1,
            max_lon=0.1,
        )
    )

print(data)

Parameters:

Name Type Description Default
min_lat float

Min latitude

required
min_lon float

Min longitude

required
max_lat float

Max latitude

required
max_lon float

Max longitude

required
limit optional int

The number of rows to be returned

None
measurement optional str

Measurement type

None

Returns:

Name Type Description
DataFrame DataFrame

A dataframe of raw timeseries data.

Source code in src/sdk/python/rtdip_sdk/queries/weather/weather_query_builder.py
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
def latest_grid(
    self,
    min_lat: float,
    min_lon: float,
    max_lat: float,
    max_lon: float,
    limit: int = None,
    measurement: str = None,
) -> DataFrame:
    """
    A function to return back the latest data for a grid.

    **Example:**
    ```python
    from rtdip_sdk.queries.weather.weather_query_builder import (
        WeatherQueryBuilder,
    )
    from rtdip_sdk.authentication.azure import DefaultAuth
    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)

    data = (
            WeatherQueryBuilder()
            .connect(connection)
            .source("example.forecast.table")
            .latest_grid(
                min_lat=0.1,
                max_lat=0.1,
                min_lon=0.1,
                max_lon=0.1,
            )
        )

    print(data)
    ```

    Args:
        min_lat (float): Min latitude
        min_lon (float): Min longitude
        max_lat (float): Max latitude
        max_lon (float): Max longitude
        limit (optional int): The number of rows to be returned
        measurement (optional str): Measurement type

    Returns:
        DataFrame: A dataframe of raw timeseries data.
    """
    raw_parameters = {
        "source": self.data_source,
        "min_lat": min_lat,
        "min_lon": min_lon,
        "max_lat": max_lat,
        "max_lon": max_lon,
        "limit": limit,
        "measurement": measurement,
        "supress_warning": True,
    }

    return latest.get_grid(self.connection, raw_parameters)

Note

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.