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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4201 - (show annotations)
Thu Feb 14 06:40:01 2013 UTC (7 years ago) by caltinay
Original Path: trunk/doc/examples/inversion/create_netcdf.py
File MIME type: text/x-python
File size: 2977 byte(s)
DomainBuilder now ensures all data is in same UTM zone (with test).

1 ##############################################################################
2 #
3 # Copyright (c) 2003-2013 by University of Queensland
4 # 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 """
16 This example shows how to create a netCDF input file that is suitable for
17 inversions in esys.downunder.
18 """
19
20 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 # Data error (can be constant or variable over the data points)
47 SIGMA = 3.
48
49 # 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
54 ##############################################################################
55 ###################### 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
60 history=datetime.now().strftime("%d-%m-%Y")+" created using python script"
61 # license
62 license="Free to use"
63
64 # Create the output file and write a few metadata entries
65 o=netcdf_file(FILENAME,'w')
66 o.Conventions=conventions
67 o.Metadata_Conventions=conventions
68 o.history=history
69 o.license=license
70 o.summary=SUMMARY
71 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)
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"])
85 v.data[:]=latitude
86 v.units="degrees_north"
87 v.long_name="Latitude"
88
89 # Create the main data variable
90 v=o.createVariable("data", DATA.dtype, ["latitude","longitude"])
91 v.missing_value=MISSING
92 v.data[:]=DATA
93 v.long_name="Bouguer_anomaly"
94
95 # Create the error variable (can be omitted)
96 v=o.createVariable("error", ERROR.dtype, ["latitude","longitude"])
97 v.missing_value=MISSING
98 v.data[:]=ERROR
99
100 # Close the file
101 o.close()
102

  ViewVC Help
Powered by ViewVC 1.1.26