Dimension Reduction Functions
Functions
- class xr_fresh.dimension_reduction.ExtendedGeoWombatAccessor(xarray_obj)[source]
- Attributes:
affineGet the affine transform object.
altitudeGet satellite altitudes (in km)
array_is_daskGet whether the array is a Dask array.
avail_sensorsGet supported sensors.
band_chunksGet the band chunk size.
bottomGet the array bounding box bottom coordinate.
boundsGet the array bounding box (left, bottom, right, top)
bounds_as_namedtupleGet the array bounding box as a
rasterio.coords.BoundingBoxcellxGet the cell size in the x direction.
cellxhGet the half width of the cell size in the x direction.
cellyGet the cell size in the y direction.
cellyhGet the half width of the cell size in the y direction.
central_umGet a dictionary of central wavelengths (in micrometers)
chunk_gridGet the image chunk grid.
col_chunksGet the column chunk size.
crs_to_pyprojGet the CRS as a
pyproj.CRSobject.data_are_separateChecks whether the data are loaded separately.
data_are_stackedChecks whether the data are stacked.
dtypeGet the data type of the DataArray.
filenamesGets the data filenames.
footprint_gridGet the image footprint grid.
geodataframeGet a
geopandas.GeoDataFrameof the array bounds.geometryGet the polygon geometry of the array bounding box.
has_bandCheck whether the DataArray has a band attribute.
has_band_coordCheck whether the DataArray has a band coordinate.
has_band_dimCheck whether the DataArray has a band dimension.
has_timeCheck whether the DataArray has a time attribute.
has_time_coordCheck whether the DataArray has a time coordinate.
has_time_dimCheck whether the DataArray has a time dimension.
leftGet the array bounding box left coordinate.
metaGet the array metadata.
nbandsGet the number of array bands.
ncolsGet the number of array columns.
ndimsGet the number of array dimensions.
nodatavalGet the ‘no data’ value from the attributes.
nrowsGet the number of array rows.
ntimeGet the number of time dimensions.
offsetvalGet the offset value.
pydatetimeGet Python datetime objects from the time dimension.
rightGet the array bounding box right coordinate.
row_chunksGet the row chunk size.
scalevalGet the scale factor value.
sensor_namesGet sensor full names.
time_chunksGet the time chunk size.
topGet the array bounding box top coordinate.
transformGet the data transform (cell x, 0, left, 0, cell y, top)
unary_unionGet a representation of the union of the image bounds.
wavelengthsGet a dictionary of sensor wavelengths.
Methods
apply(filename, user_func[, n_jobs])Applies a user function to an Xarray Dataset or DataArray and writes to file.
assign_nodata_attrs(nodata)Assigns 'no data' attributes.
avi([nodata, mask, sensor, scale_factor])Calculates the advanced vegetation index
band_mask(valid_bands[, src_nodata, ...])Creates a mask from band nonzeros.
bounds_overlay(bounds[, how])Checks whether the bounds overlay the image bounds.
calc_area(values[, op, units, row_chunks, ...])Calculates the area of data values.
check_chunksize(chunksize, array_size)Asserts that the chunk size fits within intervals of 16 and is smaller than the array.
clip(df[, query, mask_data, expand_by])Clips a DataArray by vector polygon geometry.
clip_by_polygon(df[, query, mask_data, ...])Clips a DataArray by vector polygon geometry.
compare(op, b[, return_binary])Comparison operation.
compute(**kwargs)Computes data.
evi([nodata, mask, sensor, scale_factor])Calculates the enhanced vegetation index
evi2([nodata, mask, sensor, scale_factor])Calculates the two-band modified enhanced vegetation index
extract(aoi[, bands, time_names, ...])Extracts data within an area or points of interest.
gcvi([nodata, mask, sensor, scale_factor])Calculates the green chlorophyll vegetation index
imshow([mask, nodata, flip, text_color, rot])Shows an image on a plot.
k_pca(gamma, n_components, n_workers, chunk_size)Applies Kernel PCA to the dataset and returns a DataArray with the components as bands.
kndvi([nodata, mask, sensor, scale_factor])Calculates the kernel normalized difference vegetation index
mask(df[, query, keep])Masks a DataArray.
mask_nodata()Masks 'no data' values with nans.
match_data(data, band_names)Coerces the
xarray.DataArrayto match anotherxarray.DataArray.moving([stat, perc, w, nodata, weights])Applies a moving window function to the DataArray.
n_windows([row_chunks, col_chunks])Calculates the number of windows in a row/column iteration.
nbr([nodata, mask, sensor, scale_factor])Calculates the normalized burn ratio
ndvi([nodata, mask, sensor, scale_factor])Calculates the normalized difference vegetation index
norm_brdf(solar_za, solar_az, sensor_za, ...)Applies Bidirectional Reflectance Distribution Function (BRDF) normalization.
norm_diff(b1, b2[, nodata, mask, sensor, ...])Calculates the normalized difference band ratio.
read(band, **kwargs)Reads data for a band or bands.
recode(polygon, to_replace[, num_workers])Recodes a DataArray with polygon mappings.
replace(to_replace)Replace values given in
to_replacewith value.sample([method, band, n, strata, spacing, ...])Generates samples from a raster.
save(filename[, mode, nodata, overwrite, ...])Saves a DataArray to raster using rasterio/dask.
set_nodata([src_nodata, dst_nodata, ...])Sets 'no data' values and applies scaling to an
xarray.DataArray.subset([left, top, right, bottom, rows, ...])Subsets a DataArray.
tasseled_cap([nodata, sensor, scale_factor])Applies a tasseled cap transformation
to_netcdf(filename, *args, **kwargs)Writes an Xarray DataArray to a NetCDF file.
to_polygon([mask, connectivity])Converts a
daskarray to aGeoDataFrameto_raster(filename[, readxsize, readysize, ...])Writes an Xarray DataArray to a raster file.
to_vector(filename[, mask, connectivity])Writes an Xarray DataArray to a vector file.
to_vrt(filename[, overwrite, resampling, ...])Writes a file to a VRT file.
transform_crs([dst_crs, dst_res, dst_width, ...])Transforms an
xarray.DataArrayto a new coordinate reference system.wi([nodata, mask, sensor, scale_factor])Calculates the woody vegetation index
windows([row_chunks, col_chunks, ...])Generates windows for a row/column iteration.
- k_pca(gamma: float, n_components: int, n_workers: int, chunk_size: int) DataArray[source]
Applies Kernel PCA to the dataset and returns a DataArray with the components as bands.
- Parameters:
gamma (float) – The gamma parameter for the RBF kernel.
n_components (int) – The number of components to keep.
n_workers (int) – The number of parallel jobs for KernelPCA and ParallelTask.
chunk_size (int) – The size of the chunks for processing.
- Returns:
A DataArray with the Kernel PCA components as bands.
- Return type:
xr.DataArray
Examples: .. code-block:: python
import xr_fresh.dimension_reduction # This registers the accessor
# Initialize Ray with ray.init(num_cpus=8) as rays:
# Example usage with gw.open(
- sorted(
- [
“./tests/data/RadT_tavg_202301.tif”, “./tests/data/RadT_tavg_202302.tif”, “./tests/data/RadT_tavg_202304.tif”, “./tests/data/RadT_tavg_202305.tif”,
]
), stack_dim=”band”, band_names=[0, 1, 2, 3],
- ) as src:
# get 3 k principal components - base zero counting transformed_dataarray = src.gw_ext.k_pca(
gamma=15, n_components=3, n_workers=8, chunk_size=256
) transformed_dataarray.plot.imshow(col=’component’, col_wrap=1, figsize=(8, 12)) plt.show()