Editing Creating NetCDF CF Files

Jump to: navigation, search

Warning: You are not logged in.

Your IP address will be recorded in this page's edit history.
The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.
Latest revision Your text
Line 371: Line 371:
 
import datetime
 
import datetime
  
nc = cf1.open("CMAQ_Baron_20.nc", "w")
+
nc = cf1.open("CMAQ_Baron_20.nc")
  
 
dt = datetime.datetime(2009, 1, 2)
 
dt = datetime.datetime(2009, 1, 2)
  
# create array for one time slice
+
data = cf1.create_array([1, 220, 288], float("NaN")) # one time, 220 latitudes, 288 longitudes, NaN as initial value
# 220 latitudes, 288 longitudes, NaN as initial value
+
data = cf1.create_array([220, 288], float("NaN"))  
+
 
for line in open("data.txt"):  
 
for line in open("data.txt"):  
 
     #data.txt must have lines
 
     #data.txt must have lines
Line 387: Line 385:
  
 
     x, y, v = line.split(",")
 
     x, y, v = line.split(",")
     data[int(y)][int(x)] = float(v)
+
     data[0][int(y)][int(x)] = float(v)
  
nc.put_time_slice("PM2_5", slice, dt)
+
nc.write_time_slice("PM2_5", dt, data)
 
</pre></html>
 
</pre></html>
  
 
This will write the data array into PM2_5 variable, and also write "24" into the datetime variable, since the time is 24 hours from the time dimension start 2009-01-01.
 
This will write the data array into PM2_5 variable, and also write "24" into the datetime variable, since the time is 24 hours from the time dimension start 2009-01-01.
  
Notice, that put_time_slice only supports updating or appending, inserting into the middle is not possible.
+
Notice, that write_time_slice only supports updating or appending, inserting into the middle is not possible.

WikiText

'''Bold''' | ''Italic'' | [[Wiki Page Name| Text to show]] | [http://external link.com Text to show]
==Heading== | * Bullets list | # Number List | sign ~~~ | sign and date ~~~~

More Wiki Help
Please note that all contributions to Federation of Earth Science Information Partners are considered to be released under the GNU Free Documentation License 1.2 (see Federation of Earth Science Information Partners:Copyrights for details). If you don't want your writing to be edited mercilessly and redistributed at will, then don't submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource. DO NOT SUBMIT COPYRIGHTED WORK WITHOUT PERMISSION!

Cancel | Editing help (opens in new window)
Personal tools
Namespaces

Variants
Actions
Navigation
Toolbox