earthlib.read
Functions for reading specifically formatted data, mostly spectral libraries.
check_file(path)
¶
Verifies whether a file exists and can be read.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
the file path to check. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
file status. |
Source code in earthlib/read.py
16 17 18 19 20 21 22 23 24 25 | |
envi_library(path, sensor=None)
¶
Reads the raw contents of an ENVI spectral library.
This is the low-level reader shared by earthlib.read.spectral_library and
earthlib.endmembers.Spectra.from_sli.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
path to the spectral library file. Searches for a .hdr sidecar. |
required |
sensor
|
Sensor | None
|
sensor information not recorded in the .hdr file. Derived from the header when None. |
None
|
Returns:
| Type | Description |
|---|---|
tuple[ndarray, list[str], Sensor]
|
the spectra array, the spectrum names, and the sensor. |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
when no readable header accompanies the library. |
Source code in earthlib/read.py
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 | |
envi_output_paths(path)
¶
Formats the pair of output paths used to write an ENVI spectral library.
Handles both header naming conventions, so a path produced by
find_envi_header round-trips back to the library it came from.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
the base file path, with or without an extension. |
required |
Returns:
| Type | Description |
|---|---|
tuple[str, str]
|
the spectral library path and the header path. |
Example
sli, hdr = envi_output_paths("spectra")
Source code in earthlib/read.py
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 | |
find_envi_header(path)
¶
Locates the ENVI header file that accompanies a spectral library.
Handles both header naming conventions: a sidecar that replaces the data
file's extension (spectra.hdr) and one that appends to it
(spectra.sli.hdr).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
path to the spectral library, or to the header itself. |
required |
Returns:
| Type | Description |
|---|---|
str
|
path to the header file. |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
when no readable header accompanies the library. |
Example
hdr = find_envi_header("spectra.sli")
Source code in earthlib/read.py
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | |
jfsp(path)
¶
Reads JFSP-formatted ASCII files.
Reads the ASCII format spectral data from the Joint Fire Science Program and returns an object with the mean and ± standard deviation reflectance.
www.frames.gov/assessing-burn-severity/spectral-library/overview
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
file path to the JFSP spectra text file. |
required |
Returns:
| Type | Description |
|---|---|
Spectra
|
an earthlib Spectra with the JFSP reflectance data. |
Example
spectra = jfsp("jfsp_graysoil.txt")
Source code in earthlib/read.py
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 | |
spectral_library(path, sensor=None, metadata=None)
¶
Reads an ENVI-format spectral library into memory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
path to the spectral library file. Searches for a .hdr sidecar. |
required |
sensor
|
Sensor | None
|
sensor information not recorded in the .hdr file. |
None
|
metadata
|
DataFrame | None
|
dataframe of per-spectrum metadata. |
None
|
Returns:
| Type | Description |
|---|---|
Spectra
|
endmembers from the spectral library. |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
when no readable header accompanies the library. |
Example
spectra = spectral_library("spectra.sli")
Source code in earthlib/read.py
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 | |