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

difference calculation #7

Open
marqh opened this issue Oct 18, 2017 · 4 comments
Open

difference calculation #7

marqh opened this issue Oct 18, 2017 · 4 comments

Comments

@marqh
Copy link
Member

marqh commented Oct 18, 2017

Introduced a form_of_difference attribute to indicate in which direction the difference is being calculated. A difference cell method is also added to indicate along which axis the difference has been calculated and over what length in grid cells.

difference_of_standard_orography / (m) (projection_y_coordinate: 969; projection_x_coordinate: 1042)
     Dimension coordinates:
          projection_y_coordinate                              x                             -
          projection_x_coordinate                              -                             x
     Attributes:
          Conventions: CF-1.5
          form_of_difference: forward_difference
     Cell methods:
          difference: projection_y_coordinate (1 grid length)
@marqh
Copy link
Member Author

marqh commented Oct 18, 2017

The attribute cell_methods has a grammar mandated by CF, in:
http://cfconventions.org/Data/cf-conventions/cf-conventions-1.7/cf-conventions.html#cell-methods
The allowed 'method' strings for a single cell method are defined by:
http://cfconventions.org/Data/cf-conventions/cf-conventions-1.7/cf-conventions.html#appendix-cell-methods

  • It is recommended that all cell_methods entries are CF compliant.

difference is not an allowed cell_method, so I recommend in this case that a cell_methods attribute is not used at all.
The name used indicates that this is a difference: difference_of_standard_orography

@marqh
Copy link
Member Author

marqh commented Oct 18, 2017

@marqh
Copy link
Member Author

marqh commented Oct 25, 2017

I am conscious that removing the cell_method has removed the reference to the projection_y_coordinate

I think this is an example of a core capability that we require for many definitions, the definition of a process with respect to a coordinate. I have raised this as a targeted issue: #9

@marqh
Copy link
Member Author

marqh commented Nov 16, 2017

A sample programme that would create a file similar to the above, whilst using enhanced naming:

import iris
import numpy as np
import os
import subprocess

iris.FUTURE.netcdf_no_unlimited = True

# Create a sample data set with unimportant data values.
acube = iris.cube.Cube(np.ones(6).reshape(3, 2), units='m', var_name='diff_so',
                       long_name='difference_of_standard_orography')

xcoord = iris.coords.DimCoord(np.arange(2), var_name='x_coord',
                              standard_name='projection_x_coordinate', units='1')
ycoord = iris.coords.DimCoord(np.arange(3), var_name='y_coord',
                              standard_name='projection_y_coordinate', units='1')


acube.add_dim_coord(xcoord, 1)
acube.add_dim_coord(ycoord, 0)

# Add context specific attributes to the sample data set
acube.attributes['spp__statistical_process'] = 'spv__difference'
acube.attributes['spp__with_respect_to'] = 'y_coord'
acube.attributes['spp__form_of_difference'] = 'spv__forward_difference'
acube.attributes['rdf__type'] = 'spd__statistically_processed_array'


# Create a prefix container and add prefixes to it
prefix_cube = iris.cube.Cube(0, long_name='prefixes', var_name='prefix_list')

prefix_cube.attributes['spp__'] = 'http://reference.metoffice.gov.uk/statistical-process/properties/'
prefix_cube.attributes['spv__'] = 'http://reference.metoffice.gov.uk/statistical-process/values/'
prefix_cube.attributes['spd__'] = 'http://reference.metoffice.gov.uk/statistical-process/def/'
prefix_cube.attributes['bald__'] = 'http://binary-array-ld.net/latest/'
prefix_cube.attributes['rdf__'] = 'http://www.w3.org/1999/02/22-rdf-syntax-ns#'

# place all cubes in a CubeList
cubelist = iris.cube.CubeList([acube, prefix_cube])

# Ensure that the 'bald__isPrefixedBy' attribute is present on all cubes,
# so that it is upgraded to a global attribute on the file.
for cube in cubelist:
    cube.attributes['bald__isPrefixedBy'] = 'prefix_list'

# Save to netCDF, then dump the header to stdout before deleting the file
fname = 'add_attrs.nc'
iris.save(cubelist, fname)
subprocess.check_call(['ncdump', '-h', fname ])
os.remove(fname)

This is provided to illustrate the use of prefixing for newly coined attribute names and values, and the definition of these prefixes within the file, making use of scitools' Iris to create data sets to write into a netCDF file

this programme produces:

netcdf add_attrs {
dimensions:
	y_coord = 3 ;
	x_coord = 2 ;
variables:
	double diff_so(y_coord, x_coord) ;
		diff_so:long_name = "difference_of_standard_orography" ;
		diff_so:units = "m" ;
		diff_so:rdf__type = "spd__statistically_processed_array" ;
		diff_so:spp__form_of_difference = "spv__forward_difference" ;
		diff_so:spp__statistical_process = "spv__difference" ;
		diff_so:spp__with_respect_to = "y_coord" ;
	int64 y_coord(y_coord) ;
		y_coord:axis = "Y" ;
		y_coord:units = "1" ;
		y_coord:standard_name = "projection_y_coordinate" ;
	int64 x_coord(x_coord) ;
		x_coord:axis = "X" ;
		x_coord:units = "1" ;
		x_coord:standard_name = "projection_x_coordinate" ;
	int64 prefix_list ;
		prefix_list:long_name = "prefixes" ;
		prefix_list:bald__ = "http://binary-array-ld.net/latest/" ;
		prefix_list:rdf__ = "http://www.w3.org/1999/02/22-rdf-syntax-ns#" ;
		prefix_list:spd__ = "http://reference.metoffice.gov.uk/statistical-process/def/" ;
		prefix_list:spp__ = "http://reference.metoffice.gov.uk/statistical-process/properties/" ;
		prefix_list:spv__ = "http://reference.metoffice.gov.uk/statistical-process/values/" ;

// global attributes:
		:bald__isPrefixedBy = "prefix_list" ;
		:Conventions = "CF-1.5" ;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant