nctoolkit.DataSet.subtract

DataSet.subtract(self, x=None, var=None)

Subtract from a dataset This will subtract a constant, another dataset or a NetCDF file from the dataset. :param x: An int, float, single file dataset or netcdf file to subtract from the dataset.

If a dataset or netcdf is supplied this must only have one variable, unless var is provided. The grids must be the same.

Parameters

var (str) – A variable in the x to use for the operation

Examples

If you wanted to subtract 10 from all variables in a dataset, you would do the following:

>>> data.subtract(10)

To substract the values in a dataset data2 from those in a dataset data1, you would do the following:

>>> data1.subtract(data2)

Grids in the datasets must match. Division will occur in matching timesteps in data1 and data2 if there are matching timesteps. If there is only 1 timestep in data2, then the data from that timestep in data2 will be subtracted from the data in all timesteps in data1.

Subtracting of the data from another NetCDF file will work in the same way:

>>> data1.subtract("example.nc")