Skip to content

Commit 0bf0ea9

Browse files
author
Peter Hitchcock
committed
Update to 13 Sep version
1 parent c5c4ffe commit 0bf0ea9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

82 files changed

+2077
-1447
lines changed

_images/Tcp.png

-532 Bytes
Loading

_images/contour.png

30.3 KB
Loading

_images/line.png

13.1 KB
Loading

_images/log_t1Temp.png

67.6 KB
Loading
Binary file not shown.
Binary file not shown.

_images/sind_t1lat.png

14 KB
Loading

_images/t1Temp.png

-116 Bytes
Loading

_images/t1Temp_modified.png

22.6 KB
Loading

_images/t1Temp_nometadata.png

29.7 KB
Loading

_images/t1mask.png

53.2 KB
Loading

_sources/custom.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
==================
1+
==========================
22
Creating a custom variable
3-
==================
3+
==========================
44

55
Suppose one wants to perform an operation on data represented by some pygeode
66
variable that cannot be done by existing pygeode variables. One can always

_sources/fileio.txt

+23-5
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,28 @@ File Input and Output
66
Serialized data stored in files on disk (or over the network) can be imported
77
into PyGeode with the routines :func:`open` (for single files), :func:`openall`
88
(for small numbers of files), and :func:`open_multi` (for large numbers of
9-
files). Variables and datasets can be saved to disk with :func:`save`. Several
10-
formats are supported natively by pygeode, including NetCDF (versions 3 and 4),
11-
HDF (versions 4 and 5) and grib files, though support for NetCDF and HDF is the
12-
most complete.
9+
files). Variables and datasets can be saved to disk with :func:`save`.
10+
11+
.. _formats:
12+
13+
Several formats are supported natively by pygeode, including NetCDF (versions 3
14+
and 4), HDF (versions 4 and 5) and grib files, though support for NetCDF and
15+
HDF is the most complete. By default the format is detected through the file extension;
16+
however, many of the methods below accept an optional ``format`` argument which can be used to
17+
specify the format explicitly.
18+
19+
========= ============ ================= =========
20+
Format Extension String Identifier Notes
21+
========= ============ ================= =========
22+
NetCDF .nc netcdf
23+
HDF5 netcdf Uses the same library as NetCDF
24+
HDF4 .hdf hdf4
25+
GRIB .grib grib
26+
========= ============ ================= =========
27+
28+
Code also exists to read the native binary format used by the Canadian Centre
29+
for Climate Modeling and Analysis, but this is not distributed with PyGeode by
30+
default.
1331

1432
.. autofunction:: open
1533

@@ -19,6 +37,6 @@ most complete.
1937

2038
.. autofunction:: save
2139

22-
.. currentmodule:: pygeode.format
40+
.. currentmodule:: pygeode.formats
2341

2442
.. autofunction:: autodetectformat

_sources/install.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ This is the recommended approach for Ubuntu systems, since it will automatically
3737

3838

3939
RPM-based Linux distributions (Fedora, CentOS, openSUSE, etc.)
40-
=============================================
40+
===============================================================
4141

4242
Pre-built RPM packages are available via the `openSUSE Build Service <https://build.opensuse.org/package/show/home:neishm/python-pygeode>`_
4343

_sources/plot.txt

+3-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ Plot module
2525

2626
.. module:: pygeode.plot
2727

28-
.. autoclass:: AxesWrapper
28+
.. class:: AxesWrapper
29+
30+
A PyGeode wrapper class for a matplotlib figure or subplot
2931

3032
.. autofunction:: grid

_sources/toplevel.txt

-20
This file was deleted.

_sources/tut_adv.txt

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
Advanced Variable Operations
2+
============================
3+
4+
.. currentmodule:: pygeode
5+
6+
Climatological statistics
7+
.........................
8+
9+
A variety of time averaging operations are possible. In addition to computing
10+
climatologies, one can compute monthly means, daily means, diurnal means, and
11+
trends. These should generally work as expected; however, PyGeode also
12+
implements special mapping rules for time axes so that anomalies from these time
13+
averages can be easily defined. In general these are based on the
14+
15+
A common operation is to
16+
compute climatologies. As described in the first of these tutorials this is
17+
simply performed as follows
18+
19+
.. ipython::
20+
21+
@suppress
22+
In [0]: import pygeode as pyg
23+
24+
In [10]: from pygeode.tutorial import t2
25+
26+
In [10]: Tc = pyg.climatology(t2.Temp) # Compute the climatology
27+
28+
Time averaging
29+
..............
30+
31+
Other Operations
32+
----------------
33+
34+
EOFs, correlation, and regression analysis
35+
..........................................
36+
37+
include lag correlation
38+
39+
Integration, Differentiation, Interpolation and Smoothing
40+
.........................................................
41+
42+
Composites
43+
..........

_sources/adv_ops.txt _sources/tut_axes.txt

+63-21
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,69 @@
1-
Advanced Variable Operations
1+
============================
2+
Working with Axes
23
============================
34

45
.. currentmodule:: pygeode
56

