Skip to main content

A library for SuperDARN DMAP file I/O

github

The SuperDARN DMAP file formats are all supported (IQDAT, RAWACF, FITACF, GRID, MAP, and SND) as well as a generic DMAP format that is unaware of any required fields or types (e.g. char, int32) for any fields. For more information on DMAP please see RST Documentation.

Installation

Package manager

This package is registered on PyPI as darn-dmap, you can install the package with your package manager, e.g. pip install darn-dmap.

From source

If you want to build from source, you first need to have Rust installed on your machine. Then:

  1. Clone the repository: git clone https://github.com/SuperDARNCanada/dmap
  2. Create a virtual environment and source it, then install maturin
  3. In the project directory, run maturin develop to build and install the Python bindings. This will make a wheel file based on your operating system and architecture that you can install directly on any compatible machine.

Usage

The basics

The basic code to read and write a DMAP file is:

import dmap

file = "path/to/rawacf_file"
data, _ = dmap.read_rawacf(file)  # returns `tuple[list[dict], Optional[int]]`
outfile = "path/to/outfile.rawacf"
dmap.write_rawacf(data, outfile)  # writes binary data to `outfile`
raw_bytes = dmap.write_rawacf(data)  # returns a `bytes` object

dmap.read_rawacf(...) reads the file into a list of dictionaries, returning the list as well as the byte where any corrupted records start.

The supported reading functions are:

  • read_iqdat,
  • read_rawacf,
  • read_fitacf,
  • read_grid,
  • read_map,
  • read_snd, and
  • read_dmap.

The supported writing functions are:

  • write_iqdat,
  • write_rawacf,
  • write_fitacf,
  • write_grid,
  • write_map,
  • write_snd, and
  • write_dmap.

Accessing data fields

To see the names of the variables you've loaded in and now have access to, try using the keys() method:

print(data[0].keys())

which will tell you all the variables in the first (zeroth) record.

Let's say you loaded in a MAP file, and wanted to grab the cross polar-cap potentials for each record:

import dmap
file = "20150302.n.map"
map_data, _ = dmap.read_map(file)

cpcps=[rec['pot.drop'] for rec in map_data]

I/O on a bz2 compressed file

dmap will handle compressing and decompressing .bz2 files seamlessly, detecting the compression automatically. E.g.

import dmap
fitacf_file = "path/to/file.bz2"
data, _ = dmap.read_fitacf(fitacf_file)
dmap.write_fitacf(data, "temp.fitacf.bz2")

will read in the compressed file, then also write out a new compressed file. You can also pass the argument bz2=True to compress with bzip2 regardless of file extension, or even to return compressed byte objects.

Generic I/O

dmap supports generic DMAP I/O, without verifying the field names and types. The file must still be properly formatted as a DMAP file, but otherwise no checks are conducted.

NOTE: When using the generic writing function write_dmap, scalar fields will possibly be resized; e.g., the stid field may be stored as an 8-bit integer, as opposed to a 16-bit integer as usual. As such, reading with a specific method (e.g. read_fitacf) on a file written using write_dmap will likely not pass the FITACF format checks.

import dmap
generic_file = "path/to/file"  # can be iqdat, rawacf, fitacf, grid, map, snd, and optionally .bz2 compressed
data, _ = dmap.read_dmap(generic_file)
dmap.write_dmap(data, "temp.generic.fitacf")  # fitacf as an example
data2, bad_byte = dmap.read_rawacf("temp.generic.fitacf")  # This will fail due to different types for scalar fields
assert bad_byte == 0  # The first record should be corrupted, i.e. not be a valid FITACF record
assert len(data2) == 0  # No valid records encountered

Handling corrupted data files

The self-describing data format of DMAP files makes it susceptible to corruption. The metadata fields which describe how to interpret the following bytes are very important, and so any corruption will lead to the remainder of the file being effectively useless. dmap is able to handle corruption in two ways. The keyword argument mode of the read_rawacf, etc. functions allows you to choose how to handle corrupt records.

In "lax" mode (the default), no error is raised if a corrupt file is read, and the byte where the corrupted records start is returned along with the non-corrupted records. In "strict" mode, the I/O functions will raise an error if a corrupted record is encountered.

import dmap

