Dear Dr. Christopher,<div><br></div><div>It is great command-line utility for packing .nc file. It was of great help for me...</div><div><br></div><div>Thank you sir,</div><div><br></div><div>Sincerely,</div><div>Kishore<br>
<br><div class="gmail_quote">On Sat, Jul 14, 2012 at 11:43 PM, Lynnes, Christopher S. (GSFC-6102) <span dir="ltr"><<a href="mailto:christopher.s.lynnes@nasa.gov" target="_blank">christopher.s.lynnes@nasa.gov</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">The nco package (<a href="http://nco.sourceforge.net/" target="_blank">http://nco.sourceforge.net/</a>) has a command-line utility called ncpdq that can pack netcdf data.<br>
<div><div class="h5"><br>
On Jul 14, 2012, at 11:17 AM, Reto Stauffer wrote:<br>
<br>
><br>
> Hy Kishore<br>
><br>
> I was working on that today for about 5 hours using Python.<br>
> I can say some words to the python procedure but it is nearly the same<br>
> in all other packages i guess.<br>
><br>
> # - Open new netCdf file<br>
> ncf = pupynere.NetCDFFile(outfile+".nc",'w')<br>
><br>
> # - Then you have to define the dimensions.<br>
> # If you have e.g. some surface data and only<br>
> # one timestep you need just "longitude" and "latitude"<br>
> # but there is the option to store 3-D or 4-D fields<br>
> # with additional time and vertical coordinate.<br>
> # I am creating all 4 dimensions.<br>
> londim = ncf.createDimension('longitude',longitude.shape[0]);<br>
> latdim = ncf.createDimension('latitude',latitude.shape[0]);<br>
> levdim = ncf.createDimension('levelist',len(unique_levels));<br>
> timedim = ncf.createDimension('time',len(unique_times));<br>
><br>
> # - Then store the dimension variables into the created<br>
> # Dimensions (e.g. level vector or longitude vector)<br>
> # and setting some additional attributes.<br>
> # - IMPORTANT there is no default unit for time and<br>
> # for model level. You have to define it (hPa in my case)<br>
> # - Longitude vector<br>
> nclon = ncf.createVariable('longitude','f',('longitude',))<br>
> setattr(nclon,'long_name','longitude')<br>
> setattr(nclon,'units','degrees_east')<br>
> # - Latitude vector<br>
> nclat = ncf.createVariable('latitude','f',('latitude',))<br>
> setattr(nclat,'long_name','latitude')<br>
> setattr(nclat,'units','degrees_north')<br>
> # - Level vector<br>
> nclev = ncf.createVariable('levelist','f',('levelist',))<br>
> setattr(nclev,'long_name','model_level_number')<br>
> setattr(nclev,'units','hPa')<br>
> # - Time.<br>
> nctime = ncf.createVariable('time','f',('time',))<br>
> setattr(nctime,'long_name','time')<br>
> # - Setting those variables<br>
> print "* Write long, lat, levelist and time to nc file"<br>
> nclon[:] = longitude;<br>
> nclat[:] = latitude;<br>
> nclev[:] = np.array( unique_levels );<br>
> nctime[:] = np.array( unique_times );<br>
><br>
><br>
><br>
> # - Now all the dimensions are defined and you can<br>
> # create your data variables now. First: define<br>
> # variable with sutable dimension.<br>
> # It is possible to mix fields (i am using a few<br>
> # with long/lat/time only and others with<br>
> # long/lat/level/time. But either all levels are<br>
> # in there or just one. I guess it is not possible<br>
> # to define different numbers of vertical levels<br>
> # for every single variable.<br>
><br>
> # - As an example: create one variable and<br>
> # store data into it. In this case i am creating<br>
> # a variable with all 4 dimensions. So the "data"<br>
> # variable i store at the end has to have the<br>
> # same dimension<br>
> ncvar =<br>
> ncf.createVariable(str(var),'f',('latitude','longitude','levelist','time'))<br>
> setattr(ncvar,'_FillValue',0.)<br>
> setattr(ncvar,'missing_value',-999.)<br>
> setattr(ncvar,'add_offset','0')<br>
> setattr(ncvar,'long_name',str(nc_desc[var]))<br>
> setattr(ncvar,'scale_factor',1.)<br>
> setattr(ncvar,'units','scaled radiance')<br>
> ncvar[:] = np.int32(data)<br>
><br>
> # - Syncing netcdf file (write)"<br>
> ncf.sync();<br>
><br>
> # - Close netcdf file"<br>
> ncf.close();<br>
><br>
><br>
> Probably it is getting a little bit more transparent for you. I am<br>
> using the pupynere package (pure python netcdf reader) but in newer<br>
> scipy versions it is allready included (scipy.netcdf i guess).<br>
><br>
> As checklist<br>
> - define variables (with attributes for time or levels!)<br>
> - u dont need a vertical dimension when you only have "surface" fields<br>
> (2-d-fields)<br>
> - store dimension values into created dimensions<br>
> - create variable (2,3,4-dimensional?<br>
> - store data with same size into that<br>
> - write all the stuff into the netcdf file<br>
><br>
> Greets from Austria<br>
> Reto<br>
><br>
><br>
> Zitat von Kishore Babu <<a href="mailto:kishoreragi@gmail.com">kishoreragi@gmail.com</a>>:<br>
><br>
>> Dear GrADS users,<br>
>><br>
>> Could anyone tell me how to pack the netcdf data? I do understand<br>
>> scale_factor and add_offset , but I don't know how to do with them.<br>
>><br>
>> help will greatly save my time to do that. I have already spent a lot of<br>
>> time to do that...<br>
>><br>
>><br>
>> Thank you in advance,<br>
>><br>
>> Kishore<br>
>><br>
><br>
><br>
> _______________________________________________<br>
> gradsusr mailing list<br>
> <a href="mailto:gradsusr@gradsusr.org">gradsusr@gradsusr.org</a><br>
> <a href="http://gradsusr.org/mailman/listinfo/gradsusr" target="_blank">http://gradsusr.org/mailman/listinfo/gradsusr</a><br>
<br>
</div></div>--<br>
Dr. Christopher Lynnes NASA/GSFC, Code 610.2 phone: <a href="tel:301-614-5185" value="+13016145185">301-614-5185</a><br>
<div class="HOEnZb"><div class="h5"><br>
<br>
<br>
_______________________________________________<br>
gradsusr mailing list<br>
<a href="mailto:gradsusr@gradsusr.org">gradsusr@gradsusr.org</a><br>
<a href="http://gradsusr.org/mailman/listinfo/gradsusr" target="_blank">http://gradsusr.org/mailman/listinfo/gradsusr</a><br>
</div></div></blockquote></div><br></div>