7+
Constructing variables in memory
8+
--------------------------------
9+
10+
It is also often useful to create PyGeode variables directly in memory; for
11+
instance, to evaluate analytical expressions on a given geophysical grid. A very
12+
useful set of building blocks for creating variables in this way are axes
13+
objects. If you already have a variable on the relevant grid (defined from a
14+
file for instance), it's easy to simply use the existing axes, as has been done
15+
in many cases in these tutorials. However, most axes objects have simple
16+
constructors to create them directly.
17+
18+
.. ipython::
19+
20+
@suppress
21+
In [0]: import pygeode as pyg, numpy as np
22+
23+
# The simplest, default case
24+
In [1]: print pyg.NamedAxis(np.arange(15), 'myaxis')
25+
26+
# Some simple examples
27+
In [1]: lon = pyg.Lon(180)
28+
29+
In [1]: print lon
30+
31+
In [2]: lat = pyg.Lat(92)
32+
33+
In [2]: print lat
34+
35+
In [3]: pres = pyg.Pres([1000, 900, 800, 700, 500, 300, 200, 100, 50, 30, 10])
36+
37+
# Gaussian latitudes (with appropriate weights)
38+
In [2]: lat2 = pyg.gausslat(64)
39+
40+
In [2]: print lat2
41+
42+
Time axes are somewhat more complicated, as you need to specify the calendar,
43+
the reference date (``startdate``), offsets, and the native unit:
44+
45+
.. ipython::
46+
47+
In [2]: time = pyg.ModelTime365(values=np.arange(3650), units='days', startdate=dict(year=2000, month=1))
48+
49+
Usually the easiest approach to creating variables in memory is to apply the
50+
relevant mathematical operations to the axes themselves:
51+
52+
.. ipython::
53+
54+
In [2]: pyg.sin(2*np.pi*time / 365) * pyg.exp(-(lat2 / 20.)**2)
55+
56+
In [2]: pyg.sin(2*np.pi*time / 365) * pyg.exp(-(lat2 / 20.)**2)
57+
58+
However, if you have a numpy array that you want to turn in to a PyGeode
59+
variable, this can also be done.
60+
61+
.. ipython::
62+
63+
In [2]: x = np.ones((64, 180), 'd')
64+
65+
In [3]: print pyg.Var((lat2, lon), name = 'myvar', values=x)
66+
667
.. _timeaxisops:
768

869
Time Axis Operations
@@ -109,8 +170,6 @@ simply performed as follows
109170

110171
In [10]: Tc = pyg.climatology(t2.Temp) # Compute the climatology
111172

112-
In [10]:
113-
114173

115174
Time axis utilities
116175
...................
@@ -119,21 +178,4 @@ There are a number of other useful utility functions for working with time axes
119178
in the timeutils module. For instance, it is sometimes convenient to convert
120179
data on a a standardtime axis
121180

122-
123-
EOFs, correlation and regression analysis
124-
-----------------------------------------
125-
126-
include lag correlation
127-
128-
Integration and Differentiation
129-
-------------------------------
130-
131-
Interpolation
132-
-------------
133-
134-
Composites
135-
----------
136-
137-
Smoothing
138-
---------
139-
181+
lagged variables

_sources/basic_ops.txt _sources/tut_basics.txt

+47-25
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
1-
Basic Variable Operations
2-
=========================
1+
================
2+
Basic Operations
3+
================
34

45
.. currentmodule:: pygeode
56

67
Much of the functionality of PyGeode is found in the operations you can perform
78
on Var objects. We'll start with the basics of slicing variables, then move on
8-
to more complicated operations. One important thing to keep in mind, as
9-
discussed in :doc:`gettingstarted`, is that these operations all delayed until
9+
to more complicated operations. An important thing to keep in mind, as
10+
discussed in :doc:`tut_gettingstarted`, is that these operations all delayed until
1011
the data is specifically requested. For instance, one can compute an average
1112
over longitude as follows:
1213

1314
.. ipython::
1415

16+
@suppress
17+
In [6]: import pylab as pyl; pyl.ion();
18+
1519
In [1]: import pygeode as pyg
1620

1721
In [2]: from pygeode.tutorial import t1
@@ -166,30 +170,33 @@ axes are removed in this unlike numpy slicing, degenerate axes are removed.
166170
That is, ``t1.Temp[0, 1]`` returns a scalar, while ``t1.Temp(i_lat=0, i_lon=1)``
167171
returns a two dimensional variable.
168172

169-
Arithmetic operations
170-
---------------------
173+
Arithmetic operations and broadcasting rules
174+
--------------------------------------------
171175

172176
Reference: :doc:`ufunc` and :doc:`var.arith`
173177

174-
Arithmetic and mathematical operations are also supported by PyGeode. The
178+
Arithmetic and other mathematical operations are also supported by PyGeode. The
175179
simplest are unary operations, which are performed elementwise. Most standard
176-
mathematical functions (powers, exponentials, trigonometric functions, etc.) are
177-
supported, and can be found in the main ``pygeode`` module:
180+
mathematical functions (powers, exponentials, trigonometric functions, etc.)
181+
are supported, and can be found in the main ``pygeode`` module:
178182

