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

Annotation of /trunk/doc/examples/inversion/create_netcdf_all.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4162 - (hide annotations)
Thu Jan 24 03:53:19 2013 UTC (6 years, 8 months ago) by caltinay
Original Path: trunk/doc/examples/inversion/create_netcdf.py
File MIME type: text/x-python
File size: 2869 byte(s)
Added missing example file to display netcdf data.

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 caltinay 4162 """This example shows how to create compatible netCDF input files for inversion"""
16    
17 gross 4119 from datetime import datetime
18     import numpy as np
19     from scipy.io import netcdf_file
20    
21     # output filename
22     FILENAME='output.nc'
23    
24     # a concise title and summary of the dataset
25     TITLE="custom_data"
26     SUMMARY="Bouguer gravity anomaly data"
27    
28     # Origin longitude (degrees east) and latitude (degrees north)
29     ORIGIN_X=130.2
30     ORIGIN_Y=-29.1
31    
32     # spacing in longitude,latitude direction (degrees)
33     DELTA_X=0.05
34     DELTA_Y=0.05
35    
36     # Number of data points in longitude,latitude direction
37     NX=20
38     NY=10
39    
40     # Dummy value (for unset areas)
41     MISSING=-9999
42    
43     # Units of the data array
44     UNITS='mGal'
45    
46     # The actual data array, must have shape (NY, NX)
47     DATA=10*np.random.normal(size=(NY, NX))
48    
49     ##############################################################################
50     ###################### Keep everything below this line #######################
51     ##############################################################################
52    
53     # conventions used in the file
54     conventions="CF-1.0, COARDS, Unidata Dataset Discovery v1.0"
55     # projection string
56     esri_pe_string="GEOGCS[\\\"GCS_WGS_1984\\\",DATUM[\\\"D_WGS_1984\\\",SPHEROID[\\\"WGS_1984\\\",6378137.0,298.257223563]],PRIMEM[\\\"Greenwich\\\",0.0],UNIT[\\\"Degree\\\",0.0174532925199433]]"
57     # file log
58     history=datetime.now().strftime("%d-%m-%Y")+" created using python script"
59     # license
60     license="Free to use"
61    
62     longitude=np.linspace(ORIGIN_X, ORIGIN_X+NX*DELTA_X, NX, endpoint=False)
63     latitude=np.linspace(ORIGIN_Y, ORIGIN_Y-NY*DELTA_Y, NY, endpoint=False)
64    
65     o=netcdf_file(FILENAME,'w')
66     o.cdm_data_type="Grid"
67     o.Conventions=conventions
68     o.history=history
69     o.license=license
70     o.Metadata_Conventions=conventions
71     o.summary=SUMMARY
72     o.title=TITLE
73     o.createDimension("latitude", NY)
74     o.createDimension("longitude", NX)
75    
76     v=o.createVariable("latitude", latitude.dtype, ["latitude"])
77     v.axis = "Y"
78     v.long_name="Latitude"
79     v.standard_name="latitude"
80     v.units="degrees_north"
81     v.data[:]=latitude
82    
83     v=o.createVariable("longitude", longitude.dtype, ["longitude"])
84     v.axis = "X"
85     v.long_name="Longitude"
86     v.standard_name="longitude"
87     v.units="degrees_east"
88     v.data[:]=longitude
89    
90     v=o.createVariable("data", DATA.dtype, ["latitude","longitude"])
91     v.coordinates="lon lat"
92     v.esri_pe_string=esri_pe_string
93     v.long_name="Bouguer_anomaly"
94     v.missing_value=MISSING
95     v.units=UNITS
96     v.data[:]=DATA
97    
98     o.close()
99    

  ViewVC Help
Powered by ViewVC 1.1.26