Hi - I'm so desperate to get a script working, is anybody up for a challenge please?. It fails with this comment:
Error:/usr/lib/python2.7/dist-packages/matplotlib/contour.py:1180: UserWarning: No contour levels were found within the data range.
warnings.warn("No contour levels were found"
<matplotlib.contour.QuadContourSet object at 0x7f67d4b47490>
Traceback (most recent call last):
File "init_collapse.py", line 114, in <module>
csp=cs.collections[0].get_paths()[2] # path
IndexError: list index out of range[bThis is a snap from the external file of coordinates and heights:[/b]Output:3560081.703 -3384637.321 -116.19
3560091.703 -3384637.321 -114.481
3560101.703 -3384637.321 -112.772
3560111.703 -3384637.321 -111.063
3560121.703 -3384637.321 -109.354This is how it is imported as the variable data:Output:[[ 3.56008170e+06 -3.38463732e+06 -1.16190000e+02]
[ 3.56009170e+06 -3.38463732e+06 -1.14481000e+02]
[ 3.56010170e+06 -3.38463732e+06 -1.12772000e+02]This is a list of the variables Kxx, kyy, kelevation and collapse_depth that feeds into the failure variable csOutput:[[ 3564081.703 3564091.703 3564101.703 ..., 3565551.703 3565561.703
3565571.703]
[ 3564081.703 3564091.703 3564101.703 ..., 3565551.703 3565561.703
3565571.703]
[ 3564081.703 3564091.703 3564101.703 ..., 3565551.703 3565561.703
3565571.703]
...,
[ 3564081.703 3564091.703 3564101.703 ..., 3565551.703 3565561.703
3565571.703]
[ 3564081.703 3564091.703 3564101.703 ..., 3565551.703 3565561.703
3565571.703]
[ 3564081.703 3564091.703 3564101.703 ..., 3565551.703 3565561.703
3565571.703]]
[[-3389837.321 -3389837.321 -3389837.321 ..., -3389837.321 -3389837.321
-3389837.321]
[-3389847.321 -3389847.321 -3389847.321 ..., -3389847.321 -3389847.321
-3389847.321]
[-3389857.321 -3389857.321 -3389857.321 ..., -3389857.321 -3389857.321
-3389857.321]
...,
[-3391607.321 -3391607.321 -3391607.321 ..., -3391607.321 -3391607.321
-3391607.321]
[-3391617.321 -3391617.321 -3391617.321 ..., -3391617.321 -3391617.321
-3391617.321]
[-3391627.321 -3391627.321 -3391627.321 ..., -3391627.321 -3391627.321
-3391627.321]]
[[ 964.877 967.491 970.106 ..., 723.177 721.048 718.919]
[ 966.833 969.941 973.05 ..., 722.591 720.469 718.348]
[ 968.558 971.845 975.133 ..., 721.975 719.87 717.765]
...,
[ 537.758 537.723 537.688 ..., 441.422 440.741 440.06 ]
[ 535.511 535.425 535.339 ..., 438.624 438. 437.376]
[ 533.265 533.128 532.991 ..., 435.826 435.26 434.693]]
-204This is the script up to the scrash point."""
A script that generates initial bathymetry and size of displacement of the seafloor (representing caldera collapse in our case)
initial bathymetry: crater filled
final bathymetry: present day bathymetry
INPUT PARAMETERS
--
OUTPUT FILES
-- mesh before collapse (default name:
-- displacement of sea floor (default name: collapse.xyt)
"""
from scipy import *
from pylab import *
from numpy import *
import sys
from degrees2utm import *
from copy import deepcopy
#from matplotlib.patches import PathPatch
from matplotlib.pyplot import *
#close('all')
# =================================================================================
# INPUT SECTION BEGIN
# =================================================================================
meshfile='GRID7_Before.xyz' # !!!!!!!!!!!!!!!!!!!!sr
collapse_duration=60.0 # in seconds
collapse_depth=-204 # depth of the filling cup
meshfile_start='GRID7_Before.xyz' # file with output
file_ls="collapse.xyt" # file with displacement
############# GENERAL SWITCHES; for plotting purposes
plot_bathymetry_allmesh=False # original mesh
plot_bathymetry_kolumbo=False # only small region around Kolumbo is extracted
plot_collapsed_volume=False # show collapse volume
plot_before_after=False # plot mesh before and after the collapse
plot_debugfig=False # debug figures; for checking
# =================================================================================
# INPUT SECTION END
# =================================================================================
print 'reading mesh file data; might take some time'
data=genfromtxt(meshfile)
nx=1521 # dimensions of the mesh file
ny=947
elevation=data[:,2]
xx=data[:,0]
yy=data[:,1]
#print (xx)
#print (yy)
elevation=elevation.reshape((ny,nx)) # bathymetry/topography
xx=xx.reshape((ny,nx))
yy=yy.reshape((ny,nx))
if (plot_bathymetry_allmesh or plot_bathymetry_kolumbo or plot_collapsed_volume or plot_before_after):
#mlab.close(all)
from mayavi import mlab
if plot_bathymetry_allmesh:
mlab.figure(size=(1000,800))
scale=0.00005
cmax=500
s=mlab.surf(xx.T,yy.T,-elevation.T,vmax=cmax,vmin=-cmax,colormap='GnBu',warp_scale=scale)
mlab.title('Bath/topo - original computation grid')
lut = s.module_manager.scalar_lut_manager.lut.table.to_array()
ilut = lut[::-1]
# and finally we put this LUT back in the surface object. We could have
s.module_manager.scalar_lut_manager.lut.table = ilut
# We need to force update of the figure now that we have changed the LUT.
mlab.draw()
#mlab.view(40, 85)
mlab.view()
cmax=500 # color scale
lmin=400 # cutting from east
lmax=550 # cutting from west
rmin=520 # north of santorini
rmax=700 # south of santorini
###### kolumbo data
kxx=xx[rmin:rmax,lmin:lmax]
kyy=yy[rmin:rmax,lmin:lmax]
kelevation=elevation[rmin:rmax,lmin:lmax]
print (kxx)
print (kyy)
print (kelevation)
if plot_bathymetry_kolumbo:
mlab.figure(size=(1000,800))
scale=0.00005
###### mayavi plotting
s=mlab.surf(kxx.T,kyy.T,-kelevation.T,vmax=cmax,vmin=-cmax,colormap='GnBu',warp_scale=scale)
lut = s.module_manager.scalar_lut_manager.lut.table.to_array()
ilut = lut[::-1]
s.module_manager.scalar_lut_manager.lut.table = ilut
mlab.draw()
mlab.view()
################################################## collapse bathymetry data
print (collapse_depth)
collapse_steps=2 # can be changed by USER
collapse_starttime=0.0 # in second; can be changed by USER
collapse_times=linspace(0,collapse_duration,collapse_steps)
cs=contour(kxx,kyy,-kelevation,[collapse_depth])
csp=cs.collections[0].get_paths()[2] # path
csv=csp.vertices # vertices
csv_x=csv[:,0]
csv_y=csv[:,1]
if (not plot_debugfig):
close()
Larz60+ write Mar-14-2022, 09:55 AM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Fixed for you this time. Please use BBCode in future posts.
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Fixed for you this time. Please use BBCode in future posts.
