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.

Scipy

Authors
Affiliations
University at Albany (SUNY)
Univerity of California, Berkeley
University of Miami
University of California, San Diego
University at Albany (SUNY)
Tuskegee University
University at Albany (SUNY)

Overview

Within this notebook, we will cover:

  1. How to filter continuous SLP data to identify features of interest.

  2. How to identify the lowest SLP minima associated with ETCs.

  3. How to use Scipy’s label function to identify coherent objects within the SLP field.

  4. How to track identified ETCs through successive time steps.

Prerequisites

ConceptsImportanceNotes
Intro to CartopyHelpful
Understanding of NetCDFNecessaryFamiliarity with metadata structure
Intro to NumpyNecessaryBasic n-dimensional array indexing

Imports

Core functions for this notebook

Distance function

This function serves to calculate the distance between two given latitudes, and longitudes in degrees.

Crosses dateline function

This function ensures that features adjecent to each other, but on the international dateline, are considered as the same feature.

Read in and visualize our raw data

Function to plot an animation over each time step in our data

Loading...

Get our desired objects

Here is where we convert our xarray dataarray to a numpy array.

Choose a threshold for SLP

The threshold chosen here will serve as a dividing line between what is and is not considered a feature of interest. In the block of code below, we will choose a threshold of 1000 hPa. This means that all of our features of interest must be comprised of grid cells whose SLP values are 1000 hPa or less. Other thresholds could also be used, such as a departure from a long-term mean.

Create our “binary structure”

The binary structure is a boolean array that sets the definition for our smallest possible feature of interest. It essentially looks at all grid cells in our numpy array and determines which neighboring grid cells can be connected to form a coherent spatial object. The first input into generate_binary_structure defines the number of dimensions over which an object can cover. Since our numpy array contains three dimensions (time, latitude, longitude), our desired number of dimensions will be two, corresponding to latitude and longitude. The second input defines the number of grid cells that must be connected to each other to be considered as an object. For our case here, we will define an object minimally as one that has at least two connected grid cells.

Run the label function

Here is where we actually find our desired objects given a 2-dimensional field. When we run the label function, there will be two outputs. The first output is a 2-dimensional array that is the exact same size as our input array. However, this new array contains integer values corresponding to the feature of interest. Typically, a value of zero means that the grid cell is just part of the background (i.e. not a feature of interest). Then all grid cells with a value of 1 correspond to a feature, all grid cells with a value of 2 correspond to another feature, and so on. The second output of label is the integer total of distinct objects that were found in the given 2-dimensional field.

In the block of code below, we first define our grid size resolution in degrees. Next, we set up empty arrays that will store the output from the label for each time step in our original data file. For labeled_arr, we want a 3-dimensional array to store the output (number of time steps, number of latitudes, number of longitudes). Since the second output of the label is only an integer, a 1-dimensional array will suffice.

Lastly, we loop through each time step in our data file. For our case, this is only 13 time steps. After running the label function in the for loop, we send the output to the ‘crosses_dateline’ function, which ensures that objects that cross the international dateline are counted as the same rather than separate objects. We then append our correct outputs to the arrays that we defined earlier.

Create a map of our objects

Here, we can visualize the objects identified at each time step. The shading on the plot below corresponds to the numerical object identified by the label function.

Loading...

Find SLP Minima

Here, we utlize scipy’s minimum_filter function to identify the locations of local SLP minima. The minimum_filter function first takes in the n-dimensional array over which we wish to identify local minima. Then, minimum_filter requires a numerical value that defines the size of the grid over which minima will be found. In the following example, we locate minima within 5x5 grid boxes throughout our domain. The modes keyword tells us how to find minima at the edges of the domain. In the y-direction, we simply use the nearest grid cell within our domain, whereas in the x-direction we want to wrap to the other side of our domain since our field is continuous in the x-direction. Lastly, we specify over which axes we wish to calculate minima (latitude, longitude).

Plot SLP and identified minima

In the animation produced by the following block of code, you will see a plot of SLP, with all identified local minima shown as blue dots.

Loading...

Find main SLP minimum for each feature

Below, we loop through each time step and then loop through each identified feature at that time step. First, we identify the latitudes and longitudes of our features of interest at each time step. We then look at each identified feature and find the lowest SLP minimum that occurs within that feature.

Track features through time

We now have all proper minima at each time step. It is time to stitch together the minima through successive time steps to form tracks. The goal is to take all identified minima at the first time step in our dataset and track them through time. We introduce a variable in the block below called still exists. As the name suggests, when this variable is True, the storm track still exists at a certain time step. If it is False, then the track no longer exists at a certain time step.

To track features through time, we take a look at the next time step (t+1) and caculate the distances between our minimum at time step t and all identified features at time step t+1. We then search for a minimum at t+1 that is within 500 km of our minimum at t. This minimum at t+1 is taken as the position of our feature of interest at the next time step.

