Skip to content

Commit 384ff92

Browse files
author
meihuisu
committed
update to have complete output for cross_section and horizonal_slice
1 parent 4bee0ad commit 384ff92

File tree

7 files changed

+136
-20
lines changed

7 files changed

+136
-20
lines changed
672 Bytes
Binary file not shown.

dist/ucvm_plotting-0.0.6.tar.gz

659 Bytes
Binary file not shown.

pycvm/cross_section.py

Lines changed: 65 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@
99
# Imports
1010
from .cvm_ucvm import Point, MaterialProperties, UCVM, UCVM_CVMS
1111
from .cvm_plot import Plot, math, plot_cmapDiscretize, cm, mcolors, basemap, plt, np
12-
from .cvm_common import VERSION
12+
from .cvm_common import VERSION, pycvm_filestub
1313

1414
import random
1515
import string
16+
import pdb
1617

1718
try:
1819
import pyproj
@@ -96,9 +97,16 @@ def __init__(self, startingpoint, endingpoint, meta={}):
9697
self.cvm = self.meta['cvm']
9798
else:
9899
self.cvm = None
99-
100+
101+
self.skip = None
102+
if ('skip' in self.meta) and (self.meta['skip'] == '1') :
103+
self.skip = True
104+
100105
if 'data_type' in self.meta :
101106
self.mproperty = self.meta['data_type']
107+
if self.meta['data_type'] == 'all' :
108+
if self.skip == None:
109+
self.mproperty = "vs"
102110
else:
103111
self.mproperty = "vs"
104112

@@ -140,11 +148,6 @@ def __init__(self, startingpoint, endingpoint, meta={}):
140148
self.startingpoint.latitude, self.endingpoint.longitude, self.endingpoint.latitude)
141149
self.meta['title']=self.title
142150

143-
if 'skip' in self.meta:
144-
self.skip= True;
145-
else:
146-
self.skip = None
147-
148151
self.ucvm = UCVM(install_dir=self.installdir, config_file=self.configfile, z_range=self.z_range, floors=self.floors)
149152

150153

@@ -235,18 +238,19 @@ def getplotvals(self, mproperty='vs'):
235238

236239
## The 2D array of retrieved material properties.
237240
self.materialproperties = [[MaterialProperties(-1, -1, -1) for x in range(self.num_x)] for y in range(self.num_y)]
238-
239-
240241
for y in range(0, self.num_y):
241242
for x in range(0, self.num_x):
242243
self.materialproperties[y][x] = data[y * self.num_x + x]
244+
243245
##
244246
# Plots the cross section slice either to an image or a file name.
245247
#
246248
def plot(self):
247-
248249
if self.skip :
249-
self._file()
250+
if self.mproperty == "all" :
251+
self._file_all()
252+
else:
253+
self._file()
250254
else:
251255
self._plot_file()
252256

@@ -514,3 +518,53 @@ def _file(self) :
514518
f = "cross_section"+rnd
515519
ucvm.export_metadata(self.meta,f)
516520
ucvm.export_np_float_array(datapoints,f)
521+
522+
523+
##
524+
# Create the cross section slice data files for vs, vp and density
525+
#
526+
def _file_all(self) :
527+
528+
# make sure meta.datafile is None
529+
self.datafile = None
530+
531+
#label_uid_something.png
532+
if self.filename != None:
533+
fstub=pycvm_filestub(self.filename)
534+
else:
535+
rnd=''.join(random.SystemRandom().choice(string.ascii_uppercase + string.digits) for _ in range(6))
536+
fstub = "cross_section_"+rnd
537+
538+
self.getplotvals()
539+
540+
datapoints = np.arange(self.num_x * self.num_y,dtype=np.float32).reshape(self.num_y, self.num_x)
541+
542+
for mproperty in ['vs', 'vp', 'density' ] :
543+
544+
self.meta['data_type']=mproperty
545+
# process for label + UID
546+
f = fstub+"_"+mproperty
547+
548+
for i in range(0, self.num_y):
549+
for j in range(0, self.num_x):
550+
datapoints[i][j] = self.materialproperties[i][j].getProperty(mproperty)
551+
552+
self.max_val= np.nanmax(datapoints)
553+
self.min_val=np.nanmin(datapoints)
554+
self.mean_val=np.mean(datapoints)
555+
556+
ucvm = self.ucvm
557+
558+
self.meta['num_x'] = self.num_x
559+
self.meta['num_y'] = self.num_y
560+
self.meta['datapoints'] = datapoints.size
561+
self.meta['max'] = self.max_val.item()
562+
self.meta['min'] = self.min_val.item()
563+
self.meta['mean'] = self.mean_val.item()
564+
self.meta['lon_list'] = self.lon_list
565+
self.meta['lat_list'] = self.lat_list
566+
self.meta['depth_list'] = self.depth_list
567+
568+
ucvm.export_metadata(self.meta,f+"_meta.json")
569+
ucvm.export_np_float_array(datapoints,f+"_data.bin")
570+

pycvm/cvm_common.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,3 +175,13 @@ def pycvm_is_num(value):
175175
return True
176176
except Exception:
177177
return False
178+
##
179+
# Returns file stub that is made of label_uid
180+
#
181+
# @param filename The string to extract label and uid from
182+
# @return file_uid string
183+
def pycvm_filestub(fname):
184+
tokens = fname.split("_")
185+
label=tokens[0]
186+
uid=tokens[1]
187+
return label+"_"+uid

pycvm/horizontal_slice.py

