MCPcopy Index your code
hub / github.com/aguinane/nem-reader

github.com/aguinane/nem-reader @v1.0.0

Chat with this repo
repository ↗ · DeepWiki ↗ · release v1.0.0 ↗ · + Follow
100 symbols 407 edges 24 files 66 documented · 66%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

nem-reader

PyPI version PyPi downloads

The Australian Energy Market Operator (AEMO) defines a Meter Data File Format (MDFF) for reading energy billing data. When you request energy data from your distribution utility or retailer, this is probably the format it will come in.

  • NEM12 for interval data (smart meters)
  • NEM13 for accumilation data (old style meters)

Whilst it is a pretty clever file format for sharing this data efficiently - it's not very helpful if you want to just chart it in excel. This library sets out to parse these data files into either a CSV (Excel) file or Python dataframe.

The File Format and Meter Channels

To understand the actual file format, you'll want to read the MDFF spec and the National Metering Identifier Procedure (NMIP). AEMO also publish a bunch of example files such as these NEM12 examples.

The most important thing to know is that the terms export/import are referenced from the grid and not relative to the customer. So when it talks about export channels it means importing power from the grid and not solar exports.

So for most residential customers: - E1 is the general consumption channel (11 for NEM13). - E2 is the controlled load channel - B1 is the export (Solar PV) channel

Export to CSV

You can quickly output the NEM file in a more human readable format using the command line:

nemreader output-csv "examples/nem12/nem12#S01#INTEGM#NEMMCO.zip"

Which outputs transposed values to a csv file for all channels:

t_start t_end quality evt_code evt_desc Q1 E1
2004-02-01 00:00:00 2004-02-01 00:30:00 A 2.222 1.111
2004-02-01 00:30:00 2004-02-01 01:00:00 A 2.222 1.111

Export to DataFrame

You can return the data as a polars dataframe.

from nemreader import NEMFile
m = NEMFile('examples/unzipped/Example_NEM12_actual_interval.csv')
df = m.get_data_frame_long()
print(df)
           nmi suffix      serno             t_start               t_end  value quality evt_code evt_desc
0   VABD000163     E1  METSER123 2004-02-01 00:00:00 2004-02-01 00:30:00  1.111       A                  
1   VABD000163     E1  METSER123 2004-02-01 00:30:00 2004-02-01 01:00:00  1.111       A                  
2   VABD000163     E1  METSER123 2004-02-01 01:00:00 2004-02-01 01:30:00  1.111       A                  
3   VABD000163     E1  METSER123 2004-02-01 01:30:00 2004-02-01 02:00:00  1.111       A                  
4   VABD000163     E1  METSER123 2004-02-01 02:00:00 2004-02-01 02:30:00  1.111       A                  
..         ...    ...        ...                 ...                 ...    ...     ...      ...      ...
43  VABD000163     Q1  METSER123 2004-02-01 21:30:00 2004-02-01 22:00:00  2.222       A                  
44  VABD000163     Q1  METSER123 2004-02-01 22:00:00 2004-02-01 22:30:00  2.222       A                  
45  VABD000163     Q1  METSER123 2004-02-01 22:30:00 2004-02-01 23:00:00  2.222       A                  
46  VABD000163     Q1  METSER123 2004-02-01 23:00:00 2004-02-01 23:30:00  2.222       A                  
47  VABD000163     Q1  METSER123 2004-02-01 23:30:00 2004-02-02 00:00:00  2.222       A      

Depending on the use case, the wide form of the dataframe might be preferred over the long form. This is the form used when exporting to CSV using the command line. It will group up the various channels and match them by timestamp.

df = m.get_data_frame_wide()
print(df)
               nmi             t_start               t_end quality evt_code evt_desc     E1     Q1
0       VABD000163 2004-02-01 00:00:00 2004-02-01 00:30:00       A                    1.111  2.222
1       VABD000163 2004-02-01 00:30:00 2004-02-01 01:00:00       A                    1.111  2.222
2       VABD000163 2004-02-01 01:00:00 2004-02-01 01:30:00       A                    1.111  2.222
3       VABD000163 2004-02-01 01:30:00 2004-02-01 02:00:00       A                    1.111  2.222
4       VABD000163 2004-02-01 02:00:00 2004-02-01 02:30:00       A                    1.111  2.222
5       VABD000163 2004-02-01 02:30:00 2004-02-01 03:00:00       A                    1.111  2.222
6       VABD000163 2004-02-01 03:00:00 2004-02-01 03:30:00       A                    1.111  2.222
7       VABD000163 2004-02-01 03:30:00 2004-02-01 04:00:00       A                    1.111  2.222
8       VABD000163 2004-02-01 04:00:00 2004-02-01 04:30:00       A                    1.111  2.222

Core symbols most depended-on inside this repo

nem_data
called by 28
nemreader/nem_reader.py
get_data_frame_wide
called by 10
nemreader/nem_reader.py
parse_datetime
called by 9
nemreader/nem_reader.py
output_as_data_frames
called by 5
nemreader/outputs.py
nth
called by 4
nemreader/nem_reader.py
get_data_frame_long
called by 3
nemreader/nem_reader.py
split_multiday_reads
called by 2
nemreader/split_days.py
parse_nem_file
called by 2
nemreader/nem_reader.py

Shape

Function 75
Class 13
Method 12

Languages

Python100%

Modules by API surface

nemreader/nem_reader.py27 symbols
nemreader/nem_objects.py15 symbols
tests/test_incomplete_files.py8 symbols
tests/test_file_outputs.py6 symbols
nemreader/outputs.py6 symbols
tests/test_cli.py5 symbols
nemreader/split_days.py5 symbols
nemreader/cli.py5 symbols
tests/test_open_examples.py4 symbols
tests/test_invalid_interval_mixing.py4 symbols
tests/test_actual_interval.py3 symbols
tests/test_multiple_quality.py2 symbols

For agents

$ claude mcp add nem-reader \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page