----------------------------
Track Number 1
Time step 1: 78.0 97
Time step 2: 78.0 97
Time step 3: 78.0 98
Time step 4: 79.0 101
Time step 5: 79.0 102
Time step 6: 79.0 103
Time step 7: 79.0 104
Time step 8: 79.0 104
Time step 9: 79.0 104
Time step 10: 79.0 105
Time step 11: 79.0 105
Time step 12: 80.0 106
Time step 13: 80.0 107
----------------------------
Track Number 2
Time step 1: 60.0 270
Time step 2: 60.0 271
Time step 3: 60.0 271
Time step 4: 60.0 272
Time step 5: 60.0 273
Time step 6: 60.0 274
Time step 7: 60.0 274
Time step 8: 61.0 274
Time step 9: 61.0 275
Time step 10: 61.0 276
Time step 11: 61.0 276
Time step 12: 61.0 276
Time step 13: 61.0 277
----------------------------
Track Number 3
Time step 1: 60.0 179
Time step 2: 60.0 179
Time step 3: 60.0 180
Time step 4: 60.0 180
Time step 5: 60.0 180
Time step 6: 52.0 187
Time step 7: 52.0 187
Time step 8: 60.0 181
Time step 9: 53.0 189
Time step 10: 53.0 189
Time step 11: 53.0 190
Time step 12: 54.0 190
Time step 13: 54.0 191
----------------------------
Track Number 4
Time step 1: 59.0 56
Time step 2: 55.0 58
Time step 3: 59.0 56
Time step 4: 56.0 59
Time step 5: 51.0 54
Time step 6: 51.0 54
Time step 7: 51.0 54
Time step 8: 51.0 54
Time step 9: 51.0 54
Time step 10: 51.0 54
Time step 11: 51.0 54
Time step 12: 52.0 54
Time step 13: 52.0 54
----------------------------
Track Number 5
Time step 1: 59.0 216
Time step 2: 59.0 216
Time step 3: 59.0 216
Time step 4: 60.0 180
Time step 5: 60.0 180
Time step 6: 52.0 187
Time step 7: 52.0 187
Time step 8: 60.0 181
Time step 9: 53.0 189
Time step 10: 53.0 189
Time step 11: 53.0 190
Time step 12: 54.0 190
Time step 13: 54.0 191
----------------------------
Track Number 6
Time step 1: 57.0 339
Time step 2: 57.0 339
Time step 3: 58.0 339
Time step 4: 58.0 339
Time step 5: 58.0 339
Time step 6: 58.0 339
Time step 7: 58.0 339
Time step 8: 59.0 339
Time step 9: 59.0 339
Time step 10: 59.0 339
Time step 11: 59.0 339
Time step 12: 59.0 339
Time step 13: 59.0 340
----------------------------
Track Number 7
Time step 1: 50.0 53
Time step 2: 50.0 53
Time step 3: 50.0 53
Time step 4: 50.0 54
Time step 5: 51.0 54
Time step 6: 51.0 54
Time step 7: 51.0 54
Time step 8: 51.0 54
Time step 9: 51.0 54
Time step 10: 51.0 54
Time step 11: 51.0 54
Time step 12: 52.0 54
Time step 13: 52.0 54
----------------------------
Track Number 8
Time step 1: 42.0 167
Time step 2: 42.0 168
Time step 3: 42.0 168
Time step 4: 42.0 168
Time step 5: 42.0 168
Time step 6: 42.0 168
Time step 7: 42.0 169
Time step 8: 41.0 169
Time step 9: 41.0 169
Time step 10: 41.0 169
Time step 11: 41.0 169
Time step 12: 41.0 169
Time step 13: 41.0 169
----------------------------
Track Number 9
Time step 1: 18.0 116
Time step 2: 19.0 116
Time step 3: 19.0 116
Time step 4: 19.0 116
Time step 5: 19.0 116
Time step 6: 19.0 116
Time step 7: 19.0 116
Time step 8: 19.0 116
Time step 9: 19.0 116
Time step 10: 19.0 116
Time step 11: 19.0 116
Time step 12: 19.0 116
Time step 13: 20.0 116
----------------------------
Track Number 10
Time step 1: -63.0 69
Time step 2: -64.0 71
Time step 3: -64.0 72
Time step 4: -64.0 72
Time step 5: -64.0 72
Time step 6: -64.0 72
Time step 7: -64.0 73
Time step 8: -64.0 73
Time step 9: -64.0 74
Time step 10: -65.0 76
Time step 11: -65.0 76
Time step 12: -65.0 76
Time step 13: -65.0 77
----------------------------
Track Number 11
Time step 1: -42.0 85
Time step 2: -64.0 71
Time step 3: -64.0 72
Time step 4: -64.0 72
Time step 5: -64.0 72
Time step 6: -64.0 72
Time step 7: -64.0 73
Time step 8: -64.0 73
Time step 9: -64.0 74
Time step 10: -65.0 76
Time step 11: -65.0 76
Time step 12: -65.0 76
Time step 13: -65.0 77
----------------------------
Track Number 12
Time step 1: -81.0 77
Time step 2: -80.0 91
Time step 3: -64.0 72
Time step 4: -64.0 72
Time step 5: -64.0 72
Time step 6: -64.0 72
Time step 7: -64.0 73
Time step 8: -64.0 73
Time step 9: -64.0 74
Time step 10: -65.0 76
Time step 11: -65.0 76
Time step 12: -65.0 76
Time step 13: -65.0 77