Below is an annotated version of the script ef_sort_demo.jnl
yes? go /help ef_sort_demo ! Description: examples of the sorting external functions for FERRET.
! ef_sort_demo.jnl
! *am* 9/98
! Description: Demonstration of external functions for sort/sample:
! SORTI, SORTJ, SORTK, SORTL to obtain lists of indices of sorted data
! SAMPLEI, SAMPLEJ, SAMPLEK, SAMPLEL to sample data at a list of indices
A first simple example of sorting: Sort a list of data. Use COADS sea surface data at a location where some of the data is missing.These are grid-changing functions so specify the region of the arguments in square brackets.
yes? USE coads_climatology yes? LIST sst[x=19e,y=77n,l=1:6] VARIABLE : SEA SURFACE TEMPERATURE (Deg C) FILENAME : coads_climatology.cdf FILEPATH : /home/users/tmap/ferret/linux/fer_dsets/data/ SUBSET : 6 points (TIME) LONGITUDE: 19E LATITUDE : 77N 19E 0 16-JAN / 1: 0.300 15-FEB / 2: .... 17-MAR / 3: .... 16-APR / 4: 5.000 16-MAY / 5: 1.350 16-JUN / 6: 2.799
The sequence of calls is: Compute the sorted indices, then sample the data using the new order of indices.
Show the indices and the sorted temperatures
yes? LET tsorted_indices = sortl(sst[x=19e,y=77n,l=1:6]) yes? LET tsorted_sst = samplel(sst[x=19e,y=77n,l=1:6], tsorted_indices yes? LIST tsorted_indices, tsorted_sst DATA SET: /home/users/tmap/ferret/linux/fer_dsets/data/coads_climatology.cdf T: 0.5 to 6.5 LONGITUDE: 19E LATITUDE: 77N Column 1: TSORTED_INDICES is SORTL(SST[X=19E,Y=77N,L=1:6]) Column 2: TSORTED_SST is SAMPLEL(SST[X=19E,Y=77N,L=1:6], TSORTED_INDICES) TSORTED_ TSORTED_SST 1 / 1: 1.000 0.300 2 / 2: 5.000 1.350 3 / 3: 6.000 2.799 4 / 4: 4.000 5.000 5 / 5: .... .... 6 / 6: .... .... yes?
We can also use the constant-array notation to list a couple of points to pick out:
yes? LIST samplel(sst[x=19e,y=77n,l=1:6], {1,5}) VARIABLE : SAMPLEL(SST[X=19E,Y=77N,L=1:6], {1,5}) FILENAME : coads_climatology.cdf FILEPATH : /home/users/tmap/ferret/linux/fer_dsets/data/ SUBSET : 2 points (T) LONGITUDE: 19E LATITUDE : 77N 19E 0 1 / 1: 0.300 2 / 2: 1.350
Now a more involved example: What is the Sea Surface Temperature in a region three months after the strongest winds in another region? Use the COADS monthly climatology data set. Choose a region in the Pacific, and define the westerly_wind variable to be the monthly west winds averaged over this region. Sort the westerly winds, lowest to highest. "sorted_indices3" is the indices 3 months after.
yes? SET DATA coads_climatology yes? LET westerly_wind = uwnd[x=160e:180@ave,y=5s:5n@ave] yes? LET sst_e = sst[x=180:80w@ave,y=5s:5n@ave] yes? LET sorted_indices = sortl(westerly_wind) yes? LET sorted_indices3 = MOD((sorted_indices + 2), 12) + 1
We will plot sorted winds vs the SST's, three months later, and in the other region. First sample the westerly winds by their sorted indices. Then order the SST's according to the sorted wind indices plus 3 months.
yes? LET wwe_by_wwe = samplel(westerly_wind, sorted_indices) yes? LET sst_by_wwe = samplel(sst_e, sorted_indices3)
The SST's of interest are to the east of our westerly_wind region. Get the number of valid data in the sort.
yes? LET leng = wwe_by_wwe[l=@NGD]
Make scatter plots: sampled winds vs SST, and mark the highest winds with a symbol.
yes? plot/vs/title="SST 3 months after High Westerly Winds"/SET_UP/l=1:`leng` wwe_by_wwe, sst_by_wwe ppl xaxis -3.3, -1.9, 0.1 yes? ppl yaxis, 25.4, 27.4, 0.2 yes? ppl xlab "Sorted Westerly Winds from 160E to 180" yes? ppl ylab "SST from 180 to 80W 3 months after Westerly winds" yes? ppl plot yes? plot/vs/over/symbol=18/nolabels/l=`leng-3`:`leng` wwe_by_wwe, sst_by_wwe