cwt package

Submodules

cwt.wps module

A WPS Client

class cwt.wps.WPS(url, username=None, password=None, **kwargs)

Bases: object

capabilities

Attempts to retrieve and return the WPS servers capabilities document.

describe(process, method='GET')

Return a DescribeProcess response.

Parameters:
  • process – An object of type Process to describe.
  • method – A string HTTP method to use.
Returns:

A DescribeProcessResponse object.

execute(process, inputs=None, domain=None, method='POST', **kwargs)

Execute the process on the WPS server.

Parameters:
  • process – A Process object to be executed on the WPS server.
  • inputs – A list in Variables/Processes.
  • domain – A Domain object to be used.
  • kwargs – A dict containing additional arguments.
get_process(identifier, method='GET')

Return a specified process.

Parameters:identifier – A string process identifier.
Returns:The specified process instance.
Raises:Exception – A process with identifier was not found.
static parse_data_inputs(data_inputs)

Parses a data_inputs string

The data_inputs string follows this format:

[variable=[];domain=[];operation=[]]

Parameters:data_inputs – A string containing the processes data_inputs
Returns:A tuple containing the a list of operations, domains and variables object contained in the data_inputs string.
prepare_data_inputs(process, inputs, domain, **kwargs)

Creates the data_inputs string.

processes(regex=None, refresh=False, method='GET')

Returns a list of WPS processes.

Parameters:
  • regex – A string regex used to filter the processes by identifier.
  • refresh – A boolean to force a GetCapabilites refresh.
  • method – A string HTTP method.
Returns:

A GetCapabilities object.

exception cwt.wps.WPSError

Bases: exceptions.Exception

exception cwt.wps.WPSHTTPError

Bases: exceptions.Exception

exception cwt.wps.WPSHTTPMethodError

Bases: exceptions.Exception

cwt.process module

Process Module.

exception cwt.process.ProcessError

Bases: exceptions.Exception

class cwt.process.Process(identifier=None, process=None, name=None)

Bases: cwt.parameter.Parameter

A WPS Process

Wraps a WPS Process.

Parameters:
  • process – A DescribeProcessResponse object.
  • name – A string name for the process to be used as the input of another process.
add_parameters(*args, **kwargs)

Add a parameter.

kwargs can contain two formats.

k=v where v is a NamedParameter k=v where v is a string in the format of ‘x|y|z’

Parameters:
  • args – A list of NamedParameter objects.
  • kwargs – A dict of NamedParameter objects or k=v where k is the name and v is string.
collect_input_processes(processes=None, inputs=None)

Aggregates the process trees inputs.

A DFS to collect the trees inputs into two lists, Operations and Variables.

Parameters:
  • processes – A list of current processes discovered.
  • inputs – A list of Process/Variables to processes.
Returns:

A two lists, one of Processes and the other of Variables.

error

Check if the process has errored.

classmethod from_dict(data)

Attempts to load a process from a dict.

get_parameter(name, required=False)

Retrieves a parameter

Parameters:
  • name – A string name of the parameter.
  • required – A boolean flag denoting whether the parameter is required.
Returns:

A NamedParameter object.

Raises:

Exception – The parameter is required and not present.

identifier

Returns the processes identifier.

output

Return the output of the process if done.

parameterize()

Create a dictionary representation of the Process.

processing

Checks if the process is still working.

This will update the wrapper with the latest status and return True if the process is waiting or running.

Returns:A boolean denoting whether the process is still working.
resolve_inputs(inputs, operations)

Attempts to resolve the process inputs.

Resolves the processes inputs from strings to Process/Variable objects.

Parameters:
  • inputs – A dict of Variables where the key is name.
  • operations – A dict of Processes where the key is name.
set_inputs(*args)

Set the inputs of the Process.

Parameters:args – A list of Process/Variable objects.
update_status()

Retrieves the latest process status.

cwt.variable module

Variable module.

class cwt.variable.Variable(uri, var_name, **kwargs)

Bases: cwt.parameter.Parameter

Variable.

Describes a variable to be used by an Operation.

>>> tas = Variable('http://thredds/tas.nc', 'tas', name='tas')
uri

A String URI for the file containing the variable data.

var_name

A String name of the variable.

domains

List of domain.Domain objects to constrain the variable data.

mime_type

A String name of the URI mime-type.

name

Custom name of the Variable.

classmethod from_dict(data)

Create variable from dict representation.

localize(filename=None)
parameterize()

Parameterize variable for GET request.

resolve_domains(domains)

Resolves the domain identifiers to objects.

