set_values
- set_values(fs, values[, mode])
Creates a new fieldset with all the values in
fsreplaced byvalues.- Parameters
fs (
Fieldset) – input fieldsetvalues (ndarray or list of ndarray) – values to be written into
fsmode (str) – resize mode. If specified must be set to “resize”.
- Return type
If
valuesis an ndarray the same values are set in each field offs.If
valuesis a list of ndarray the list size must be same as the number of fields infs.The default behaviour is to produce an error if the number points in a field and the given ndarray are not the same. If, however,
modeis specified and set to “resize” the resulting fieldset will be resized to have the same number of values as the ndarray. This can be a useful option when creating a newFieldsetfrom a template.Missing values in the
valuesare retained as missing values in the fieldset.
- set_values(gpt, values)
- set_values(gpt, index_or_name, values)
Creates a new
Geopointswith the specified values column ingptreplaced byvalues.- Parameters
gpt (
Geopoints) – input geopointsindex_or_name (number or str) – index or name of the values column to be replaced in
gptvalues (number or list or ndarray) – values to be written into
gpt
- Return type
If
index_or_nameis specified and is a number it refers to the index of the column within the value columns (and not within all the columns ingpt). E.g. 0 means the first value column.index_or_namehas to be used forGeopointsof ‘ncols’ type. In all the other types the values column is uniquely identified.If
valuesis a number all the values are replaced with it. Ifvaluesis a list or ndarray and is shorter than the geopoints count then only the first values that have a corresponding value invaluesare changed.- Example
import metview as mv new_gpt_b = set_values(gpt_b, np.array([12.4, 13.3, 1.1])) # update the 4th value column new_gpt_c = set_values(gpt_c, 3, np.array([3.3, 4.4, 5.5])) # update the column labelled "precip" new_gpt_d = set_values(gpt_d, "precip", np.array([0.3, 0.2, 0.1]))
Note
set_values()generates a new geopoints object, leaving the original one intact. If you wish to modify the original object, then a more efficient way is to directly access the columns using the following syntax, following the examples above:gpt['value'] = np.array([2.4, 13.3, 1.1]) gpt[name_of_column_4] = np.array([3.3, 4.4, 5.5]) gpt["precip"] = np.array([0.3, 0.2, 0.1])