179183
.. ipython::
180184

181185
@suppress
182186
In [6]: import pylab as pyl; pyl.ion()
183187

184-
@showfig log_t1Temp.png width=4in
188+
@suppress
189+
In [6]: import matplotlib as mpl; mpl.rc('figure', figsize=(5, 3))
190+
191+
@savefig log_t1Temp.png width=4in
185192
In [8]: pyg.showvar(pyg.log(t1.Temp)) # Plot the natural logarithm of Temp
186193

187194
There are some convenience functions included, for instance, most trig functions
188195
have a version which takes arguments in degrees rather than radians:
189196

190197
.. ipython::
191198

192-
@showfig sind_t1lat.png width=4in
199+
@savefig sind_t1lat.png width=4in
193200
In [10]: pyg.showvar(pyg.sind(t1.lat)) # Compute the sine of latitude
194201

195202
In most cases the underlying operation is performed by the numpy equivalent,
@@ -199,13 +206,23 @@ variables, so one should get accustomed to including the ``pyg`` prefix. This
199206
is also a good reason to import pygeode into its own namespace, rather than
200207
into the top-level namespace itself.
201208

202-
Standard Python arithmetic operations (``+``, ``-``, ``*``, ``/``, ``**``,
203-
etc.) are also supported and work as one would expect if all the variables are
204-
defined on the same axes. If the variables do not share the same axes, PyGeode
205-
follows a set of rules for automatically broadcasting them so that the
206-
operations behave as one might typically desire - it's important to be aware of
207-
these rules as you can sometimes end up with some unexpected results, so they
208-
are described here in some detail.
209+
Standard Python binary arithmetic operations (``+``, ``-``, ``*``, ``/``,
210+
``**``, etc.) are supported and work as one would expect if all the
211+
variables are defined on the same axes. Comparison operators (``>``, ``<``, etc.)
212+
are also supported and produce a boolean variable on the same axes with the result of
213+
the operation performed elementwise. This can be very useful for masking data,
214+
since when cast to scalar values, ``True`` is equal to 1 and ``False`` is equal to 0:
215+
216+
.. ipython::
217+
218+
@savefig t1mask.png width=4in
219+
In [11]: pyg.showvar(2 + 3 * (t1.Temp > 280.))
220+
221+
If the variables do not share the same axes, PyGeode follows a set of rules for
222+
automatically broadcasting them so that the operations behave as one might
223+
typically desire - it's important to be aware of these rules as you can
224+
sometimes end up with some unexpected results, so they are described here in
225+
some detail.
209226

210227
.. _broadcasting:
211228

@@ -343,18 +360,17 @@ be specified; those that are not will be appended in their present order.
343360

344361
.. ipython::
345362

346-
In[8]: t2.Temp.axes
363+
In [8]: t2.Temp.axes
347364

348-
In[9]: print t2.Temp.transpose('lon', 'lat', 'pres', 'time').axes
365+
In [9]: print t2.Temp.transpose('lon', 'lat', 'pres', 'time').axes
349366

350367
:func:`Var.replace_axes()` replaces any or all axes of a variable. The new
351368
axes must have the same length as those they are replacing.
352369

353370
.. ipython::
354371

355372
# The logPAxis method returns a log-pressure axis with a given scale height
356-
In[8]: print t2.Temp.replace_axes(pres=t2.pres.logPAxis(H=7000)).axes
357-
373+
In [8]: print t2.Temp.replace_axes(pres=t2.pres.logPAxis(H=7000)).axes
358374

359375
:func:`Var.squeeze()` removes degenerate axes (those with one or fewer elements).
360376
As mentioned above, the default selection behaviour is to always return a
@@ -365,11 +381,17 @@ all degenerate axes. Several other methods of calling are also available:
365381

366382
.. ipython::
367383

368-
In[8]: print t2.Temp(time = 4, lon = 20).squeeze().axes
384+
# Squeeze all degenerate axes
385+
In [8]: print t2.Temp(time = 4, lon = 20).squeeze()
386+
387+
# Squeeze only the time axis (if it is degenerate)
388+
In [8]: print t2.Temp(time = 4, lon = 20).squeeze('time')
369389

370-
In[8]: print t2.Temp(time = 4, lon = 20).squeeze('time').axes
390+
# Select a single value then squeeze the time axis
391+
In [8]: print t2.Temp.squeeze(time = 4)
371392

372-
In[8]: print t2.Temp.squeeze(i_time = 3, lon = (20, 40))
393+
# Select a single value and sqeeze the time axis using a selection prefix
394+
In [8]: print t2.Temp(s_time = 4, lon = (20, 40))
373395

374396
There are also commands to rename variables and their axes
375397
(:func:`Var.rename()`, :func:`Var.rename_axes()`), for adding axes to a

_sources/tut_datasets.txt

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
======================
2+
Working with Datasets
3+
======================
4+
5+
.. currentmodule:: pygeode
6+
7+
selections on whole datasets
8+
combining datasets
9+
operating on datasets

0 commit comments

Comments
 (0)