Skip to content

Weather

Accessed via sdk.weather on an AspiaSpace instance.

Service wrapper for the Weather endpoints.

Source code in src/aspiaspace/services/weather.py
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
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
class WeatherService:
    """
    Service wrapper for the Weather endpoints.
    """

    def __init__(self, client):
        self._client = client

    def point(self, coord: str, start: str, end:str, resolution:int = 5):
        """ Retrieve weather for a single point and date range.

        Args:
            coord (str): Coordinate as (lon,lat)
            start (str, optional): Start of date range.
            end (str, optional): End of date range.
            resolution (int, optional): Resolution of weather model. Defaults to 5.

        Raises:
            ValueError: If coordinate is invalid.
            ValueError: If resolution is not one of the allowed sizes (1 or 5, depending on subscription).
            ValueError: If start or end date is missing.
            ValueError: If start date is not in YYYY-MM-DD format.
            ValueError: If end date is not in YYYY-MM-DD format.

        Returns:
            Weather data (json): API response
        """

        if coord == "" or is_valid_coordinate(coord) == False:
            raise ValueError("Please enter a valid decimal coordinate to retreive weather data: lat,long")

        if resolution not in (1,5):
            raise ValueError("Resolution must be either 1 or 5 (defaults to 5)")


        if start != "" or end != "":
            if start == "" or end == "":
                raise ValueError("If entering a date range then both start and end parameters need to be passed: YYYY-MM-DD")

            if not re.fullmatch(r"\d{4}-\d{2}-\d{2}", start):
                raise ValueError("Start date must be in format 'yyyy-mm-dd'")

            if not re.fullmatch(r"\d{4}-\d{2}-\d{2}", end):
                raise ValueError("End date must be in format 'yyyy-mm-dd'")


        return self._client._request(
            "GET",
            "/customer/weather",
            params={"coord": coord, "resolution": resolution,"start_date": start, "end_date": end}, 
            )

point(coord, start, end, resolution=5)

Retrieve weather for a single point and date range.

Parameters:

Name Type Description Default
coord str

Coordinate as (lon,lat)

required
start str

Start of date range.

required
end str

End of date range.

required
resolution int

Resolution of weather model. Defaults to 5.

5

Raises:

Type Description
ValueError

If coordinate is invalid.

ValueError

If resolution is not one of the allowed sizes (1 or 5, depending on subscription).

ValueError

If start or end date is missing.

ValueError

If start date is not in YYYY-MM-DD format.

ValueError

If end date is not in YYYY-MM-DD format.

Returns:

Type Description

Weather data (json): API response

Source code in src/aspiaspace/services/weather.py
15
16
17
18
19
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
def point(self, coord: str, start: str, end:str, resolution:int = 5):
    """ Retrieve weather for a single point and date range.

    Args:
        coord (str): Coordinate as (lon,lat)
        start (str, optional): Start of date range.
        end (str, optional): End of date range.
        resolution (int, optional): Resolution of weather model. Defaults to 5.

    Raises:
        ValueError: If coordinate is invalid.
        ValueError: If resolution is not one of the allowed sizes (1 or 5, depending on subscription).
        ValueError: If start or end date is missing.
        ValueError: If start date is not in YYYY-MM-DD format.
        ValueError: If end date is not in YYYY-MM-DD format.

    Returns:
        Weather data (json): API response
    """

    if coord == "" or is_valid_coordinate(coord) == False:
        raise ValueError("Please enter a valid decimal coordinate to retreive weather data: lat,long")

    if resolution not in (1,5):
        raise ValueError("Resolution must be either 1 or 5 (defaults to 5)")


    if start != "" or end != "":
        if start == "" or end == "":
            raise ValueError("If entering a date range then both start and end parameters need to be passed: YYYY-MM-DD")

        if not re.fullmatch(r"\d{4}-\d{2}-\d{2}", start):
            raise ValueError("Start date must be in format 'yyyy-mm-dd'")

        if not re.fullmatch(r"\d{4}-\d{2}-\d{2}", end):
            raise ValueError("End date must be in format 'yyyy-mm-dd'")


    return self._client._request(
        "GET",
        "/customer/weather",
        params={"coord": coord, "resolution": resolution,"start_date": start, "end_date": end}, 
        )