corrupted_file = "path/to/file"
data, bad_byte = dmap.read_dmap(corrupted_file, mode="lax")
assert bad_byte > 0

good_file = "path/to/file"
data, bad_byte = dmap.read_dmap(good_file, mode="lax")
assert bad_byte is None

In both uses of the above example, data will be a list of all records extracted from the file, but may be considerably smaller than the file.

import dmap

corrupted_file = "path/to/file"
try:
    data = dmap.read_dmap(corrupted_file, mode="strict")
    had_error = False
except:
    had_error = True
assert had_error

good_file = "path/to/file"
try:
    data = dmap.read_dmap(good_file, mode="strict")
    had_error = False
except:
    had_error = True
assert had_error is False

Stream I/O

dmap also can conduct read/write operations from/to Python bytes objects directly. These bytes must be formatted in accordance with the DMAP format. Simply pass in a bytes object to any of the read_[type] functions instead of a path and the input will be parsed.

While not the recommended way to read data from a DMAP file, the following example shows the use of these byte I/O functions:

import dmap
file = "path/to/file.fitacf"
with open(file, 'rb') as f:  # 'rb' specifies to open the binary (b) file as read-only (r)
    raw_bytes = f.read()  # reads the file in its entirety
data, _ = dmap.read_dmap(raw_bytes)
binary_data = dmap.write_fitacf(data)
assert binary_data == raw_bytes

As a note, this binary data can be compressed ~2x typically using zlib, or with another compression utility. This is quite useful if sending data over a network where speed and bandwidth must be considered. Note that the binary writing functions can compress with bzip2 by passing bz2=True as an argument.

File "sniffing"

If you only want to inspect a file, without actually needing access to all the data, you can use the read_[type] functions in with the optional indices argument. This will only read in the specified records from a file, and works in all modes.

import dmap
path = "path/to/file"
recs = dmap.read_dmap(path, mode="...", indices=[0, 1, -2, -1])

Reading only metadata fields

Each DMAP format consists of metadata and data fields. You can read only the metadata fields by passing mode="metadata" to any of the writing functions. Note that the generic read function read_dmap will return all fields, as it by nature has no knowledge of the underlying fields. Note also that the read functions operating on a file still read the entire file into memory first, so reading metadata only may not significantly decrease read times. Also, bzipped files are fully decompressed before reading begins, so again read times may not be significantly quicker in this mode under certain circumstances.

Metadata

Release files for darn-dmap 0.8.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for darn-dmap 0.8.2
File Size Uploaded
darn_dmap-0.8.2.tar.gz 44.2 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for darn-dmap 0.8.2
File
darn_dmap-0.8.2-cp38-abi3-win_amd64.whl CPython 3.8 abi3 Windows x86-64 Details
darn_dmap-0.8.2-cp38-abi3-win32.whl CPython 3.8 abi3 Windows x86-32 Details
darn_dmap-0.8.2-cp38-abi3-musllinux_1_2_x86_64.whl CPython 3.8 abi3 Linux musl 1.2+ x86-64 Details
darn_dmap-0.8.2-cp38-abi3-musllinux_1_2_i686.whl CPython 3.8 abi3 Linux musl 1.2+ x86-32 Details
darn_dmap-0.8.2-cp38-abi3-musllinux_1_2_armv7l.whl CPython 3.8 abi3 Linux musl 1.2+ ARMv7l Details
darn_dmap-0.8.2-cp38-abi3-musllinux_1_2_aarch64.whl CPython 3.8 abi3 Linux musl 1.2+ ARM64 Details
darn_dmap-0.8.2-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.8 abi3 Linux glibc 2.17+ x86-64 Details
darn_dmap-0.8.2-cp38-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl CPython 3.8 abi3 Linux glibc 2.17+ IBM System/390x Details
darn_dmap-0.8.2-cp38-abi3-manylinux_2_17_i686.manylinux2014_i686.whl CPython 3.8 abi3 Linux glibc 2.17+ x86-32 Details
darn_dmap-0.8.2-cp38-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl CPython 3.8 abi3 Linux glibc 2.17+ ARMv7l Details
darn_dmap-0.8.2-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl CPython 3.8 abi3 Linux glibc 2.17+ ARM64 Details
darn_dmap-0.8.2-cp38-abi3-macosx_11_0_arm64.whl CPython 3.8 abi3 macOS 11.0+ ARM64 Details
darn_dmap-0.8.2-cp38-abi3-macosx_10_12_x86_64.whl CPython 3.8 abi3 macOS 10.12+ x86-64 Details

