Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Searching by region and scaling up

This notebook demonstrates:

Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...

xopr includes a helper module xopr.geometry with some useful utilities. You can call get_antarctic_regions to select one or more regions from the MEaSUREs Antarctic Boundaries dataset.

Before we dive in, let’s look at a few examples. Note that the GeoJSON returned is EPSG:4326 (WGS84), so they look a bit weird. In the examples below, we reproject them to a more familiar EPSG:3031 for the previews.

You can select any (combination) of the three regions: Peninsula, West, and East like this:

Warning: 'regions' parameter is deprecated; use 'region' instead.
Area is 2772102.2 km^2, automatically applying 1km simplification tolerance
To disable simplification, set simplify_tolerance=0
Loading...

The MEaSUREs dataset categorizes regions as GR (grounded), FL (floating), or IS (island). You can select by those:

Area is 1527034.4 km^2, automatically applying 1km simplification tolerance
To disable simplification, set simplify_tolerance=0
Loading...

You can also select by name. Note that you can pass a list to any of these parameters, as shown here.

By default merge_regions=True and the return value is a single GeoJSON geometry. If you set merge_regions=False, you’ll instead get back a GeoDataFrame with information about the regions included.

Loading...

For the rest of this notebook, we’re going to look at just the Dotson ice shelf, which we select as follows:

Loading...

Here we see a new way of searching for radar frames by geometry. Simply passing our GeoJSON region gives us every available frame that intersects it.

data_product controls what you get back. If you set this to CSARP_standard (or another CSARP_ standard data product), you’ll get back a list of loaded radar frames. If you set it to None, you’ll get back the actual STAC items. That’s helpful here because we’re going to distribute the process of analyzing these frames, so we don’t actually want to load any data just yet.

Passing max_items=10 limits the search to a maximum of 10 items to keep this running quickly on the GitHub Actions runners, but feel free to experiment with removing it.

Plotting a map should look familiar. Here we’ve also overlaid the region we’re searching.

You’ll notice that the region doesn’t quite line up with the GeoViews coastline feature. That’s expected. The coastline feature is a relatively low resolution global data product that you shouldn’t treat as a real grounding line.

Loading...

Now that we’ve picked out some data, we’re going to define some functions to do some simple analysis on it. We won’t explain every detail of the code below, but basically it’s picking out the surface and bed reflection powers and giving us back a Dataset with those powers in decibels.

Let’s try out our analysis function on one frame. The plot below shows surface and bed power for a single frame of radar data.

/home/runner/work/xopr/xopr/src/xopr/opr_access.py:577: UserWarning: Warning: Unexpected result from ops_api: ERROR: SEGMENT DOES NOT EXIST.
  warnings.warn(f"Warning: Unexpected result from ops_api: {result['data']}", UserWarning)
/home/runner/work/xopr/xopr/src/xopr/opr_access.py:577: UserWarning: Warning: Unexpected result from ops_api: ERROR: SEGMENT DOES NOT EXIST.
  warnings.warn(f"Warning: Unexpected result from ops_api: {result['data']}", UserWarning)
/home/runner/work/xopr/xopr/src/xopr/opr_access.py:577: UserWarning: Warning: Unexpected result from ops_api: ERROR: SEGMENT DOES NOT EXIST.
  warnings.warn(f"Warning: Unexpected result from ops_api: {result['data']}", UserWarning)
/home/runner/work/xopr/xopr/src/xopr/opr_access.py:577: UserWarning: Warning: Unexpected result from ops_api: ERROR: SEGMENT DOES NOT EXIST.
  warnings.warn(f"Warning: Unexpected result from ops_api: {result['data']}", UserWarning)
/tmp/ipykernel_2393/185946170.py:88: FutureWarning: In a future version of xarray the default value for join will change from join='outer' to join='exact'. This change will result in the following ValueError: cannot be aligned with join='exact' because index/labels/sizes are not equal along these coordinates (dimensions): 'slow_time' ('slow_time',) The recommendation is to set join explicitly for this case.
  reflectivity_dataset = xr.merge([reflectivity_dataset, flight_line_metadata])
<Figure size 800x400 with 1 Axes>

Ok, that works, so now let’s scale up. You could just write a loop, but this is a parallelizable task, so we want to share the load out across whatever computational resources you might have.

This is good time to pause and note a few things:

If you’re still with us, this would probably be a good time to briefly read up on Dask. In short, Dask gives us a way to write code that looks pretty close to standard Python code but also easily distribute jobs across available compute infrastructure.

