project_extract.sh 4.77 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 30 31 32 33 34 35 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 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
#!/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.
##
# points of interest in lon/lat
poi_lonlat=../poi_lonlat.csv

# receivers in lon/lat
receivers_lonlat=../receivers_lonlat.csv

# create output directory
out_dir=out_pe
mkdir ${out_dir}

# points of interest in meters
poi=${out_dir}/poi.csv

# receivers in meters
receivers=${out_dir}/receivers.csv

# region of interest cut from the mesh
region_cut=-50012.5/50012.5/-50012.5/50012.5

# sampling of the topo mesh (25m)
region_sampling=25/25

# projection center is the epicenter of the 2004 Parfield earthquake
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 receiver coordinates
#cat ${receivers_lonlat} | cs2cs +proj=latlong +datum=WGS84 +to +proj=tmerc +units=m +axis=end +no_defs +ellps=GRS80 +k=0.9996 +lon_0=-120.365 +lat_0=35.817 -f %.12f > ${receivers}

# add receivers (symbols only)
#gmt psxy ${receivers} -R${blend_region} -Z -J${projection}/8c -Sd.1 -Gblack -O -K -V2  >> ${tmp_dir}/blend.ps

# add points of interests
#gmt psxy ${poi_lonlat} -R${blend_region} -Z -J${projection}/8c -Sd.25 -Gblack -O -K -V2  >> ${tmp_dir}/blend.ps

# add captions
#gmt pstext ${poi_lonlat} -R${blend_region} -J${projection}/8c -F+f7+jL -D0.2/0c -O -V2 >> ${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

# convert point of interests
#cat ${poi_lonlat} | cs2cs +proj=latlong +datum=WGS84 +to +proj=tmerc +units=m +axis=end +no_defs +ellps=GRS80 +k=0.9996 +lon_0=-120.365 +lat_0=35.817 -f %.12f > ${poi}

# 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

# add receivers
#gmt psxy ${receivers} -Z -JX6.5i -R${region_cut} -Sd.1 -Gblack -O -K -V2  >> ${tmp_dir}/map.ps

#gmt pstext ${receivers} -Z -R${region_cut} -JX6.5i -F+f3+jL -D0.05/0c -O -K -V2 >> ${tmp_dir}/map.ps

# add points of interests
#gmt psxy ${poi} -Z -JX6.5i -R${region_cut} -Sd.25 -Gblack -O -K -V2  >> ${tmp_dir}/map.ps

#gmt pstext ${poi} -Z -R${region_cut} -JX6.5i -F+f7+jL -D0.2/0c -O -V2 >> ${tmp_dir}/map.ps

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

# remove work directory
rm -r ${tmp_dir}