Ejemplo n.º 1
0
import numpy as np
import scipy as sc
import scipy.stats as stats
import pySALEPlot as psp
import matplotlib.pyplot as plt

field1 = 'Pre'
field2 = 'V_y'
field3 = 'Den'
field4 = 'TPS'
field5 = 'Tmp'
dirname = 'shockfronts'
model = psp.opendatfile('./jdata.dat')  # Open datafile
psp.mkdir_p('./shockfronts')
model.setScale('mm')

tstart = 1  # Start at t>0 such that there IS a shock present
tfin = 250
tintv = 1
YC = model.yc
XC = model.xc
TME = np.zeros((int((tfin - tstart + 1) / tintv)))  # time
YSF = np.zeros((int((tfin - tstart + 1) / tintv)))  # Shock Front Y position
PBD = np.zeros((int((tfin - tstart + 1) /
                    tintv)))  # Shock in Particle Bed array. 1 is yes 0 is no
QUP = np.zeros((int(
    (tfin - tstart + 1) / tintv)))  # Quasi steady state Particle velocity

Us = np.zeros((int((tfin - tstart + 1) / (5 * tintv)) + 1))
Up = np.zeros(
    (int((tfin - tstart + 1) / (5 * tintv)) +
Ejemplo n.º 2
0
p_list = list(eval(file2.readline().replace('\n','')))
T_list = list(eval(file2.readline().replace('\n','')))
m_list = list(eval(file2.readline().replace('\n','')))
t_list = list(eval(file2.readline().replace('\n','')))
r_list = list(eval(file2.readline().replace('\n','')))
used =   list(eval(file2.readline().replace('\n','')))
jumps, start_time, end_time, save_step, R, grid_spacing, g, a, v_0, layers, datafile  = eval(file2.readline().replace('\n',''))
print('DONE\n')

# Make an output directory
dirname='Origin_Landing'
psp.mkdir_p(dirname)

print('Extracting Materials...')
# Open the datafile
model=psp.opendatfile(datafile)
model.setScale('km')
step = model.readStep('TrP', 0)
yy = np.append(np.zeros(0), step.ymark)
col = []
for i in range(len(yy)): # find materials based on starting height
    if yy[i] > layers[0]:
        co = 'black'
    elif yy[i] > layers[1]:
        co = 'darkgrey'
    elif yy[i] > layers[2]:
        co = 'y'
    else:
        co = 'r'
    col.append(co)
print('DONE\n')
Ejemplo n.º 3
0
iplt.morphology(path1, paths, norm, normpath, timei, showtransient, showhline,
                lbl)

#path1 = '/uio/kant/geo-ceed-u1/nilscp/Desktop/stallo_work/benchmarkFI/CPPR/UAVG/CPPR10/IVANOVS/IVANOVS_L100/'
#path2 = '/uio/kant/geo-ceed-u1/nilscp/Desktop/stallo_work/benchmarkFI/CPPR/UAVG/CPPR10/COLDWPO/COLDWPO_L100/'
#path3 = '/uio/kant/geo-ceed-u1/nilscp/Desktop/stallo_work/benchmarkFI/CPPR/UAVG/CPPR10/COLDNOP/COLDNOP_L100/'
#path4 = '/uio/kant/geo-ceed-u1/nilscp/Desktop/stallo_work/benchmarkFI/CPPR/UAVG/CPPR10/SANDCOH/SANDCOH_L100/'

path1 = '/uio/kant/geo-ceed-u1/nilscp/Desktop/stallo_work/benchmarkFI/CPPR/UAVG/CPPR5/CDILWPO/CDILWPO_L100/'
path2 = '/uio/kant/geo-ceed-u1/nilscp/Desktop/stallo_work/benchmarkFI/CPPR/UAVG/CPPR10/CDILWPO/CDILWPO_L100/'
path3 = '/uio/kant/geo-ceed-u1/nilscp/Desktop/stallo_work/benchmarkFI/CPPR/UAVG/CPPR20/CDILWPO/CDILWPO_L100/'
#path4 = '/uio/kant/geo-ceed-u1/nilscp/Desktop/stallo_work/benchmarkFI/CPPR/UAVG/CPPR10/SANDCOH/SANDCOH_L100/'

os.chdir(path1)
model1 = psp.opendatfile('jdata.dat')
den1 = model1.readStep('Den', 68)

os.chdir(path2)
model2 = psp.opendatfile('jdata.dat')
den2 = model2.readStep('Den', 68)

os.chdir(path3)
model3 = psp.opendatfile('jdata.dat')
den3 = model3.readStep('Den', 68)

os.chdir(path4)
model4 = psp.opendatfile('jdata.dat')
den4 = model4.readStep('Den', 400)

plt.figure(1)
Ejemplo n.º 4
0
import ejecta as ej
'''
***********************************************************************
'''
path = '/work/nilscp/iSALE/isaleruns/testruns/ejecta/L20km_part1_HYDRO_CPPR1000/results/L20km_HYDRO_part2_CPPR80g/'
path = '/work/nilscp/iSALE/isaleruns/testruns/ejecta/L20km_part1_HYDRO_CPPR1000/results/L20km_HYDRO_part1g/'
path = '/uio/kant/geo-ceed-u1/nilscp/Desktop/stallo_work/ejecta/results/length/a2km/'
path = '/uio/kant/geo-ceed-u1/nilscp/Desktop/stallo_work/ejecta/results/length/a2km_C1000/'

path = '/work/nilscp/iSALE/isaleruns/testruns/multilayers/NILS_L100/'
'''
***********************************************************************
'''

os.chdir(path)
model = psp.opendatfile('jdata.dat')
'''
***********************************************************************
'''
# print a single saved timesteps
u = 0

den = model.readStep(['Den', 'Yld'], u)
step = copy.deepcopy(den)

a = 2000.
plt.pcolormesh(model.x / a, model.y / a, step.cmc[0], cmap='Pastel1')

# plot the high resolution zone
plt.hlines(model.yhires[0] / a,
           model.xhires[0] / a,
Ejemplo n.º 5
0
import pySALEPlot as psp
from matplotlib.pyplot import figure,colorbar
import matplotlib.pyplot as plt
import numpy as np
from mpl_toolkits.axes_grid1 import make_axes_locatable
# This example plotting script designed to plot 
# damage in the demo2D example simulation

# Make an output directory
#field1 = 'Den'#raw_input('Which field is to be considered? (3 chars) =>')
field2 = 'Den'#raw_input('Which field is to be considered? (3 chars) =>')
dirname='./%s'%field2
psp.mkdir_p(dirname)

# Open the datafile
model=psp.opendatfile('jdata.dat')

# Set the distance units to km
model.setScale('um')

# Set up a pylab figure
fig=figure()
ax=fig.add_subplot(111,aspect='equal')
fig.set_size_inches(4,3)
# Loop over timesteps, in increments of 5

#step_1=model.readStep('%s'%field2,0)
#MAXvalue = abs(np.amax(step_1.data[0]))
plt.tight_layout()
for i in np.arange(0,37,1):
    # Set the axis labels
Ejemplo n.º 6
0
from mpl_toolkits.axes_grid1 import make_axes_locatable

# If viridis colormap is available, use it here
try:
    plt.set_cmap('viridis')
except:
    plt.set_cmap('YlGnBu_r')

# This example plotting script designed to plot 
# damage and pressure for the demo2D example

# Make an output directory
dirname = './generatedPlots/25kms'

# Open the datafile
model = psp.opendatfile('./data/job-25kmhr/jdata.dat')

# Set the distance units to km
model.setScale('km')

# Set up a pylab figure
fig = plt.figure(figsize=(8, 4))

ax = fig.add_subplot(111, aspect='equal')
divider = make_axes_locatable(ax)

# Loop over timesteps
for i in np.arange(0,5000,5):

    # Set the axis labels
    ax.set_xlabel('r [km]')
Ejemplo n.º 7
0
import pySALEPlot as psp
import matplotlib.pyplot as plt
import numpy as np

# This example plotting script designed to plot
# a vertical pressure profile of the Chicxulub example

# Open the datafile
#model=psp.opendatfile('/media/sf_Public/data/job-1_6km/jdata.dat')
model = psp.opendatfile('./data/job-9i/jdata.dat')

# Set the distance units to mm
model.setScale('km')

[model.tru[u].truInfo() for u in range(model.tracer_numu)]

step0 = model.readStep('TrM', 0)
stepTrT0 = model.readStep('TrT', 0)

# Set up a pyplot figure
fig = plt.figure(figsize=(20, 10))

ax = fig.add_subplot(111, aspect='equal')

# Set the axis labels
ax.set_xlabel('r [km]')
ax.set_ylabel('z [km]')

# Set the axis limits
rad_km = 50
depth_km = 30
Ejemplo n.º 8
0
III =0

field1 = 'Pre'                                                       
field2 = 'V_y'
field3 = 'Den'
field4 = 'TPS'
field5 = 'Syy'
                                                      
tstart = 1									    # Start at t>0 such that there IS a shock present
tfin   = 56 
tintv  = 1



for directory in dirs:
    modelv150 = psp.opendatfile('{}/v150/jdata.dat'.format(directory))					     # Open datafile 
    modelv200 = psp.opendatfile('{}/v200/jdata.dat'.format(directory))					     # Open datafile 
    modelv250 = psp.opendatfile('{}/v250/jdata.dat'.format(directory))					     # Open datafile 
    modelv300 = psp.opendatfile('{}/v300/jdata.dat'.format(directory))					     # Open datafile 
    modelv350 = psp.opendatfile('{}/v350/jdata.dat'.format(directory))					     # Open datafile 
    modelv450 = psp.opendatfile('{}/v450/jdata.dat'.format(directory))					     # Open datafile 
    modelv550 = psp.opendatfile('{}/v550/jdata.dat'.format(directory))					     # Open datafile 
    modelv650 = psp.opendatfile('{}/v650/jdata.dat'.format(directory))					     # Open datafile 
    modelv750 = psp.opendatfile('{}/v750/jdata.dat'.format(directory))					     # Open datafile 
    modelv850 = psp.opendatfile('{}/v850/jdata.dat'.format(directory))					     # Open datafile 
    modelv950 = psp.opendatfile('{}/v950/jdata.dat'.format(directory))					     # Open datafile 
    models = [modelv150,modelv200,modelv250,modelv300,modelv350,modelv450,modelv550,modelv650,modelv750,modelv850,modelv950]
    modelS = (['v150','v200','v250','v300','v350','v450','v550','v650','v750','v850','v950'])
    VI     = ([150,200,250,300,350,450,550,650,750,850,950])
    [model.setScale('mm') for model in models]
    III = 0
Ejemplo n.º 9
0
          'name_file3',
          'name_file4')

label_name = ('Y$_{d0}$ = 100 kPa',
		      'Y$_{d0}$ = 10 kPa',
              'Y$_{d0}$ = 1 kPa',
	          'Y$_{d0}$ = 0.1 kPa')

colour = ('#f58f00', '#f35757', '#617BB7','#E06AAF')

# Open the data files.
for i in range(4):

	# Read simulation files
	# Replace name of the files as appropriate
    model=psp.opendatfile(moddir[i]+'/jdata.dat', tracermassvol=True)
    model.addRestartFile(moddir[i]+'regrid/jdata.dat')

    # Define simulation constants
    rho =  # Target density
    delta = # Impactor density
    U = # Impact velocity
    a = # Impactor radius
    m = 4./3.*np.pi*delta*a**3. # Impactor mass (if spherical)

    # Define numerical constants
    # Initial guess for constants
    c1 = # Approximation of C1 constant
    k = # Approximation of k constant
    mu = # Approximation of mu constant
    p = # Approximation of p constant
Ejemplo n.º 10
0
import numpy as np
import scipy as sc
import scipy.stats as stats
import pySALEPlot as psp
import matplotlib.pyplot as plt


field1 = 'Pre'                                                       
field2 = 'V_y'
field3 = 'Den'
field4 = 'TPS'
field5 = 'Tmp'
dirname= 'shockfronts'                                                      
model = psp.opendatfile('./jdata.dat')					     # Open datafile 
psp.mkdir_p('./shockfronts')
model.setScale('mm') 

tstart = 1								     # Start at t>0 such that there IS a shock present
tfin   = 250
tintv  = 1
YC     = model.yc
XC     = model.xc
TME    = np.zeros(( int((tfin-tstart+1)/tintv) ))				    # time 
YSF    = np.zeros(( int((tfin-tstart+1)/tintv) ))				    # Shock Front Y position
PBD    = np.zeros(( int((tfin-tstart+1)/tintv) ))				    # Shock in Particle Bed array. 1 is yes 0 is no
QUP    = np.zeros(( int((tfin-tstart+1)/tintv) ))				    # Quasi steady state Particle velocity

Us     = np.zeros(( int((tfin-tstart+1)/(5*tintv))+1 ))
Up     = np.zeros(( int((tfin-tstart+1)/(5*tintv))+1 ))				    # Shock and particle velocities calculated every 5 timesteps
Time   = np.zeros(( int((tfin-tstart+1)/(5*tintv))+1 ))				    # Equivalent time every 5 timesteps (=.1 us)
Ejemplo n.º 11
0
layers.append(-1 * 10**16)

print('DONE\n')

# make sure Results.dat exists
open('Results.dat', 'a').close()
filetest = open('Results.dat', 'r')
filetest.close()

#============================================================
#                 Peak Values Search Starts Here
#============================================================

#Find the peak pressures of all tracers
print('Extracting Peak Pressure')
model1 = psp.opendatfile(peak_file)
model1.setScale('km')
step1 = model1.readStep('TrP', model1.nsteps - 1)
pres = np.append(np.zeros(0), step1.TrP / 10**9)
print('Using timestep {0} of {1} with {2} tracers'.format(
    model1.nsteps - 1, peak_file, len(pres)))
print('DONE\n')

# extract the materials and weights
print('Extracting Materials...')
model = psp.opendatfile(data_file)
model.setScale('km')
step = model.readStep('TrT', 0)
xx_0 = np.append(np.zeros(0), step.xmark)
yy_0 = np.append(np.zeros(0), step.ymark)
Ejemplo n.º 12
0
	P_avg = np.mean(P[j-1:j+1])
	if (P_avg<0.2*P_Quasi and JJ == 0):
	    JJ = j
    return II,JJ
	
    
    

field1 = 'Pre'                                                       
field2 = 'V_x'                                                       
field3 = 'V_y'
field4 = 'Den'                                                      
field5 = 'Syy' 
dirname='./del-t'								     # Directory name for the output files

modelv150 = psp.opendatfile('./v150/jdata.dat')					     # Open datafile 
modelv250 = psp.opendatfile('./v250/jdata.dat')					     # Open datafile 
modelv350 = psp.opendatfile('./v350/jdata.dat')					     # Open datafile 
modelv450 = psp.opendatfile('./v450/jdata.dat')					     # Open datafile 
modelv550 = psp.opendatfile('./v550/jdata.dat')					     # Open datafile 
modelv650 = psp.opendatfile('./v650/jdata.dat')					     # Open datafile 
modelv750 = psp.opendatfile('./v750/jdata.dat')					     # Open datafile 
modelv850 = psp.opendatfile('./v850/jdata.dat')					     # Open datafile 
modelv950 = psp.opendatfile('./v950/jdata.dat')					     # Open datafile 
modelv1050 = psp.opendatfile('./v1050/jdata.dat')					     # Open datafile 

models = [modelv150,modelv250,modelv350,modelv450,modelv550,modelv650,modelv750,modelv850,modelv950,modelv1050]
VI = ([150,250,350,450,550,650,750,850,950,1050])
[model.setScale('mm') for model in models]
N = 10 
t1 = .2 
Ejemplo n.º 13
0
    for j in range(j_i, j_f, -1):
        P_avg = np.mean(P[j - 1:j + 1])
        if (P_avg < 0.2 * P_Quasi and JJ == 0):
            JJ = j
    return II, JJ


field1 = 'Pre'
field2 = 'V_x'
field3 = 'V_y'
field4 = 'Den'
field5 = 'Syy'
dirname = './del-t'  # Directory name for the output files

modelv150 = psp.opendatfile('./v150/jdata.dat')  # Open datafile
modelv250 = psp.opendatfile('./v250/jdata.dat')  # Open datafile
modelv350 = psp.opendatfile('./v350/jdata.dat')  # Open datafile
modelv450 = psp.opendatfile('./v450/jdata.dat')  # Open datafile
modelv550 = psp.opendatfile('./v550/jdata.dat')  # Open datafile
modelv650 = psp.opendatfile('./v650/jdata.dat')  # Open datafile
modelv750 = psp.opendatfile('./v750/jdata.dat')  # Open datafile
modelv850 = psp.opendatfile('./v850/jdata.dat')  # Open datafile
modelv950 = psp.opendatfile('./v950/jdata.dat')  # Open datafile
modelv1050 = psp.opendatfile('./v1050/jdata.dat')  # Open datafile

models = [
    modelv150, modelv250, modelv350, modelv450, modelv550, modelv650,
    modelv750, modelv850, modelv950, modelv1050
]
VI = ([150, 250, 350, 450, 550, 650, 750, 850, 950, 1050])
Ejemplo n.º 14
0
def main(path, folders, paths, method, thresholdf, g):
    '''
    description:
    loading of the data + all calculation in the function wrap

    inputs:
    path: directory contaning all the models
    folders: folders containing all the models
    paths: saving directory
    method: 2 or 3 dots

    outputs:
    Three .txt files are saved:

    one text file that contains the depth, diameter and volume of the excavated
    cavity, name : modelname + '_excavated.txt'

    one text file that contains the tracers and their original position
    name : modelname + '_tracersXY_excavated.txt'

    one text file that contains the boundary between excavated and non excavated
    materials (i.e, the hinge streamline)
    name : modelname + '_tracersXY_contour_excavated.txt'
    '''

    # Change path to working directory
    os.chdir(path)

    # select folders in directory
    #folders = glob.glob(search)

    for modelname in folders:

        patht = path + modelname
        os.chdir(patht)

        # print modelname
        print modelname

        model = psp.opendatfile('jdata.dat')
        (Ve, de, Re, X, Y, Xc, Yc, timesteps, tracer_idx, n, v, angle, xpos,
         tair, xland) = wrap(model, method, thresholdf, g)

        # create plots directory
        path_data = paths + modelname + "/excavated/"

        if not os.path.exists(path_data):
            os.makedirs(path_data)

        os.chdir(path_data)

        # DATA
        header_txt = "Volume_exc;depth_exc;diameter_exc"
        # we need to define the name of the txt file that will be saved
        fname = modelname + '_excavated.txt'
        # time, depth, diameter, volume
        output = np.column_stack((Ve, de, Re*2.))
        np.savetxt(fname, output, header=header_txt,
                   delimiter=';', fmt=['%1.6e', '%1.6e', '%1.6e'])

        # DATA TRACERS XY ALL
        fname = modelname + '_tracersXY_excavated.txt'
        header_txt = "X;Y"
        output = np.column_stack((X, Y))
        np.savetxt(fname, output, header=header_txt,
                   delimiter=';', fmt=['%1.6e', '%1.6e'])

        # DATA TRACERS XY contours
        fname = modelname + '_tracersXY_contour_excavated.txt'
        header_txt = "XC;YC"
        output = np.column_stack((Xc, Yc))
        np.savetxt(fname, output, header=header_txt,
                   delimiter=';', fmt=['%1.6e', '%1.6e'])

        # tracers
        path_ej = paths + modelname + "/ejtracers/"

        if not os.path.exists(path_ej):
            os.makedirs(path_ej)

        os.chdir(path_ej)

        header_txt = "tracer_idx;timesteps;v;angle;xpos;tair;xland"
        # we need to define the name of the txt file that will be saved
        fname_ej = modelname + '_ejtracers.txt'
        # time, depth, diameter, volume
        output = np.column_stack((tracer_idx, timesteps, v, angle, xpos,
                                  tair, xland))
        np.savetxt(fname_ej, output, header=header_txt,
                   delimiter=';', fmt=['%1.6e', '%1.6e', '%1.6e',
                                       '%1.6e', '%1.6e', '%1.6e', '%1.6e'])

        header_txt = "ntracers"
        # we need to define the name of the txt file that will be saved
        fname_ej = modelname + '_ntracers.txt'
        # time, depth, diameter, volume
        output = n
        np.savetxt(fname_ej, output, header=header_txt,
                   delimiter=';', fmt='%1.6e')

        # close model file
        model.closeFile()
Ejemplo n.º 15
0
def main(path, folders, paths, mode, id_mat, transient, idx_manual=0):
    '''
    description:
    calculate all final crater dimensions for 1-layer targets

    inputs:
    path: path containing folders with models (jdata in each modelled case)
    folders: all models
    paths: saving directory
    mode: mostly equal to 0 (if artifacts along the boundary, can be set to 1)
    id_mat: material id (0: all, 1: projectile, 2: first layer, 3: second ...)
    transient: 0 (by volume)
             : 1 (by the maximum depth along the crater cavity)
    outputs:
    1 .txt file with all crater dimensions every saved timesteps
    1. txt file with all transient crater dimensions
    1. txt file with all final crater dimensions

    each of these text files are saved in different folders
    so 3 txt files are created per models
    '''

    # Change path to working directory
    os.chdir(path)

    # loop through models in folders
    for modelname in folders:

        # change directory to
        patht = path + modelname
        os.chdir(patht)

        # print modelname
        print(modelname)

        # open model with pySALEplot
        model = psp.opendatfile('jdata.dat')

        # calculate all final crater dimensions
        time, depth, mdepth, diam, vol, ec, ls, pf, alt, drim, Vrim = craterdimensions(
            model, mode, id_mat)

        ####################################################
        # CALCULATE CRATER DIMENSIONS DURING CRATER EVOLUTION (EACH STEP)
        ####################################################

        # create plots directory if not existing
        path_data = paths + modelname + "/evolution/"

        if not os.path.exists(path_data):
            os.makedirs(path_data)

        os.chdir(path_data)

        # export data to .txt file
        header_txt = "time\tdepth\tmdepth\tdiameter\tvolume\tls\tec\tpf\talt\tdrim\tVrim"

        # we need to define the name of the txt file that will be saved
        fname = modelname + '_data.txt'

        # output file
        output = np.column_stack(
            (time, depth, mdepth, diam, vol, ls, ec, pf, alt, drim, Vrim))
        np.savetxt(fname,
                   output,
                   header=header_txt,
                   delimiter='\t',
                   fmt=[
                       '%1.6e', '%1.6e', '%1.6e', '%1.6e', '%1.6e', '%1.6e',
                       '%1.6e', '%1.6e', '%1.6e', '%1.6e', '%1.6e'
                   ])

        ####################################################
        # CALCULATE CRATER DIMENSIONS AT THE TRANSIENT CRATER
        ####################################################

        # create plots directory if not existing
        path_data = paths + modelname + "/transient/"

        if not os.path.exists(path_data):
            os.makedirs(path_data)

        os.chdir(path_data)

        fname = modelname + '_tr.txt'
        header_txt = "tr_time\ttr_depth\ttr_diameter\ttr_vol\talt\td_rim\tV_rim\tidx"

        # the transient crater diameter is defined at the maximum volume
        if transient == 0:
            idx_tr = np.nanargmax(vol)
        else:
            idx_tr = np.nanargmax(mdepth)  # if maximum depth is used
        # transient crater values are stored in another .txt file and folder
        if mode == 0:
            output2 = np.column_stack(
                (time[idx_tr], depth[idx_tr], diam[idx_tr], vol[idx_tr],
                 alt[idx_tr], drim[idx_tr], Vrim[idx_tr], idx_tr))
            np.savetxt(fname,
                       output2,
                       header=header_txt,
                       delimiter='\t',
                       fmt=[
                           '%1.6e', '%1.6e', '%1.6e', '%1.6e', '%1.6e',
                           '%1.6e', '%1.6e', '%1.6e'
                       ])
        else:
            output2 = np.column_stack(
                (time[idx_tr], mdepth[idx_tr], diam[idx_tr], vol[idx_tr],
                 alt[idx_tr], drim[idx_tr], Vrim[idx_tr], idx_tr))
            np.savetxt(fname,
                       output2,
                       header=header_txt,
                       delimiter='\t',
                       fmt=[
                           '%1.6e', '%1.6e', '%1.6e', '%1.6e', '%1.6e',
                           '%1.6e', '%1.6e', '%1.6e'
                       ])

        ####################################################
        # CALCULATE CRATER DIMENSIONS AT THE FINAL CRATER
        ####################################################

        # it should take the value at t/tr = 10 and not as the mean of the last 5 values, it could make some of the other codes easier
        # the problem that I should not take any values maybe I should say that it should be at least

        # create plots directory if not existing
        path_data = paths + modelname + "/final/"

        if not os.path.exists(path_data):
            os.makedirs(path_data)

        os.chdir(path_data)

        # at t/tr for different times
        tnorm = time / time[idx_tr]

        # save for t/tr = 2, 3, 4, 5, 7.5 and 10.0
        tnorm_fname = ['020', '030', '040', '050', '070', '100']

        for iv, tnormv in enumerate([2.0, 3.0, 4.0, 5.0, 7.0, 10.0]):

            __, stp1 = find_nearest(tnorm, tnormv)

            fname = modelname + '_final' + tnorm_fname[iv] + '.txt'
            header_txt = "f_time\tf_depth\tf_diameter\tf_vol\tf_alt\tf_drim\tf_Vrim"

            # if it did not reach the final crater, then nothing should be save in the final folder
            if tnorm[np.where(~np.isnan(diam))[0][-1]] >= tnormv - 0.20:

                # final crater values are stored in another .txt file and folder
                if mode == 0:
                    output2 = np.column_stack(
                        (np.nanmean(time[stp1]), np.nanmean(depth[stp1]),
                         np.nanmean(diam[stp1]), np.nanmean(vol[stp1]),
                         np.nanmean(alt[stp1]), np.nanmean(drim[stp1]),
                         np.nanmean(Vrim[stp1])))
                    np.savetxt(fname,
                               output2,
                               header=header_txt,
                               delimiter='\t',
                               fmt=[
                                   '%1.6e', '%1.6e', '%1.6e', '%1.6e', '%1.6e',
                                   '%1.6e', '%1.6e'
                               ])
                else:
                    output2 = np.column_stack(
                        (np.nanmean(time[stp1]), np.nanmean(mdepth[stp1]),
                         np.nanmean(diam[stp1]), np.nanmean(vol[stp1]),
                         np.nanmean(alt[stp1]), np.nanmean(drim[stp1]),
                         np.nanmean(Vrim[stp1])))
                    np.savetxt(fname,
                               output2,
                               header=header_txt,
                               delimiter='\t',
                               fmt=[
                                   '%1.6e', '%1.6e', '%1.6e', '%1.6e', '%1.6e',
                                   '%1.6e', '%1.6e'
                               ])

            else:
                if mode == 0:
                    output2 = np.column_stack((np.nan, np.nan, np.nan, np.nan,
                                               np.nan, np.nan, np.nan))
                    np.savetxt(fname,
                               output2,
                               header=header_txt,
                               delimiter='\t',
                               fmt=[
                                   '%1.6e', '%1.6e', '%1.6e', '%1.6e', '%1.6e',
                                   '%1.6e', '%1.6e'
                               ])
                else:
                    output2 = np.column_stack((np.nan, np.nan, np.nan, np.nan,
                                               np.nan, np.nan, np.nan))
                    np.savetxt(fname,
                               output2,
                               header=header_txt,
                               delimiter='\t',
                               fmt=[
                                   '%1.6e', '%1.6e', '%1.6e', '%1.6e', '%1.6e',
                                   '%1.6e', '%1.6e'
                               ])

        ####################################################################
        # CALCULATE CRATER DIMENSIONS AT THE FINAL CRATER (MANUAL)
        ####################################################################

        # it should take the value at t/tr = 10 and not as the mean of the last 5 values, it could make some of the other codes easier
        # the problem that I should not take any values maybe I should say that it should be at least

        # create plots directory if not existing
        path_data = paths + modelname + "/manual/"

        if not os.path.exists(path_data):
            os.makedirs(path_data)

        os.chdir(path_data)

        # only run the script if idx_manual is specified
        if idx_manual > 0:
            stp1 = idx_manual

            fname = modelname + '_final.txt'
            header_txt = "f_time\tf_depth\tf_diameter\tf_vol\tf_alt\tf_drim\tf_Vrim"

            if mode == 0:
                output2 = np.column_stack(
                    (np.nanmean(time[stp1]), np.nanmean(depth[stp1]),
                     np.nanmean(diam[stp1]), np.nanmean(vol[stp1]),
                     np.nanmean(alt[stp1]), np.nanmean(drim[stp1]),
                     np.nanmean(Vrim[stp1])))
                np.savetxt(fname,
                           output2,
                           header=header_txt,
                           delimiter='\t',
                           fmt=[
                               '%1.6e', '%1.6e', '%1.6e', '%1.6e', '%1.6e',
                               '%1.6e', '%1.6e'
                           ])
            else:
                output2 = np.column_stack(
                    (np.nanmean(time[stp1]), np.nanmean(mdepth[stp1]),
                     np.nanmean(diam[stp1]), np.nanmean(vol[stp1]),
                     np.nanmean(alt[stp1]), np.nanmean(drim[stp1]),
                     np.nanmean(Vrim[stp1])))
                np.savetxt(fname,
                           output2,
                           header=header_txt,
                           delimiter='\t',
                           fmt=[
                               '%1.6e', '%1.6e', '%1.6e', '%1.6e', '%1.6e',
                               '%1.6e', '%1.6e'
                           ])

        else:
            None

        # close model file
        model.closeFile()
Ejemplo n.º 16
0
def craterProfiles(folders, path, paths, idx, mode):
    '''
    description:
    return the profile of the crater for the transient crater (mode = 1), 
    the final crater (mode = 2), or for a chosen time step (mode = 3, and idx = stp)    

    input:
    mode = 1 # transient crater
    mode = 2 # final crater
    mode = 3 # any other craters

    if mode = 1 or 2, idx does not count
    if mode = 3, the values in idx will be taken

    example:
    folders = ['C00P20F06_L250','C00P20F06_L500']
    path = '/media/nilscp/Cloud1/SENS/PORFRIC/results/'
    paths = '/media/nilscp/Zell/Collapse/plots2/'

    #transient
    idx = 0
    mode = 1
    craterProfiles(folders, path, paths, idx, mode)

    #final
    idx = 0
    mode = 2
    craterProfiles(folders, path, paths, idx, mode)

    #arbitrary (timestep = 4)
    idx = 4
    mode = 3
    craterProfiles(folders, path, paths, idx, mode)
    '''

    # we can loop through models
    for ix, modelname in enumerate(folders):

        # change to working directory
        patht = paths + modelname
        os.chdir(patht)

        # print modelname
        print(modelname)

        # id_mat
        id_mat = 0

        # load jdata.data
        model = psp.opendatfile(path + modelname + '/jdata.dat')

        # Get the y-index of the pre-surface
        oridy = np.where(model.yy == 0.)[0][0]

        # get the time step (in sec)
        den1 = model.readStep('Den', 1)
        timestep = den1.time

        # get the total time of the simulation
        total_time = model.laststep * timestep

        # get the index at when the transient crater is reached
        tr_time, __, __, __, __, __, __, idx_tr = np.loadtxt(paths +
                                                             modelname +
                                                             '/transient/' +
                                                             modelname +
                                                             '_tr.txt')

        idx_tr = idx_tr.astype('int')

        # get the total time of the simulation (in normalized time)
        total_time_norm = total_time / tr_time

        # default normalized time
        default_ntime = np.array([2.0, 3.0, 4.0, 5.0, 7.0, 10.0])
        default_ntime = default_ntime.astype('int')
        default_nfname = np.array(['020', '030', '040', '050', '070', '100'])

        # where we have actually data for
        real_ntime = default_ntime[default_ntime <= total_time_norm]
        real_nfname = default_nfname[default_ntime <= total_time_norm]

        # load data depending on the mode (if transient only)
        if mode == 1:

            ####################################################
            # TRANSIENT CRATER
            ####################################################

            den = model.readStep('Den', idx_tr)
            step = copy.deepcopy(den)
            (rrim, altr) = get_cross_section(model, step, id_mat, oridy)

            path_to_save = paths + modelname + '/transient/'

            if not os.path.exists(path_to_save):
                os.makedirs(path_to_save)

            os.chdir(path_to_save)

            fname = modelname + '_XYtransientprofile.txt'

            header_txt = "distance\tdepth"

            output = np.column_stack((rrim, altr))

            np.savetxt(fname,
                       output,
                       header=header_txt,
                       delimiter='\t',
                       fmt=['%1.6e', '%1.6e'])

        elif mode == 3:

            ####################################################
            # SELECTED CRATER
            ####################################################

            den = model.readStep('Den', idx)
            step = copy.deepcopy(den)
            (rrim, altr) = get_cross_section(model, step, id_mat, oridy)

            path_to_save = paths + modelname + '/arbitrary/'

            if not os.path.exists(path_to_save):
                os.makedirs(path_to_save)

            os.chdir(path_to_save)

            fname = modelname + '_XY' + str(idx) + '_profile.txt'

            header_txt = "distance\tdepth"

            output = np.column_stack((rrim, altr))

            np.savetxt(fname,
                       output,
                       header=header_txt,
                       delimiter='\t',
                       fmt=['%1.6e', '%1.6e'])

        else:  # mode == 2

            ####################################################
            # FINAL CRATER at different normalized time
            ####################################################

            for ir, r in enumerate(real_ntime):

                idx = r * idx_tr
                den = model.readStep('Den', idx)
                step = copy.deepcopy(den)
                (rrim, altr) = get_cross_section(model, step, id_mat, oridy)

                path_to_save = paths + modelname + '/final/'

                if not os.path.exists(path_to_save):
                    os.makedirs(path_to_save)

                os.chdir(path_to_save)
                fname = modelname + '_XYfinalprofile' + real_nfname[ir] + '.txt'

                header_txt = "distance\tdepth"

                output = np.column_stack((rrim, altr))

                np.savetxt(fname,
                           output,
                           header=header_txt,
                           delimiter='\t',
                           fmt=['%1.6e', '%1.6e'])

        # close model file
        model.closeFile()

    print("transient/final crater profiles are saved")