Total release size: 9.1 MB

Release files / darn_dmap-0.8.2.tar.gz

Download URL darn_dmap-0.8.2.tar.gz
Size 44.2 kB
Tags Source
SHA-256 checksum
How to use checksums
81a4de285ed68eb480d24bfb8536169b2906249cc22a25d3e597cc99a59c2604
BLAKE2b-256 checksum
How to use checksums
c02ffdbd867e6dd24f43323eda8bb9c9974a53ffeee8e2c8263fcb523d3f2650
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.14.1

Release files / darn_dmap-0.8.2-cp38-abi3-win_amd64.whl

Download URL darn_dmap-0.8.2-cp38-abi3-win_amd64.whl
Size 566.5 kB
Tags CPython 3.8 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
c66af6edabbffe45a015f40afd178e00623745ee9df5a7c9b95e765a6c35c70d
BLAKE2b-256 checksum
How to use checksums
e9c3dfea9e54249630765e55bc38b8e4e7c1bf3fe85ddc49122a53a631487934
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.14.1

Release files / darn_dmap-0.8.2-cp38-abi3-win32.whl

Download URL darn_dmap-0.8.2-cp38-abi3-win32.whl
Size 515.2 kB
Tags CPython 3.8 Windows x86-32 abi3
SHA-256 checksum
How to use checksums
f2bf39ccb94494785812ae919ad17cb8bc31696656544587d5cf4d54347cb206
BLAKE2b-256 checksum
How to use checksums
e42890907d066062da19e476331fd451168455f66910385f197957ac01ddc68f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.14.1

Release files / darn_dmap-0.8.2-cp38-abi3-musllinux_1_2_x86_64.whl

Download URL darn_dmap-0.8.2-cp38-abi3-musllinux_1_2_x86_64.whl
Size 873.1 kB
Tags CPython 3.8 Linux musl 1.2+ x86-64 abi3
SHA-256 checksum
How to use checksums
03ff3e5ee7835a0064dafc8cfbcddd20f5dea5560e29724c8854aa7da3414e59
BLAKE2b-256 checksum
How to use checksums
88dde8bc8637254953a08b8bb8b9f8445f9ac18550b9c4d6fcd2f73c70ade681
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.14.1

Release files / darn_dmap-0.8.2-cp38-abi3-musllinux_1_2_i686.whl

Download URL darn_dmap-0.8.2-cp38-abi3-musllinux_1_2_i686.whl
Size 909.7 kB
Tags CPython 3.8 Linux musl 1.2+ x86-32 abi3
SHA-256 checksum
How to use checksums
b90bc0427ca91257f4a33d46a0deb6c8e56854eacba644369c1845e7ecd59874
BLAKE2b-256 checksum
How to use checksums
30c90ff80ba7b1d3d06a9ef2daa58b4ff0b5183deceba66b50d98bc241378be5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.14.1

Release files / darn_dmap-0.8.2-cp38-abi3-musllinux_1_2_armv7l.whl

Download URL darn_dmap-0.8.2-cp38-abi3-musllinux_1_2_armv7l.whl
Size 893.5 kB
Tags CPython 3.8 Linux musl 1.2+ ARMv7l abi3
SHA-256 checksum
How to use checksums
337291787d010358f88e98ad07f3ce584d82055d96ab829691510af3fd669b2b
BLAKE2b-256 checksum
How to use checksums
e2ef35f4abfa4ed6a7ffc172f4fb97b55c30dd01fcf368cea6153ba66501ad4b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.14.1

Release files / darn_dmap-0.8.2-cp38-abi3-musllinux_1_2_aarch64.whl

Download URL darn_dmap-0.8.2-cp38-abi3-musllinux_1_2_aarch64.whl
Size 799.4 kB
Tags CPython 3.8 Linux musl 1.2+ ARM64 abi3
SHA-256 checksum
How to use checksums
f3a79cbea46065fd7d53642d23a75fd4bf1f3082dfa4a6229a7ead01efc73c39
BLAKE2b-256 checksum
How to use checksums
6d7460215682aad0d0a421ce2205f5db2aa79d24d7600b23e81bdaba184378c9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.14.1

