Skip to content

Commit

Permalink
Add pace module (#19)
Browse files Browse the repository at this point in the history
* Add pace module

* Add pace module to docs

* Update README

* Add docstrings
  • Loading branch information
giswqs authored Apr 30, 2024
1 parent 5428956 commit 431eee7
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 6 deletions.
11 changes: 8 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,16 @@

## Features

- Visualize hyperspectral data
- Analyze hyperspectral data
-
- Interactive visualization and analysis of hyperspectral data (e.g., [EMIT](https://earth.jpl.nasa.gov/emit/), [PACE](https://pace.gsfc.nasa.gov/))
- Interactive extraction and visualization of spectral signatures
- Saving spectral signatures as CSV files

## Demo

- Visualizing spectral signature interactively

![](https://i.imgur.com/zeyABMq.gif)

## Acknowledgement

This projects draws inspiration and adapts source code from the [nasa/EMIT-Data-Resources](https://github.com/nasa/EMIT-Data-Resources) repository. Credit goes to the original authors.
11 changes: 8 additions & 3 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,16 @@

## Features

- Visualize hyperspectral data
- Analyze hyperspectral data
- Interactive visualization and analysis of hyperspectral data (e.g., [EMIT](https://earth.jpl.nasa.gov/emit/), [PACE](https://pace.gsfc.nasa.gov/))
- Interactive extraction and visualization of spectral signatures
- Saving spectral signatures as CSV files

## Demo

- Visualizing spectral signature interactively

![](https://i.imgur.com/zeyABMq.gif)
![](https://i.imgur.com/zeyABMq.gif)

## Acknowledgement

This projects draws inspiration and adapts source code from the [nasa/EMIT-Data-Resources](https://github.com/nasa/EMIT-Data-Resources) repository. Credit goes to the original authors.
3 changes: 3 additions & 0 deletions docs/pace.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# pace module

::: hypercoast.pace
1 change: 1 addition & 0 deletions hypercoast/hypercoast.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import xarray as xr
from .common import download_file
from .emit import read_emit, plot_emit, viz_emit, emit_to_netcdf, emit_to_image
from .pace import *


class Map(leafmap.Map):
Expand Down
50 changes: 50 additions & 0 deletions hypercoast/pace.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
"""This module contains functions to read and process PACE data.
"""

import xarray as xr


def read_pace(filepath, wavelengths=None, method="nearest", **kwargs):
"""
Reads PACE data from a given file and returns an xarray Dataset.
Args:
filepath (str): Path to the file to read.
wavelengths (array-like, optional): Specific wavelengths to select. If None, all wavelengths are selected.
method (str, optional): Method to use for selection when wavelengths is not None. Defaults to "nearest".
**kwargs: Additional keyword arguments to pass to the `sel` method when wavelengths is not None.
Returns:
xr.Dataset: An xarray Dataset containing the PACE data.
"""
ds = xr.open_dataset(filepath, group="geophysical_data")
ds = ds.swap_dims(
{
"number_of_lines": "latitude",
"pixels_per_line": "longitude",
}
)
wvl = xr.open_dataset(filepath, group="sensor_band_parameters")
loc = xr.open_dataset(filepath, group="navigation_data")

lat = loc.latitude
lat = lat.swap_dims(
{"number_of_lines": "latitude", "pixel_control_points": "longitude"}
)

lon = loc.longitude
wavelengths = wvl.wavelength_3d
Rrs = ds.Rrs

dataset = xr.Dataset(
{"Rrs": (("latitude", "longitude", "wavelengths"), Rrs.data)},
coords={
"latitude": (("latitude", "longitude"), lat.data),
"longitude": (("latitude", "longitude"), lon.data),
"wavelengths": ("wavelengths", wavelengths.data),
},
)

if wavelengths is not None:
dataset = dataset.sel(wavelengths=wavelengths, method=method, **kwargs)
return dataset
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,5 @@ nav:
- common module: common.md
- emit module: emit.md
- hypercoast module: hypercoast.md
- pace module: pace.md
- ui module: ui.md

0 comments on commit 431eee7

Please sign in to comment.