Visualizing PACE chlorophyll-a data interactively with HyperCoast¶
This notebook demonstrates how to visualize Plankton, Aerosol, Cloud, ocean Ecosystem (PACE) data interactively with HyperCoast.
# %pip install "hypercoast[extra]"
import hypercoast
To download PACE data, you will need to create an Earthdata login. You can register for an account at urs.earthdata.nasa.gov. Once you have an account, you can uncomment the code below to search and download the data.
# hypercoast.nasa_earth_login()
# temporal = ("2024-06-01", "2024-07-01")
# results= hypercoast.search_pace_chla(temporal=temporal)
# hypercoast.download_nasa_data(results, "chla")
Alternatively, you can download some sample data from here.
url = "https://github.com/opengeos/datasets/releases/download/hypercoast/pace_chla.zip"
hypercoast.download_file(url)
'/home/runner/work/HyperCoast/HyperCoast/docs/examples/pace_chla.zip'
The downloaded zip file is automatically extracted and saved in the chla
directory, which contains 17 daily files of chlorophyll-a concentration data in the netCDF format. The date range of the data is from 2024-06-01 to 2024-06-17.
files = "chla/*nc"
Load all the data files in the chla
directory as an xarray DataArray
array = hypercoast.read_pace_chla(files)
array
<xarray.DataArray 'chlor_a' (lat: 1800, lon: 3600, date: 17)> Size: 441MB dask.array<transpose, shape=(1800, 3600, 17), dtype=float32, chunksize=(512, 1024, 1), chunktype=numpy.ndarray> Coordinates: * lat (lat) float32 7kB 89.95 89.85 89.75 ... -89.75 -89.85 -89.95 * lon (lon) float32 14kB -179.9 -179.9 -179.8 ... 179.8 179.9 180.0 * date (date) <U10 680B '2024-06-01' '2024-06-02' ... '2024-06-17' spatial_ref int64 8B 0 Attributes: long_name: Chlorophyll Concentration, OCI Algorithm units: lg(mg m^-3) standard_name: mass_concentration_of_chlorophyll_in_sea_water valid_min: 0.001 valid_max: 100.0 reference: Hu, C., Lee Z., and Franz, B.A. (2012). Chlorophyll-a alg... display_scale: log display_min: 0.01 display_max: 20.0 date: ['2024-06-01', '2024-06-02', '2024-06-03', '2024-06-04', ...
Select a date and visualize the chlorophyll-a concentration data with Matplotlib.
hypercoast.viz_pace_chla(array, date="2024-06-01", cmap="jet", size=6)
<matplotlib.collections.QuadMesh at 0x7f19fc5fa4d0>
If the date is not specified, the data are averaged over the entire time range.
hypercoast.viz_pace_chla(array, cmap="jet", size=6)
<matplotlib.collections.QuadMesh at 0x7f19f83f6ad0>
To visualize the data interactively, we can select either a single date or aggregate the data over a time range.
First, let's select a single date from the data array:
single_array = array.sel(date="2024-06-01")
single_array
<xarray.DataArray 'chlor_a' (lat: 1800, lon: 3600)> Size: 26MB dask.array<getitem, shape=(1800, 3600), dtype=float32, chunksize=(512, 1024), chunktype=numpy.ndarray> Coordinates: * lat (lat) float32 7kB 89.95 89.85 89.75 ... -89.75 -89.85 -89.95 * lon (lon) float32 14kB -179.9 -179.9 -179.8 ... 179.8 179.9 180.0 date <U10 40B '2024-06-01' spatial_ref int64 8B 0 Attributes: long_name: Chlorophyll Concentration, OCI Algorithm units: lg(mg m^-3) standard_name: mass_concentration_of_chlorophyll_in_sea_water valid_min: 0.001 valid_max: 100.0 reference: Hu, C., Lee Z., and Franz, B.A. (2012). Chlorophyll-a alg... display_scale: log display_min: 0.01 display_max: 20.0 date: ['2024-06-01', '2024-06-02', '2024-06-03', '2024-06-04', ...
Convert the data array to an image that can be displayed on an interactive map.
single_image = hypercoast.pace_chla_to_image(single_array)
Create an interactive map and display the image on the map.
m = hypercoast.Map(center=[40, -100], zoom=4)
m.add_basemap("Hybrid")
m.add_raster(
single_image,
cmap="jet",
vmin=-1,
vmax=2,
layer_name="Chlorophyll a",
zoom_to_layer=False,
)
label = "Chlorophyll Concentration [lg(lg(mg m^-3))]"
m.add_colormap(cmap="jet", vmin=-1, vmax=2, label=label)
m
The daily image does not have a global coverage. To visualize the data globally, we can aggregate the data over a time range.
mean_array = array.mean(dim="date")
Convert the aggregated data array to an image that can be displayed on an interactive map.
image = hypercoast.pace_chla_to_image(mean_array)
Create an interactive map and display the image on the map.
m = hypercoast.Map(center=[40, -100], zoom=4)
m.add_basemap("Hybrid")
m.add_raster(
image, cmap="jet", vmin=-1, vmax=2, layer_name="Chlorophyll a", zoom_to_layer=False
)
label = "Chlorophyll Concentration [lg(lg(mg m^-3))]"
m.add_colormap(cmap="jet", vmin=-1, vmax=2, label=label)
m