用于创建netcdf文件的dsl
Pupp的Python项目详细描述
用于创建netcdf文件的dsl。下面是一个简单的示例:
frompupimport*classTest(NetCDF):# NC_GLOBAL attributes go herehistory='Created for a test'# dimensions need to be set explicitly only when they# have no variable associated with themdim0=Dimension(2)# variables that don't specify dimensions are assumed to# be their own dimensiontime=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')
这将生成以下netcdf文件:
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 ; }
将其与使用公共netcdf执行相同操作所需的代码进行比较 库:
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)
默认情况下,它使用pupyere创建文件,但这可能会被重载;我们 例如,可以使用netcdf4模块,它允许我们指定组:
fromnetCDF4importDatasetclassTest(NetCDF):loader=Dataset...foo=Group(dim=Dimension(10),var=Variable(range(10)),...)Test.save('simple.nc',format='NETCDF4')
更改日志:
0.1.8: | Ensure record dimensions are created first. |
---|---|
0.1.7: | Convert strings to array of chars. |
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. |