Marine Data Literacy 2.0

Providing instruction for managing, converting, analyzing and displaying oceanographic station data, marine meteorological data, GIS-compatible marine and coastal data or model simulations, and mapped remote sensing imagery





Home > 5. Gridded Data > 5.4 Grid Masks

5.4 Masking Methods for Depth- or Height-Limited Grids in Saga

  • Exercise Title:  Masking Methods for Depth- or Height-Limited Grids in Saga

  • Abstract:  In many cases, the gridding of earth science data creates arrays that extend beyond the logical limits of the dataset, for instance the coastline in the case of marine data.  Also, grids for data at a specific depth in the sea should not extend over shallower areas.  GIS systems have evolved methods to remove (or "blank" or "mask") the unwanted portion of the grid, using either special grids ("grid masks") or special vector lines that surround areas of wanted (or unwanted) grid cell values.  You may have seen these unwanted areas identified by a special "no data value" in some datasets.  In Saga, grid masks are used to assign no data values to the unwanted parts of the grids.  In this exercise you'll learn how to make a library of grid masks, for various grid resolutions./

  • Preliminary Reading (in OceanTeacher, unless otherwise indicated):

  • Required Software:

  • Other Resources: 

    • temp_grid_from_osd_jfm_0m_5m_liberia_wod_odv_saga - (Grid product; made in Gridding Point Shapes in Saga)
    • temp_grid_from_osd_jas_0m_5m_liberia_wod_odv_saga - Same source)
    • temp_grid_from_osd_jfm_3500m_4500m_liberia_wod_odv_saga - Same source
    • temp_grid_from_osd_jas_3500m_4500m_liberia_wod_odv_saga - Same source)
    • frame_grid_liberia_1deg.sgrd - The dummy grid you used to make these grids. 

    • Either one of these two relief grids:

    • World Borders Dataset, by Bjorn Sandvik (use

  • Author:  Murray Brown

  • Version:  6-22-2014

1.  This is an example of a gridded data product (sea surface temperature offshore Liberia) that intrudes onto land.  This exercise will show you how to fix that.
2.  Run Saga, and load:

You made these in previous exercises, cited above, or you downloaded them.

3.  This is the Liberia relief grid.  It has an original resolution of 1 minute, which is the same as 0.016667 degree.

Move your cursor over the raster, and you'll see that all the depth values are negative, as expected.

4.  We're going to use the method you learned in Resampling Grid Data to the Project Map Extent with a "Dummy" Grid to resample the relief grid to the resolution of the grids we want to mask:  1 degree.
6.  Make these selections:
  • For GRID SYSTEM, select the relief grid system to be resampled.
  • For GRID, select the relief grid itself.
  • Then for TARGET GRID, select GRID.  You will be asked next for the grid to use.

Click OK to continue

7.  Now it asks you which grid system to use as the target.  Select the system for the 1-degree dummy grid.

For <<GRID select CREATE to make a new grid.  Always reset to CREATE when you do resampling, to avoid over-writing an existing object (unless you want to).

Click OK to continue.


8.  The safest method for INTERPOLATION is to select NEAREST NEIGHBOR then click OK.

You can explore the other choices on your own, later.

9.  A new data object appears, in the 1-degree system.  Its name is based on the original relief raster's name.


10.  Here the file has been renamed (to say "1deg") with the NAME feature and SETTINGS > APPLY, in the right-hand settings panel.
11.  You can show the new object in its own map, and see that it is similar to the original, but very rough, i.e. low resolution.  We say that it has "lost information" when it went from high resolution to low resolution.
12.  As needed you may make other low-resolution relief grids like this one, at various "standard" resolutions.  They will be needed someday for height- or depth-masking of various data products, as we are about to do.  Each different product grid resolution requires a specific height or depth grid of the same resolution, for masking.

13.  In general, here are the steps for masking unwanted map areas (by relief):
  • Make the masking grid (1, 0.5, 0.1, 0.05, 0.01, etc.) according to the above steps, if you don't already have it for your area
  • Make sure you have a data product grid and a masking grid of exactly the same "system" (i.e. geometry)
  • Perform the masking steps shown below
15.  For GRID SYSTEM, select the 1-degree system (from a drop-down menu).
16.  For GRIDS, click on the ellipsis (...) on the right.
17.  This object selection window opens.  To begin, all the grids are on the left, but we need to move some of them to the right for use in calculations.
18.  Select the objects on the left side, and use the arrows to move them to the right side.  Arrange them exactly like this:
  • grid 1 = g1 = 1-degree relief grid mask
  • grid 2 = g2 = jfm_0m_5m grid
  • grid 3 = g3 = jas_0m_5m grid
  • grid 4 = g4 = jfm_3500m_4000m grid
  • grid 5 = g5 = jas_3500m_4000m grid

You can use the UP and DOWN keys to re-arrange the grids, if needed.

Then click OK.

19.  Make these selection:
  • FORMULA -  enter this formula to mask the g2 grid.
    • On your own time, you can read about the operators recognized by Saga for this module.  The LT operator has 2 arguments, and returns 1=TRUE if the first argument is less than the second argument.  It returns 0=FALSE if the first argument is not less than the second argument.
    • Here g1 is the relief grid, so for every cell in the relief grid where the depth value is less than zero (i.e. everywhere in the sea), the LT operator would return 1=TRUE.  Else for cells where the value is more than zero (i.e. on the land), the LT operator would return 0=FALSE.
    • And finally, what happens to g2 in the formula?  If g2 is divided by 1, then you get g2, that is no change.  But if g2 is divided by 0, then you get an impossible value, or the NO DATA value in Saga.
    • The LT argument can be edited to enter any depth or height value BELOW WHICH we want to keep the grid values, but ABOVE WHICH we want to eliminate the grid values.  We'll use 0 m now and -4000 m later on below.
  • NAME - Give a short version of the g2 grid, "jfm_0_masked". 
  • TAKE FORMULA - Must be unchecked to enter your own name like at.
  • USE NODATA - Insures that any no-data cells in the relief grid will carry over to the result as a no-data cell
  • DATA TYPE - Has to be able to handle real temperature values; check reference paper above if you have questions about number types for data

So click OK to see what happens.

20.  This new grid object, "jfm_0_masked," appears, identified according to the NAME you supplied
21.  You can repeat the process, from Panel 14, with the g3 grid.
  • Make sure RESULT is set to CREATE
  • Insert g3 in the FORMULA
  • Also enter a new NAME that reflects the contents of g3, such as jas_0_masked.
22. Be very careful to check that you do have TWO new grid objects, as shown here, with different useful names.
23.  And here are the 0-m grids, masked to remove land cells.  You can see the north-eastern corner has been chopped off.
24.  Now let's fix the color palette for the JFM_0_MASKED grid (the upper one).
  • TYPE - Graduated Colors
  • COLORS - Click the ellipsis to set them
25.  Set the color count to 100, then click OK.
26.  Select PRESETS > RAINBOW.  Then click OK and OK again to get back to the properties panel. 9
27.  Here on the properties panel, select VALUE RANGE > MINIMUM > 21, and MAXIMUM > 30.  We have used these values before when making the original grids.

Then at the bottom of the properties panel, click SETTINGS > APPLY.

28.  Here is the JFM_0_MASKED grid.  You can still see the north-south bad data trail, but everything else looks good.
29.  And here is the JAS_0_MASKED grid, using all the same settings.

A direct visual comparison between the above figure and this one shows a clear indication of strong seasonal differences.

30.  You can repeat the process, from Panel 14, using the g4 grid, but the formula must have -4000 instead of 0, as you see here.

Make sure RESULT is set to CREATE, and also enter a new NAME that reflects the contents of g4.

31.  You can repeat the process with the g5 grid.

Make sure RESULT is set to CREATE, and also enter a new NAME that reflects the contents of g5.

32.  Now you have these 4 new masked grids (#15-18).
33  Here we've used ADD TO MAP to display them with the World Borders shapefile, and arranged them so you can see the g2 and g3 grids on top, and the g4 and g5 grids on the bottom (both left to right).
  • The top maps (0-5 m) are using the 21-30 scale we used previously.  The seasonal difference is very easy to see.
  • The bottom maps (3500-4500 m) are using the 0-3 scale we used previously.  The slight indication of a seasonal difference is possibly just an artifact of a small dataset, so don't take it seriously until you do some further research.
  • All maps are using graduated colors based on temperature, 100 colors, and the rainbow preset palette.
  • The masking completely removes the land in the top pair.  In the bottom pair the land, shelf and upper slope are removed, and a huge fraction of the deep ocean where the bottom is shallower than 4000 m.  Essentially the Liberia area of interest is cut through by the mid-Atlantic ridge, and the water on the east side is slightly warmer. 
34.  Here are the respective color legends for the above maps:

35.  Recall the following identities:
  • g2 = jfm_0m_masked grid
  • g3 = jas_0m_masked grid
  • g4 = jfm_4000m_masked grid
  • g5 = jas_4000m_masked grid
36.  Navigate to PRODUCTS > SAGA > GRIDS and save the grids, one by one, as:
  • temp_grid_from_osd_jfm_0m_5m_liberia_wod_odv_saga_masked
  • temp_grid_from_osd_jas_0m_5m_liberia_wod_odv_saga_masked
  • temp_grid_from_osd_jfm_3500m_4500m_liberia_wod_odv_saga_masked
  • temp_grid_from_osd_jas_3500m_4500m_liberia_wod_odv_saga_masked

Also, select FILE > PROJECT and save the currently visible map products in the folder PRODUCTS > SAGA > PROJECTS with the filename temp_grids_liberia_jfm_jas_0m_5m_350m_450m_wod_odv_masked.sprj.  You definitely will need it in further exercises.

37.  Now for a final bit of grid magic, close all the other grids (after saving them, of course) and load in the original, full resolution Liberia GEBCO 08 grid. 
38.  Then select the GRID CALCULATOR module again.  But this time for the GRID SYSTEM, select the original relief grid (1 min or 0.016667 degree).  This time there is only one grid available for selections, so move it to the right side and click OK.
39.  Now you can edit the formula to refer only to the g1 grid, as you see here.

Make sure RESULT is set to CREATE, and you have entered a good easy name. 

Then click OK.

40.  The formula above cuts off all the land, and leaves only the high-resolution marine bathymetry.
41.  Another thing you could do is to use the GT operator, as you see here.  It works exactly the opposite of the LT operator.  [Look closely to see the GT in the formula.]
42.  The above GT operator formula would give you the land and not the sea.
43.  So now you know how to mask any grid, to remove unwanted cells on land or in inappropriate parts of the sea.  The library of masks you made will always be available for easy masking (for Liberia).  Just make sure to match the resolution of the mask to the grid to be masked.  Also, make sure you take care with the filenames to identify everything properly.