> For the complete documentation index, see [llms.txt](https://docs.jua.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.jua.ai/api-v2/query-engine/examples/aggregated-queries.md).

# Aggregated Queries

### Daily Min & Max for a location

{% tabs %}
{% tab title="Example (Python)" %}

```python
query = {
    "models": ["ept2"],
    "geo": {
        "type": "point",
        "value": [47.3784, 8.5387],  # [latitude, longitude] - Zurich
        "method": "nearest",
    },
    "variables": [
        "air_temperature_at_height_level_2m",
        "wind_speed_at_height_level_100m",
    ],
    "init_time": "latest",
    "prediction_timedelta": {"start": 0, "end": 72},  # 0-72 hours ahead
}

response = requests.post(url, headers=headers, json=query)
response.raise_for_status()

data = response.json()
df = pd.DataFrame(data)
print(f"✅ Retrieved {len(df)} rows")
print(df.head())
```

{% endtab %}

{% tab title="Output" %}

```
✅ Retrieved 73 rows
  model             init_time  ...  air_temperature_at_height_level_2m  wind_speed_at_height_level_100m
0  ept2  2025-10-23T06:00:00Z  ...                          284.600006                              4.7
1  ept2  2025-10-23T06:00:00Z  ...                          285.399994                              5.0
2  ept2  2025-10-23T06:00:00Z  ...                          286.399994                              4.8
3  ept2  2025-10-23T06:00:00Z  ...                          286.500000                              9.3
4  ept2  2025-10-23T06:00:00Z  ...                          284.800018                             10.8

[5 rows x 7 columns]
```

{% endtab %}
{% endtabs %}

### Hourly Wind Statistics in Germany

{% tabs %}
{% tab title="Example (Python)" %}

```python
query = {
    "models": ["ept2"],
    "geo": {
        "type": "market_zone",
        "value": "DE",  # Germany
    },
    "variables": ["wind_speed_at_height_level_100m"],
    "init_time": "latest",
    "prediction_timedelta": {"start": 0, "end": 72},  # 3 days
    "group_by": [
        {
            # Explicit use of the "to_start_of" transformation
            "field": "time",
            "transformation": "to_start_of",
            "parameters_list": ["hour"],
        }
    ],
    "aggregation": [
        {"aggregation": "max"},
        "min",
        "avg",
        "std",
        "quantile_(0.05)",
        "quantile_(0.95)",
    ],
    "include_time": True,
    "order_by": ["time"],
}

response = requests.post(url, headers=headers, json=query)
response.raise_for_status()

data = response.json()
df = pd.DataFrame(data)
print(f"Retrieved {len(df)} rows")
print(df.head(20))

return df
```

{% endtab %}

{% tab title="Output" %}

```
Retrieved 73 rows
                    time  max__wind_speed_at_height_level_100m  min__wind_speed_at_height_level_100m  ...  std__wind_speed_at_height_level_100m  quantile_(0.05)__wind_speed_at_height_level_100m  quantile_(0.95)__wind_speed_at_height_level_100m
0   2025-10-23T06:00:00Z                             16.500000                                   2.2  ...                              1.972303                                          6.400000                                         13.000000
1   2025-10-23T07:00:00Z                             14.400001                                   4.3  ...                              1.616050                                          6.800000                                         12.300000
2   2025-10-23T08:00:00Z                             14.200000                                   4.4  ...                              1.601147                                          6.600000                                         12.100000
3   2025-10-23T09:00:00Z                             14.300000                                   3.5  ...                              1.763546                                          5.900000                                         12.100000
4   2025-10-23T10:00:00Z                             14.800000                                   2.5  ...                              1.986278                                          4.800000                                         12.100000
5   2025-10-23T11:00:00Z                             16.900000                                   0.8  ...                              2.325559                                          4.300000                                         13.200000
6   2025-10-23T12:00:00Z                             18.500000                                   0.3  ...                              2.384850                                          7.200000                                         14.200000
7   2025-10-23T13:00:00Z                             18.400000                                   3.0  ...                              2.306951                                          7.400000                                         15.000000
8   2025-10-23T14:00:00Z                             18.700001                                   2.8  ...                              2.426426                                          7.300000                                         15.200000
9   2025-10-23T15:00:00Z                             18.700001                                   2.0  ...                              2.556340                                          7.100000                                         15.200000
10  2025-10-23T16:00:00Z                             18.900000                                   2.0  ...                              2.614214                                          7.100000                                         15.300000
11  2025-10-23T17:00:00Z                             18.200001                                   2.1  ...                              2.600091                                          7.500000                                         15.400001
12  2025-10-23T18:00:00Z                             17.100000                                   2.4  ...                              2.495059                                          7.600000                                         15.500000
13  2025-10-23T19:00:00Z                             16.600000                                   3.0  ...                              2.329726                                          7.900000                                         15.500000
14  2025-10-23T20:00:00Z                             16.500000                                   3.0  ...                              2.047417                                          8.500000                                         15.000000
15  2025-10-23T21:00:00Z                             15.800000                                   3.4  ...                              1.769095                                          8.700000                                         14.700000
16  2025-10-23T22:00:00Z                             15.900001                                   3.8  ...                              1.552549                                          8.800000                                         14.100000
17  2025-10-23T23:00:00Z                             17.100000                                   4.1  ...                              1.521312                                          8.900001                                         13.900001
18  2025-10-24T00:00:00Z                             17.900000                                   4.1  ...                              1.475617                                          9.000000                                         13.600000
19  2025-10-24T01:00:00Z                             18.200001                                   4.4  ...                              1.409908                                          9.200000                                         13.500000

[20 rows x 7 columns]
```

{% endtab %}
{% endtabs %}

### Capacity Weighted Average Wind Speed in Germany

{% tabs %}
{% tab title="Example (Python)" %}

```python
 query = {
    "models": ["ept2"],
    "geo": {
        "type": "market_zone",
        "value": "DE",  # Germany
    },
    "variables": ["wind_speed_at_height_level_100m"],
    "init_time": "latest",
    "prediction_timedelta": {"start": 0, "end": 72},  # 3 days
    "weighting": {"type": "wind_capacity"},
    "group_by": [
        {
            "field": "time",
            "transformation": "to_start_of",
            "parameters_list": ["hour"],
        }
    ],
    "aggregation": [{"aggregation": "avg"}],
    "include_time": True,
    "order_by": ["time"],
}

response = requests.post(url, headers=headers, json=query)
response.raise_for_status()

data = response.json()
df = pd.DataFrame(data)
print(f"Retrieved {len(df)} rows")
print(df.head(20))
```

{% endtab %}

{% tab title="Output" %}

```
Retrieved 73 rows
                    time  avg__wind_speed_at_height_level_100m
0   2025-10-23T06:00:00Z                             10.473292
1   2025-10-23T07:00:00Z                             10.559825
2   2025-10-23T08:00:00Z                             10.471903
3   2025-10-23T09:00:00Z                             10.234161
4   2025-10-23T10:00:00Z                              9.740825
5   2025-10-23T11:00:00Z                              9.817058
6   2025-10-23T12:00:00Z                              9.906179
7   2025-10-23T13:00:00Z                             10.051497
8   2025-10-23T14:00:00Z                             10.096489
9   2025-10-23T15:00:00Z                             10.191436
10  2025-10-23T16:00:00Z                             10.326234
11  2025-10-23T17:00:00Z                             10.489385
12  2025-10-23T18:00:00Z                             10.661165
13  2025-10-23T19:00:00Z                             10.938301
14  2025-10-23T20:00:00Z                             11.160419
15  2025-10-23T21:00:00Z                             11.237437
16  2025-10-23T22:00:00Z                             11.150809
17  2025-10-23T23:00:00Z                             11.313920
18  2025-10-24T00:00:00Z                             11.484743
19  2025-10-24T01:00:00Z                             11.695437
```

{% endtab %}
{% endtabs %}

### Capacity Weighted Average in a Polygon

{% tabs %}
{% tab title="Example (Python)" %}

```python
query = {
    "models": ["ept2"],
    "geo": {
        "type": "polygon",
        "value": [
            [
                [53.0, 8.0],
                [53.0, 12.0],
                [55.0, 12.0],
                [55.0, 8.0],
                [53.0, 8.0],
            ]
        ],
    },
    "variables": ["wind_speed_at_height_level_100m"],
    "init_time": "latest",
    "prediction_timedelta": {"start": 0, "end": 48},  # 2 days
    "weighting": {"type": "wind_capacity"},
    "group_by": [
        {
            "field": "time",
            "transformation": "to_start_of",
            "parameters_list": ["hour"],
        }
    ],
    "aggregation": [{"aggregation": "avg"}],
    "include_time": True,
    "order_by": ["time"],
}

response = requests.post(url, headers=headers, json=query)
response.raise_for_status()

data = response.json()
df = pd.DataFrame(data)
print(f"Retrieved {len(df)} rows")
print(df.head(20))
```

{% endtab %}

{% tab title="Output" %}

```
Retrieved 49 rows
                    time  avg__wind_speed_at_height_level_100m
0   2025-10-23T06:00:00Z                             11.385012
1   2025-10-23T07:00:00Z                             11.701327
2   2025-10-23T08:00:00Z                             11.644365
3   2025-10-23T09:00:00Z                             11.242075
4   2025-10-23T10:00:00Z                             10.356984
5   2025-10-23T11:00:00Z                              9.627563
6   2025-10-23T12:00:00Z                              8.863163
7   2025-10-23T13:00:00Z                              8.323935
8   2025-10-23T14:00:00Z                              7.914524
9   2025-10-23T15:00:00Z                              7.662574
10  2025-10-23T16:00:00Z                              7.734694
11  2025-10-23T17:00:00Z                              8.140329
12  2025-10-23T18:00:00Z                              8.584207
13  2025-10-23T19:00:00Z                              8.879365
14  2025-10-23T20:00:00Z                              9.181939
15  2025-10-23T21:00:00Z                              9.383254
16  2025-10-23T22:00:00Z                              9.735419
17  2025-10-23T23:00:00Z                             10.298345
18  2025-10-24T00:00:00Z                             10.977109
19  2025-10-24T01:00:00Z                             11.730488
```

{% endtab %}
{% endtabs %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.jua.ai/api-v2/query-engine/examples/aggregated-queries.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
