Skip to main content
  • Home
  • Documentation
  • FAQ
  • Downloads
  • Support
  • Current Release Notes
  • Ferret Users Guide
    • Users Guide Index
    • Commands Reference
    • 1. Introduction
    • 2. Data Set Basics
    • 3. Variables & Expressions
    • 4. Grids & Regions
    • 5. Animations & Gif Images
    • 6. Customizing Plots
    • 7. Handling String Data Symbols
    • 8. Working with Special Data Sets
    • 9. Computing Environment
    • 10. Converting to NetCDF
    • 11. Writing External Functions
    • Glossary
    • Appendix A: Functions
    • Appendix B: PPLUS Guide
    • Appendix C: Ferret-Specific PPLUS Enhancements
  • Previous Release Notes
  • Tutorials and Demos
    • Ferret Tour
    • DSG files: Discrete Sampling Geometries Demo
    • Ferret sorting demo
    • Fast Fourier Transforms demo
    • Empirical Orthogonal Functions demo
    • Ferret objective analysis demo
    • Ferret Palette Demo
    • Map projections
    • Ferret polygon vector demo
    • Ferret Graticules demo
    • Ferret Polytube Demo
    • Ferret Polymark Demo
    • Ferret Constant-Array demo
    • Ferret land_detail demo
    • COADS Tour
    • Levitus Tour
    • Use OPeNDAP
    • Ferret binary read demo
  • PyFerret
    • PyFerret Downloads and Install
    • What is PyFerret?
    • Why use PyFerret?
    • PyFerret for the Ferret user
    • PyFerret command syntax: quick-start notes
    • PyFerret for the Python user
    • Graphics in PyFerret ?
    • New Ferret functionality
    • PyFerret Python functions and constants
    • PyFerret Python objects and methods
    • Ferret external functions in Python
    • Ferret Fortran external functions
    • PyFerret metadata-and-data dictionaries
  • OPeNDAP
    • OPeNDAP usage in Ferret
    • Use OPeNDAP Demo
    • Test OPeNDAP

Sorting Demo

This is an annotated version of the script ef_sort_demo.jnl

 

Call the functions SORTI, SORTJ, SORTK, SORTL to obtain lists of indices ofsorted data
Call the functions SAMPLEI, SAMPLEJ, SAMPLEK, SAMPLEL to sample data at a listof indices

A first simple example of sorting: Sort a list of data. Use COADSsea surface data at a location where some of the data is missing.These are grid-changing functions so specify the region of the argumentsin square brackets.

yes? USE coads_climatology
yes? LIST sst[x=19e,y=77n,l=1:6] SEA SURFACE TEMPERATURE (Deg C) LATITUDE: 77N DATA SET: /opt/local/ferret/fer_dsets/descr/coads_climatology.des 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, thensample 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: /opt/local/ferret/fer_dsets/descr/coads_climatology.des COADS Monthly Climatology (1946-1989) 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_ 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: .... ....

We can also use the constant-array notation to pick out a

yes? LIST samplel(sst[x=19e,y=77n,l=1:6], {1,5})
yes? LIST samplel(sst[x=19e,y=77n,l=1:6], {1,5}) SAMPLEL(SST[X=19E,Y=77N,L=1:6], {1,5}) LATITUDE: 77N DATA SET: /opt/local/ferret/fer_dsets/descr/coads_climatology.des 19E 0 1 / 1: 0.300 2 / 2: 1.350
 

Now a more involved example: What is the Sea Surface Temperaturein a region three months after the strongest winds in anotherregion? Use the COADS monthly climatology data set. Choose a region in the Pacific, and define the westerly_wind variableto be the monthly west winds averaged over this region. Sort thewesterly winds, lowest to highest. "sorted_indices3"is the indices 3 months after.

yes? LET westerly_wind = uwnd[x=160e:180@ave,y=35n:45n@ave]
yes? LET sst_e = sst[x=180:80w@ave,y=35n:45n@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 monthslater, and in the other region. First sample the westerly windsby their sorted indices. Then order the SST's according to thesorted 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 a scatter plots: sampled winds vs SST, using the PLOT/VS/RIBBON style to color the symbols by the magnitude of the winds
 

yes? SET VAR/TITLE="Sorted Westerly Winds from 160E to 180" wwe_by_ww
 
yes? SET VAR/TITLE="SST from 180 to 80W 3 months after Westerly winds" sst_by_wwe
 
yes? PLOT/VS/RIBBON/THICK/SYM=18/TITLE="SST 3 months after High Westerly Winds, colored by Wind"\
/pal=blue_purple_orange/hlim=0:5.5/l=1:`leng` wwe_by_wwe, sst_by_wwe, wwe_by_wwe