Replacing data values
- remote_sensing_processor.replace_value(input_path, values=None, old=None, new=None, output_path=None, write_stac=True)[source]
Replaces specific values in a raster.
- Parameters:
input_path (string or STAC Item) – Path to input file, directory or STAC dataset or a STAC Item (e.g., from Planetary Computer).
values (dict of ints or floats (optional)) – Mapping from old values to new values.
old (int or float (optional)) – An old value to replace.
new (int or float (optional)) – A new value to insert.
output_path (string (optional)) – Path to an output file, directory, or STAC dataset. If not set, then will overwrite the input files. Must be set if input is a remote STAC Item.
write_stac (bool (default = True)) – If True, then output metadata is saved to a STAC file.
- Returns:
Path where output raster is saved.
- Return type:
pathlib.Path
Examples
>>> import remote_sensing_processor as rsp >>> rsp.replace_value( ... input_path="/home/rsp_test/mosaics/sentinel/B1.tif", ... output_path="/home/rsp_test/mosaics/sentinel/B1_new.tif", ... old=0, ... new=-9999, ... )
>>> rsp.replace_value( ... input_path="/home/rsp_test/replace/WorldCover.tif", ... output_path="/home/rsp_test/replace/WorldCover_replaced.tif", ... values={10: 1, 20: 1, 30: 2, 40: 2, 50: 4, 60: 4, 70: 3, 80: 2, 90: 1, 100: 2}, ... )
- remote_sensing_processor.replace_nodata(input_path, new, old=None, output_path=None, write_stac=True)[source]
Replaces a nodata value in a raster.
- Parameters:
input_path (string or STAC Item) – Path to input file, directory or STAC dataset or a STAC Item (e.g., from Planetary Computer).
new (int or float) – A new nodata value to insert.
old (int or float (optional)) – An old nodata value to replace. If not set, then is read from inputs.
output_path (string (optional)) – Path to an output file, directory, or STAC dataset. If it is not set, then will overwrite the input files. Must be set if input is a remote STAC Item.
write_stac (bool (default = True)) – If True, then output metadata is saved to a STAC file.
- Returns:
Path where output raster is saved.
- Return type:
pathlib.Path
Examples
>>> import remote_sensing_processor as rsp >>> rsp.replace_nodata( ... input_path="/home/rsp_test/mosaics/landcover/landcover.tif", ... output_path="/home/rsp_test/mosaics/landcover/landcover_new.tif", ... new=0, ... )
- remote_sensing_processor.replace_nan(input_path, output_path=None, new=None, write_stac=True)[source]
Replaces nans with a nodata value.
- Parameters:
input_path (string or STAC Item) – Path to input file, directory or STAC dataset or a STAC Item (e.g., from Planetary Computer).
output_path (string (optional)) – Path to an output file, directory, or STAC dataset. If it is not set, then will overwrite the input files. Must be set if input is a remote STAC Item.
new (int or float (optional)) – A new nodata value to insert. If not set, then is read from inputs.
write_stac (bool (default = True)) – If True, then output metadata is saved to a STAC file.
- Returns:
Path where output raster is saved.
- Return type:
pathlib.Path
Examples
>>> import remote_sensing_processor as rsp >>> rsp.replace_nan( ... input_path="/home/rsp_test/mosaics/landcover/landcover.tif", ... output_path="/home/rsp_test/mosaics/landcover/landcover_new.tif", ... new=0, ... )