/[escript]/branches/doubleplusgood/doc/examples/inversion/create_netcdf.py
ViewVC logotype

Diff of /branches/doubleplusgood/doc/examples/inversion/create_netcdf.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 4191 by gross, Mon Feb 11 08:22:47 2013 UTC revision 4201 by caltinay, Thu Feb 14 06:40:01 2013 UTC
# Line 13  Line 13 
13  ##############################################################################  ##############################################################################
14    
15  """  """
16  This example shows how to create a netCDF input files for inversion with  This example shows how to create a netCDF input file that is suitable for
17  inversion in esys.downunder.  inversions in esys.downunder.
18  """  """
19    
20  from datetime import datetime  from datetime import datetime
# Line 43  NY=10 Line 43  NY=10
43  # Dummy value (for unset areas)  # Dummy value (for unset areas)
44  MISSING=-9999  MISSING=-9999
45    
46  # Data error  # Data error (can be constant or variable over the data points)
47  SIGMA = 3.  SIGMA = 3.
48    
49    # The actual data array, must have shape (NY, NX).
50    # These are just some random numbers.
51  # The actual data array, must have shape (NY, NX)  DATA = 10*np.random.normal(size=(NY, NX), scale=SIGMA)
52  # these are just some random numbers.  ERROR = np.ones((NY, NX)) * SIGMA
 DATA=10*np.random.normal(size=(NY, NX), scale=SIGMA)  
 ERROR=np.ones((NY, NX)) * SIGMA  
53    
54  ##############################################################################  ##############################################################################
55  ###################### Keep everything below this line #######################  ###################### Keep everything below this line #######################
56  ##############################################################################  ##############################################################################
57    # conventions used in the file
58    conventions="CF-1.0, COARDS, Unidata Dataset Discovery v1.0"
59  # file log  # file log
60  history=datetime.now().strftime("%d-%m-%Y")+" created using python script"  history=datetime.now().strftime("%d-%m-%Y")+" created using python script"
61  # license  # license
62  license="Free to use"  license="Free to use"
63    
64  longitude=np.linspace(ORIGIN_X, ORIGIN_X+NX*DELTA_X, NX, endpoint=False)  # Create the output file and write a few metadata entries
 latitude=np.linspace(ORIGIN_Y, ORIGIN_Y-NY*DELTA_Y, NY, endpoint=False)  
   
65  o=netcdf_file(FILENAME,'w')  o=netcdf_file(FILENAME,'w')
66    o.Conventions=conventions
67    o.Metadata_Conventions=conventions
68  o.history=history  o.history=history
69  o.license=license  o.license=license
 o.title=TITLE  
70  o.summary=SUMMARY  o.summary=SUMMARY
71  o.createDimension("latitude", NY)  o.title=TITLE
72    
73    # Create longitude dimension and variable
74    longitude=np.linspace(ORIGIN_X, ORIGIN_X+NX*DELTA_X, NX, endpoint=False)
75  o.createDimension("longitude", NX)  o.createDimension("longitude", NX)
76    v=o.createVariable("longitude", longitude.dtype, ["longitude"])
77    v.data[:]=longitude
78    v.units="degrees_east"
79    v.long_name="Longitude"
80    
81    # Create latitude dimension and variable
82    latitude=np.linspace(ORIGIN_Y, ORIGIN_Y-NY*DELTA_Y, NY, endpoint=False)
83    o.createDimension("latitude", NY)
84  v=o.createVariable("latitude", latitude.dtype, ["latitude"])  v=o.createVariable("latitude", latitude.dtype, ["latitude"])
85  v.data[:]=latitude  v.data[:]=latitude
86    v.units="degrees_north"
87    v.long_name="Latitude"
88    
89  v=o.createVariable("longitude", longitude.dtype, ["longitude"])  # Create the main data variable
 v.data[:]=longitude  
   
90  v=o.createVariable("data", DATA.dtype, ["latitude","longitude"])  v=o.createVariable("data", DATA.dtype, ["latitude","longitude"])
91  v.missing_value=MISSING  v.missing_value=MISSING
92  v.data[:]=DATA  v.data[:]=DATA
93    v.long_name="Bouguer_anomaly"
94    
95  # can be omitted.  # Create the error variable (can be omitted)
96  v=o.createVariable("error", DATA.dtype, ["latitude","longitude"])  v=o.createVariable("error", ERROR.dtype, ["latitude","longitude"])
97  v.missing_value=MISSING  v.missing_value=MISSING
98  v.data[:]=ERROR  v.data[:]=ERROR
99    
100    # Close the file
101  o.close()  o.close()
102    

Legend:
Removed from v.4191  
changed lines
  Added in v.4201

  ViewVC Help
Powered by ViewVC 1.1.26