project_extract.sh 3.38 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
#!/bin/bash
##
# @file This file is part of EDGE.
#
# @author Alexander Breuer (anbreuer AT ucsd.edu)
#
# @section LICENSE
# Copyright (c) 2020, Alexander Breuer
# Copyright (c) 2018, Regents of the University of California
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
#
# 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
# @section DESCRIPTION
# Plots and projects the data.
##
# create output directory
out_dir=out_pe
mkdir ${out_dir}

# region of interest cut from the mesh
30
region_cut=-50025/50025/-50025/50025
31

32 33
# sampling of the topo mesh (50m)
region_sampling=50/50
34

35
# projection center is the epicenter of the "M 5.1 - 2km NW of Brea, CA"-event https://earthquake.usgs.gov/earthquakes/eventpage/ci15481673/executive
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
projection="tmerc/-117.916/33.933"

grids=(grids/n34w119/grdn34w119_13/w001001.adf  grids/n34w118/grdn34w118_13/w001001.adf grids/n35w119/grdn35w119_13/w001001.adf grids/n35w118/grdn35w118_13/w001001.adf)

# blend region
blend_region=-119/-117/33/35

# create work directory
tmp_dir=$(mktemp -d)

# generate a color table
gmt makecpt -Cetopo1 > ${tmp_dir}/gmt_colors.cpt

# blend the two grids together
gmt grdblend ${grids[*]} -R${blend_region} -G${tmp_dir}/blend.nc -V2

# plot topography in lon/lat
gmt grdimage -J${projection}/8c ${tmp_dir}/blend.nc -Ba -E75 -C${tmp_dir}/gmt_colors.cpt > ${tmp_dir}/blend.ps

# convert to pdf
ps2pdf ${tmp_dir}/blend.ps ${out_dir}/blend.pdf

# project grid
gmt grdproject ${tmp_dir}/blend.nc -J${projection}/0.9996 -C -G${tmp_dir}/proj.nc -Fe -V2

# extract and resample mesh
gmt grdsample ${tmp_dir}/proj.nc -I${region_sampling} -R${region_cut} -G${tmp_dir}/topo.nc -r -V2

# convert to ascii
gmt grd2xyz ${tmp_dir}/topo.nc > ${tmp_dir}/topo.xyz

# replace all nans (under water) with zeroes, grdfill tends to segfault: manual sed
sed 's/NaN/0/g' ${tmp_dir}/topo.xyz > ${out_dir}/topo.xyz

# plot topography
gmt grdimage -JX6.5i -C${tmp_dir}/colors.cpt ${tmp_dir}/topo.nc -Ba -C${tmp_dir}/gmt_colors.cpt -V2 > ${tmp_dir}/map.ps

# convert to pdf
ps2pdf ${tmp_dir}/map.ps ${out_dir}/map.pdf

# remove work directory
rm -r ${tmp_dir}