Skip to main content

SuperDARN DMAP file format I/O

Project description

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 "sniff" mode. This will only read in the first record from a file, and works on both compressed and non-compressed files. Note that this mode does not work with bytes objects directly.

import dmap
path = "path/to/file"
first_rec = dmap.read_dmap(path, mode="sniff")

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 does not largely decrease read times.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

darn_dmap-0.7.0.tar.gz (41.6 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

darn_dmap-0.7.0-pp310-pypy310_pp73-manylinux_2_17_s390x.manylinux2014_s390x.whl (692.1 kB view details)

Uploaded PyPymanylinux: glibc 2.17+ s390x

darn_dmap-0.7.0-pp39-pypy39_pp73-manylinux_2_17_s390x.manylinux2014_s390x.whl (696.0 kB view details)

Uploaded PyPymanylinux: glibc 2.17+ s390x

darn_dmap-0.7.0-cp38-abi3-win_amd64.whl (600.5 kB view details)

Uploaded CPython 3.8+Windows x86-64

darn_dmap-0.7.0-cp38-abi3-win32.whl (540.4 kB view details)

Uploaded CPython 3.8+Windows x86

darn_dmap-0.7.0-cp38-abi3-musllinux_1_2_x86_64.whl (896.4 kB view details)

Uploaded CPython 3.8+musllinux: musl 1.2+ x86-64

darn_dmap-0.7.0-cp38-abi3-musllinux_1_2_i686.whl (930.8 kB view details)

Uploaded CPython 3.8+musllinux: musl 1.2+ i686

darn_dmap-0.7.0-cp38-abi3-musllinux_1_2_armv7l.whl (915.2 kB view details)

Uploaded CPython 3.8+musllinux: musl 1.2+ ARMv7l

darn_dmap-0.7.0-cp38-abi3-musllinux_1_2_aarch64.whl (817.5 kB view details)

Uploaded CPython 3.8+musllinux: musl 1.2+ ARM64

darn_dmap-0.7.0-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (710.8 kB view details)

Uploaded CPython 3.8+manylinux: glibc 2.17+ x86-64

darn_dmap-0.7.0-cp38-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl (695.7 kB view details)

Uploaded CPython 3.8+manylinux: glibc 2.17+ s390x

darn_dmap-0.7.0-cp38-abi3-manylinux_2_17_i686.manylinux2014_i686.whl (759.5 kB view details)

Uploaded CPython 3.8+manylinux: glibc 2.17+ i686

darn_dmap-0.7.0-cp38-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (648.8 kB view details)

Uploaded CPython 3.8+manylinux: glibc 2.17+ ARMv7l

darn_dmap-0.7.0-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (659.0 kB view details)

Uploaded CPython 3.8+manylinux: glibc 2.17+ ARM64

darn_dmap-0.7.0-cp38-abi3-macosx_11_0_arm64.whl (590.3 kB view details)

Uploaded CPython 3.8+macOS 11.0+ ARM64

darn_dmap-0.7.0-cp38-abi3-macosx_10_12_x86_64.whl (627.3 kB view details)

Uploaded CPython 3.8+macOS 10.12+ x86-64

File details

Details for the file darn_dmap-0.7.0.tar.gz.

File metadata

  • Download URL: darn_dmap-0.7.0.tar.gz
  • Upload date:
  • Size: 41.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/1.11.5

File hashes

Hashes for darn_dmap-0.7.0.tar.gz
Algorithm Hash digest
SHA256 10efc5896a11b25889e971d700daa58c4695572d204d47b4ff9799899013941c
MD5 d20dce32c1cc24b1c77d3d0e9da15a38
BLAKE2b-256 e0e3438d350a529c5f22a317bf9c559e1ce5c7b18a39330095ca1437645d65eb

See more details on using hashes here.

File details

Details for the file darn_dmap-0.7.0-pp310-pypy310_pp73-manylinux_2_17_s390x.manylinux2014_s390x.whl.

File metadata

File hashes

Hashes for darn_dmap-0.7.0-pp310-pypy310_pp73-manylinux_2_17_s390x.manylinux2014_s390x.whl
Algorithm Hash digest
SHA256 0aa6108f6821a876ce028f842179bd10b9b3578fce30cda9cd0c976e4b415d10
MD5 aa69c3a71f2383b16d441284d66a3372
BLAKE2b-256 83202e164d92a877b8df05efb0bf3b1188a3ea9192410ff10c558f9ed5db642b

See more details on using hashes here.

File details

Details for the file darn_dmap-0.7.0-pp39-pypy39_pp73-manylinux_2_17_s390x.manylinux2014_s390x.whl.

File metadata

File hashes

Hashes for darn_dmap-0.7.0-pp39-pypy39_pp73-manylinux_2_17_s390x.manylinux2014_s390x.whl
Algorithm Hash digest
SHA256 5e6a123058ee0eed0cbe86af52c86431eb6800c5f602fd49d9ba9c9cc5141c50
MD5 5b0f7d19da191f54ede6e171b670315d
BLAKE2b-256 f48192c9f1dfd016e0a620b5deb21860d23d7d61d097f9e67a4abe91c6ed8079

See more details on using hashes here.

File details

Details for the file darn_dmap-0.7.0-cp38-abi3-win_amd64.whl.

File metadata

  • Download URL: darn_dmap-0.7.0-cp38-abi3-win_amd64.whl
  • Upload date:
  • Size: 600.5 kB
  • Tags: CPython 3.8+, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/1.11.5

File hashes

Hashes for darn_dmap-0.7.0-cp38-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 c1ed454153219d331cc689f819fa4b500e04a4bdc678b59a63768b5d46a11dd0
MD5 b414c4868e8aa009064fe64cdbc6ea77
BLAKE2b-256 53f66f912e33c1d4f4b66dc1e6ef38cd07df4d0ffbaebe1b484692ceff4944d8

See more details on using hashes here.

File details

Details for the file darn_dmap-0.7.0-cp38-abi3-win32.whl.

File metadata

  • Download URL: darn_dmap-0.7.0-cp38-abi3-win32.whl
  • Upload date:
  • Size: 540.4 kB
  • Tags: CPython 3.8+, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/1.11.5

File hashes

Hashes for darn_dmap-0.7.0-cp38-abi3-win32.whl
Algorithm Hash digest
SHA256 6fe28587c2d2a930023c77ba4cf8a862c8a6a1c8f16999df096ec59f342dc00e
MD5 ef8e7d9b5b118101e584c50fa99db421
BLAKE2b-256 31e5617cc3461425ae091abc0283fa730d05f839e4f355357930e979daeb8105

See more details on using hashes here.

File details

Details for the file darn_dmap-0.7.0-cp38-abi3-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for darn_dmap-0.7.0-cp38-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 7a4798716589fc2706207b9c432db45344c33a0b40ec94a479d2a0cb8aaeb648
MD5 27e6f12465ddc5fdad29be529f76069d
BLAKE2b-256 a220a8cee02ddb13998adb5b62fec9a760c869608e1e280ccee1c52986f677f9

See more details on using hashes here.

File details

Details for the file darn_dmap-0.7.0-cp38-abi3-musllinux_1_2_i686.whl.

File metadata

File hashes

Hashes for darn_dmap-0.7.0-cp38-abi3-musllinux_1_2_i686.whl
Algorithm Hash digest
SHA256 e60a20e5b63f24015f3029434d2d33c13f2b6b313cace8a24a3952c59607e645
MD5 a1f138ff553fbf6a314cb9bd4f13872d
BLAKE2b-256 5e80d3275fa1278ca5876222d29fa75d5d8594e511782e481dbded6bf84b113c

See more details on using hashes here.

File details

Details for the file darn_dmap-0.7.0-cp38-abi3-musllinux_1_2_armv7l.whl.

File metadata

File hashes

Hashes for darn_dmap-0.7.0-cp38-abi3-musllinux_1_2_armv7l.whl
Algorithm Hash digest
SHA256 0224411fc5cd7b0b412782406eb580a8b8706fbd62a84b1cf0df3d55713ea06b
MD5 c65646f1fdc42738a8e6dd2deeefe38f
BLAKE2b-256 d3d9dc782250a144f63e2615e4e47c0b50420ca30058b0358de86b522d4ebe89

See more details on using hashes here.

File details

Details for the file darn_dmap-0.7.0-cp38-abi3-musllinux_1_2_aarch64.whl.

File metadata

File hashes

Hashes for darn_dmap-0.7.0-cp38-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 68ece3ab3278e03ee6dd03fb3f7688031a945d927506e55144ba314f9cc1cb2e
MD5 b5209c48e633b7135b4a41b520e5df47
BLAKE2b-256 c25cd97db6cf88157a28aa6b9cda49c111f1b2f0f4a322e0f3463c06305b160c

See more details on using hashes here.

File details

Details for the file darn_dmap-0.7.0-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for darn_dmap-0.7.0-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 47c24aaaa210a398b19a4eeea9014f13778b961552f5056be301b56c24422646
MD5 3bef28ce057a03ee9ed3ec1032138121
BLAKE2b-256 44173d13ac691d3026133bf9b2bb2a4dc56031b42c942e5b79fe9eeaeab710b5

See more details on using hashes here.

File details

Details for the file darn_dmap-0.7.0-cp38-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl.

File metadata

File hashes

Hashes for darn_dmap-0.7.0-cp38-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl
Algorithm Hash digest
SHA256 93bced1303fa2c909a4d9a0298a537b00ced5abe519d603e830b2dd1ba345982
MD5 7fa5e922d996174c7f686b8daf463878
BLAKE2b-256 50a5dffe4cf3c8ef290e67b011e83dad4e2145ae22dd4f4edc13d77defc6cf67

See more details on using hashes here.

File details

Details for the file darn_dmap-0.7.0-cp38-abi3-manylinux_2_17_i686.manylinux2014_i686.whl.

File metadata

File hashes

Hashes for darn_dmap-0.7.0-cp38-abi3-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 b9bf4da73d7ee7d444a17d4c849923ab32444f6daf3c2732a7e75464006c1a27
MD5 d5d205e8ca2340645b92b843e31e10f8
BLAKE2b-256 9e488c21fc5a1394d80d161f2dfb1ee6cce72f05b6b0d5792dfdc2418e9f887f

See more details on using hashes here.

File details

Details for the file darn_dmap-0.7.0-cp38-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl.

File metadata

File hashes

Hashes for darn_dmap-0.7.0-cp38-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
Algorithm Hash digest
SHA256 d3259738964421a9869f06558194b725a10eb2925af1de2efc1ee27d7b1e0f99
MD5 7404ddff7365d6f6bd7d170ebbfd1167
BLAKE2b-256 27ce93f66b2eb2716ef58c93dd6f679b4f73700aac3669853a1a393928b9bde7

See more details on using hashes here.

File details

Details for the file darn_dmap-0.7.0-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for darn_dmap-0.7.0-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 bb6b80d76110f727f7fcb0a21f934e0dcfb9ab4fbb34fd0ddb3d92d1cc6cdb49
MD5 3c0d64feb586731acf603a1b00346840
BLAKE2b-256 16c7d07df0b3d498eb8057b218fe0af6b73494765d40e10e115aed7a34dabe63

See more details on using hashes here.

File details

Details for the file darn_dmap-0.7.0-cp38-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for darn_dmap-0.7.0-cp38-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 688a5c6b2b3ec6aeefb49ecb6ae4a6198097196aeaf69adcfa91c27453d36173
MD5 e7ccd99fd042e54b5781174a361e42d2
BLAKE2b-256 d5855f33f35f28ceb605ef14d2d158671f79f0775e058ab82182cae2702a49fd

See more details on using hashes here.

File details

Details for the file darn_dmap-0.7.0-cp38-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for darn_dmap-0.7.0-cp38-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 079a1250c03f21f01bafcf22cfb5465bd6caa8a4e5b19704293955365a9352a0
MD5 dbd2bf1fe1c740849ed7661b80f1befb
BLAKE2b-256 3adb01b59469346d8a5057b55ffa1b5ea7d4567bad48c0d66936961ea0dfa5a0

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page