Skip to main content

DSL for creating NetCDF files

Project description

A DSL for creating NetCDF files. Here’s a simple example:

from pup import *

class Test(NetCDF):
    # NC_GLOBAL attributes go here
    history = 'Created for a test'

    # dimensions need to be set explicitly only when they
    # have no variable associated with them
    dim0 = Dimension(2)

    # variables that don't specify dimensions are assumed to
    # be their own dimension
    time = Variable(range(10), record=True, units='days since 2008-01-01')

    # now a variable with dimensions (time,)
    temperature = Variable(range(10), (time,), units='deg C')

Test.save('simple.nc')

This will produce the following NetCDF file:

netcdf simple {
dimensions:
    dim0 = 2 ;
    time = UNLIMITED ; // (10 currently)
variables:
    int time(time) ;
        time:units = "days since 2008-01-01" ;
    int temperature(time) ;
        temperature:units = "deg C" ;

// global attributes:
        :history = "Created for a test" ;
data:

 time = 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ;

 temperature = 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ;
}

Compare this with the code necessary to do the same using common NetCDF libraries:

f = netcdf_file("simple.nc", "w")

f.history = "Created for a test"

f.createDimension("dim0", 2)

f.createDimension("time", None)
time = f.createVariable("time", "i", ("time",))
time.units = "days since 2008-01-01"
time[:] = range(10)

temperature = f.createVariable("temperature", "i", ("time",))
temperature.units = "deg C"
temperature[:] = range(10)

By default it uses pupynere for creating files, but this can be overloaded; we can use the netCDF4 module, for example, which allows us to specify groups:

from netCDF4 import Dataset

class Test(NetCDF):
    loader = Dataset
    ...

    foo = Group(
        dim = Dimension(10),
        var = Variable(range(10)),
        ...
    )
Test.save('simple.nc', format='NETCDF4')

Changelog:

0.1.6:

Fix bug in dimension name.

0.1.5:

Added support for Groups when using netcdf4.

0.1.4:

Added support for masked arrays.

0.1.3:

Pass keyword arguments in save() to the loader.

0.1.2:

Improved optional loader detection.

0.1.1:

Added pupynere dependency.

0.1:

Initial release.

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

Puppy-0.1.6.tar.gz (3.2 kB view details)

Uploaded Source

Built Distribution

Puppy-0.1.6-py2.7.egg (4.7 kB view details)

Uploaded Source

File details

Details for the file Puppy-0.1.6.tar.gz.

File metadata

  • Download URL: Puppy-0.1.6.tar.gz
  • Upload date:
  • Size: 3.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for Puppy-0.1.6.tar.gz
Algorithm Hash digest
SHA256 b4c64e132bf7c31d48409687336ad7c18d637538a967604a41289fb1cc766dd9
MD5 affdac88313d9fcdaec8f8a592b10457
BLAKE2b-256 586599176bcde0a75c92e3fe0d999467b543136b0a0c6ad5fc3e4f74f372d418

See more details on using hashes here.

Provenance

File details

Details for the file Puppy-0.1.6-py2.7.egg.

File metadata

  • Download URL: Puppy-0.1.6-py2.7.egg
  • Upload date:
  • Size: 4.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for Puppy-0.1.6-py2.7.egg
Algorithm Hash digest
SHA256 0ebf4104a18422fffe034636726717e4002cd236cc85e7d848d20f126aa2207a
MD5 7b2b7ecebed70614e7a3f9376f92b4c3
BLAKE2b-256 623efaacab1bcdd4664cc4b76585f0e099c5445ec797f4730f8041884f28060f

See more details on using hashes here.

Provenance

Supported by

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