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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4257 - (hide annotations)
Wed Feb 27 03:42:40 2013 UTC (6 years, 11 months ago) by jfenwick
File MIME type: text/x-python
File size: 2977 byte(s)
Some simple experiments for c++ Finley

1 gross 4119 ##############################################################################
2     #
3 jfenwick 4154 # Copyright (c) 2003-2013 by University of Queensland
4 gross 4119 # http://www.uq.edu.au
5     #
6     # Primary Business: Queensland, Australia
7     # Licensed under the Open Software License version 3.0
8     # http://www.opensource.org/licenses/osl-3.0.php
9     #
10     # Development until 2012 by Earth Systems Science Computational Center (ESSCC)
11     # Development since 2012 by School of Earth Sciences
12     #
13     ##############################################################################
14    
15 gross 4191 """
16 caltinay 4201 This example shows how to create a netCDF input file that is suitable for
17     inversions in esys.downunder.
18 gross 4191 """
19 caltinay 4162
20 gross 4119 from datetime import datetime
21     import numpy as np
22     from scipy.io import netcdf_file
23    
24     # output filename
25     FILENAME='output.nc'
26    
27     # a concise title and summary of the dataset
28     TITLE="custom_data"
29     SUMMARY="Bouguer gravity anomaly data"
30    
31     # Origin longitude (degrees east) and latitude (degrees north)
32     ORIGIN_X=130.2
33     ORIGIN_Y=-29.1
34    
35     # spacing in longitude,latitude direction (degrees)
36     DELTA_X=0.05
37     DELTA_Y=0.05
38    
39     # Number of data points in longitude,latitude direction
40     NX=20
41     NY=10
42    
43     # Dummy value (for unset areas)
44     MISSING=-9999
45    
46 caltinay 4201 # Data error (can be constant or variable over the data points)
47 gross 4191 SIGMA = 3.
48 gross 4119
49 caltinay 4201 # The actual data array, must have shape (NY, NX).
50     # These are just some random numbers.
51     DATA = 10*np.random.normal(size=(NY, NX), scale=SIGMA)
52     ERROR = np.ones((NY, NX)) * SIGMA
53 gross 4191
54 gross 4119 ##############################################################################
55     ###################### Keep everything below this line #######################
56     ##############################################################################
57 caltinay 4201 # conventions used in the file
58     conventions="CF-1.0, COARDS, Unidata Dataset Discovery v1.0"
59 gross 4119 # file log
60     history=datetime.now().strftime("%d-%m-%Y")+" created using python script"
61     # license
62     license="Free to use"
63    
64 caltinay 4201 # Create the output file and write a few metadata entries
65 gross 4119 o=netcdf_file(FILENAME,'w')
66 caltinay 4201 o.Conventions=conventions
67     o.Metadata_Conventions=conventions
68 gross 4119 o.history=history
69     o.license=license
70 caltinay 4201 o.summary=SUMMARY
71 gross 4191 o.title=TITLE
72 caltinay 4201
73     # Create longitude dimension and variable
74     longitude=np.linspace(ORIGIN_X, ORIGIN_X+NX*DELTA_X, NX, endpoint=False)
75 gross 4119 o.createDimension("longitude", NX)
76 caltinay 4201 v=o.createVariable("longitude", longitude.dtype, ["longitude"])
77     v.data[:]=longitude
78     v.units="degrees_east"
79     v.long_name="Longitude"
80 gross 4119
81 caltinay 4201 # 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 gross 4119 v=o.createVariable("latitude", latitude.dtype, ["latitude"])
85     v.data[:]=latitude
86 caltinay 4201 v.units="degrees_north"
87     v.long_name="Latitude"
88 gross 4119
89 caltinay 4201 # Create the main data variable
90 gross 4119 v=o.createVariable("data", DATA.dtype, ["latitude","longitude"])
91     v.missing_value=MISSING
92     v.data[:]=DATA
93 caltinay 4201 v.long_name="Bouguer_anomaly"
94 gross 4119
95 caltinay 4201 # Create the error variable (can be omitted)
96     v=o.createVariable("error", ERROR.dtype, ["latitude","longitude"])
97 gross 4191 v.missing_value=MISSING
98     v.data[:]=ERROR
99    
100 caltinay 4201 # Close the file
101 gross 4119 o.close()
102    

  ViewVC Help
Powered by ViewVC 1.1.26