nctoolkit.DataSet.subtract#
- DataSet.subtract(x=None, var=None)#
subtract: Subtract from a dataset.
This will subtract a constant, another dataset or a netCDF file from the dataset.
- Parameters:
x (int, float, DataSet or netCDF file) – 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.
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:
>>> ds.subtract(10)
Or, you could use standard python subtraction syntax:
>>> ds - 10
To substract the values in a dataset ds2 from those in a dataset ds1, you would do the following:
>>> ds1.subtract(ds2)
Or, you could use standard python subtraction syntax:
>>> ds1 - ds2
Grids in the datasets must match. Division will occur in matching timesteps in ds1 and ds2 if there are matching timesteps. If there is only 1 timestep in ds2, then the data from that timestep in ds2 will be subtracted from the data in all timesteps in ds1.