diff --git a/README.md b/README.md index a907654..843e2f5 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,7 @@ Supported products include: - AVIRIS-NG L2A Reflectance - [EMIT L1B Radiance](https://lpdaac.usgs.gov/products/emitl1bradv001/) - [EMIT L2A Reflectance](https://lpdaac.usgs.gov/products/emitl2arflv001/) +- [PRISM Reflectance](https://daacweb-prod.ornl.gov/BIOSCAPE/guides/BioSCape_PRISM_L2A_RFL.html) - ENVI format inputs ## Installation @@ -25,6 +26,24 @@ Or with pip: pip install spectral_util ``` +## Python API + +Common IO access patterns - probably the single most useful thing in this repo - are provided acorss datasets. Use: +``` +from spectral_util.spec_io import load_data +meta, rfl = load_data('AV320250809t182459_000_L1B_RDN_4842d6a3_RDN.nc') +print(len(meta.wl)) +print(rfl.shape) +``` + +Will return: +``` +284 +(1280, 1234, 284) +``` + +load_data supports options for orthoing nc files that are not natively orthod (e.g. radiance .nc files) during read, and lazy loading (still only partially supported). All CLI options used below (and more) have supporint api function calls. + ## Running the CLI If installed into your current environment: @@ -195,15 +214,7 @@ spectral_util reformat nc-to-envi ./downloads/AV320250809t182459_000_L1B_RDN_484 spectral_util reformat nc-to-envi ./downloads/AV320250809t182459_000_L1B_RDN_4842d6a3_RDN.nc output_envi --overwrite ``` -## Python API - -For programmatic use: -```python -from spectral_util.common import quicklooks -from spectral_util.mosaic import mosaic -from spectral_util.ea_assist import earthaccess_helpers_AV3, earthaccess_helpers_EMIT -``` ## Help diff --git a/spectral_util/spec_io/spec_io.py b/spectral_util/spec_io/spec_io.py index 5025ef9..6256d4f 100644 --- a/spectral_util/spec_io/spec_io.py +++ b/spectral_util/spec_io/spec_io.py @@ -319,32 +319,34 @@ def open_netcdf(input_file, lazy=True, load_glt=False, load_loc=False, mask_type - numpy.ndarray or netCDF4.Variable: The data, either as a lazy-loaded variable or a fully loaded numpy array. """ input_filename = os.path.basename(input_file) - if 'emit' in input_filename.lower() and ('rad' in input_filename.lower() or 'rdn' in input_filename.lower()): + input_filename_lower = input_filename.lower() + + if 'emit' in input_filename_lower and ('rad' in input_filename_lower or 'rdn' in input_filename_lower): if return_loc_from_l1b_rad_nc: return open_loc_l1b_rad_nc(input_file, lazy=lazy, load_glt=load_glt) else: return open_emit_rdn(input_file, lazy=lazy, load_glt=load_glt) - if 'emit' in input_filename.lower() and 'rfl' in input_filename.lower(): + if 'emit' in input_filename_lower and 'rfl' in input_filename_lower: return open_emit_rfl(input_file, lazy=lazy, load_glt=load_glt) - elif ('emit' in input_filename.lower() and 'obs' in input_filename.lower()): + elif ('emit' in input_filename_lower and 'obs' in input_filename_lower): return open_emit_obs_nc(input_file, lazy=lazy, load_glt=load_glt, load_loc=load_loc) - elif ('emit' in input_filename.lower() and 'l2a_mask' in input_filename.lower()): + elif ('emit' in input_filename_lower and 'l2a_mask' in input_filename_lower): return open_emit_l2a_mask_nc(input_file, mask_type, lazy=lazy, load_glt=load_glt, load_loc=load_loc) - elif 'AV3' in input_filename and 'RFL' in input_filename: + + is_airborne_like = any(tag in input_filename_lower for tag in ['av3', 'ang', 'prm', 'prism']) + if is_airborne_like and 'rfl' in input_filename_lower: return open_airborne_rfl(input_file, lazy=lazy) - elif 'AV3' in input_filename and 'BANDMASK' in input_filename: + elif 'av3' in input_filename_lower and 'bandmask' in input_filename_lower: return open_av3_bandmask_nc(input_file, lazy=lazy) - elif 'AV3' in input_filename and 'RDN' in input_filename: + elif is_airborne_like and 'rdn' in input_filename_lower: if return_loc_from_l1b_rad_nc: return open_loc_l1b_rad_nc(input_file, lazy=lazy, load_glt=load_glt) else: return open_airborne_rdn(input_file, lazy=lazy) - elif ('av3' in input_filename.lower() or 'ang' in input_filename.lower()) and 'OBS' in input_filename: + elif is_airborne_like and 'obs' in input_filename_lower: return open_airborne_obs(input_file, lazy=lazy, load_glt=load_glt, load_loc=load_loc) - elif 'ang' in input_filename.lower() and 'rfl' in input_filename.lower(): - return open_airborne_rfl(input_file, lazy=lazy) else: raise ValueError(f'Unknown file type for {input_file}')