## MATLAB script for 3D visualizing geodata on a rotating globe: MANUALThis is a user's guide to a free Matlab package rotating_3d_globe.zip. To have an idea of images and animations that can be produced, have a look at the package website: http://www.asu.cas.cz/~bezdek/vyzkum/rotating_3d_globe/. It was our intention to prepare this package so that it can be used in a "copy and paste" style of programming. More eloquently: "Copy, paste and quickly modify according to your needs." ## 1. Installation of the package♣ First download the package rotating_3d_globe.zip, unpack it and add the '.../rotating_3d_globe/bin_geoid_3d' subfolder to your Matlab path. This package contains also the data for the lower resolution images.♣ For high resolution images, download data_high_resolution.zip (122 MB) separately. To produce 3D images based on these data, you will need 4 GB of RAM memory. ♣ To create videos in compressed formats WMV, MP4, xvid AVI, download, install and add to your Matlab path: ffmpeg. ## Adding the package to the Matlab search pathModify and put the following line to your Matlab script or to your startup.m file:addpath('REPLACE_BY_YOUR_PARTICULAR_FOLDER/rotating_3d_globe/bin_geoid_3d'); ## Running a test exampleCopy some example code from the section Matlab scripts for all the examples of the package website and paste the copied code into your Matlab command window, possibly press Enter. First the data should be read from a file and then a figure with the graph should open. Finally the output image or animation should be produced and saved to your current Matlab folder.Let's take the first example: Geoid height on 3D globe. Copy and paste the code for loading the data: %% Selection of geopotential model and computation/loading of the grid values model='egm2008'; %nmax=2190 nmax=500; % Computation of grid for the selected geopotential functional [lond,latd,gh]=compute_geopot_grids(model,nmax,'functional','gh');If you use the code for the first time, there will be some time needed to compute the EGM2008 grid, next time this computed grid will be loaded quickly. The response in the Matlab command window should be something like: ------------------------------- Model: egm2008, nmax=500, half-wave: 40 km Grid step: 0.167 deg = 10 arcmin = 18.5 km Compute_geopot_grids: geoid heights (m) Normal field was subtracted. Number of points: 2334960 = 2.3 mil = 0.0 mld Time of computation: 4 sec = 0.1 min Saved file: grid_egm2008_500_gh_010m_subtr1.mat
Function: ROTATING_3D_GLOBE Elevation data: min=-106, max=86.7 Preview PNG image has been created: rotating_3d_globe_preview_Geoid_height_EGM2008_nmax500_BlueWhiteOrangeRed_px0650.pngEach time the function rotating_3d_globe is invoked, it outputs the maximum and minimum values of the elevation data, the name of the created png image is also reported. If you encounter a problem, look at Troubleshooting section or contact me directly:
.
## 2. Making of 3D graphs step by stepThis chapter provides an explanation of how to use the main function of the package rotate_3d_globe. We demonstrate its basic usage on simple examples using the Earth topography data, which we chose because the topography of our home planet is familiar to all of us.## 2.1. Earth topography: Getting started
The first three arguments of the function rotating_3d_globe are always the same: rotating_3d_globe(lond,latd,elev,'radius',R,'units','km');where lond is vector of N longitudes and latd a vector of M latitudes (both in degrees); the third parameter elev is an M×N matrix with the elevation data. Then there follow two other arguments, 'radius' defines the radius R, to which the elev data are added and then visualized; the argument 'units' is used as the colorbar label. ## Earth topography: Omission of specifying the radius
## 2.2. Earth topography: Label, larger image size and colorbar limits
'graph_label' is followed by the string for the label; 'cptcmap_pm' determines the color palette used (see Color Palette Tables (.cpt) for Matlab); for the Earth topography data to be represented reliably it is indispensable to use a specific colour scale (here "GMT_globe.cpt"), with other data one is free to choose arbitrary colour scale, see Section 6.1. Choosing and editing a colour scale; 'clbr_limits' and 'clbr_tick' specify the colorbar limits and ticks; finally 'window_height' defines the figure window size, which is then used also for the png image produced. ## 2.3. Earth topography: Slight exaggeration of elevation
## 2.4. Earth topography: Draw data as colour scale on perfect sphere
## 2.5. Earth topography: Changing the view point
## Earth topography: Changing the view point, zoom in
## Earth topography: Changing the view point, zoom in, more details (figure invisible)
## Earth topography: Changing the view point, plot a point
## Earth topography: Changing the view point, zoom in, plot a point (figure invisible)
## 2.6. Earth topography: Coastlines and country boundaries, zoom in, more details (figure invisible)
## 2.6. Earth topography: Adding grid lines
## 3. Making of 3D animations step by step## 3.1. Earth topography in 3D as animated GIF: 36-degree segment, 1 fps
## Earth topography in 3D as animated GIF: 36-degree segment, 10 fps
## Earth topography in 3D as animated GIF: 36-degree segment, 20 fps, flickering
## Earth topography in 3D as animated GIF: 36-degree segment, 20 fps, smoothed
## 3.2. Earth topography in 3D as animated GIF: full revolution, smooth motion
## 3.3. Earth topography in 3D as video files: WMV, MP4, xvid AVI
## 3.4. Earth topography in 3D animation: PNG files for slideshow
## 4. Geoid height in 3D image/animation## 4.1. Selection of geopotential model and computation/loading of the grid valuesTo visualize a gravity field model, we need a grid of the required geopotential functional computed from the given model. A model is defined by its harmonic coefficients (see the reference paper for details). The harmonic coefficients are saved in mat files named after the model. In the package, there are several models available, of different maximum resolution (stated in comments):%% Selection of geopotential model and computation/loading of the grid values % model='asu-ch-0309'; %nmax 120 % model='itg-grace2010s'; %nmax 180 % model='GOCO03S'; %nmax 250 model='egm2008'; %nmax=2190According to the spatial resolution of the model defined by its maximum degree 'nmax', the function compute_geopot_grids selects a corresponding value for the step of the grid, also the vectors of longitudes and latitudes are output: model='egm2008'; nmax=500; %selection of geopotential model [lond,latd,gh]=compute_geopot_grids(model,nmax,'functional','gh');An suitable spatial resolution of the 3D image determines the necessary maximum degree 'nmax', if available for the given model, for example: nmax=180 grid_stepd*60 = 30 arcmin = 0.5 deg nmax=500 grid_stepd*60 = 10 arcmin = 0.1666... deg nmax=1000 grid_stepd*60 = 5 arcmin = 0.8333... degFor small images/animations of say 110 px, a grid of 0.5 deg is sufficient (nmax=180), for medium sized images of 300–1000 px a grid of 10 arcmin is adequate (nmax=500), for high-resolution images presented on the package website we used 4 or 5 arcmin data (nmax equal to 1100 or 1000), e.g. high resolution example image of geoid height, its Matlab code is here. The computation of the grid needed for the visualization is done by invoking e.g.: model='egm2008'; nmax=500; %selection of geopotential model [lond,latd,gh]=compute_geopot_grids(model,nmax,'functional','gh');The function compute_geopot_grids tests, whether the grid has already been computed and stored. In the folder 'temp', the computed geopotential grids are stored for speeding up the execution of the function. You may delete its contents if you wish. We save only grids which took more than 'time_limit_to_save_grids' seconds to compute (the default is 1 sec). ## Reading geopotential coefficients from an ICGEM fileWe provide the user a possibility of using any of the gravity field models stored at ICGEM website (click on 'Table of models' in the menu on the left). The downloaded gfc file is then transformed into our internal format by typing:icgem2matThis function finds all the ICGEM files (*.gfc) in the current directory, reads the geopotential coefficients and transforms them into Matlab variables for much faster loading. The new mat file with the same name is moved into 'data_icgem' subdirectory; the original gfc file is moved into 'data_icgem/gfc/' subdirectory. Add the 'data_icgem' folder into your Matlab path. The model coefficients are then loaded by typing, e.g. load egm2008 ## 4.2. Geoid height in 3D as PNG image
## 4.3. Geoid height in 3D as animated GIF/compressed video: 1 fps
## Geoid height in 3D as animated GIF: full revolution, smooth motion
## Geoid height in 3D as video files: WMV, MP4, xvid AVIThis is an example of smoothly rotating geoid, whose definition and properties are described above in Section 3.3 for Earth topography. As above, for this smooth animation covering the full 360-deg rotation angle, with high time resolution of 20 fps, the size of the wmv file is 13 MB, much smaller than the corresponding animated gif of 37 MB.
## 5. Elevation 2D mapsWe provide the functionality of creating 2D elevation maps only as an addendum to our main 3D visualization function compute_geopot_grids, because often it is useful to project the elevation data also to a 2D map. Our 2D calling function elevation_2d_map shares the basic syntax with the 3D function compute_geopot_grids, but in fact it serves only as a wrapper, which uses M_Map: A mapping package for Matlab.## Earth topography as 2D map
## Earth topography as 2D map (centred on the Pacific)
## 6. Optional argumentsAll the functions in our package have a help, which could be invoked by typing 'help' or 'doc', for exampledoc rotating_3d_globeIn addition to the help, you can have a look and modify the code. ## 6.1. Choosing and editing a colour scaleSometimes, users complain that Matlab does not produce nicely looking images with varied colour scales. We believe that this is not true, look for example at our high resolution example image of Earth topography. In fact, a user can quickly and easily change and edit a color scale for 2D or 3D images.## Default Matlab colormap
## Color palette files (cpt)
## Matlab built-in colormaps
## User defined colormaps
## 6.2. Exporting STL file for 3D printersIt is possible to fabricate a physical model representing the output of our visualization package by means of a 3D printer (e.g. the geiod with exaggerated variations). To produce an STL file, add an optional argument:'stl_file_export',1,...In this file, test_file_for_3d_printer.m, you can find a Matlab script that produces an STL file of the EGM2008 model. There is a short description at the beginning of the script, first try to produce a small smooth model (nmax=30), then by increasing the nmax parameter you can obtain a nicely looking STL model of the geoid. To create the STL file, the function surf2stl.m by Bill McDonald is used and acknowledged. ## 7. Troubleshooting## 7.1. An AVI video was produced instead of WMVIf you selected 'wmv' video format and obtained an 'avi' file, then there is a problem with calling the external program "ffmpeg". To create videos in compressed formats WMV, MP4, xvid AVI, download, install and add to your Matlab path: ffmpeg.## 7.2. Animated GIF was not createdTo be able to produce animated GIFs within Matlab, you need the function rgb2ind. In our experience, Matlab version R2011a has it in its basic module; with older version R2008a, either you use the image processing toolbox, or you can contact me and possibly I can help you.## 7.3. Artefact line on a 3D image
Any comments or questions will be appreciated – if you have some, please contact: Ales Bezdek <>.
Last modified: 25 January 2017 |