The defaults in this notebook will simply parallelize this workflow across however many CPU cores you have on your machine. We’ll also discuss using Coiled to scale your workflows into the cloud.

There are many more options, which you can read about in the Dask documentation. These options allow you to distribute your workflow across various cloud services or using any HPC resources you may have acesss to.

Getting started, we’ll create a Dask LocalCluster, which is just going to let us distribute the workload across the CPUs on our machine:

We could have alternatively created any cluster we want. For example, this is how you’d create a Coiled cluster:

Now we’re going to use client.map to run our function across whatever resources are in the client object.

Note that if you’re using a cloud cluster, you probably don’t want to pass your local opr object. Since you don’t have shared storage anyway, it’ll be better to let it load a default OPRConnection() object on each worker.

/home/runner/work/xopr/xopr/src/xopr/opr_access.py:577: UserWarning: Warning: Unexpected result from ops_api: ERROR: SEGMENT DOES NOT EXIST.
  warnings.warn(f"Warning: Unexpected result from ops_api: {result['data']}", UserWarning)
/home/runner/work/xopr/xopr/src/xopr/opr_access.py:577: UserWarning: Warning: Unexpected result from ops_api: ERROR: SEGMENT DOES NOT EXIST.
  warnings.warn(f"Warning: Unexpected result from ops_api: {result['data']}", UserWarning)
/home/runner/work/xopr/xopr/src/xopr/opr_access.py:577: UserWarning: Warning: Unexpected result from ops_api: ERROR: SEGMENT DOES NOT EXIST.
  warnings.warn(f"Warning: Unexpected result from ops_api: {result['data']}", UserWarning)
/home/runner/work/xopr/xopr/src/xopr/opr_access.py:577: UserWarning: Warning: Unexpected result from ops_api: ERROR: SEGMENT DOES NOT EXIST.
  warnings.warn(f"Warning: Unexpected result from ops_api: {result['data']}", UserWarning)
/tmp/ipykernel_2393/185946170.py:88: FutureWarning: In a future version of xarray the default value for join will change from join='outer' to join='exact'. This change will result in the following ValueError: cannot be aligned with join='exact' because index/labels/sizes are not equal along these coordinates (dimensions): 'slow_time' ('slow_time',) The recommendation is to set join explicitly for this case.
/tmp/ipykernel_2393/185946170.py:88: FutureWarning: In a future version of xarray the default value for join will change from join='outer' to join='exact'. This change will result in the following ValueError: cannot be aligned with join='exact' because index/labels/sizes are not equal along these coordinates (dimensions): 'slow_time' ('slow_time',) The recommendation is to set join explicitly for this case.
/tmp/ipykernel_2393/185946170.py:88: FutureWarning: In a future version of xarray the default value for join will change from join='outer' to join='exact'. This change will result in the following ValueError: cannot be aligned with join='exact' because index/labels/sizes are not equal along these coordinates (dimensions): 'slow_time' ('slow_time',) The recommendation is to set join explicitly for this case.
/tmp/ipykernel_2393/185946170.py:88: FutureWarning: In a future version of xarray the default value for join will change from join='outer' to join='exact'. This change will result in the following ValueError: cannot be aligned with join='exact' because index/labels/sizes are not equal along these coordinates (dimensions): 'slow_time' ('slow_time',) The recommendation is to set join explicitly for this case.
/tmp/ipykernel_2393/185946170.py:88: FutureWarning: In a future version of xarray the default value for join will change from join='outer' to join='exact'. This change will result in the following ValueError: cannot be aligned with join='exact' because index/labels/sizes are not equal along these coordinates (dimensions): 'slow_time' ('slow_time',) The recommendation is to set join explicitly for this case.
/tmp/ipykernel_2393/185946170.py:88: FutureWarning: In a future version of xarray the default value for join will change from join='outer' to join='exact'. This change will result in the following ValueError: cannot be aligned with join='exact' because index/labels/sizes are not equal along these coordinates (dimensions): 'slow_time' ('slow_time',) The recommendation is to set join explicitly for this case.

Great! If that ran successfully, results should now be a list of Dataset’s. Now we’re back to normal code to visualize our results.

Loading...

If you’re using a cloud or HPC cluster, it’s good practice to explicitly close it. In most cases, it’ll have an auto-timeout, but we’ll just close ours to be safe.

Congrats! If you made it this far, you’ve learned how to parallelize your radar analysis workflows!