Lines changed: 59 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
# Imports
1111
from .cvm_ucvm import Point, MaterialProperties, UCVM, UCVM_CVMS
1212
from .cvm_plot import Plot, math, plot_cmapDiscretize, cm, mcolors, basemap, plt, np
13-
from .cvm_common import VERSION
13+
from .cvm_common import VERSION, pycvm_filestub
1414

1515
##
1616
# @class HorizontalSlice
@@ -134,16 +134,18 @@ def __init__(self, upperleftpoint, bottomrightpoint, meta={}) :
134134
self.title = "%s%s Horizontal Slice at %.0fm" % (location_text, cvmdesc, self.upperleftpoint.depth)
135135
self.meta['title'] = self.title
136136

137+
self.skip = None
138+
if ('skip' in self.meta) and (self.meta['skip'] == '1'):
139+
self.skip = True
140+
137141
if 'data_type' in self.meta :
138142
self.mproperty = self.meta['data_type']
143+
if self.meta['data_type'] == 'all' :
144+
if self.skip == None:
145+
self.mproperty = "vs"
139146
else:
140147
self.mproperty = "vs"
141148

142-
if 'skip' in self.meta:
143-
self.skip = self.meta['skip']
144-
else:
145-
self.skip = None;
146-
147149
self.ucvm = UCVM(install_dir=self.installdir, config_file=self.configfile, z_range=self.z_range, floors=self.floors)
148150

149151
##
@@ -227,7 +229,10 @@ def getplotvals(self, mproperty="vs"):
227229
def plot(self, horizontal_label = None):
228230

229231
if self.skip :
230-
self._file(horizontal_label)
232+
if self.mproperty == "all" :
233+
self._file_all(horizontal_label)
234+
else:
235+
self._file(horizontal_label)
231236
else:
232237
self._plot_file(horizontal_label)
233238

@@ -467,3 +472,50 @@ def _file(self, horizontal_label = None):
467472
ucvm.export_metadata(self.meta,f)
468473
ucvm.export_np_float_array(datapoints,f)
469474

475+
476+
##
477+
# Create the horizontal slice data file only and one of each of vs, vp, density
478+
#
479+
def _file_all(self, horizontal_label = None):
480+
481+
self.datafile = None
482+
483+
self.getplotvals()
484+
485+
#label_uid_something.png
486+
if self.filename != None:
487+
fstub=pycvm_filestub(self.filename)
488+
else:
489+
rnd=''.join(random.SystemRandom().choice(string.ascii_uppercase + string.digits) for _ in range(6))
490+
fstub = "horizontal_slice_"+rnd
491+
492+
# Get the properties.
493+
datapoints = np.arange(self.num_x * self.num_y,dtype=np.float32).reshape(self.num_y, self.num_x)
494+
for mproperty in ['vs', 'vp', 'density' ] :
495+
496+
self.meta['data_type']=mproperty
497+
# process for label + UID
498+
f = fstub+"_"+mproperty
499+
500+
for i in range(0, self.num_y):
501+
for j in range(0, self.num_x):
502+
datapoints[i][j] = self.materialproperties[i][j].getProperty(mproperty)
503+
504+
self.max_val= np.nanmax(datapoints)
505+
self.min_val=np.nanmin(datapoints)
506+
self.mean_val=np.mean(datapoints)
507+
508+
ucvm = self.ucvm
509+
510+
self.meta['num_x'] = self.num_x
511+
self.meta['num_y'] = self.num_y
512+
self.meta['datapoints'] = datapoints.size
513+
self.meta['max'] = self.max_val.item()
514+
self.meta['min'] = self.min_val.item()
515+
self.meta['mean'] = self.mean_val.item()
516+
self.meta['lon_list']=self.lons
517+
self.meta['lat_list']=self.lats
518+
519+
ucvm.export_metadata(self.meta,f+"_meta.json")
520+
ucvm.export_np_float_array(datapoints,f+"_data.bin")
521+

ucvm_plotting/plot_cross_section.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def usage():
2121
print("\t-e, --ending: ending depth for cross-section (meters)")
2222
print("\t-h, --horizontal: horizontal spacing for cross-section (meters)")
2323
print("\t-v, --vertical: vertical spacing for cross-section (meters)")
24-
print("\t-d, --datatype: either 'vs', 'vp', 'density', or 'poisson', without quotation marks")
24+
print("\t-d, --datatype: either 'vs', 'vp', 'density', 'all', or 'poisson', without quotation marks")
2525
print("\t-c, --cvm: one of the installed CVMs")
2626
print("\t-z, --zrange: optional Z-range for elygtl:ely (e.g. -z 0,350)")
2727
print("\t-L, --floors: optional vs/vp/density floors for taper (e.g. -L 500,1700,1700)")

ucvm_plotting/plot_horizontal_slice.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def usage():
2020
print("\t-u, --upperright: upper-right latitude, longitude (e.g. 35,-117)")
2121
print("\t-s, --spacing: grid spacing in degrees (typically 0.01)")
2222
print("\t-e, --depth: depth for horizontal slice in meters (e.g. 1000)")
23-
print("\t-d, --datatype: either 'vs', 'vp', 'density', or 'poisson', without quotation marks")
23+
print("\t-d, --datatype: either 'vs', 'vp', 'density', 'all', or 'poisson', without quotation marks")
2424
print("\t-c, --cvm: one of the installed velocity models")
2525
print("\t-z, --zrange: optional Z-range for elygtl:ely (e.g. -z 0,350)")
2626
print("\t-L, --floors: optional vs/vp/density floors for taper (e.g. -L 500,1700,1700)")

0 commit comments

Comments
 (0)