### Install GMT.jl Source: https://github.com/genericmappingtools/gmt.jl/blob/master/README.md Standard Julia package installation command for GMT.jl. ```julia ] add GMT ``` -------------------------------- ### Start and Plot in Modern Mode Source: https://github.com/genericmappingtools/gmt.jl/blob/master/_autodocs/api-reference/color-and-config.md Starts a new modern mode GMT session for building figures from multiple plotting commands. Use this to group related plots into a single figure. Requires `gmtbegin` and `gmtend`. ```julia gmtbegin("myfigure") coast(region="d", proj=:Mercator, land="gray", water="lightblue") plot!(rand(10), rand(10), marker=:circle, fill="red") gmtend() # Finalize and save figure ``` -------------------------------- ### Configure System-Wide GMT Installation Source: https://github.com/genericmappingtools/gmt.jl/blob/master/README.md Instructions for configuring GMT.jl to use a system-wide GMT installation instead of the default JLL artifact, particularly useful on Windows or when manual control is desired. Requires restarting the Julia REPL and potentially setting a permanent environment variable. ```julia ENV["SYSTEMWIDE_GMT"] = 1 import Pkg; Pkg.build("GMT") restart Julia ``` -------------------------------- ### Build a Figure with Multiple Commands Source: https://github.com/genericmappingtools/gmt.jl/blob/master/_autodocs/QUICK-REFERENCE.md Use `gmtbegin` and `gmtend` to manage figure creation. This example shows how to add coastlines, plot data, and include a color bar. ```julia # Start session gmtbegin("myfigure", fmt="png") # Build figure with multiple commands coast(region="d", proj=:Mercator, land="gray", water="lightblue") plot!(rand(10), rand(10), marker=:circle, fill="red") colorbar(cpt, pos="RB") # Finalize gmtend(show=true) ``` -------------------------------- ### Get GMT Module Help Source: https://github.com/genericmappingtools/gmt.jl/blob/master/_autodocs/api-reference/color-and-config.md Use `gmthelp()` to display command-line help for specific GMT modules. This is useful for understanding available options and syntax. ```julia gmthelp("psxy") ``` ```julia gmthelp("grdinfo") ``` -------------------------------- ### Complete GMT.jl Workflow Example Source: https://github.com/genericmappingtools/gmt.jl/blob/master/_autodocs/QUICK-REFERENCE.md Demonstrates a complete workflow including loading data, creating a 3D visualization, generating a colormap, and plotting a 2D contour map with a colorbar. ```julia using GMT # Load data dem = gmtread("elevation.grd") # Create figure with modern mode gmtbegin("analysis", fmt="png") # 3D visualization grdview(dem, cmap=:turbo, view="200/30", title="Digital Elevation Model") # Create colormap cpt = grd2cpt(dem, cmap=:relief) # 2D contour map subplot(1, 2) grcontour(dem, interval=100, annot=500, pen="0.5p", frame="a") # Colorbar colorbar(cpt, pos="RB", frame="a+l'Elevation (m)'") gmtend(show=true) ``` -------------------------------- ### Perform Grid Operations Source: https://github.com/genericmappingtools/gmt.jl/blob/master/_autodocs/QUICK-REFERENCE.md Provides examples for common grid operations such as filtering, calculating gradients, clipping, resampling, subsetting, and obtaining grid information. ```julia smooth = grdfilter(grid, filter="g300") ``` ```julia slope = grdgradient(grid, slope=true) aspect = grdgradient(grid, aspect=true) ``` ```julia clipped = grdclip(grid, range=(0, 100)) ``` ```julia coarse = grdsample(grid, inc=0.5) ``` ```julia subset = grdcut(grid, region=(-10, 10, -10, 10)) ``` ```julia info = grdinfo(grid) volume = grdvolume(grid, level=0) ``` -------------------------------- ### grdinfo Source: https://github.com/genericmappingtools/gmt.jl/blob/master/_autodocs/api-reference/utilities-and-analysis.md Get grid summary (dimensions, range, statistics). ```APIDOC ## grdinfo ### Description Get grid summary (dimensions, range, statistics). ### Signature ```julia grdfinfo(grid::GMTgrid; kwargs...) ``` ### Return Type Dict or String ``` -------------------------------- ### gmtbegin Source: https://github.com/genericmappingtools/gmt.jl/blob/master/_autodocs/api-reference/color-and-config.md Starts a new modern mode GMT session for building figures from multiple plotting commands. You can specify the output format and a figure name. ```APIDOC ## gmtbegin ### Description Start a new modern mode GMT session where figures are built from multiple plotting commands. ### Parameters - `name` (String) - Optional - Figure name (default: "GMTplot") - `fmt` / `format` (String) - Optional - Output format: "png", "pdf", "eps", etc. ### Example ```julia # Start a figure building session gmtbegin("myfigure") # Plot multiple elements on same figure coast(region="d", proj=:Mercator, land="gray", water="lightblue") plot!(rand(10), rand(10), marker=:circle, fill="red") gmtend() # Finalize and save figure ``` ``` -------------------------------- ### Create Inset Map Source: https://github.com/genericmappingtools/gmt.jl/blob/master/_autodocs/api-reference/color-and-config.md Starts an inset (map-in-map) drawing context within a larger map. Use `inset` to define the position and size of the inset, then plot its content. Requires `gmtbegin` and `gmtend`. ```julia gmtbegin("map_with_inset", fmt="png") coast(region="d", proj=:Mercator) inset(position="TL", size=(5, 5)) coast(region=(-10, 10, -10, 10), proj=:Mercator, land="wheat") gmtend(show=true) ``` -------------------------------- ### Monolithic GMT Command Usage Source: https://github.com/genericmappingtools/gmt.jl/blob/master/README.md Example of using the monolithic `gmt()` command in GMT.jl, passing all GMT options as a single string. This method is robust and keeps pace with GMT developments. ```julia gmt("options", data) ``` -------------------------------- ### Set SYSTEMWIDE_GS Environment Variable Source: https://github.com/genericmappingtools/gmt.jl/blob/master/_autodocs/configuration.md Specify the path to a system Ghostscript installation. This is useful when JLL Ghostscript is not desired or available. The path format depends on the operating system. ```julia ENV["SYSTEMWIDE_GS"] = "C:\\Program Files\\Ghostscript\\gs9.56.1\\bin\\gswin64c.exe" ``` -------------------------------- ### Manipulate Data with GMT Source: https://github.com/genericmappingtools/gmt.jl/blob/master/_autodocs/QUICK-REFERENCE.md Shows how to select data points within a region, reduce data to block means, get statistical summaries, and fit circles or lines to data. ```julia region_data = gmtselect(data, region=(0, 10, 0, 10)) ``` ```julia reduced = blockmean(data, region=(-180, 180, -90, 90), inc=10) ``` ```julia info = gmtinfo(data) ``` ```julia cx, cy, r = fitcircle(points) line = linearfitxy(x, y) trend = trend2d(data, order=2) ``` -------------------------------- ### Reset GMT Configuration to Defaults Source: https://github.com/genericmappingtools/gmt.jl/blob/master/_autodocs/api-reference/color-and-config.md Reset specific GMT configuration parameters to their default values. This example resets the page orientation to portrait. ```julia gmtset(PS_PAGE_ORIENTATION="portrait") ``` -------------------------------- ### inset Source: https://github.com/genericmappingtools/gmt.jl/blob/master/_autodocs/api-reference/color-and-config.md Starts an inset (map-in-map) drawing context within a larger map. Allows specifying the position and size of the inset, useful for adding detail maps. ```APIDOC ## inset ### Description Start an inset (map-in-map) drawing context within a larger map. ### Parameters - `position` (String) - Optional - Inset position: "TL", "TR", "BL", "BR", or absolute coordinates - `size` (Tuple) - Optional - Inset dimensions [width, height] in cm - `save` (Bool) - Optional - Save inset region for cleanup ### Example ```julia gmtbegin("map_with_inset", fmt="png") coast(region="d", proj=:Mercator) inset(position="TL", size=(5, 5)) coast(region=(-10, 10, -10, 10), proj=:Mercator, land="wheat") gmtend(show=true) ``` ``` -------------------------------- ### Convert Plot to PNG and Display Source: https://github.com/genericmappingtools/gmt.jl/blob/master/WL_Example_II.ipynb Converts the generated plot to a PNG image with specified resolution and displays it using PyPlot. Ensure PyPlot is installed and configured. ```julia # Convert plot to a PNG and display it using PyPlot I = gmt("psconvert -TG -P -E300 -A", P); imshow(I.image) ``` -------------------------------- ### Set SYSTEMWIDE_GMT Environment Variable Source: https://github.com/genericmappingtools/gmt.jl/blob/master/_autodocs/configuration.md Configure GMT.jl to use a system-wide GMT installation instead of JLL artifacts. This requires setting the SYSTEMWIDE_GMT environment variable to 1 and then rebuilding the GMT package. ```julia ENV["SYSTEMWIDE_GMT"] = 1 Pkg.build("GMT") ``` -------------------------------- ### Simplify Line Segments with gmtsimplify Source: https://github.com/genericmappingtools/gmt.jl/blob/master/_autodocs/api-reference/geospatial-operations.md Simplify line segments by removing redundant points using gmtsimplify. Set the `tolerance` parameter to define the minimum distance threshold for point retention. This example simplifies a coastline dataset with a 10km tolerance. ```julia # Simplify a coastline with 10km tolerance coast_data = gmtread("coastline.txt") simplified = gmtsimplify(coast_data, tolerance=10) ``` -------------------------------- ### Perform Mathematical Operations on Grids with grdmath Source: https://github.com/genericmappingtools/gmt.jl/blob/master/_autodocs/api-reference/grid-operations.md Use `grdmath` or `gmtmath` to perform mathematical operations on grids or tables using Reverse Polish Notation (RPN). Examples include multiplying a grid by a constant or adding two grids. ```julia # Multiply grid by constant result = grdmath(grid, "*2") ``` ```julia # Add two grids result = grdmath(grid1, grid2, "+") ``` -------------------------------- ### Create and Display Color Maps Source: https://github.com/genericmappingtools/gmt.jl/blob/master/_autodocs/QUICK-REFERENCE.md Demonstrates creating color palettes using different colormaps and ranges, and displaying a colorbar. Supports various colormaps like :turbo, :viridis, and :relief. ```julia cpt = makecpt(cmap=:turbo, range=(0, 100)) cpt = makecpt(cmap=:viridis, range=(0, 1000), reverse=true) cpt = grd2cpt(grid, cmap=:relief) ``` ```julia colorbar(cpt, pos="RB", show=true) ``` -------------------------------- ### ds2df Source: https://github.com/genericmappingtools/gmt.jl/blob/master/_autodocs/types.md Converts a GMTdataset into a DataFrame, which requires the DataFrames.jl package to be installed. ```APIDOC ### `ds2df(dataset)` - Convert a GMTdataset to a DataFrame (requires DataFrames.jl) ``` -------------------------------- ### Query GMT Module Help Source: https://github.com/genericmappingtools/gmt.jl/blob/master/_autodocs/configuration.md Displays detailed help information for a specific GMT module, such as 'psxy'. This is equivalent to running the module with '-h' in the command line. ```julia gmthelp("psxy") ``` -------------------------------- ### Convert GMTdataset to DataFrame Source: https://github.com/genericmappingtools/gmt.jl/blob/master/_autodocs/types.md Converts a GMTdataset into a DataFrame. Requires the DataFrames.jl package to be installed. ```julia # Convert a GMTdataset to a DataFrame (requires DataFrames.jl) ds2df(dataset) ``` -------------------------------- ### gmtinfo Source: https://github.com/genericmappingtools/gmt.jl/blob/master/_autodocs/api-reference/utilities-and-analysis.md Get summary statistics (min, max, range) per column or grid. ```APIDOC ## gmtinfo ### Description Get summary statistics (min, max, range) per column or grid. ### Signature ```julia gmtinfo(data::Union{GMTdataset, GMTgrid}; kwargs...) ``` ### Return Type Dict or String with statistics ### Examples ```julia data = gmtread("points.txt") info = gmtinfo(data) ``` ``` -------------------------------- ### Convert PostScript to Encapsulated PDF Source: https://github.com/genericmappingtools/gmt.jl/blob/master/WL_Example_III.ipynb Converts the generated PostScript file ('WL_example_3.ps') into an encapsulated PDF file ('WL_example_3.ef'). ```julia gmt("psconvert -Tef -P -A WL_example_3.ps"); ``` -------------------------------- ### resetGMT Source: https://github.com/genericmappingtools/gmt.jl/blob/master/_autodocs/api-reference/color-and-config.md Resets the GMT session to a clean state, clearing all temporary data and settings. This is useful for ensuring a fresh start before new plotting operations. ```APIDOC ## resetGMT ### Description Reset GMT session to clean state, clearing all temporary data and settings. ### Signature ```julia resetGMT() ``` ### Examples ```julia resetGMT() # Clear everything plot([1, 2, 3], [1, 2, 1]) # Start fresh ``` ``` -------------------------------- ### Select Color Table and Generate Initial Plot Source: https://github.com/genericmappingtools/gmt.jl/blob/master/WL_Example_III.ipynb Selects a color table ('jet') for SST data and generates an initial PostScript plot using 'grdimage'. The output is saved to 'WL_example_3.ps'. ```julia cpt_s = gmt("grd2cpt -Cjet -E -M --COLOR_NAN=255", G); cpt_t = gmt("makecpt -Celevation -T0/3000"); gmt("grdimage -JM15c -C -Ba -BWSne -P -K > WL_example_3.ps", G, cpt_s); ``` -------------------------------- ### showfig Source: https://github.com/genericmappingtools/gmt.jl/blob/master/_autodocs/api-reference/color-and-config.md Display a figure file using the system's default image viewer. ```APIDOC ## showfig ### Description Display a figure file using the system's default image viewer. ### Signature ```julia showfig(filename::String) ``` ``` -------------------------------- ### Reset GMT Session Source: https://github.com/genericmappingtools/gmt.jl/blob/master/_autodocs/configuration.md Clears all temporary data associated with the current GMT session and resets it to its default state. This is useful for starting a clean session. ```julia resetGMT() ``` -------------------------------- ### Create a Map with GMT.jl Source: https://github.com/genericmappingtools/gmt.jl/blob/master/_autodocs/INDEX.md Generates a PNG map with a Mercator projection, displaying coastlines and plotting specified points. This workflow requires `lon` and `lat` variables to be defined. The `show=true` argument displays the generated map. ```julia gmtbegin("map", fmt="png") coast(region="d", proj=:Mercator, land="gray", water="lightblue") plot!(lon, lat, marker=:star, fill="red", size=10) colorbar(cpt, pos="RB") gmtend(show=true) ``` -------------------------------- ### basemap / basemap! Source: https://github.com/genericmappingtools/gmt.jl/blob/master/_autodocs/api-reference/plotting-functions.md Creates a basemap including axes, frames, and labels without plotting any data. ```APIDOC ## basemap / basemap! ### Description Create a basemap (axes, frames, and labels) without data. ### Signature ```julia basemap(; kwargs...) basemap!(; kwargs...) ``` ### Request Example ```julia basemap(region="d", proj=:Merc, frame="a", show=true) ``` ``` -------------------------------- ### Data Analysis Pipeline with GMT.jl Source: https://github.com/genericmappingtools/gmt.jl/blob/master/_autodocs/INDEX.md Demonstrates a data analysis pipeline: loading scattered points, filtering them within a specified region, interpolating to create a grid, and visualizing the resulting grid. Ensure 'scattered_points.txt' exists. ```julia # Load → Filter → Interpolate → Visualize data = gmtread("scattered_points.txt") filtered = gmtselect(data, region=(0, 10, 0, 10)) grid = surface(filtered, region=(0, 10, 0, 10), inc=0.5) grdimage(grid, cmap=:viridis, show=true) ``` -------------------------------- ### Create a Basic Map with GMT.jl Source: https://github.com/genericmappingtools/gmt.jl/blob/master/_autodocs/README.md Generates a simple world map using the coast function. Specify the region, projection, and colors for land and water. ```julia using GMT coast(region="d", proj=:Mercator, land="gray", water="lightblue", show=true) ``` -------------------------------- ### Data Analysis Pipeline with GMT.jl Source: https://github.com/genericmappingtools/gmt.jl/blob/master/_autodocs/README.md A multi-step workflow involving reading point data, filtering it by region, creating a surface grid, and visualizing the grid. Requires data points in 'points.txt'. ```julia data = gmtread("points.txt") filtered = gmtselect(data, region=(0, 10, 0, 10)) grid = surface(filtered, inc=0.5) grdimage(grid, show=true) ``` -------------------------------- ### Coastline Plotting with GMT.jl Source: https://github.com/genericmappingtools/gmt.jl/blob/master/README.md Demonstrates the module-based approach in GMT.jl for plotting coastlines with specified region, projection, and land/water colors. This is an alternative to the verbose GMT command-line syntax. ```julia coast(region=:global, proj=:Winkel, frame=:g, area=10000, land=:burlywood4, water=:wheat1, show=true) ``` ```bash gmt coast -Rd -JR12 -Bg -Dc -A10000 -Gburlywood4 -Swheat1 -P > GMT_winkel.ps ``` -------------------------------- ### Set Single GMT Configuration Parameter Source: https://github.com/genericmappingtools/gmt.jl/blob/master/_autodocs/api-reference/color-and-config.md Configure a specific GMT behavior or appearance setting using the `gmtset` function. This example sets the map frame type to 'plain'. ```julia gmtset(MAP_FRAME_TYPE="plain") ``` -------------------------------- ### gmthelp Source: https://github.com/genericmappingtools/gmt.jl/blob/master/_autodocs/api-reference/color-and-config.md Displays GMT command-line help for a specified module. This function is helpful for understanding the usage and options of various GMT commands. ```APIDOC ## gmthelp ### Description Display GMT command-line help for a module. ### Signature ```julia gmthelp(module::String; kwargs...) ``` ### Examples ```julia gmthelp("psxy") gmthelp("grdinfo") ``` ``` -------------------------------- ### Create Polygons and Plot Trench/Profiles Source: https://github.com/genericmappingtools/gmt.jl/blob/master/WL_Example_II.ipynb Converts profile data into polygons and plots them along with the trench and individual profiles. Styling options control color, width, and appearance. ```julia # Use first and last point of each profile and create a polygon of the area A = gmt("convert -Ef -T", profiles); B = gmt("convert -El -T -Is", profiles); # Join the two segments area = [A[1].data; B[1].data]; P = gmt("psxy -R -J -O -K -Ggreen@85", area); P = gmt("psxy -R -J -O -K -W2p+v0.3c+gred+p0.25p+bc+ec", T); P = gmt("psxy -R -J -O -K -W0.5p,red+v0.25c+p0.25p+bt+et", profiles); ``` -------------------------------- ### Configure GMT Parameters and Themes Source: https://github.com/genericmappingtools/gmt.jl/blob/master/_autodocs/QUICK-REFERENCE.md Use `gmtset` to modify global GMT parameters and `theme` to apply predefined visual styles. `resetGMT` reverts to default settings. ```julia # Set GMT parameters gmtset(MAP_FRAME_TYPE="rounded", FONT_LABEL="14p,Helvetica-Bold") # Apply theme theme("dark") theme("cookbook") # Reset resetGMT() ``` -------------------------------- ### Start and End Modern Mode Plotting Source: https://github.com/genericmappingtools/gmt.jl/blob/master/_autodocs/configuration.md Initiate a plotting session with a specified figure name and finalize it, optionally displaying the result. Supports various output formats like PNG, PDF, and PS. ```julia gmtbegin("figure_name") # Start modern mode # ... plotting commands ... gmtend(show=true) # Finalize and display ``` -------------------------------- ### Control Plot Display and Output Source: https://github.com/genericmappingtools/gmt.jl/blob/master/_autodocs/configuration.md Use `show=true` to display the plot immediately or `savefig` to save it to a file. Various other options like `region`, `proj`, `frame`, and `marker` can be combined. ```julia # Display immediately plot(data, show=true) ``` ```julia # Save to file plot(data, savefig="output.png") ``` ```julia # With all options plot(data, region=(0, 10, 0, 10), proj=:Mercator, frame="a", xlabel="X", ylabel="Y", marker=:circle, size=5, fill="red", show=true) ``` -------------------------------- ### Get Summary Statistics for GMT Grid Source: https://github.com/genericmappingtools/gmt.jl/blob/master/_autodocs/api-reference/utilities-and-analysis.md The `grdinfo` function provides summary information for a GMT grid, including its dimensions, range, and statistical properties. This function is useful for understanding the characteristics of gridded data. ```julia grdinfo(grid::GMTgrid; kwargs...) ``` -------------------------------- ### Grid as Image Source: https://github.com/genericmappingtools/gmt.jl/blob/master/_autodocs/QUICK-REFERENCE.md Display a 2D grid as an image using a specified colormap. ```julia grid = gmtread("topography.grd") grdimage(grid, cmap=:relief, show=true) ``` -------------------------------- ### Basic Line Plot with GMT.jl Source: https://github.com/genericmappingtools/gmt.jl/blob/master/README.md Illustrates the simplified syntax for plotting a line from a file using GMT.jl, compared to the classic GMT command. ```julia plot("filename", show=true) ``` ```bash gmt psxy filename -R0/10/0/5 -JX12 -W1p -Ba -P > psfile.ps ``` -------------------------------- ### Get Summary Statistics for GMT Dataset Source: https://github.com/genericmappingtools/gmt.jl/blob/master/_autodocs/api-reference/utilities-and-analysis.md Use `gmtinfo` to retrieve summary statistics like min, max, and range for each column of a GMT dataset. Ensure the data is read using `gmtread` before passing it to `gmtinfo`. ```julia data = gmtread("points.txt") info = gmtinfo(data) ``` -------------------------------- ### Access Remote Grid Datasets with remotegrid Source: https://github.com/genericmappingtools/gmt.jl/blob/master/_autodocs/api-reference/geospatial-operations.md Use `remotegrid` to fetch data like topography or bathymetry from GMT's remote servers. Specify the dataset ID and optionally a region and resolution. Requires GMT.jl to be installed. ```julia # Get 5-minute resolution topography dem = remotegrid("@earth_relief_05m", region=(-180, 180, -90, 90)) ``` ```julia # Get local region with 1-minute resolution local_dem = remotegrid("@earth_relief_01m", region=(-10, 10, -10, 10)) ``` -------------------------------- ### Sample Grid Along Trench Profiles Source: https://github.com/genericmappingtools/gmt.jl/blob/master/WL_Example_II.ipynb Samples the relief grid along profiles normal to the trench. The -C option specifies the profile length, sampling interval, and spacing between profiles. ```julia # Sample grid along profiles normal to the trench profiles, stack = gmt("grdtrack -G -C300k/1k/25k -Sm+s+a", T, G); ``` -------------------------------- ### makecpt Source: https://github.com/genericmappingtools/gmt.jl/blob/master/_autodocs/api-reference/color-and-config.md Create a color palette table (CPT) from a built-in or custom color map. Supports various customization options for color range, number of colors, and color models. ```APIDOC ## makecpt ### Description Create a color palette table (CPT) from a built-in or custom color map. ### Signature ```julia makecpt(; cmap=nothing, range=nothing, kwargs...) makecpt(; colormap=nothing, levels=nothing, kwargs...) ``` ### Parameters | Parameter | Type | Default | Description | |-----------|------|---------|-------------| | `cmap` / `colormap` | String \| Symbol | `:turbo` | Built-in colormap name or RGB triplets | | `range` / `Z` | Tuple \| Vector | — | Value range [z_min, z_max] or vector of values | | `ncolors` / `H` | Int | 256 | Number of colors in palette | | `categorical` | Bool | false | Create categorical (step) color map | | `hinge` | Number | — | Discontinuous color break at value | | `background` / `B` | String | — | Background color for NaN values | | `foreground` / `F` | String | — | Foreground color for out-of-range values | | `model` | String | "rgb" | Color model: "rgb", "hsv", or "cmyk" | | `reverse` / `R` | Bool | false | Reverse color map direction | | `shift` | Number | — | Shift color map by N colors | | `cyclic` | Bool | false | Make colormap cyclic | ### Return Type GMTcpt ### Built-in Colormaps Common names: `:turbo`, `:viridis`, `:plasma`, `:inferno`, `:magma`, `:cividis`, `:gray`, `:jet`, `:hot`, `:cool`, `:spring`, `:summer`, `:autumn`, `:winter`, `:rainbow`, `:seismic`, `:RdYlBu`, `:Spectral`, `:GMT_haxby`, `:GMT_drywet`, `:GMT_relief`, `:GMT_globe` ### Examples ```julia # Create basic CPT cpt = makecpt(cmap=:viridis, range=(0, 100)) # Categorical colormap cpt = makecpt(cmap=:tab20, categorical=true, range=0:10) # Reverse colormap cpt = makecpt(cmap=:turbo, range=(0, 1000), reverse=true) # Custom colors cpt = makecpt(cmap="0,0,0/1,1,1", range=(0, 1)) # With NaN handling cpt = makecpt(cmap=:turbo, range=(0, 100), background="gray") ``` ### Source `src/makecpt.jl` ``` -------------------------------- ### Image Color Space and Format Conversions Source: https://github.com/genericmappingtools/gmt.jl/blob/master/_autodocs/api-reference/utilities-and-analysis.md Utilities for converting image color spaces (RGB to Grayscale, LAB, YCbCr) and formats between GMTimage and GMTgrid. ```APIDOC ## rgb2gray / rgb2lab / rgb2YCbCr / grid2img / img2grid ### Description Image color space and format conversions. ### Signature ```julia rgb2gray(img::GMTimage) rgb2lab(img::GMTimage) rgb2YCbCr(img::GMTimage) grid2img(grid::GMTgrid) img2grid(img::GMTimage) ``` ### Return Type GMTimage (different color space) or GMTgrid ### Example ```julia img = gmtread("photo.jpg") gray = rgb2gray(img) # Single channel ``` ``` -------------------------------- ### Extract Region and Resolution from GMT Objects Source: https://github.com/genericmappingtools/gmt.jl/blob/master/_autodocs/api-reference/geospatial-operations.md Use `getregion` to retrieve the bounding box of a GMT object (grid, image, or dataset) and `getres` to get its resolution. These functions are useful for analyzing spatial data properties. Ensure the object is read using `gmtread` first. ```julia grid = gmtread("dem.grd") region = getregion(grid) # [x_min, x_max, y_min, y_max] res = getres(grid) # [dx, dy] ``` -------------------------------- ### Perform Interpolation Source: https://github.com/genericmappingtools/gmt.jl/blob/master/_autodocs/QUICK-REFERENCE.md Illustrates converting scattered data to a grid using xyz2grd, interpolating from table data with surface, and performing spherical interpolation. ```julia grid = xyz2grd(x, y, z, region=(-3, 3, -3, 3), inc=0.1) ``` ```julia grid = surface(data, region=(-3, 3, -3, 3), inc=0.1) ``` ```julia grid = sphinterpolate(data, region="g", inc=1) ``` -------------------------------- ### Display Stacked Relief Profiles Source: https://github.com/genericmappingtools/gmt.jl/blob/master/WL_Example_II.ipynb Iterates through each profile and plots its data, then plots the computed median stack profile with a thicker line. Requires PyPlot for visualization. ```julia # Show the stacked relief profiles across the trench for k=1:length(profiles) plot(profiles[k].data[:,3], profiles[k].data[:,5]) end plot(stack[1].data[:,1], stack[1].data[:,2], linewidth=3) ``` -------------------------------- ### Basemap Creation Source: https://github.com/genericmappingtools/gmt.jl/blob/master/_autodocs/api-reference/plotting-functions.md Creates a basemap with axes, frames, and labels without any data. Useful for setting up geographic or Cartesian plots. ```julia basemap(region="d", proj=:Merc, frame="a", show=true) ``` -------------------------------- ### Load and Display Grid Data with GMT.jl Source: https://github.com/genericmappingtools/gmt.jl/blob/master/_autodocs/INDEX.md Loads a grid file and visualizes it using a specified colormap. Ensure the 'dem.grd' file exists in the working directory. The `show=true` argument displays the plot. ```julia using GMT # Load and display grid grid = gmtread("dem.grd") grdimage(grid, cmap=:turbo, show=true) ``` -------------------------------- ### Create Buffer Zone Around Geometry Source: https://github.com/genericmappingtools/gmt.jl/blob/master/_autodocs/api-reference/geospatial-operations.md Generates a buffer zone around a given geometry (e.g., a point). The `distance` parameter specifies the buffer size in the geometry's current units. ```julia point = mat2ds([0 0]) buffered = buffergeo(point, distance=100) ``` -------------------------------- ### grdinfo Source: https://github.com/genericmappingtools/gmt.jl/blob/master/_autodocs/api-reference/grid-operations.md Retrieves summary statistics and metadata from a GMT grid file. ```APIDOC ## grdinfo ### Description Get summary statistics about a grid. ### Signature ```julia grinfo(grid::GMTgrid; kwargs...) ``` ### Return Type Dictionary or string with metadata ### Examples ```julia grid = gmtread("dem.grd") info = grdinfo(grid) ``` ``` -------------------------------- ### Load and Plot Point Data with GMT.jl Source: https://github.com/genericmappingtools/gmt.jl/blob/master/_autodocs/INDEX.md Loads point data from a text file and plots the first two columns as circles. Assumes 'points.txt' contains data with at least two columns. The `show=true` argument displays the plot. ```julia # Load and plot points data = gmtread("points.txt") plot(data[:, 1], data[:, 2], marker=:circle, show=true) ``` -------------------------------- ### Locate GMT Data Files Source: https://github.com/genericmappingtools/gmt.jl/blob/master/_autodocs/api-reference/color-and-config.md Use `gmtwhich()` to find the full path to a file, including those in GMT's data directories. It supports checking the cache and downloading remote files if needed. ```julia path = gmtwhich("@earth_relief_01m") ``` -------------------------------- ### Reset GMT Theme to Default Source: https://github.com/genericmappingtools/gmt.jl/blob/master/_autodocs/api-reference/color-and-config.md Revert all theme settings back to the default GMT theme. This is helpful after making extensive customizations and wanting to return to the standard appearance. ```julia theme("default") ``` -------------------------------- ### Using DataFrames with GMT.jl Source: https://github.com/genericmappingtools/gmt.jl/blob/master/_autodocs/configuration.md Demonstrates how to use DataFrames with GMT.jl. This requires the DataFrames package to be imported. ```julia using DataFrames, GMT df = DataFrame(x=1:10, y=rand(10)) ds = df2ds(df) # Works only if DataFrames imported ``` -------------------------------- ### Generate Image and Coastlines Source: https://github.com/genericmappingtools/gmt.jl/blob/master/WL_Example_II.ipynb Creates a relief image of the specified region and overlays coastlines. Options control the region, projection, grid, and appearance. ```julia P = gmt("grdimage -R141/147/35/42 -JM6i -P -Baf -BWSne -I -K -C --FORMAT_GEO_MAP=dddF", G, intens, C); P = gmt("pscoast -R -J -O -K -W0.25p -Dh -LjTR+w200k+u+f+c38:30N+o0.5i/0.2i -F+gwhite+p0.5p"); ``` -------------------------------- ### Visualize a Grid with GMT.jl Source: https://github.com/genericmappingtools/gmt.jl/blob/master/_autodocs/README.md Reads a grid file and visualizes it as an image using grdimage. Supports colormap customization. ```julia grid = gmtread("dem.grd") grdimage(grid, cmap=:turbo, show=true) ``` -------------------------------- ### Finalize and Show Modern Mode Session Source: https://github.com/genericmappingtools/gmt.jl/blob/master/_autodocs/api-reference/color-and-config.md Finalizes a modern mode GMT session, optionally rendering or displaying the output. Use `show=true` to display the figure immediately. The `savefig` parameter can override the format set in `gmtbegin`. ```julia gmtbegin("myfigure", fmt="png") plot([1, 2, 3], [1, 2, 1]) gmtend(show=true) ``` -------------------------------- ### Convert Matrix to Grid (Julia) Source: https://github.com/genericmappingtools/gmt.jl/blob/master/_autodocs/api-reference/grid-operations.md Use `mat2grid` to convert a matrix into a GMTgrid. Requires associated x and y coordinates or grid spacing and region. ```julia data = randn(100, 100) x = LinRange(-10, 10, 100) y = LinRange(-10, 10, 100) grid = mat2grid(data, x, y) ``` -------------------------------- ### Create Coordinate Grids Source: https://github.com/genericmappingtools/gmt.jl/blob/master/_autodocs/api-reference/utilities-and-analysis.md Generates coordinate matrices from 1D vectors for creating 2D or 3D grids. Use when defining spatial domains for plotting or analysis. ```julia x = 0:10 y = 0:5 X, Y = meshgrid(x, y) ``` -------------------------------- ### Array Utilities in GMT.jl Source: https://github.com/genericmappingtools/gmt.jl/blob/master/_autodocs/QUICK-REFERENCE.md Commonly used functions for array manipulation, including grid creation, spacing, element counting, flipping, and squeezing. ```julia meshgrid(x, y) # Create coordinate grids ``` ```julia linspace(0, 1, 100) # Linear spacing ``` ```julia logspace(0, 3, 10) # Log spacing ``` ```julia numel(array) # Element count ``` ```julia squeeze(array) # Remove singleton dimensions ``` ```julia flipud(array) # Flip up-down ``` ```julia fliplr(array) # Flip left-right ``` -------------------------------- ### Display Grid as Image with GMT Source: https://github.com/genericmappingtools/gmt.jl/blob/master/_autodocs/api-reference/plotting-functions.md Use `grdimage` to display a grid as a color-shaded image. It supports custom coloring and shading for relief effects. Ensure the grid data is read using `gmtread`. ```julia dem = gmtread("elevation.grd") grdimage(dem, shade=true, show=true) ``` ```julia grdimage(dem, cmap=:turbo, show=true) ``` ```julia grdimage(dem, shade="-A45", show=true) ``` -------------------------------- ### grdblend Source: https://github.com/genericmappingtools/gmt.jl/blob/master/_autodocs/api-reference/grid-operations.md Blend multiple grids with weights. Allows specifying output region and spacing. ```APIDOC ## grdblend ### Description Blend multiple grids with weights. ### Signature ```julia grdblend(grids::Vector{GMTgrid}; region=nothing, inc=nothing, kwargs...) ``` ### Parameters - `region` (Tuple): Output region. - `inc` (Number): Output spacing. ### Return Type GMTgrid ``` -------------------------------- ### Apply Dark Theme in GMT Source: https://github.com/genericmappingtools/gmt.jl/blob/master/_autodocs/api-reference/color-and-config.md Use the `theme` function to apply a predefined dark theme. This is useful for creating plots with a dark background and contrasting elements. ```julia theme("dark") ``` -------------------------------- ### Line Plot with Custom Styling Source: https://github.com/genericmappingtools/gmt.jl/blob/master/_autodocs/api-reference/plotting-functions.md Creates a line plot with specified data and custom pen attributes for styling. The 'show=true' argument is necessary for immediate display. ```julia # Line plot with custom styling plot([1, 2, 3], [1, 2, 1], pen="1p,red", show=true) ``` -------------------------------- ### Specify Map Region and Projection Source: https://github.com/genericmappingtools/gmt.jl/blob/master/_autodocs/configuration.md Use `region` and `proj` to define the map boundaries and projection. `region` can be a tuple of bounds or a string like "d" for global. `proj` accepts symbols or strings. ```julia # Full region plot(data, region=(-10, 10, -10, 10), proj=:Mercator, frame="a", show=true) ``` ```julia # Auto-detect projection from data plot(data, region="d", proj=:Mollweide, frame="g", show=true) ``` ```julia # Custom frame specification plot(data, frame="a10g5 +tPlot Title", show=true) ``` -------------------------------- ### Core Import for GMT.jl Source: https://github.com/genericmappingtools/gmt.jl/blob/master/_autodocs/QUICK-REFERENCE.md Import the main GMT module to access all its exported functions and types. ```julia using GMT ``` -------------------------------- ### Import Satellite Data from HDF5 Source: https://github.com/genericmappingtools/gmt.jl/blob/master/WL_Example_III.ipynb Reads sea surface temperature, quality flags, latitude, and longitude from an HDF5 file into GMT data structures. Ensure the HDF5 file is accessible. ```julia using GMT file = "A2016152023000.L2_LAC_SST.nc=gd?HDF5:\"A2016152023000.L2_LAC_SST.nc\""; sst = gmt("read -Tg " * file * "://geophysical_data/sst"); qual = gmt("read -Tg " * file * "://geophysical_data/qual_sst"); lat = gmt("read -Tg " * file * "://navigation_data/latitude"); lon = gmt("read -Tg " * file * "://navigation_data/longitude"); ``` -------------------------------- ### Set GMT Parameters via `par` Source: https://github.com/genericmappingtools/gmt.jl/blob/master/_autodocs/configuration.md Configure GMT parameters using the `par` keyword argument, which accepts a dictionary. This allows for fine-tuning of GMT's behavior, such as output formatting. ```julia plot(data, par=(PROJ_LENGTH_UNIT="inch", FORMAT_FLOAT_OUT="%.2f")) ``` -------------------------------- ### Read Relief Grid and Trench Data Source: https://github.com/genericmappingtools/gmt.jl/blob/master/WL_Example_II.ipynb Imports a relief grid and trench location data using GMT.jl. Ensure the data files (JP.nc and JP.txt) are accessible. ```julia using GMT # Read in relief grid and Japan trench location G = gmt("read -Tg JP.nc"); T = gmt("read -Td JP.txt"); ``` -------------------------------- ### Type Conversion Utilities in GMT.jl Source: https://github.com/genericmappingtools/gmt.jl/blob/master/_autodocs/QUICK-REFERENCE.md Functions for converting between different data types, such as matrices to datasets, grids, or images, and for file path manipulation. ```julia mat2ds(matrix) # Matrix to dataset ``` ```julia mat2grid(matrix, x, y) # Matrix to grid ``` ```julia mat2img(matrix) # Matrix to image ``` ```julia fileparts(path) # Split file path ``` -------------------------------- ### Convert Grid to XYZ Data (Julia) Source: https://github.com/genericmappingtools/gmt.jl/blob/master/_autodocs/api-reference/grid-operations.md Use `grd2xyz` to convert a GMTgrid into (x, y, z) data points. Can optionally dump only z values or report errors/NaNs. ```julia grid = gmtread("dem.grd") data = grd2xyz(grid) ``` -------------------------------- ### violin / violin! Source: https://github.com/genericmappingtools/gmt.jl/blob/master/_autodocs/api-reference/plotting-functions.md Displays a violin plot, which is a kernel density estimate of data distribution. ```APIDOC ## violin / violin! ### Description Display violin plot (kernel density estimate) of data distribution. ### Signature ```julia violin(data::Array; kwargs...) violin!(data::Array; kwargs...) ``` ``` -------------------------------- ### gmtwhich Source: https://github.com/genericmappingtools/gmt.jl/blob/master/_autodocs/api-reference/color-and-config.md Determines the full path to a file, including GMT data directories. It can also check the GMT cache directory and download remote files if necessary. ```APIDOC ## gmtwhich ### Description Determine full path to a file, including GMT data directories. ### Signature ```julia gmtwhich(fname::String; kwargs...) ``` ### Parameters #### Query Parameters - **cache** (Bool) - Check GMT cache directory - **download** (Bool) - Download remote files if needed ### Examples ```julia path = gmtwhich("@earth_relief_01m") ``` ``` -------------------------------- ### meshgrid Source: https://github.com/genericmappingtools/gmt.jl/blob/master/_autodocs/api-reference/utilities-and-analysis.md Creates coordinate grids from 1D vectors. ```APIDOC ## meshgrid ### Description Create coordinate grids from 1D vectors. ### Signature ```julia meshgrid(x::Vector, y::Vector) meshgrid(x::Vector, y::Vector, z::Vector) ``` ### Return Type Tuple of coordinate matrices ### Examples ```julia x = 0:10 y = 0:5 X, Y = meshgrid(x, y) ``` ``` -------------------------------- ### Create CPT from Colormap Source: https://github.com/genericmappingtools/gmt.jl/blob/master/_autodocs/api-reference/color-and-config.md Use `makecpt` to generate a color palette table (CPT) from a specified colormap. Supports built-in or custom colormaps, range specification, and categorical or reversed color maps. ```julia cpt = makecpt(cmap=:viridis, range=(0, 100)) ``` ```julia cpt = makecpt(cmap=:tab20, categorical=true, range=0:10) ``` ```julia cpt = makecpt(cmap=:turbo, range=(0, 1000), reverse=true) ``` ```julia cpt = makecpt(cmap="0,0,0/1,1,1", range=(0, 1)) ``` ```julia cpt = makecpt(cmap=:turbo, range=(0, 100), background="gray") ``` -------------------------------- ### Color Map Operations Source: https://github.com/genericmappingtools/gmt.jl/blob/master/_autodocs/QUICK-REFERENCE.md Functions for creating and displaying color palettes and colorbars. ```APIDOC ## Color Maps ```julia # Create color palette cpt = makecpt(cmap=:turbo, range=(0, 100)) cpt = makecpt(cmap=:viridis, range=(0, 1000), reverse=true) cpt = grd2cpt(grid, cmap=:relief) # Display colorbar colorbar(cpt, pos="RB", show=true) ``` ``` -------------------------------- ### Reduce Data Points with blockmean Source: https://github.com/genericmappingtools/gmt.jl/blob/master/_autodocs/api-reference/utilities-and-analysis.md Use blockmean to reduce dense data points by computing the mean within specified rectangular blocks. Requires GMTdataset input and block region/size parameters. ```julia data = gmtread("dense_points.txt") reduced = blockmean(data, region=(-180, 180, -90, 90), inc=10) ``` -------------------------------- ### Split File Path Source: https://github.com/genericmappingtools/gmt.jl/blob/master/_autodocs/api-reference/utilities-and-analysis.md Splits a given file path into its directory, name, and extension components. Useful for isolating parts of a file path. ```julia dir, name, ext = fileparts("/path/to/data.txt") # dir = "/path/to", name = "data", ext = ".txt" ``` -------------------------------- ### Project Geographic Data with GMT.jl Source: https://github.com/genericmappingtools/gmt.jl/blob/master/_autodocs/INDEX.md Reads geographic data, transforms it to a Mercator map projection, and saves the transformed data to a new file. Assumes 'data_geographic.txt' exists and contains geographic coordinates. ```julia # Read geographic data data = gmtread("data_geographic.txt") # Transform to map projection projected = mapproject(data, proj=:Mercator) # Save transformed data gmtwrite("data_projected.txt", projected) ``` -------------------------------- ### Convert PostScript to Images Source: https://github.com/genericmappingtools/gmt.jl/blob/master/_autodocs/api-reference/color-and-config.md Use `psconvert()` to convert PostScript files to various image formats like PNG, PDF, or TIFF. You can specify the output format, input file, resolution, and anti-aliasing options. ```python # Convert PS to PNG psconvert(filein="myplot.ps", fmt="g", dpi=300) ``` ```python # Get rendered image in memory img = psconvert(filein="myplot.ps", fmt="g") ``` -------------------------------- ### Convert Scattered Data to Grid (Julia) Source: https://github.com/genericmappingtools/gmt.jl/blob/master/_autodocs/api-reference/grid-operations.md Use `xyz2grd` to interpolate scattered points into a regular grid. Supports conversion from vectors or GMTdataset objects. Specify region and grid spacing for desired output. ```julia x = randn(100) y = randn(100) z = x.^2 + y.^2 grid = xyz2grd(x, y, z, region=(-2, 2, -2, 2), inc=0.1) ``` ```julia data = gmtread("points.txt") grid = xyz2grd(data, region="d", inc=1) ``` -------------------------------- ### Append Raw PostScript Source: https://github.com/genericmappingtools/gmt.jl/blob/master/_autodocs/api-reference/color-and-config.md Use `add2PSfile()` to append raw PostScript code to the current figure. This allows for fine-grained control over the output. ```julia add2PSfile(ps_string::String) ```