# SETGENDATAREGION

> SETGENDATAREGION sets out summary settlement data for generation within the specified region. The table is populated for participants using Data Model 5.2. For participants using Data Model 5.3 or higher, [`SET_ENERGY_REGION_SUMMARY`](./SET_ENERGY_REGION_SUMMARY.md) replace SETGENDATAREGION.

!!! tip "Deprecation Warning"
    This table is in the [HISTORICAL TABLES](../packages/HISTORICAL TABLES.md) package,
    so is likely deprecated.

> SETGENDATAREGION shows the regional summary. SETGENDATAREGION is public
> data.
> 
> Source
> 
> SETGENDATAREGION updates with each Settlement run.

## Column Schema

### PERIODID

> Settlements Trading Interval.

SQL Type: `NUMBER(22,10)`
Polars Type: `pl.Float64`

This column is mandatory, and a primary key.

Examples:
`1`, `200`

### REGIONID

> Region Identifier

For more information, see the [dedicated documentation page](../../guide/querying.md#region-id).

The SQL type is `VARCHAR2(10)`.
This is actually a factor/enum, with values:

- `QLD1` 

- `VIC1` 

- `TAS1` 

- `NSW1` 

- `SA1` 

- `SNOWY1` (in very old files)

This column is mandatory, and a primary key.

### SETTLEMENTDATE

> Calendar Settlement Date

SQL Type: `DATE`
Polars Type: `pl.Date()`

This column is mandatory, and a primary key.

Example: `2024/05/05 00:00:00`

Note that AEMO represents dates as datetimes with a midnight time component.

### VERSIONNO

> Settlement run no

SQL Type: `NUMBER(22,10)`
Polars Type: `pl.Float64`

This column is mandatory, and a primary key.

Example: `12`

### ENERGYCOST

> Cost of net energy $

SQL Type: `NUMBER(27,5)`
Polars Type: `pl.Float64`

This column is not mandatory.

Examples:
`-269.95147`, `1.59712`, `-18021.17474`, `167606.21924`

### EXCESSENERGYCOST

> Cost of excess energy $

SQL Type: `NUMBER(27,5)`
Polars Type: `pl.Float64`

This column is not mandatory.

Example: `0`

### EXPENERGY

> Export Energy (Generator Purchases)

SQL Type: `NUMBER(27,6)`
Polars Type: `pl.Float64`

This column is not mandatory.

Examples:
`-0.212487`, `-49.58294`

### EXPENERGYCOST

> Export Energy Cost

SQL Type: `NUMBER(27,6)`
Polars Type: `pl.Float64`

This column is not mandatory.

Examples:
`-0.013823`, `2.251715`, `-7037.281457`, `2792.867124`

### LASTCHANGED

> current system date, to enable automatic replication

For more information, see the [dedicated documentation page](../../guide/querying.md#deduplication).

SQL Type: `DATE`
Polars Type: `pl.Datetime()`

This column is not mandatory.

Example: `2024/11/25 07:51:48`

### NETENERGY

> Net energy MW/hours

SQL Type: `NUMBER(27,5)`
Polars Type: `pl.Float64`

This column is not mandatory.

Examples:
`52.65059`, `636.02502`

### AENERGY {: .unused-column }

> Purchased Energy - Not used in MMS Data Model

SQL Type: `NUMBER(22,0)`
Polars Type: `pl.Int128`

This column is unused.

### APOWER {: .unused-column }

> Not used in MMS Data Model

SQL Type: `NUMBER(22,0)`
Polars Type: `pl.Int128`

This column is unused.

### GENERGY {: .unused-column }

> Generated energy - Not used in MMS Data Model

SQL Type: `NUMBER(22,0)`
Polars Type: `pl.Int128`

This column is unused.

### GPOWER {: .unused-column }

> Not used in MMS Data Model

SQL Type: `NUMBER(22,0)`
Polars Type: `pl.Int128`

This column is unused.

## New Data Timing

> After each settlement run

## Code Examples

### Polars

Explicitly listing every column, casting to enums, categoricals etc is not essential, but may speed up parsing.
Swapping `int` for `pl.UInt16`, `pl.Int32` would also speed up parsing. However some of the datatypes are inferred, so they may be wrong.

This code deduplicates for you.
Deduplication is normally only required across multiple months.

This code assumes that all columns are present, which may not be true for older files.

```python
import polars as pl
import polars.selectors as cs

# e.g. "2029/03/15 00:05:00"
dt_s_fmt = "%Y/%m/%d %H:%M:%S"

# Dates are represented as datetimes at midnight

d_fmt = "%Y/%m/%d 00:00:00"

csv_paths = ["SOMEFILE.CSV", "OTHERFILE.CSV"]

lf = (
    pl.concat(
        [
            pl.scan_csv(
                csv_path,  # must be unzipped beforehand
                skip_rows=1,  # skip the header
                infer_schema=False,  # much faster
            )
            .filter(cs.by_index(0) == "D")  # drop the footer
            .select(~cs.by_index(range(4)))  # drop metadata columns
            for csv_path in csv_paths
        ],
        how="diagonal_relaxed",
    )
    .with_columns(
        pl.col("LASTCHANGED").str.strptime(pl.Datetime, dt_s_fmt),
        pl.col("SETTLEMENTDATE").str.strptime(pl.Date, d_fmt),
    )
    .cast(
        {
            "PERIODID": pl.Float64,
            "REGIONID": pl.Enum(["QLD1", "VIC1", "TAS1", "NSW1", "SA1", "SNOWY1"]),
            "SETTLEMENTDATE": pl.Date(),
            "VERSIONNO": pl.Float64,
            "ENERGYCOST": pl.Float64,
            "EXCESSENERGYCOST": pl.Float64,
            "EXPENERGY": pl.Float64,
            "EXPENERGYCOST": pl.Float64,
            "NETENERGY": pl.Float64,
            "AENERGY": int,  # or pl.Int128
            "APOWER": int,  # or pl.Int128
            "GENERGY": int,  # or pl.Int128
            "GPOWER": int,  # or pl.Int128
        }
    )
    # Drop deprecated/unused columns
    .drop("AENERGY", "APOWER", "GENERGY", "GPOWER")
    # Deduplicate
    # We want one row per ['PERIODID', 'REGIONID', 'SETTLEMENTDATE', 'VERSIONNO']
    # Tie-breaker: greatest value of ['LASTCHANGED']
    .sort(["LASTCHANGED"], descending=False)
    .unique(subset=["PERIODID", "REGIONID", "SETTLEMENTDATE", "VERSIONNO"], keep="last")
)

```

### Nemosis

This table is not yet available in [Nemosis](https://github.com/UNSW-CEEM/NEMOSIS/#static_table).

## Example File

From [PUBLIC_ARCHIVE_SETGENDATAREGION_FILE01_202412010000.zip](https://www.nemweb.com.au/Data_Archive/Wholesale_Electricity/MMSDM/2024/MMSDM_2024_12/MMSDM_Historical_Data_SQLLoader/DATA/PUBLIC_ARCHIVE%23SETGENDATAREGION%23FILE01%23202412010000.zip)

=== "Raw Text with Metadata"
    ```csv
    C,SETP.WORLD,DVD_SETGENDATAREGION,AEMO,PUBLIC,2025/01/10,15:05:52,001736485552614,MONTHLY_ARCHIVE,001736485552614
    I,SETTLEMENTS,GENDATAREGION,5,SETTLEMENTDATE,VERSIONNO,PERIODID,REGIONID,GENERGY,AENERGY,GPOWER,APOWER,NETENERGY,ENERGYCOST,EXCESSENERGYCOST,EXPENERGY,EXPENERGYCOST,LASTCHANGED
    D,SETTLEMENTS,GENDATAREGION,5,"2024/05/05 00:00:00",12,1,NSW1,,,,,598.70275,49322.81853,0,-3.611445,-296.584229,"2024/11/25 07:51:48"
    D,SETTLEMENTS,GENDATAREGION,5,"2024/05/05 00:00:00",12,1,QLD1,,,,,487.78355,37936.49344,0,-2.998403,-233.959604,"2024/11/25 07:51:48"
    D,SETTLEMENTS,GENDATAREGION,5,"2024/05/05 00:00:00",12,1,SA1,,,,,117.89164,10009.68483,0,-0.618345,-53.68201,"2024/11/25 07:51:48"
    D,SETTLEMENTS,GENDATAREGION,5,"2024/05/05 00:00:00",12,1,TAS1,,,,,100.04426,14679.75815,0,-0.872541,-123.063697,"2024/11/25 07:51:48"
    D,SETTLEMENTS,GENDATAREGION,5,"2024/05/05 00:00:00",12,1,VIC1,,,,,413.54728,34831.13902,0,-43.378173,-3691.528264,"2024/11/25 07:51:48"
    D,SETTLEMENTS,GENDATAREGION,5,"2024/05/05 00:00:00",12,2,NSW1,,,,,594.92834,78019.1356,0,-3.544855,-462.658031,"2024/11/25 07:51:48"
    D,SETTLEMENTS,GENDATAREGION,5,"2024/05/05 00:00:00",12,2,QLD1,,,,,491.61365,60482.12206,0,-2.974245,-367.095378,"2024/11/25 07:51:48"
    D,SETTLEMENTS,GENDATAREGION,5,"2024/05/05 00:00:00",12,2,SA1,,,,,116.46095,15787.4473,0,-0.70283,-97.116298,"2024/11/25 07:51:48"
    D,SETTLEMENTS,GENDATAREGION,5,"2024/05/05 00:00:00",12,2,TAS1,,,,,100.01615,14677.15634,0,-0.916187,-129.459984,"2024/11/25 07:51:48"
    D,SETTLEMENTS,GENDATAREGION,5,"2024/05/05 00:00:00",12,2,VIC1,,,,,412.27699,55129.32412,0,-43.604794,-5890.896609,"2024/11/25 07:51:48"
    D,SETTLEMENTS,GENDATAREGION,5,"2024/05/05 00:00:00",12,3,NSW1,,,,,590.406,76879.9715,0,-3.522257,-455.951553,"2024/11/25 07:51:48"
    ...
    C,"END OF REPORT",1003
    ```

## Availability

This table is in the public monthly [MMSDM archive](https://www.nemweb.com.au/Data_Archive/Wholesale_Electricity/MMSDM/).

I have collated the list of all those files for this table into one place, in [this CSV metadata file](../../manifests/per_table/csv/SETGENDATAREGION.csv). (Columns `year`, `month`, `url`, `compressed_size` in bytes).

    

The earliest available data is month 1 of 2015.
The most recent available data is month 12 of 2024.!!! warning Warning
    There are some months with no files.

## Data Size

    

Each year of data is approximately
13 MB when zipped,
131 MB as unzipped CSV.

        

    

## Deduplication and PDR Loader Configuration

The primary keys are:

- [`PERIODID`](#periodid)

- [`REGIONID`](#regionid)

- [`SETTLEMENTDATE`](#settlementdate)

- [`VERSIONNO`](#versionno)

The transaction type is ["insert"](https://di-help.docs.public.aemo.com.au/Content/pdrLoader/How_it_works.htm?TocPath=pdrLoader%7CAbout+pdrLoader%7C_____5#INSERT), which means that you will usually not see duplicate data.
If you do, you can deduplicate based on the primary keys, without sorting first.
Rows from different files with the same primary keys should have the same values.

[PDR Loader configuration](https://nemweb.com.au/Reports/Current/MMSDataModelReport/PDRCONFIG/PROD_PUBLIC_PDR_CONFIG_FULL.zip) is:

| Report Name | Report Subtype | Version |
|---------------|-------------------|-----------|
| SETTLEMENTS | GENDATAREGION  | 5 |

This means that the CSV files start with metadata columns:

```csv
I,SETTLEMENTS,GENDATAREGION,5,...
D,SETTLEMENTS,GENDATAREGION,5,...
```

## Indexes

- [`LASTCHANGED`](#lastchanged)

## Links

[This page as JSON](../json/tables/SETGENDATAREGION/bespoke.json) (schema documented [here](https://gitlab.com/MatthewDavis/mms-schema/-/blob/master/schema.py?ref_type=heads), but may change)

Download a [JSON Schema](../json/tables/SETGENDATAREGION/json-schema.json) specification for this table.

[Official AEMO schema documentation](https://nemweb.com.au/Reports/Current/MMSDataModelReport/Electricity/ElectricityDataModelReport_files/Elec65.htm#1082)

## Other Information

Package: [HISTORICAL TABLES](../packages/HISTORICAL TABLES.md)