Release files / darn_dmap-0.8.2-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL darn_dmap-0.8.2-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 674.5 kB
Tags CPython 3.8 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
409998776b99f63ddcc3ffae946c8fb1a996e7b86e17e548b27dcc9205a6ae23
BLAKE2b-256 checksum
How to use checksums
ab041c5b7068823898043bb15ebc10ca5211df889d2665b5e1feb48c4fa3e78f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.14.1

Release files / darn_dmap-0.8.2-cp38-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl

Download URL darn_dmap-0.8.2-cp38-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl
Size 669.5 kB
Tags CPython 3.8 Linux glibc 2.17+ IBM System/390x abi3
SHA-256 checksum
How to use checksums
b6e998fe003ace5665b093b606630850362fdf2c7dd760a27f40db5d245a40ab
BLAKE2b-256 checksum
How to use checksums
33bad2381c9238af84e4d4bbeb121db57ef300c0524e4df7fc183a6f0a3bc372
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.14.1

Release files / darn_dmap-0.8.2-cp38-abi3-manylinux_2_17_i686.manylinux2014_i686.whl

Download URL darn_dmap-0.8.2-cp38-abi3-manylinux_2_17_i686.manylinux2014_i686.whl
Size 736.8 kB
Tags CPython 3.8 Linux glibc 2.17+ x86-32 abi3
SHA-256 checksum
How to use checksums
0d40f03662c6d43c95debd05f1d3bbb8ccfcdbd1e8370364cec13b2de0d601d2
BLAKE2b-256 checksum
How to use checksums
dfafa182afe8028a920c0f79cce9b04c45f06278c66d3502f5851766b23b8e12
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.14.1

Release files / darn_dmap-0.8.2-cp38-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl

Download URL darn_dmap-0.8.2-cp38-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
Size 617.5 kB
Tags CPython 3.8 Linux glibc 2.17+ ARMv7l abi3
SHA-256 checksum
How to use checksums
3074af16b5dc958ec2b32efaaa5b9a53065ac47bc0f3ecc2e09c23baa1884d33
BLAKE2b-256 checksum
How to use checksums
7920f05199704a394e9131015cedde9958da37797b7e63ce763f963ba0d5798c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.14.1

Release files / darn_dmap-0.8.2-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL darn_dmap-0.8.2-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 634.6 kB
Tags CPython 3.8 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
32382e4874b46a8935750a4332642e72f530af2ef5ebf21158274cc94a3e7a9c
BLAKE2b-256 checksum
How to use checksums
d4696a9aa4ae5ce0fd5775781ed5b8c3b549bd135bb1a19a4273a3b3e8b55b2f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.14.1

Release files / darn_dmap-0.8.2-cp38-abi3-macosx_11_0_arm64.whl

Download URL darn_dmap-0.8.2-cp38-abi3-macosx_11_0_arm64.whl
Size 570.3 kB
Tags CPython 3.8 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
523a10f522cd9710db759dc21c481b739f2ca98a42a3dc3cb629e6d744853c79
BLAKE2b-256 checksum
How to use checksums
3937420e4613292ea5746fb68f0be79c46677b6348d584d07d5a426fd8c46b9d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.14.1

Release files / darn_dmap-0.8.2-cp38-abi3-macosx_10_12_x86_64.whl

Download URL darn_dmap-0.8.2-cp38-abi3-macosx_10_12_x86_64.whl
Size 595.3 kB
Tags CPython 3.8 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
49983460ed6a6bb5cc0131fedcf7b22f8c40bf48167539e22895cfca13ab82e9
BLAKE2b-256 checksum
How to use checksums
cf69d8b66d6cdc7342449f3cef240b3ec20dd97d14cde8d4d0236be70236bf54
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.14.1

Release history Release notifications | RSS feed

This release

0.8.2 This release

14 release files

0.7.0

16 release files

0.4.0

14 release files

0.3.0

14 release files

0.1.6

13 release files

0.1.4

14 release files

0.1.3

14 release files

0.1.1

17 release files

0.1.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page