Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sampledata #19

Closed
wants to merge 19 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions docs/iris/example_code/graphics/COP_1d_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@ def cop_metadata_callback(cube, field, filename):

def main():
# Load data into three Cubes, one for each set of PP files
e1 = iris.load_strict(iris.sample_data_path('PP', 'A1B-Image_E1', 'E1', '*.pp'),
e1 = iris.load_strict(iris.sample_data_path('PP', 'A1B-Image_E1', 'E1_subset', '*_subset.pp'),
callback=cop_metadata_callback)

a1b = iris.load_strict(iris.sample_data_path('PP', 'A1B-Image_E1', 'A1B', '*.pp'),
a1b = iris.load_strict(iris.sample_data_path('PP', 'A1B-Image_E1', 'A1B_subset', '*_subset.pp'),
callback=cop_metadata_callback)

global_avg = iris.load_strict(iris.sample_data_path('PP', 'A1B-Image_E1', 'pp_1859_1889_avg.pp'))
global_avg = iris.load_strict(iris.sample_data_path('PP', 'A1B-Image_E1', 'pp_1859_1889_avg_subset.pp'))

pre_industrial_mean = global_avg.collapsed(['latitude', 'longitude'], iris.analysis.MEAN)
e1_global_mean = e1.collapsed(['latitude', 'longitude'], iris.analysis.MEAN)
Expand Down
9 changes: 2 additions & 7 deletions docs/iris/example_code/graphics/COP_maps.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,11 @@ def cop_metadata_callback(cube, field, filename):

def main():
# Load e1 and a1 using the callback to update the metadata
e1 = iris.load_strict(iris.sample_data_path('PP', 'A1B-Image_E1', 'E1', '*.pp'),
e1 = iris.load_strict(iris.sample_data_path('PP', 'A1B-Image_E1', 'E1_subset', '*_full.pp'),
callback=cop_metadata_callback)
a1b = iris.load_strict(iris.sample_data_path('PP', 'A1B-Image_E1', 'A1B', '*.pp'),
a1b = iris.load_strict(iris.sample_data_path('PP', 'A1B-Image_E1', 'A1B_subset', '*_full.pp'),
callback=cop_metadata_callback)

# For the purposes of this example, take the final timestep of the data we have just loaded
e1 = e1[-1, :, :]
a1b = a1b[-1, :, :]

# Load the global average data and add an 'Experiment' coord it
global_avg = iris.load_strict(iris.sample_data_path('PP', 'A1B-Image_E1', 'pp_1859_1889_avg.pp'))

Expand All @@ -72,7 +68,6 @@ def main():
for e1_slice, a1b_slice in itertools.izip(e1.slices(['latitude', 'longitude']), a1b.slices(['latitude', 'longitude'])):

time_coord = a1b_slice.coord('time')

# Calculate the difference from the mean
delta_e1 = e1_slice - global_avg
delta_a1b = a1b_slice - global_avg
Expand Down
2 changes: 1 addition & 1 deletion docs/iris/example_code/graphics/cross_section.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@


def main():
fname = iris.sample_data_path('PP', 'COLPEX', 'theta_and_orog_subset.pp')
fname = iris.sample_data_path('PP', 'COLPEX', 'theta_and_orog_subset_b.pp')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This plot looks far less interesting now. Can the number of levels be increased slightly to see any improvement?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of chopping it down to (2, 8, 50, 50), why not leave the displayed dimensions intact and the chop the others? e.g. (2, 70, 2, 100). That would look as good as the original but be even smaller than your current file.

Or you could go even further, and pre-trim the vertical data as well (ditching the comment about emphasising the terrain) -> (2, 15, 2, 100).

theta = iris.load_strict(fname, 'air_potential_temperature')

# Extract a height vs longitude cross-section. N.B. This could easily changed to
Expand Down
3 changes: 1 addition & 2 deletions docs/iris/example_code/graphics/custom_file_loading.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,8 @@ def NAME_to_cube(filenames, callback):
# ---------------------------------------------

def main():
fname = iris.sample_data_path('ascii', 'NAME', '20100509_18Z_variablesource_12Z_VAAC', 'Fields_grid1_201005110600.txt')

fname = iris.sample_data_path('ascii', 'NAME', '20100509_18Z_variablesource_12Z_VAAC_subset', 'Fields_grid1_201005110600.txt')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know you've inherited them, but the file names in the Iris examples are crazy! The complicated directory structure stuff is just an artefact of the original data zoo. We need much more user-friendly names. E.g. perhaps just "VAAC.txt" for this one, or "NAME.txt".

And certainly, there's no need for any of them to have a "_subset" suffix.

boundary_volc_ash_constraint = iris.Constraint('VOLCANIC_ASH_AIR_CONCENTRATION', flight_level='Boundary layer')

# Callback shown as None to illustrate where a cube-level callback function would be used if required
Expand All @@ -237,4 +237,3 @@ def main():

if __name__ == '__main__':
main()

2 changes: 1 addition & 1 deletion docs/iris/example_code/graphics/deriving_phenomena.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def limit_colorbar_ticks(contour_object):


def main():
fname = iris.sample_data_path('PP', 'COLPEX', 'air_potential_and_air_pressure.pp')
fname = iris.sample_data_path('PP', 'COLPEX', 'air_potential_and_air_pressure_subset_b.pp')

# the list of phenomena of interest
phenomena = ['air_potential_temperature', 'air_pressure']
Expand Down
2 changes: 1 addition & 1 deletion docs/iris/example_code/graphics/hovmoller.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def first_day_of_month(cube):


def main():
fname = iris.sample_data_path('PP', 'ostia', 'ostia_sst_200604_201009_N216.pp')
fname = iris.sample_data_path('PP', 'ostia', 'ostia_sst_200604_201009_N216_subset.pp')

# load a single cube of surface temperature between +/- 5 latitude, where each constituent field was the first day
# of the month
Expand Down
4 changes: 2 additions & 2 deletions docs/iris/example_code/graphics/lagged_ensemble.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def lagged_ensemble_metadata(cube, field, fname):
# add an ensemble member coordinate if one doesn't already exist
if not cube.coords('realization'):
# the ensemble member is encoded in the filename as *_???.pp where ??? is the ensemble member
ensemble_member = fname[-6:-3]
ensemble_member = fname[-13:-10]

import iris.coords
ensemble_coord = iris.coords.AuxCoord(numpy.int32(ensemble_member), 'realization')
Expand All @@ -46,7 +46,7 @@ def lagged_ensemble_metadata(cube, field, fname):

def main():
# extract surface temperature cubes which have an ensemble member coordinate, adding appropriate lagged ensemble metadata
surface_temp = iris.load_strict(iris.sample_data_path('PP', 'GloSea4', 'prodf*_???.pp'),
surface_temp = iris.load_strict(iris.sample_data_path('PP', 'GloSea4', 'prodf*_???_subset.pp'),
iris.Constraint('surface_temperature', realization=lambda value: True),
callback=lagged_ensemble_metadata,
)
Expand Down
6 changes: 3 additions & 3 deletions docs/iris/src/userguide/cube_maths.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Calculating the difference between two cubes

Let's load some data which represents air pressure on the first model level of a single model run::

filename = iris.sample_data_path('PP', 'COLPEX', 'air_potential_and_air_pressure.pp')
filename = iris.sample_data_path('PP', 'COLPEX', 'air_potential_and_air_pressure_subset_b.pp')
air_press_lev1 = iris.Constraint('air_pressure', model_level_number=1)
air_press = iris.load_strict(filename, air_press_lev1)

Expand All @@ -31,7 +31,7 @@ We can now get the first and last time slices using indexing (see :doc:`reducing

.. testsetup::

filename = iris.sample_data_path('PP', 'COLPEX', 'air_potential_and_air_pressure.pp')
filename = iris.sample_data_path('PP', 'COLPEX', 'air_potential_and_air_pressure_subset_b.pp')
cube = iris.load_strict(filename, iris.Constraint('air_pressure', model_level_number=1))
t_first = cube[0, :, :]
t_last = cube[1, :, :]
Expand Down Expand Up @@ -72,7 +72,7 @@ reference pressure and :math:`T` is temperature.

First, let's load pressure and potential temperature cubes::

filename = iris.sample_data_path('PP', 'COLPEX', 'air_potential_and_air_pressure.pp')
filename = iris.sample_data_path('PP', 'COLPEX', 'air_potential_and_air_pressure_subset_b.pp')
phenomenon_names = ['air_potential_temperature', 'air_pressure']
pot_temperature, pressure = iris.load_strict(filename, phenomenon_names)

Expand Down
8 changes: 4 additions & 4 deletions docs/iris/src/userguide/cube_statistics.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Collapsing entire data dimensions
.. testsetup::

import iris
filename = iris.sample_data_path('PP', 'globClim1', 'theta.pp')
filename = iris.sample_data_path('PP', 'globClim1', 'theta_subset.pp')
cube = iris.load_strict(filename)

import iris.analysis.cartography
Expand All @@ -22,7 +22,7 @@ In the section :doc:`reducing_a_cube` we saw how to extract a subset of a cube i
Instead of downsampling the data, a similar goal can be achieved using statistical operations over *all* of the data. Suppose we have a cube:

>>> import iris
>>> filename = iris.sample_data_path('PP', 'globClim1', 'theta.pp')
>>> filename = iris.sample_data_path('PP', 'globClim1', 'theta_subset.pp')
>>> cube = iris.load_strict(filename)
>>> print cube
air_potential_temperature (level_height: 38; latitude: 145; longitude: 192)
Expand Down Expand Up @@ -133,7 +133,7 @@ First, let's create two coordinates on a cube which represent the climatological
import iris
import iris.coord_categorisation

filename = iris.sample_data_path('PP', 'decadal', 'ajnuqa.pm*.pp')
filename = iris.sample_data_path('PP', 'decadal_subset', 'ajnuqa.pm*.pp')
cube = iris.load_strict(filename, 'air_temperature')

iris.coord_categorisation.add_season(cube, 'time', name='clim_season')
Expand All @@ -144,7 +144,7 @@ First, let's create two coordinates on a cube which represent the climatological

import iris

filename = iris.sample_data_path('PP', 'decadal', 'ajnuqa.pm*.pp')
filename = iris.sample_data_path('PP', 'decadal_subset', 'ajnuqa.pm*.pp')
cube = iris.load_strict(filename, 'air_temperature')

import iris.coord_categorisation
Expand Down
2 changes: 1 addition & 1 deletion docs/iris/src/userguide/iris_cubes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ output as this is the quickest way of inspecting the contents of a cube. Here is
:hide:

import iris
filename = iris.sample_data_path('PP', 'ukV2', 'THOxayrk.pp')
filename = iris.sample_data_path('PP', 'ukV2', 'THOxayrk_subset.pp')
# NOTE: Every time the output of this cube changes, the full list of deductions below should be re-assessed.
print iris.load_strict(filename, 'air_potential_temperature')

Expand Down
26 changes: 13 additions & 13 deletions docs/iris/src/userguide/loading_iris_cubes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ to produce Iris Cubes from their contents.
In order to find out what has been loaded, the result can be printed:

>>> import iris
>>> filename = iris.sample_data_path('PP', 'ukV2', 'THOxayrk.pp')
>>> filename = iris.sample_data_path('PP', 'ukV2', 'THOxayrk_subset.pp')
>>> cubes = iris.load(filename)
>>> print cubes
0: air_potential_temperature (forecast_period: 3; level_height: 40; grid_latitude: 810; grid_longitude: 622)
Expand Down Expand Up @@ -62,7 +62,7 @@ To get the air potential temperature cube from the list of cubes returned by :py
example, list indexing *could* be used:

>>> import iris
>>> filename = iris.sample_data_path('PP', 'ukV2', 'THOxayrk.pp')
>>> filename = iris.sample_data_path('PP', 'ukV2', 'THOxayrk_subset.pp')
>>> cubes = iris.load(filename)
>>> # get the first cube (list indexing is 0 based)
>>> air_potential_temperature = cubes[0]
Expand Down Expand Up @@ -100,7 +100,7 @@ Loading multiple files

To load more than one file into a list of cubes, a list of filenames can be provided to :py:func:`iris.load`::

filenames = [iris.sample_data_path('PP', 'ukV2', 'THOxayrk.pp'),
filenames = [iris.sample_data_path('PP', 'ukV2', 'THOxayrk_subset.pp'),
iris.sample_data_path('PP', 'aPPglob1', 'global.pp')]
cubes = iris.load(filenames)

Expand All @@ -121,7 +121,7 @@ Constrained loading provides the ability to generate a cube from a specific subs

As we have seen, loading the following file creates several Cubes::

filename = iris.sample_data_path('PP', 'ukV2', 'THOxayrk.pp')
filename = iris.sample_data_path('PP', 'ukV2', 'THOxayrk_subset.pp')
cubes = iris.load(filename)

Specifying a name as a constraint argument to :py:func:`iris.load` will mean only cubes with a
Expand All @@ -133,27 +133,27 @@ matching :meth:`name <iris.cube.Cube.name>` will be returned::
To constrain the load to multiple distinct constraints, a list of constraints can be provided.
This is equivalent to running load once for each constraint but is likely to be more efficient::

filename = iris.sample_data_path('PP', 'ukV2', 'THOxayrk.pp')
filename = iris.sample_data_path('PP', 'ukV2', 'THOxayrk_subset.pp')
cubes = iris.load(filename, ['air_potential_temperature', 'specific_humidity'])

The :class:`iris.Constraint` class can be used to restrict coordinate values on load. For example, to constrain the load to
match a specific ``model_level_number``::

filename = iris.sample_data_path('PP', 'ukV2', 'THOxayrk.pp')
filename = iris.sample_data_path('PP', 'ukV2', 'THOxayrk_subset.pp')
level_10 = iris.Constraint(model_level_number=10)
cubes = iris.load(filename, level_10)

Constraints can be combined using ``&`` to represent a more restrictive constraint to ``load``::

filename = iris.sample_data_path('PP', 'ukV2', 'THOxayrk.pp')
filename = iris.sample_data_path('PP', 'ukV2', 'THOxayrk_subset.pp')
forecast_6 = iris.Constraint(forecast_period=6)
level_10 = iris.Constraint(model_level_number=10)
cubes = iris.load(filename, forecast_6 & level_10)

As well as being able to combine constraints using ``&``, the :class:`iris.Constraint` class can accept multiple
arguments, and a list of values can be given to constrain a coordinate to one of a collection of values::

filename = iris.sample_data_path('PP', 'ukV2', 'THOxayrk.pp')
filename = iris.sample_data_path('PP', 'ukV2', 'THOxayrk_subset.pp')
level_10_or_12_fp_6 = iris.Constraint(model_level_number=[10, 12], forecast_period=6)
cubes = iris.load(filename, level_10_or_12_fp_6)

Expand All @@ -164,7 +164,7 @@ a function::
# return True or False as to whether the cell in question should be kept
return cell <= 20

filename = iris.sample_data_path('PP', 'ukV2', 'THOxayrk.pp')
filename = iris.sample_data_path('PP', 'ukV2', 'THOxayrk_subset.pp')
level_lt_20 = iris.Constraint(model_level_number=bottom_20_levels)
cubes = iris.load(filename, level_lt_20)

Expand All @@ -177,7 +177,7 @@ a function::
Cube attributes can also be part of the constraint criteria. Supposing a cube attribute of ``STASH`` existed, as is the case
when loading ``PP`` files, then specific STASH codes can be filtered::

filename = iris.sample_data_path('PP', 'ukV2', 'THOxayrk.pp')
filename = iris.sample_data_path('PP', 'ukV2', 'THOxayrk_subset.pp')
level_10_with_stash = iris.AttributeConstraint(STASH='m01s00i004') & iris.Constraint(model_level_number=10)
cubes = iris.load(filename, level_10_with_stash)

Expand All @@ -199,7 +199,7 @@ A single cube is loaded in the following example::

However, when attempting to load data which would result in anything other than one cube, an exception is raised::

filename = iris.sample_data_path('PP', 'ukV2', 'THOxayrk.pp')
filename = iris.sample_data_path('PP', 'ukV2', 'THOxayrk_subset.pp')
cube = iris.load_strict(filename)

.. note::
Expand All @@ -214,7 +214,7 @@ This fact can be utilised to make code only run successfully if the data provide
For example, suppose that code needed 'air_potential_temperature' in order to run::

import iris
filename = iris.sample_data_path('PP', 'ukV2', 'THOxayrk.pp')
filename = iris.sample_data_path('PP', 'ukV2', 'THOxayrk_subset.pp')
air_pot_temp = iris.load_strict(filename, 'air_potential_temperature')
print air_pot_temp

Expand All @@ -223,7 +223,7 @@ Should the file not contain exactly one cube with a standard name of air potenti
Similarly, supposing a routine needed both 'surface_altitude' and 'specific_humidity' to be able to run::

import iris
filename = iris.sample_data_path('PP', 'ukV2', 'THOxayrk.pp')
filename = iris.sample_data_path('PP', 'ukV2', 'THOxayrk_subset.pp')
altitude_cube, humidity_cube = iris.load_strict(filename, ['surface_altitude', 'specific_humidity'])

The result of :func:`iris.load_strict` in this case will be a list of 2 cubes ordered by the constraints provided.
Expand Down
10 changes: 5 additions & 5 deletions docs/iris/src/userguide/navigating_a_cube.rst
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ model mean that the run is spread over several days.

If we try to load the data directly for air_temperature:

>>> filename = iris.sample_data_path('PP', 'GloSea4', 'prodf*_???.pp')
>>> filename = iris.sample_data_path('PP', 'GloSea4', 'prodf*_???_subset.pp')
>>> print iris.load(filename, 'precipitation_flux')
0: precipitation_flux (forecast_reference_time: 2; time: 6; latitude: 145; longitude: 192)
1: precipitation_flux (forecast_reference_time: 2; time: 6; latitude: 145; longitude: 192)
Expand All @@ -193,8 +193,8 @@ In this case, two of the PP files have been encoded without the appropriate ``re
the appropriate coordinate cannot be added to the resultant cube. Fortunately, the missing attribute has been encoded in the filename
which, given the filename, we could extract::

filename = iris.sample_data_path('PP', 'GloSea4', 'prodf_op_sfc_cam_11_20110718_001.pp')
realization = int(filename[-6:-3])
filename = iris.sample_data_path('PP', 'GloSea4', 'prodf_op_sfc_cam_11_20110718_001_subset.pp')
realization = int(filename[-13:-10])
print realization

We can solve this problem by adding the appropriate metadata, on load, by using a callback function, which runs on a field
Expand All @@ -209,11 +209,11 @@ by field basis *before* they are automatically merged together:
def lagged_ensemble_callback(cube, field, filename):
# Add our own realization coordinate if it doesn't already exist.
if not cube.coords('realization'):
realization = numpy.int32(filename[-6:-3])
realization = numpy.int32(filename[-13:-10])
ensemble_coord = icoords.AuxCoord(realization, standard_name='realization')
cube.add_aux_coord(ensemble_coord)

filename = iris.sample_data_path('PP', 'GloSea4', 'prodf*_???.pp')
filename = iris.sample_data_path('PP', 'GloSea4', 'prodf*_???_subset.pp')

print iris.load(filename, 'precipitation_flux', callback=lagged_ensemble_callback)

Expand Down
12 changes: 6 additions & 6 deletions docs/iris/src/userguide/reducing_a_cube.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Cube extraction
^^^^^^^^^^^^^^^^
A subset of a cube can be "extracted" from a multi-dimensional cube in order to reduce its dimensionality::

filename = iris.sample_data_path('PP', 'globClim1', 'theta.pp')
filename = iris.sample_data_path('PP', 'globClim1', 'theta_subset.pp')
cube = iris.load_strict(filename)
print cube
equator_slice = cube.extract(iris.Constraint(latitude=0))
Expand Down Expand Up @@ -51,7 +51,7 @@ For example to get a model_level_number of 10 at the equator the following line

The two steps required to get ``model_level_number`` of 10 at the equator can be simplified into a single constraint::

filename = iris.sample_data_path('PP', 'globClim1', 'theta.pp')
filename = iris.sample_data_path('PP', 'globClim1', 'theta_subset.pp')
cube = iris.load_strict(filename)
equator_model_level_10_slice = cube.extract(iris.Constraint(latitude=0, model_level_number=10))
print equator_model_level_10_slice
Expand All @@ -62,7 +62,7 @@ same way as loading with constraints::

air_temp_and_fp_6 = iris.Constraint('air_potential_temperature', forecast_period=6)
level_10 = iris.Constraint(model_level_number=10)
filename = iris.sample_data_path('PP', 'ukV2', 'THOxayrk.pp')
filename = iris.sample_data_path('PP', 'ukV2', 'THOxayrk_subset.pp')
cubes = iris.load(filename).extract(air_temp_and_fp_6 & level_10)
print cubes

Expand All @@ -74,7 +74,7 @@ For example, to deal with a 3 dimensional cube (z,y,x) you could iterate over al
which make up the full 3d cube.::

import iris
filename = iris.sample_data_path('PP', 'globClim1', 'theta.pp')
filename = iris.sample_data_path('PP', 'globClim1', 'theta_subset.pp')
cube = iris.load_strict(filename)
print cube
for yx_slice in cube.slices(['latitude', 'longitude']):
Expand All @@ -93,7 +93,7 @@ line ``print repr(yx_slice)`` was run 38 times.
This method can handle n-dimensional slices by providing more or fewer coordinate names in the list to **slices**::

import iris
filename = iris.sample_data_path('PP', 'globClim1', 'theta.pp')
filename = iris.sample_data_path('PP', 'globClim1', 'theta_subset.pp')
cube = iris.load_strict(filename)
print cube
for i, x_slice in enumerate(cube.slices(['longitude'])):
Expand Down Expand Up @@ -152,7 +152,7 @@ Here are some examples of array indexing in :py:mod:`numpy`::
Similarly, Iris cubes have indexing capability::

import iris
filename = iris.sample_data_path('PP', 'globClim1', 'theta.pp')
filename = iris.sample_data_path('PP', 'globClim1', 'theta_subset.pp')
cube = iris.load_strict(filename)

print cube
Expand Down
Loading