/[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 4119 - (hide annotations)
Mon Dec 17 04:53:15 2012 UTC (7 years, 2 months ago) by gross
Original Path: trunk/doc/examples/inversion/create_ncinput.py
File MIME type: text/x-python
File size: 2785 byte(s)
some adjustments to the documentation
1 gross 4119 ##############################################################################
2     #
3     # Copyright (c) 2003-2012 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     from datetime import datetime
16     import numpy as np
17     from scipy.io import netcdf_file
18    
19     # output filename
20     FILENAME='output.nc'
21    
22     # a concise title and summary of the dataset
23     TITLE="custom_data"
24     SUMMARY="Bouguer gravity anomaly data"
25    
26     # Origin longitude (degrees east) and latitude (degrees north)
27     ORIGIN_X=130.2
28     ORIGIN_Y=-29.1
29    
30     # spacing in longitude,latitude direction (degrees)
31     DELTA_X=0.05
32     DELTA_Y=0.05
33    
34     # Number of data points in longitude,latitude direction
35     NX=20
36     NY=10
37    
38     # Dummy value (for unset areas)
39     MISSING=-9999
40    
41     # Units of the data array
42     UNITS='mGal'
43    
44     # The actual data array, must have shape (NY, NX)
45     DATA=10*np.random.normal(size=(NY, NX))
46    
47     ##############################################################################
48     ###################### Keep everything below this line #######################
49     ##############################################################################
50    
51     # conventions used in the file
52     conventions="CF-1.0, COARDS, Unidata Dataset Discovery v1.0"
53     # projection string
54     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]]"
55     # file log
56     history=datetime.now().strftime("%d-%m-%Y")+" created using python script"
57     # license
58     license="Free to use"
59    
60     longitude=np.linspace(ORIGIN_X, ORIGIN_X+NX*DELTA_X, NX, endpoint=False)
61     latitude=np.linspace(ORIGIN_Y, ORIGIN_Y-NY*DELTA_Y, NY, endpoint=False)
62    
63     o=netcdf_file(FILENAME,'w')
64     o.cdm_data_type="Grid"
65     o.Conventions=conventions
66     o.history=history
67     o.license=license
68     o.Metadata_Conventions=conventions
69     o.summary=SUMMARY
70     o.title=TITLE
71     o.createDimension("latitude", NY)
72     o.createDimension("longitude", NX)
73    
74     v=o.createVariable("latitude", latitude.dtype, ["latitude"])
75     v.axis = "Y"
76     v.long_name="Latitude"
77     v.standard_name="latitude"
78     v.units="degrees_north"
79     v.data[:]=latitude
80    
81     v=o.createVariable("longitude", longitude.dtype, ["longitude"])
82     v.axis = "X"
83     v.long_name="Longitude"
84     v.standard_name="longitude"
85     v.units="degrees_east"
86     v.data[:]=longitude
87    
88     v=o.createVariable("data", DATA.dtype, ["latitude","longitude"])
89     v.coordinates="lon lat"
90     v.esri_pe_string=esri_pe_string
91     v.long_name="Bouguer_anomaly"
92     v.missing_value=MISSING
93     v.units=UNITS
94     v.data[:]=DATA
95    
96     o.close()
97    

  ViewVC Help
Powered by ViewVC 1.1.26