cwt.domain module

Domain Module.

class cwt.domain.Domain(dimensions=None, mask=None, name=None)

Bases: cwt.parameter.Parameter

Domain.

A domain consist of one or more dimensions. A mask can be associated with a domain, further construing the domain being represented.

Simple domain.

>>> domain = Domain([Dimesnion(90, -90, Dimension.values)])

Domain with a mask.

>>> domain = Domain([
        Dimension(90, -90, Dimension.values, name='lon'),
        Dimension(0, 90, Dimension.values, name='lat'),
    ],
    mask = Mask('http://thredds/clt.nc', 'clt', 'var_data<0.5'))
dimensions

List of Dimensions.

mask

Mask to be applied to the domain.

name

Name of the domain.

add_dimension(dimension)

Add a dimension.

classmethod from_dict(data)

Creates domain from dict reperesentation.

get_dimension(names)
parameterize()

Returns parameter for GET request.

cwt.dimension module

Dimension module.

class cwt.dimension.CRS(name)

Bases: object

Coordinate Reference System (CRS).

Provides information about the CRS of a dimensions values.

name

A String name of the CRS.

class cwt.dimension.Dimension(name, start, end, crs=CRS(name=values), step=None)

Bases: cwt.parameter.Parameter

Dimension.

Describes a dimension of a plane. This dimension can be constrained between two points and the length between each step can be specified or it will default to 1.

There are two pre-defined CRS’s; indices and values.

A dimension starting at 90, ending at -90 with step width of 0.5 degrees.

>>> lat = Dimension(90, -90, Dimension.values, step=0.5)

A dimension representing a single point at 90.

>>> lat = Dimension.from_single_value(90)

A dimension with a custom name.

>>> lat = Dimension(90, -90, Dimension.values, step=0.5, name='lat')
start

A (str, int, float) of the starting point.

end

A (str, int, float) of the ending point.

crs

The CRS of the start and end points.

step

The distance between each step between the start and end points.

classmethod from_dict(data, name)

Create dimension from dict representation.

classmethod from_single_index(name, value, step=None)

Creates dimension from single index.

classmethod from_single_value(name, value, step=None)

Creates dimension from single value.

parameterize()

Parameterizes object for get queries.

cwt.gridder module

Gridder Module.

class cwt.gridder.Gridder(tool='esmf', method='linear', grid='T85')

Bases: cwt.parameter.Parameter

Gridder.

Describes the regridder and target grid for an operation.

Gridder from a known target grid.

>>> Gridder('esmf', 'linear', 'T85')

Gridder from a Domain.

>>> new_grid = Domain([Dimension(90, -90, step=1)], name='lat')
>>> Gridder('esmf', 'linear', new_grid)

Gridder from a Variable.

>>> tas = Variable('http://thredds/tas.nc', 'tas', name='tas')
>>> Gridder('esmf', 'linear', tas)
tool

A String name of the regridding tool to be used.

method

A String method that the regridding tool will use.

grid

A String, Domain or Variable of the target grid.

classmethod from_dict(data)
parameterize()

Parameterizes a gridder.

cwt.mask module

Mask Module.

class cwt.mask.Mask(uri, var_name, operation, name=None)

Bases: object

Mask.

Describes a mask to be applied to a give domain.

There are some resvered words.

  • var_data
  • mask_data
  • sin
  • cos
  • tan
var_data: refers to the data in the variable that the domain is being
applied to.

mask_data: refers to the data in masks URI.

Masks out points in the domain where the mask_data of the location is less than 0.5.

>>> lsm = Mask('http://thredds/clt.nc', 'clt', 'mask_data<0.5')
uri

URI of the file containing the mask.

var_name

Name of the variable that will be used in the operation.

operation

Expression that defines where the mask is activate.

name

Custom name for the mask.

classmethod from_dict(data)

Create mask from dict representation.

parameterize()

Create a parameter from mask.

cwt.named_parameter module

NamedParameter Module.

class cwt.named_parameter.NamedParameter(name, args)

Bases: cwt.parameter.Parameter

Named Parameter.

Describes a parameter to be passed to an Operation.

A NamedParameter with a single value.

>>> axis = NamedParameter('axis', 'time')

A NamedParameter with multiple values.

>>> axes = NamedParameter('axes', 'latitude', 'longitude')
name

Name of the parameter.

*args

Values of the parameter.

classmethod from_string(name, values)

Creates NamedParameter from string value.

parameterize()

Parameterizes NamedParameter for GET request.

Module contents

WPS Client library imports.