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

Contents of /trunk/doc/examples/inversion/create_netcdf.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4191 - (show annotations)
Mon Feb 11 08:22:47 2013 UTC (7 years, 1 month ago) by gross
File MIME type: text/x-python
File size: 2427 byte(s)
more on gravity cook book
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 files for inversion with
17 inversion 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
47 SIGMA = 3.
48
49
50
51 # The actual data array, must have shape (NY, NX)
52 # these are just some random numbers.
53 DATA=10*np.random.normal(size=(NY, NX), scale=SIGMA)
54 ERROR=np.ones((NY, NX)) * SIGMA
55
56 ##############################################################################
57 ###################### Keep everything below this line #######################
58 ##############################################################################
59 # file log
60 history=datetime.now().strftime("%d-%m-%Y")+" created using python script"
61 # license
62 license="Free to use"
63
64 longitude=np.linspace(ORIGIN_X, ORIGIN_X+NX*DELTA_X, NX, endpoint=False)
65 latitude=np.linspace(ORIGIN_Y, ORIGIN_Y-NY*DELTA_Y, NY, endpoint=False)
66
67 o=netcdf_file(FILENAME,'w')
68 o.history=history
69 o.license=license
70 o.title=TITLE
71 o.summary=SUMMARY
72 o.createDimension("latitude", NY)
73 o.createDimension("longitude", NX)
74
75 v=o.createVariable("latitude", latitude.dtype, ["latitude"])
76 v.data[:]=latitude
77
78 v=o.createVariable("longitude", longitude.dtype, ["longitude"])
79 v.data[:]=longitude
80
81 v=o.createVariable("data", DATA.dtype, ["latitude","longitude"])
82 v.missing_value=MISSING
83 v.data[:]=DATA
84
85 # can be omitted.
86 v=o.createVariable("error", DATA.dtype, ["latitude","longitude"])
87 v.missing_value=MISSING
88 v.data[:]=ERROR
89
90 o.close()
91

  ViewVC Help
Powered by ViewVC 1.1.26