Skip to content

nc4 classic file can't be edited #144

@doutriaux1

Description

@doutriaux1
import cdms2
import cdat_info
import os

fnm = "sst_ice_DECK_1x1_c20170602.nc"
fnm = os.path.join(cdat_info.get_sampledata_path(),"clt.nc")
f=cdms2.open(fnm)
s=f("clt")
print "original shape",s.shape
f.close()
cdms2.setNetcdfDeflateFlag(0)
cdms2.setNetcdfDeflateLevelFlag(0)
cdms2.setNetcdfShuffleFlag(0)
cdms2.setNetcdf4Flag(1)
cdms2.setNetcdfClassicFlag(1)
f=cdms2.open("nc4.nc","w")
f.write(s)
f.close()

f=cdms2.open("nc4.nc","r+")
print "nc4 shape",f["clt"].shape
t=f["time"]
t[:]=t[:]*100.
f.close()

hangs for a while and dies.

A subsequemnt ncdump shows that it seems as if it is trying to extend the time dimension rather than altering the time dimensions

doutriaux1@crunchy:[Phillip]:[14460]> python edit.py
Traceback (most recent call last):
  File "edit.py", line 21, in <module>
    t[:]=t[:]*100.
  File "/export/doutriaux1/miniconda2/envs/2.10-nox/lib/python2.7/site-packages/cdms2/axis.py", line 2200, in __setslice__
    return self._obj_.setslice(*(low, high, numpy.ma.filled(value)))
ValueError: shapes are not aligned
doutriaux1@crunchy:[Phillip]:[14460]> ncdump -h nc4.nc 
netcdf nc4 {
dimensions:
	time = UNLIMITED ; // (2147483647 currently)
	latitude = 46 ;
	bound = 2 ;
	longitude = 72 ;
variables:
	double time(time) ;
		time:units = "months since 1979-1-1 0" ;
		time:calendar = "gregorian" ;
		time:axis = "T" ;
		time:realtopology = "linear" ;
	float latitude(latitude) ;
		latitude:bounds = "bounds_latitude" ;
		latitude:units = "degrees_north" ;
		latitude:long_name = "Latitude" ;
		latitude:axis = "Y" ;
		latitude:realtopology = "linear" ;
	double bounds_latitude(latitude, bound) ;
	float longitude(longitude) ;
		longitude:bounds = "bounds_longitude" ;
		longitude:modulo = 360. ;
		longitude:realtopology = "circular" ;
		longitude:long_name = "Longitude" ;
		longitude:units = "degrees_east" ;
		longitude:topology = "circular" ;
		longitude:axis = "X" ;
	double bounds_longitude(longitude, bound) ;
	float clt(time, latitude, longitude) ;
		clt:_FillValue = 1.e+20f ;
		clt:missing_value = 1.e+20f ;
		clt:time_statistic = "average" ;
		clt:comments = "YONU_AMIP1" ;
		clt:long_name = "Total cloudiness" ;
		clt:grid_name = "YONU4X5" ;
		clt:units = "%" ;
		clt:grid_type = "gaussian" ;

// global attributes:
		:Conventions = "CF-1.0" ;
}

Metadata

Metadata

Assignees

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions