NemReader: Reading NEM Meter Data with F#

- 2 mins read

I have published NemReader, an F#/.NET library for reading Australian electricity meter data. It is a port of nem-reader, the Python library by Alex Guinman. The parsing rules and example files come from that project.

NemReader reads AEMO NEM12 files, which contain interval data such as smart meter readings, and NEM13 files, which contain accumulated data such as readings from manually read meters.

Install

Version 0.1.0 is available on NuGet:

dotnet add package NemReader

The library targets netstandard2.0, so it works with .NET Framework 4.6.1 and later, and .NET 6, 8 and 10. Its only dependency is FSharp.Core 6.0.7.

Reading a file

NemFile.read returns a Result<NemData, NemError>. The data is immutable, and readings are nested by NMI and channel. This example uses an NMI and channel from one of the example files:

open System
open NemReader

let path = "NEM12.zip"

match NemFile.read path with
| Ok data ->
  for nmi in NemData.nmis data do
    let channels = String.concat ", " (NemData.channels nmi data)
    printfn $"{nmi} has channels {channels}"

  for reading in data.Readings["VABD000163"]["E1"] |> List.truncate 3 do
    printfn $"{reading.TStart} to {reading.TEnd}: {reading.ReadValue} {reading.Uom}"
| Error error ->
  printfn $"Could not read {path}: {NemError.describe error}"

NemFile.read accepts a CSV file or a zip archive containing a single entry. Parser warnings are collected in NemData.Warnings instead of being written to logs. The library also has a small built-in Frame type in place of polars, and there is a small CLI in the repository.

Tests and source

The tests use the original project’s example files. The result was 39 passed and 2 skipped, with the same two tests skipped in the original project.

The source is on GitHub. It is available under the MIT license, keeping Alex Guinman’s original copyright notice alongside my own.