hytools package

Subpackages

Submodules

hytools.base module

HyTools: Hyperspectral image processing library Copyright (C) 2021 University of Wisconsin

Authors: Adam Chlus, Zhiwei Ye, Philip Townsend.

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 3 of the License.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.

Base

TODO: Add corrections to ndi()

class hytools.base.Decoder(*, object_hook=None, parse_float=None, parse_int=None, parse_constant=None, strict=True, object_pairs_hook=None)[source]

Bases: JSONDecoder

decode(s)[source]

Return the Python representation of s (a str instance containing a JSON document).

class hytools.base.HyTools[source]

Bases: object

HyTools file object

close_data()[source]

Close data object.

correct(data, dimension, index, corrections)[source]
cosine_i()[source]

Calculate the cosine of the solar incidence angle. Assumes path to required ancillary datasets have been specified.

Returns

Cosine of solar incidence angle.

Return type

cos_i numpy.ndarray

create_bad_bands(bad_regions)[source]

Create bad bands mask, Good: True, bad : False.

Parameters
  • bad_regions (list of lists) – start and end values of wavelength

  • as (regions considered bad. Wavelengths should be in the same units) –

  • ex (data units.) – [[350,400]…..[2450,2500]].

Returns

None.

do(function, args=None)[source]

Run a function and return the results.

gen_mask(masker, name, args=None)[source]

Generate mask using masking function which takes a HyTools object as an argument.

geom_kernel(kernel, b_r=1.0, h_b=2.0)[source]

Calculate volume scattering kernel.

get_anc(anc, radians=True, mask=None)[source]

Read ancillary datasets to memory.

Parameters
  • anc (str) – Ancillary dataset name.

  • radians (bool, optional) – Convert angular measures to radians. Defaults to True.

Returns

anc_data (numpy.ndarray)

get_band(index, corrections=[], mask=None)[source]
Parameters
  • index (int) – Zero-indexed band index.

  • mask (str) – Return masked values using named mask.

  • corrections (list) – Corrections to apply, will be applied in

  • listed. (order) –

Returns

A 2D (lines x columns) array or 1D if masked.

Return type

numpy.ndarray

get_chunk(col_start, col_end, line_start, line_end, corrections=[], resample=False)[source]
Parameters
  • col_start (int) – Chunk starting column.

  • col_end (int) – Noninclusive chunk ending column index.

  • line_start (int) – Chunk starting line.

  • line_end (int) – Noninclusive chunk ending line index.

  • corrections (list) – Corrections to apply, will be applied in

  • listed. (order) –

  • resample (bool) – Resample wavelengths. Defaults to False.

Returns

Chunk array (line_end-line_start,col_end-col_start,bands).

Return type

numpy.ndarray

get_column(index, corrections=[], resample=False)[source]
Parameters

index (int) – Zero-indexed column index.

Returns

Column array (lines, bands).

Return type

numpy.ndarray

get_header()[source]

Return header dictionary

get_line(index, corrections=[], resample=False)[source]
Parameters

index (int) – Zero-indexed line index.

Returns

Line array (columns, bands).

Return type

numpy.ndarray

get_pixels(lines, columns, corrections=[], resample=False)[source]
Parameters
  • lines (list) – List of zero-indexed line indices.

  • columns (list) – List of zero-indexed column indices.

Returns

Pixel array (pixels,bands).

Return type

numpy.ndarray

get_wave(wave, corrections=[], mask=None)[source]

Return the band image corresponding to the input wavelength. If not an exact match the closest wavelength will be returned.

Parameters
  • wave (float) – Wavelength in image units.

  • mask (str) – Return masked values using named mask.

Returns

Band image array (line,columns).

Return type

numpy.ndarray

iterate(by, chunk_size=(100, 100), corrections=[], resample=False)[source]

Create data Iterator.

Parameters
  • by (str) – Dimension along which to iterate: “line”,”column”,”band”,”chunk”.

  • chunk_size (tuple, optional) – Two dimensional chunk size (Y,X). Applies only when “chunk” selected. Defaults to (100,100).

Returns

Data Iterator.

Return type

Iterator class object

load_anc(anc, radians=True)[source]
load_coeffs(coeff_file, kind)[source]
load_data(mode='r')[source]

Load data object to memory.

Parameters
  • mode (str, optional) – File read mode. Defaults to ‘r’.

  • offset (int, optional) – Offset in bytes. Defaults to 0.

Returns

None.

ndi(wave1=850, wave2=660, mask=None)[source]
Calculate normalized difference index.

Defaults to NDVI. Assumes input wavelengths are in nanometers

Parameters
  • wave1 (int,float) – Wavelength of first band. Defaults to 850.

  • wave2 (int,float) – Wavelength of second band. Defaults to 660.

  • mask (bool) – Mask data

Return type

ndi numpy.ndarray

read_file(file_name, file_type='envi', anc_path=None, ext=False)[source]
set_mask(mask, name)[source]

Generate mask using masking function which takes a HyTools object as an argument.

volume_kernel(kernel)[source]

Calculate volume scattering kernel.

wave_to_band(wave)[source]
Return band index corresponding to input wavelength. Return closest band if

not an exact match.

Parameters

wave (float) – Wavelength of band to be retrieved in image wavelength units.

Returns

Band index.

Return type

int

class hytools.base.Iterator(hy_obj, by, chunk_size=None, corrections=[], resample=False)[source]

Bases: object

Iterator class

read_next()[source]

Return next line/column/band/chunk.

reset()[source]

Reset counters.

Module contents

HyTools: Hyperspectral image processing library Copyright (C) 2021 University of Wisconsin

Authors: Adam Chlus, Zhiwei Ye, Philip Townsend.

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 3 of the License.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.

Initialize hytools