Skip to content

Commit

Permalink
Cleans up 02_Data_Visualization_Tools.md, 03_Using_PySTAC.md
Browse files Browse the repository at this point in the history
  • Loading branch information
dhavide committed Sep 17, 2024
1 parent ead2d88 commit 9589c2e
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 28 deletions.
14 changes: 7 additions & 7 deletions book/02_Software_Tools/02_Data_Visualization_Tools.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,9 @@ print(type(tokyo_point))
<!-- #endregion -->

```python jupyter={"source_hidden": true}
# simple utility to make a rectangle of width dx & height dy & centre pt
def make_rect(pt,dx,dy):
'''Returns rectangle represented as tuple (x_lo, y_lo, x_hi, y_hi)
# simple utility to make a rectangle centered at pt of width dx & height dy
def make_bbox(pt,dx,dy):
'''Returns bounding-box represented as tuple (x_lo, y_lo, x_hi, y_hi)
given inputs pt=(x, y), width & height dx & dy respectively,
where x_lo = x-dx/2, x_hi=x+dx/2, y_lo = y-dy/2, y_hi = y+dy/2.
'''
Expand All @@ -115,19 +115,19 @@ We can test the preceding function using the longitude-latitude coordinates of M
# Verify that the function bounds works as intended
marrakesh_lonlat = (-7.93, 31.67)
dlon, dlat = 0.5, 0.25
marrakesh_rect = make_rect(marrakesh_lonlat, dlon, dlat)
print(marrakesh_rect)
marrakesh_bbox = make_bbox(marrakesh_lonlat, dlon, dlat)
print(marrakesh_bbox)
```

<!-- #region jupyter={"source_hidden": true} -->
The utility `geoviews.Rectangles` accepts a list of bounding boxes (each described by a tuple of the form `(x_min, y_min, x_max, y_max)`) to plot. We can again use `geoviews.opts` to tailor the rectangle as needed.
<!-- #endregion -->

```python jupyter={"source_hidden": true}
rectangle = gv.Rectangles([marrakesh_rect])
rectangle = gv.Rectangles([marrakesh_bbox])
rect_opts = opts.Rectangles(
line_width=0,
alpha=0.25,
alpha=0.1,
color='red'
)
```
Expand Down
44 changes: 23 additions & 21 deletions book/03_Using_NASA_EarthData/03_Using_PySTAC.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,12 @@ Next, let's define search parameters so we can retrieve data pertinent to that f
# Define AOI as left, bottom, ri/ght and top lat/lon extent
aoi = (-59.63818, -35.02927, -58.15723, -33.77271)
# We will search data for the month of March 2024
date_range = '2024-03-01/2024-03-31'
date_range = '2024-03-08/2024-03-15'
# Define a dictionary with appropriate keys: 'bbox' and 'datetime'
search_params = {
'bbox' : aoi,
'datetime' : date_range,
}
```

<!-- #region jupyter={"source_hidden": true} -->
Expand All @@ -77,37 +82,34 @@ Make a quick visual check that the tuple `aoi` actually describes the geographic

```python jupyter={"source_hidden": true}
basemap = gv.tile_sources.OSM
rect = gv.Rectangles(aoi).opts(opts.Rectangles(alpha=0.25, color='cyan'))
rect = gv.Rectangles([aoi]).opts(opts.Rectangles(alpha=0.25, color='cyan'))

rect*basemap
```

## Executing a search with the PySTAC API

```python jupyter={"source_hidden": true}
# We open a client instance to search for data, and retrieve relevant data records
# Define the base URL for the STAC to search
STAC_URL = 'https://cmr.earthdata.nasa.gov/stac'

# Setup PySTAC client
catalog = Client.open(f'{STAC_URL}/POCLOUD/')
collections = ["OPERA_L3_DSWX-HLS_V1"]

# We would like to search data using the search parameters defined above.
opts = {
'bbox' : aoi,
'collections': collections,
'datetime' : date_range,
}

search = catalog.search(**opts)
# Update the dictionary opts with list of collections to search
collections = ["OPERA_L3_DSWX-HLS_V1_1.0"]
search_params.update(collections=collections)
print(search_params)
```

```python jupyter={"source_hidden": true}
print(f'{type(search)=}')
```
<!-- #region jupyter={"source_hidden": true} -->
Having defined the search parameters, we can instantiate a `Client` and search the spatio-temporal asset catalog.
<!-- #endregion -->

```python jupyter={"source_hidden": true}
results = list(search.items_as_dicts())
# We open a client instance to search for data, and retrieve relevant data records
catalog = Client.open(f'{STAC_URL}/POCLOUD/')
search_results = catalog.search(**search_params)

print(f'{type(search_results)=}')

results = list(search_results.items_as_dicts())
print(f"Number of tiles found intersecting given bounding box: {len(results)}")
```

Expand Down Expand Up @@ -180,7 +182,7 @@ granules
Examining the index reveals that the timestamps of the granules returned are not unique, i.e., granules correspond to distinct data products deriveded during a single aerial acquisition by a satellite.
<!-- #endregion -->

```python jupyter={"source_hidden": true}
```python
len(granules.index.unique()) / len(granules) # Notice the timestamps are not all unique, i.e., some are repeated
```

Expand Down

0 comments on commit 9589c2e

Please sign in to comment.