Mentions légales du service

Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • mgenet/dolfin_warp
  • cpatte/dolfin_dic
  • falvarez/dolfin_dic
  • eberbero/dolfin_dic
4 results
Show changes
Showing
with 2249 additions and 0 deletions
# noise_level regul_level disp_err_avg disp_err_std
0.0 0.99 0.00028417829801934103 0.0
0.0 0.8 0.0003457815404307538 0.0
0.0 0.4 0.00048022273764362124 0.0
0.0 0.2 0.0005187809178222003 0.0
0.0 0.1 0.0005727119360465418 0.0
0.0 0.05 0.0006031837067736637 0.0
0.0 0.025 0.0006152841902575706 0.0
0.0 0.0125 0.0006327861685430558 0.0
0.0 0.001 0.00051934522280663 0.0
0.1 0.99 0.010808800056539232 0.0005362249539470191
0.1 0.8 0.010998468754528798 0.000513820171066674
0.1 0.4 0.011445329187696335 0.000499032559731241
0.1 0.2 0.012050804289884066 0.0004919115862185821
0.1 0.1 0.012848654311811569 0.0005231416696091857
0.1 0.05 0.013773600764662258 0.0005722444400992171
0.1 0.025 0.014795863755446309 0.0006029591540843283
0.1 0.0125 0.015961096090562656 0.0006104985419226959
0.1 0.001 0.045490139274622865 0.0012476881321506167
0.2 0.99 0.026694547123949218 0.0018301458601376595
0.2 0.8 0.027197602224481005 0.0017351067479708829
0.2 0.4 0.028112744459432126 0.0017628395543780606
0.2 0.2 0.029358346059759188 0.0017821687207432296
0.2 0.1 0.03101443574992488 0.0017770034262748675
0.2 0.05 0.03295340205044829 0.0016801447023513908
0.2 0.025 0.03511307172840204 0.0016211818594785413
0.2 0.0125 0.037663108582119 0.0015421612224518777
0.2 0.001 0.11150907609292038 0.012440521530165165
0.3 0.99 0.04448140844311659 0.0026469651118007234
0.3 0.8 0.04552478515713853 0.0023049185210227796
0.3 0.4 0.047631497199161266 0.0021862014198355084
0.3 0.2 0.04992015264542798 0.0022558429655571265
0.3 0.1 0.05279810070342519 0.0025947856850757787
0.3 0.05 0.05664129894279596 0.0032576144883590267
0.3 0.025 0.06170224878168764 0.00417203677801766
0.3 0.0125 0.06867557970895152 0.007062262540548239
0.3 0.001 0.3482779609304819 0.05642379778753999
# noise_level regul_level disp_err_avg disp_err_std
0.0 0.99 0.0004939777824945341 0.0
0.0 0.8 0.0004895933401073531 0.0
0.0 0.4 0.00047927496566707535 0.0
0.0 0.2 0.000492425073157513 0.0
0.0 0.1 0.0005249913432411667 0.0
0.0 0.05 0.0005676021212820686 0.0
0.0 0.025 0.0005827204691458032 0.0
0.0 0.0125 0.0006175980727173215 0.0
0.0 0.001 0.00051934522280663 0.0
0.1 0.99 0.010613237991169455 0.0008870640037359933
0.1 0.8 0.01061608591396033 0.0008887130148058874
0.1 0.4 0.010696601938418893 0.0008862295690914342
0.1 0.2 0.010881254201210493 0.0008775412294714439
0.1 0.1 0.011197697976652992 0.0008632619481391089
0.1 0.05 0.011690782342297847 0.0008274495349259126
0.1 0.025 0.012426661742411188 0.0007765157397798059
0.1 0.0125 0.013483391893395095 0.0007080595461771215
0.1 0.001 0.045490139274622865 0.0012476881321506167
0.2 0.99 0.02562151209051621 0.0018314105215969164
0.2 0.8 0.025632476314662776 0.0018154371667222003
0.2 0.4 0.02585983877259581 0.001789177307108364
0.2 0.2 0.026273179953875587 0.0016777537253578286
0.2 0.1 0.0269348453751898 0.0015919311249241867
0.2 0.05 0.027916182205298005 0.001522095104091548
0.2 0.025 0.029346206388701758 0.0015195867614792005
0.2 0.0125 0.031467330912025276 0.001414247394787981
0.2 0.001 0.11150907609292038 0.012440521530165165
0.3 0.99 0.04242314118063274 0.0023897216627500875
0.3 0.8 0.0424498220339548 0.002428189672830974
0.3 0.4 0.04274883364688399 0.002415496643651663
0.3 0.2 0.04353475413042809 0.0022954375211470114
0.3 0.1 0.04498996962241809 0.001978302238239705
0.3 0.05 0.04698834655954552 0.002057910139721028
0.3 0.025 0.049998910060690085 0.0022150083155624742
0.3 0.0125 0.05475595492218235 0.0028456279193838133
0.3 0.001 0.3482779609304819 0.05642379778753999
# noise_level regul_level disp_err_avg disp_err_std
0.0 0.99 0.000894913670686505 0.0
0.0 0.8 0.0008948327179141007 0.0
0.0 0.4 0.00089290201603703 0.0
0.0 0.2 0.0008862638827011979 0.0
0.0 0.1 0.0008769778732517048 0.0
0.0 0.05 0.0008720787937504464 0.0
0.0 0.025 0.0008721458661482371 0.0
0.0 0.0125 0.0008720579255821412 0.0
0.0 0.001 0.00051934522280663 0.0
0.1 0.99 0.016105411896270468 0.0007258011373982465
0.1 0.8 0.016109243064581977 0.0007311772104687502
0.1 0.4 0.01611884665680863 0.0007287207364561438
0.1 0.2 0.016153000991802082 0.0007210462526533489
0.1 0.1 0.016230004855970682 0.0007082043176172654
0.1 0.05 0.016368822091143095 0.0006847327203703247
0.1 0.025 0.016604795025722083 0.0006625048426703339
0.1 0.0125 0.0169986088823817 0.0006257721154723544
0.1 0.001 0.045490139274622865 0.0012476881321506167
0.2 0.99 0.03853231705879241 0.0023641006823163723
0.2 0.8 0.03854061551737574 0.002369832562862271
0.2 0.4 0.0384773210839831 0.0024015709300898133
0.2 0.2 0.03841481763141202 0.002393691493218177
0.2 0.1 0.03855678428371194 0.0024759738828724876
0.2 0.05 0.03891614350264622 0.002536896350436595
0.2 0.025 0.0393994408405145 0.0025418442830418557
0.2 0.0125 0.04041462131455802 0.0025202659781279895
0.2 0.001 0.11150907609292038 0.012440521530165165
0.3 0.99 0.09165374169581116 0.04289249439570307
0.3 0.8 0.0913182215815278 0.041783107099622595
0.3 0.4 0.09191025152684898 0.041253316677020445
0.3 0.2 0.09179321972673232 0.040810191824664915
0.3 0.1 0.09093594800390138 0.03989890323008269
0.3 0.05 0.09715721408187769 0.043353204628432396
0.3 0.025 0.09635428308632522 0.040053949614048
0.3 0.0125 0.0958144737147211 0.03686015146166034
0.3 0.001 0.3482779609304819 0.05642379778753999
# noise_level regul_level disp_err_avg disp_err_std
0.0 0.99 5.334322109343638e-05 0.0
0.0 0.8 5.0768752468158725e-05 0.0
0.0 0.4 0.00011648584764873425 0.0
0.0 0.2 0.00022072287190903758 0.0
0.0 0.1 0.00032829309066352265 0.0
0.0 0.05 0.00042525576218150983 0.0
0.0 0.025 0.0005455545875389306 0.0
0.0 0.0125 0.0006936116847384577 0.0
0.0 0.001 0.00051934522280663 0.0
0.1 0.99 0.0030587897095403953 0.0005450315912807827
0.1 0.8 0.003328476672127558 0.00047496561214216735
0.1 0.4 0.005063220055420892 0.00023749556277365404
0.1 0.2 0.007155359335828481 0.00016354311598568624
0.1 0.1 0.00978370935321516 0.0001399879454544922
0.1 0.05 0.013009855277245602 0.00015009732361750787
0.1 0.025 0.016783569142765627 0.00017171216567023282
0.1 0.0125 0.021152445392149406 0.00020809950386278266
0.1 0.001 0.045490139274622865 0.0012476881321506167
0.2 0.99 0.007836581635251808 0.0015530568647414628
0.2 0.8 0.008416287134760886 0.0014545723857287637
0.2 0.4 0.011948296730618318 0.0011416429677772362
0.2 0.2 0.01637155198318624 0.0011253263218829561
0.2 0.1 0.02190267357880416 0.0010209862479467395
0.2 0.05 0.02884985695202552 0.0008350126792848217
0.2 0.025 0.03738351904901983 0.0006720086143020984
0.2 0.0125 0.0477715160651345 0.0009338555773492819
0.2 0.001 0.11150907609292038 0.012440521530165165
0.3 0.99 0.02280264444506426 0.008968485548405113
0.3 0.8 0.021471246987665428 0.007264514399909607
0.3 0.4 0.0213046658320458 0.0032656852230482647
0.3 0.2 0.027035125405266248 0.002043189697793837
0.3 0.1 0.03606952480495309 0.0015824225277902297
0.3 0.05 0.047306980812514166 0.001434055870590802
0.3 0.025 0.06147573687252247 0.0016673492217698157
0.3 0.0125 0.07918268862780517 0.0019135388789697587
0.3 0.001 0.3482779609304819 0.05642379778753999
# noise_level regul_level disp_err_avg disp_err_std
0.0 0.99 0.00089491711664884 0.0
0.0 0.8 0.0008948587196891053 0.0
0.0 0.4 0.0008928375052203912 0.0
0.0 0.2 0.0008862684730681632 0.0
0.0 0.1 0.0008770314556670836 0.0
0.0 0.05 0.0008723137556135655 0.0
0.0 0.025 0.0008730238032763445 0.0
0.0 0.0125 0.000874111722227979 0.0
0.0 0.001 0.00051934522280663 0.0
0.1 0.99 0.01610541784764838 0.0007257892661009569
0.1 0.8 0.01610921916594025 0.0007311810092881902
0.1 0.4 0.01611869349482291 0.0007286521342049172
0.1 0.2 0.016152168918725954 0.0007209719760162287
0.1 0.1 0.01622811769811038 0.0007076543001709818
0.1 0.05 0.016363940350526775 0.0006840550036146843
0.1 0.025 0.016596657560431376 0.0006544480487288193
0.1 0.0125 0.01697780854883297 0.0006185083150726038
0.1 0.001 0.045490139274622865 0.0012476881321506167
0.2 0.99 0.038532292126443615 0.0023641083910049404
0.2 0.8 0.03854041890926114 0.0023697950224300175
0.2 0.4 0.03847642957292373 0.00240126034441312
0.2 0.2 0.038415936628001884 0.0023894135701014274
0.2 0.1 0.03855595137253273 0.002470497347057294
0.2 0.05 0.03889993708986826 0.0025353143563041462
0.2 0.025 0.03940092907329074 0.002554026860141877
0.2 0.0125 0.04034834821980717 0.0025189610859531787
0.2 0.001 0.11150907609292038 0.012440521530165165
0.3 0.99 0.09165362691387817 0.042892557902672185
0.3 0.8 0.0913282506964351 0.04177830572254213
0.3 0.4 0.09334974669555635 0.042465481858771734
0.3 0.2 0.09399334630214862 0.04317162624313504
0.3 0.1 0.09028586681441339 0.03865280729375347
0.3 0.05 0.09495793214763824 0.040516138519015164
0.3 0.025 0.09776432242913413 0.04397321836986062
0.3 0.0125 0.09449071066882184 0.03595686308479016
0.3 0.001 0.3482779609304819 0.05642379778753999
#coding=utf8
########################################################################
import numpy
import os
import myPythonLibrary as mypy
import dolfin_warp as dwarp
########################################################################
def plot_disp_error_vs_regul_strength(
images_folder : str ,
sol_folder : str ,
structure_type : str ,
deformation_type : str ,
texture_type : str ,
regul_type : str ,
noise_level_lst : list ,
n_runs_for_noisy_images : int ,
regul_level_lst : list ,
mesh_size : float = 0.1 ,
regul_level_for_zero : float = 1e-3 ,
generate_datafile : bool = True ,
generate_datafile_with_limited_precision : bool = False,
generate_plotfile : bool = True ,
generate_plot : bool = True ):
print ("images_folder:" , images_folder )
print ("sol_folder:" , sol_folder )
print ("structure_type:" , structure_type )
print ("deformation_type:", deformation_type)
print ("texture_type:" , texture_type )
print ("regul_type:" , regul_type )
script_basename = "plot_disp_error_vs_regul_strength"
if not os.path.exists(script_basename):
os.mkdir(script_basename)
datafile_basename = script_basename
datafile_basename += "/"+structure_type
datafile_basename += "-"+deformation_type
datafile_basename += "-"+texture_type
datafile_basename += "-"+regul_type
########################################################################
if (generate_datafile) or (generate_datafile_with_limited_precision):
if (generate_datafile): data_printer = mypy.DataPrinter(
names=["noise_level", "regul_level", "disp_err_avg", "disp_err_std"],
filename=datafile_basename+".dat",
limited_precision=False)
if (generate_datafile_with_limited_precision): data_printer2 = mypy.DataPrinter(
names=["noise_level", "regul_level", "disp_err_avg", "disp_err_std"],
filename=datafile_basename+"-limited_precision.dat",
limited_precision="True")
if (generate_datafile): data_printer3 = mypy.DataPrinter(
names=["noise_level", "regul_level", "disp_err"],
filename=datafile_basename+"-all_points.dat",
limited_precision=False)
if (structure_type in ("square", "disc", "ring")):
ref_disp_array_name = "displacement"
elif (structure_type in ("heart")):
ref_disp_array_name = "U"
else: assert (0)
for noise_level in noise_level_lst:
for regul_level in regul_level_lst:
print ("noise_level:", noise_level)
print ("regul_level:", regul_level)
if (regul_level == 0.0):
regul_level_for_write = regul_level_for_zero
else:
regul_level_for_write = regul_level
n_runs = n_runs_for_noisy_images if (noise_level > 0) else 1
disp_err_lst = []
for k_run in range(1, n_runs+1):
print ("k_run:", k_run)
images_basename = structure_type
images_basename += "-"+deformation_type
images_basename += "-"+texture_type
images_basename += "-noise="+str(noise_level)
if (n_runs > 1):
images_basename += "-run="+str(k_run).zfill(2)
sol_basename = images_basename
sol_basename += "-h="+str(mesh_size)
sol_basename += "-"+regul_type
sol_basename += "-regul="+str(regul_level)
disp_err = dwarp.compute_displacement_error(
working_folder=sol_folder,
working_basename=sol_basename,
ref_folder=images_folder,
ref_basename=structure_type+"-"+deformation_type+"-h=0.1",
working_disp_array_name="displacement",
ref_disp_array_name=ref_disp_array_name,
verbose=0)
print ("disp_err:", disp_err)
if (generate_datafile): data_printer3.write_line([noise_level, regul_level_for_write, disp_err])
disp_err_lst.append(disp_err)
disp_err_avg = numpy.mean(disp_err_lst)
disp_err_std = numpy.std(disp_err_lst)
print ("disp_err_avg:", disp_err_avg)
print ("disp_err_std:", disp_err_std)
if (generate_datafile ): data_printer.write_line([noise_level, regul_level_for_write, disp_err_avg, disp_err_std])
if (generate_datafile_with_limited_precision): data_printer2.write_line([noise_level, regul_level_for_write, disp_err_avg, disp_err_std])
if (generate_datafile ): data_printer.write_line(); data_printer.write_line()
if (generate_datafile_with_limited_precision): data_printer2.write_line(); data_printer2.write_line()
if (generate_datafile ): data_printer3.write_line(); data_printer3.write_line()
if (generate_datafile ): data_printer.close()
if (generate_datafile_with_limited_precision): data_printer2.close()
if (generate_datafile ): data_printer3.close()
########################################################################
if (generate_plotfile):
plotfile = open(datafile_basename+".plt", "w")
plotfile.write('''\
set terminal pdf enhanced size 4,3; datafile_ext = "pdf"
load "Set1.plt"
set linestyle 1 pointtype 0
set linestyle 2 pointtype 0
set linestyle 3 pointtype 0
set linestyle 4 pointtype 0
set linestyle 5 pointtype 0
set linestyle 6 pointtype 0
set linestyle 7 pointtype 0
set linestyle 8 pointtype 0
set linestyle 9 pointtype 0
set style fill transparent solid 0.1 noborder
datafile_basename = "'''+datafile_basename+'''"
datafile_name = datafile_basename.".dat"
poinfile_name = datafile_basename."-all_points.dat"
set output datafile_basename.".".datafile_ext
set title "'''+regul_type+'''"
# set title "'''+structure_type+'''-'''+deformation_type+'''-'''+regul_type+'''"
set key right box opaque textcolor variable width -1
set grid
set xlabel "regularization strength"
set xrange ['''+str(regul_level_for_zero)+''':1]
set xtics add ("0" '''+str(regul_level_for_zero)+''')
set xtics add ("0.99" 1e0)
set format x "%g"
set logscale x
set ylabel "normalized displacement error (%)"
set yrange [1e-1:1e+2]
set logscale y
plot ''')
for k_noise_level,noise_level in enumerate(noise_level_lst):
plotfile.write(((''' ''')*(k_noise_level>0))+'''datafile_name index '''+str(k_noise_level)+''' using ($2):(100*$3) with lines linestyle '''+str(k_noise_level+1)+''' linewidth 3 title "noise = '''+str(noise_level)+'''"'''+''',\\\n''')
#plotfile.write( ''' ''' +'''datafile_name index '''+str(k_noise_level)+''' using ($2):(100*$3):(100*$4) with errorbars linestyle '''+str(k_noise_level+1)+''' notitle''' +''',\\\n''')
#plotfile.write( ''' ''' +'''datafile_name index '''+str(k_noise_level)+''' using ($2):(100*$3-100*$4):(100*$3+100*$4) with filledcurves linestyle '''+str(k_noise_level+1)+''' notitle''' +((''',\\
plotfile.write( ''' ''' +'''poinfile_name index '''+str(k_noise_level)+''' using ($2):(100*$3) with points linestyle '''+str(k_noise_level+1)+''' notitle''' +((''',\\
''')*(k_noise_level<len(noise_level_lst)-1)))
plotfile.close()
########################################################################
if (generate_plot):
os.system("gnuplot "+datafile_basename+".plt")
os.system("convert -density 300 "+datafile_basename+".pdf"+" "+datafile_basename+".png")
########################################################################
if (__name__ == "__main__"):
import fire
fire.Fire(plot_disp_error_vs_regul_strength)
#coding=utf8
################################################################################
import os
import myPythonLibrary as mypy
import dolfin_warp as dwarp
################################################################################
res_folder = "plot_disp_error_vs_mesh_size"
test = mypy.Test(
res_folder=res_folder,
perform_tests=1,
stop_at_failure=1,
clean_after_tests=1,
qois_suffix="")
################################################################################
images_folder = "generate_images"
n_voxels = 100
deformation_type_lst = [ ]
deformation_type_lst += ["contractandtwist"]
texture_type_lst = [ ]
texture_type_lst += ["tagging"]
noise_level_lst = [ ]
noise_level_lst += [0.0]
noise_level_lst += [0.1]
# noise_level_lst += [0.2]
# noise_level_lst += [0.3]
n_runs_for_noisy_images = 10
working_folder = "run_warp"
mesh_size_lst = [ ]
mesh_size_lst += [0.1 ]
mesh_size_lst += [0.1/2**1] # 0.05
mesh_size_lst += [0.1/2**2] # 0.025
mesh_size_lst += [0.1/2**3] # 0.0125
mesh_size_lst += [0.1/2**4] # 0.00625
regul_type_lst = [ ]
# regul_type_lst += ["continuous-linear-elastic" ]
# regul_type_lst += ["continuous-linear-equilibrated" ]
# regul_type_lst += ["continuous-elastic" ]
# regul_type_lst += ["continuous-equilibrated" ]
# regul_type_lst += ["discrete-simple-elastic" ]
# regul_type_lst += ["discrete-simple-equilibrated" ]
# regul_type_lst += ["discrete-linear-equilibrated" ]
# regul_type_lst += ["discrete-linear-equilibrated-tractions-normal" ]
# regul_type_lst += ["discrete-linear-equilibrated-tractions-tangential" ]
# regul_type_lst += ["discrete-linear-equilibrated-tractions-normal-tangential"]
# regul_type_lst += ["discrete-equilibrated" ]
# regul_type_lst += ["discrete-equilibrated-tractions-normal" ]
# regul_type_lst += ["discrete-equilibrated-tractions-tangential" ]
regul_type_lst += ["discrete-equilibrated-tractions-normal-tangential" ]
regul_level_lst = [ ]
regul_level_lst += [0.0 ]
# regul_level_lst += [0.1/2**3] # 0.0125
# regul_level_lst += [0.1/2**2] # 0.025
# regul_level_lst += [0.1/2**1] # 0.05
regul_level_lst += [0.1 ]
# regul_level_lst += [0.1*2**1] # 0.2
# regul_level_lst += [0.1*2**2] # 0.4
# regul_level_lst += [0.1*2**3] # 0.8
# regul_level_lst += [0.99]
do_generate_images = 1
do_generate_meshes = 1
do_run_warp = 1
do_run_warp_and_refine = 1
do_plot_disp_error_vs_mesh_size = 1
do_plot_disp_error_vs_mesh_size_with_refine = 1
use_subprocesses = 1
write_subprocesses_output_to_files = 1
################################################################################
if (use_subprocesses):
subprocess_manager = mypy.SubprocessManager()
else:
from generate_images_and_meshes_from_HeartSlice import generate_images_and_meshes_from_HeartSlice
from plot_disp_error_vs_mesh_size import plot_disp_error_vs_mesh_size
############################################################ generate_images ###
if (do_generate_images):
for deformation_type in deformation_type_lst:
# Need to run the model before generating all images in parallel
print("*** running model ***" )
print("deformation_type:", deformation_type)
texture_type = "no"
noise_level = 0
run_model = True
generate_images = False
if (use_subprocesses):
command_lst = []
command_lst += ["python", "generate_images_and_meshes_from_HeartSlice.py"]
command_lst += ["--n_voxels" , str(n_voxels) ]
command_lst += ["--deformation_type", deformation_type ]
command_lst += ["--texture_type" , texture_type ]
command_lst += ["--noise_level" , str(noise_level) ]
command_lst += ["--run_model" , str(run_model) ]
command_lst += ["--generate_images" , str(generate_images)]
if (write_subprocesses_output_to_files):
stdout_folder = "generate_images"
if not os.path.exists(stdout_folder): os.mkdir(stdout_folder)
stdout_basename = "heart"
stdout_basename += "-"+deformation_type
stdout_filename = stdout_folder+"/"+stdout_basename+".out"
else:
stdout_filename = None
subprocess_manager.start_new_process_when_available(
command_lst = command_lst,
stdout_filename = stdout_filename)
subprocess_manager.wait_for_finished_processes()
else:
generate_images_and_meshes_from_HeartSlice(
n_voxels = n_voxels ,
deformation_type = deformation_type,
texture_type = texture_type ,
noise_level = noise_level ,
run_model = run_model ,
generate_images = generate_images )
for texture_type in texture_type_lst:
for noise_level in noise_level_lst :
n_runs = n_runs_for_noisy_images if (noise_level > 0) else 1
run_model = False
generate_images = True
for k_run in range(1, n_runs+1):
print("*** generate_images ***")
print("deformation_type:", deformation_type)
print("texture_type:" , texture_type )
print("noise_level:" , noise_level )
print("k_run:" , k_run )
if (use_subprocesses):
command_lst = []
command_lst += ["python", "generate_images_and_meshes_from_HeartSlice.py"]
command_lst += ["--n_voxels" , str(n_voxels) ]
command_lst += ["--deformation_type", deformation_type ]
command_lst += ["--texture_type" , texture_type ]
command_lst += ["--noise_level" , str(noise_level) ]
if (n_runs > 1):
command_lst += ["--k_run" , str(k_run) ]
command_lst += ["--run_model" , str(run_model) ]
command_lst += ["--generate_images" , str(generate_images)]
if (write_subprocesses_output_to_files):
stdout_folder = "generate_images"
if not os.path.exists(stdout_folder): os.mkdir(stdout_folder)
stdout_basename = "heart"
stdout_basename += "-"+deformation_type
stdout_basename += "-"+texture_type
stdout_basename += "-noise="+str(noise_level)
if (n_runs > 1):
stdout_basename += "-run="+str(k_run).zfill(2)
stdout_filename = stdout_folder+"/"+stdout_basename+".out"
else:
stdout_filename = None
subprocess_manager.start_new_process_when_available(
command_lst = command_lst,
stdout_filename = stdout_filename)
else:
generate_images_and_meshes_from_HeartSlice(
n_voxels = n_voxels ,
deformation_type = deformation_type ,
texture_type = texture_type ,
noise_level = noise_level ,
k_run = k_run if (n_runs > 1) else None,
run_model = run_model ,
generate_images = generate_images )
if (use_subprocesses): subprocess_manager.wait_for_finished_processes()
############################################################ generate_meshes ###
if (do_generate_meshes):
for deformation_type in deformation_type_lst:
for mesh_size in mesh_size_lst :
print("*** generate_meshes ***" )
print("deformation_type:", deformation_type)
print("mesh_size:" , mesh_size )
texture_type = "no"
noise_level = 0
run_model = True
generate_images = False
if (use_subprocesses):
command_lst = []
command_lst += ["python", "generate_images_and_meshes_from_HeartSlice.py"]
command_lst += ["--n_voxels" , str(n_voxels) ]
command_lst += ["--deformation_type", deformation_type ]
command_lst += ["--texture_type" , texture_type ]
command_lst += ["--noise_level" , str(noise_level) ]
command_lst += ["--run_model" , str(run_model) ]
command_lst += ["--generate_images" , str(generate_images)]
command_lst += ["--mesh_size" , str(mesh_size) ]
if (write_subprocesses_output_to_files):
stdout_folder = "generate_images"
if not os.path.exists(stdout_folder): os.mkdir(stdout_folder)
stdout_basename = "heart"
stdout_basename += "-"+deformation_type
stdout_basename += "-h="+str(mesh_size)
stdout_filename = stdout_folder+"/"+stdout_basename+".out"
else:
stdout_filename = None
subprocess_manager.start_new_process_when_available(
command_lst = command_lst,
stdout_filename = stdout_filename)
else:
generate_images_and_meshes_from_HeartSlice(
n_voxels = n_voxels ,
deformation_type = deformation_type,
texture_type = texture_type ,
noise_level = noise_level ,
run_model = run_model ,
generate_images = generate_images ,
mesh_size = mesh_size )
if (use_subprocesses): subprocess_manager.wait_for_finished_processes()
################################################################### run_warp ###
if (do_run_warp):
for deformation_type in deformation_type_lst:
for texture_type in texture_type_lst :
for noise_level in noise_level_lst :
n_runs = n_runs_for_noisy_images if (noise_level > 0) else 1
for k_run in range(1, n_runs+1):
for mesh_size in mesh_size_lst :
for regul_type in regul_type_lst :
for regul_level in regul_level_lst :
if any([_ in regul_type for _ in ["linear", "simple"]]):
regul_model = "hooke"
else:
regul_model = "ciarletgeymonatneohookean"
regul_poisson = 0.3
print("*** run_warp ***" )
print("deformation_type:", deformation_type)
print("texture_type:" , texture_type )
print("noise_level:" , noise_level )
print("k_run:" , k_run )
print("mesh_size:" , mesh_size )
print("regul_type:" , regul_type )
print("regul_model:" , regul_model )
print("regul_level:" , regul_level )
print("regul_poisson:" , regul_poisson )
images_basename = "heart"
images_basename += "-"+deformation_type
images_basename += "-"+texture_type
images_basename += "-noise="+str(noise_level)
if (n_runs > 1):
images_basename += "-run="+str(k_run).zfill(2)
mesh_folder = images_folder
mesh_basename = "heart"
mesh_basename += "-"+deformation_type
mesh_basename += "-h="+str(mesh_size)
mesh_basename += "-mesh"
working_basename = images_basename
working_basename += "-h="+str(mesh_size)
working_basename += "-"+regul_type
working_basename += "-regul="+str(regul_level)
relax_type = "backtracking"
tol_dU = 1e-2
n_iter_max = 100
normalize_energies = 1
continue_after_fail = 1
write_VTU_files = 1
write_VTU_files_with_preserved_connectivity = 1
if (use_subprocesses):
command_lst = []
command_lst += ["python", "../../dolfin_warp/warp.py"]
command_lst += ["--working_folder" , working_folder ]
command_lst += ["--working_basename" , working_basename ]
command_lst += ["--images_folder" , images_folder ]
command_lst += ["--images_basename" , images_basename ]
command_lst += ["--mesh_folder" , mesh_folder ]
command_lst += ["--mesh_basename" , mesh_basename ]
command_lst += ["--regul_type" , regul_type ]
command_lst += ["--regul_model" , regul_model ]
command_lst += ["--regul_level" , str(regul_level) ]
command_lst += ["--regul_poisson" , str(regul_poisson) ]
command_lst += ["--relax_type" , relax_type ]
command_lst += ["--normalize_energies" , str(normalize_energies) ]
command_lst += ["--tol_dU" , str(tol_dU) ]
command_lst += ["--n_iter_max" , str(n_iter_max) ]
command_lst += ["--continue_after_fail" , str(continue_after_fail) ]
command_lst += ["--write_VTU_files" , str(write_VTU_files) ]
command_lst += ["--write_VTU_files_with_preserved_connectivity", str(write_VTU_files_with_preserved_connectivity)]
if (write_subprocesses_output_to_files):
if not os.path.exists(working_folder): os.mkdir(working_folder)
stdout_filename = working_folder+"/"+working_basename+".out"
else:
stdout_filename = None
subprocess_manager.start_new_process_when_available(
command_lst = command_lst,
stdout_filename = stdout_filename)
else:
dwarp.warp(
working_folder = working_folder ,
working_basename = working_basename ,
images_folder = images_folder ,
images_basename = images_basename ,
mesh_folder = mesh_folder ,
mesh_basename = mesh_basename ,
regul_type = regul_type ,
regul_model = regul_model ,
regul_level = regul_level ,
regul_poisson = regul_poisson ,
relax_type = relax_type ,
normalize_energies = normalize_energies ,
tol_dU = tol_dU ,
n_iter_max = n_iter_max ,
continue_after_fail = continue_after_fail ,
write_VTU_files = write_VTU_files ,
write_VTU_files_with_preserved_connectivity = write_VTU_files_with_preserved_connectivity)
######################################################## run_warp_and_refine ###
if (do_run_warp_and_refine):
for deformation_type in deformation_type_lst:
for texture_type in texture_type_lst :
for noise_level in noise_level_lst :
n_runs = n_runs_for_noisy_images if (noise_level > 0) else 1
for k_run in range(1, n_runs+1):
for regul_type in regul_type_lst :
for regul_level in regul_level_lst :
if any([_ in regul_type for _ in ["linear", "simple"]]):
regul_model = "hooke"
else:
regul_model = "ciarletgeymonatneohookean"
regul_poisson = 0.3
print("*** run_warp_and_refine ***" )
print("deformation_type:", deformation_type)
print("texture_type:" , texture_type )
print("noise_level:" , noise_level )
print("k_run:" , k_run )
print("regul_type:" , regul_type )
print("regul_model:" , regul_model )
print("regul_level:" , regul_level )
print("regul_poisson:" , regul_poisson )
images_basename = "heart"
images_basename += "-"+deformation_type
images_basename += "-"+texture_type
images_basename += "-noise="+str(noise_level)
if (n_runs > 1):
images_basename += "-run="+str(k_run).zfill(2)
mesh_folder = "generate_images"
mesh_basenames = []
for mesh_size in mesh_size_lst:
mesh_basename = "heart"
mesh_basename += "-"+deformation_type
mesh_basename += "-h="+str(mesh_size)
mesh_basename += "-mesh"
mesh_basenames += [mesh_basename]
working_basename = images_basename
working_basename += "-"+regul_type
working_basename += "-regul="+str(regul_level)
relax_type = "backtracking"
tol_dU = 1e-2
n_iter_max = 100
normalize_energies = 1
continue_after_fail = 1
if (use_subprocesses):
command_lst = []
command_lst += ["python", "../../dolfin_warp/warp.py"]
command_lst += ["--working_folder" , working_folder ]
command_lst += ["--working_basename" , working_basename ]
command_lst += ["--images_folder" , images_folder ]
command_lst += ["--images_basename" , images_basename ]
command_lst += ["--mesh_folder" , mesh_folder ]
command_lst += ["--mesh_basenames" , str(mesh_basenames).replace(" ", "")]
command_lst += ["--regul_type" , regul_type ]
command_lst += ["--regul_model" , regul_model ]
command_lst += ["--regul_level" , str(regul_level) ]
command_lst += ["--regul_poisson" , str(regul_poisson) ]
command_lst += ["--relax_type" , relax_type ]
command_lst += ["--normalize_energies" , str(normalize_energies) ]
command_lst += ["--tol_dU" , str(tol_dU) ]
command_lst += ["--n_iter_max" , str(n_iter_max) ]
command_lst += ["--continue_after_fail", str(continue_after_fail) ]
if (write_subprocesses_output_to_files):
if not os.path.exists(working_folder): os.mkdir(working_folder)
stdout_filename = working_folder+"/"+working_basename+".out"
else:
stdout_filename = None
subprocess_manager.start_new_process_when_available(
command_lst = command_lst,
stdout_filename = stdout_filename)
else:
dwarp.warp_and_refine(
working_folder = working_folder ,
working_basename = working_basename ,
images_folder = images_folder ,
images_basename = images_basename ,
mesh_folder = mesh_folder ,
mesh_basenames = mesh_basenames ,
regul_type = regul_type ,
regul_model = regul_model ,
regul_level = regul_level ,
regul_poisson = regul_poisson ,
relax_type = relax_type ,
normalize_energies = normalize_energies ,
tol_dU = tol_dU ,
n_iter_max = n_iter_max ,
continue_after_fail = continue_after_fail)
if (use_subprocesses): subprocess_manager.wait_for_finished_processes()
############################################### plot_disp_error_vs_mesh_size ###
if (do_plot_disp_error_vs_mesh_size) or (do_plot_disp_error_vs_mesh_size_with_refine):
with_refine_lst = []
if (do_plot_disp_error_vs_mesh_size ): with_refine_lst += [False]
if (do_plot_disp_error_vs_mesh_size_with_refine): with_refine_lst += [True ]
for with_refine in with_refine_lst :
for deformation_type in deformation_type_lst:
for texture_type in texture_type_lst :
for regul_type in regul_type_lst :
structure_type = "heart"
error_for_nan = 10
generate_datafile = 1
generate_plotfile = 1
generate_plot = 1
if (use_subprocesses):
command_lst = []
command_lst += ["python", "plot_disp_error_vs_mesh_size.py"]
command_lst += ["--images_folder" , images_folder ]
command_lst += ["--sol_folder" , working_folder ]
command_lst += ["--structure_type" , structure_type ]
command_lst += ["--deformation_type" , deformation_type ]
command_lst += ["--texture_type" , texture_type ]
command_lst += ["--regul_type" , regul_type ]
command_lst += ["--noise_level_lst" , str(noise_level_lst).replace(" ", "")]
command_lst += ["--n_runs_for_noisy_images", str(n_runs_for_noisy_images) ]
command_lst += ["--regul_level_lst" , str(regul_level_lst).replace(" ", "")]
command_lst += ["--mesh_size_lst" , str(mesh_size_lst).replace(" ", "") ]
command_lst += ["--error_for_nan" , str(error_for_nan) ]
command_lst += ["--with_refine" , str(with_refine) ]
command_lst += ["--generate_datafile" , str(generate_datafile) ]
command_lst += ["--generate_plotfile" , str(generate_plotfile) ]
command_lst += ["--generate_plot" , str(generate_plot) ]
if (write_subprocesses_output_to_files):
stdout_folder = "plot_disp_error_vs_mesh_size"
if not os.path.exists(stdout_folder): os.mkdir(stdout_folder)
stdout_basename = structure_type
stdout_basename += "-"+deformation_type
stdout_basename += "-"+texture_type
stdout_basename += "-"+regul_type
if (with_refine):
stdout_basename += "-with_refine"
stdout_filename = stdout_folder+"/"+stdout_basename+".out"
else:
stdout_filename = None
subprocess_manager.start_new_process_when_available(
command_lst = command_lst,
stdout_filename = stdout_filename)
else:
plot_disp_error_vs_mesh_size(
images_folder = images_folder ,
sol_folder = working_folder ,
structure_type = structure_type ,
deformation_type = deformation_type ,
texture_type = texture_type ,
regul_type = regul_type ,
noise_level_lst = noise_level_lst ,
n_runs_for_noisy_images = n_runs_for_noisy_images,
regul_level_lst = regul_level_lst ,
mesh_size_lst = mesh_size_lst ,
error_for_nan = error_for_nan ,
with_refine = with_refine ,
generate_datafile = generate_datafile ,
generate_plotfile = generate_plotfile ,
generate_plot = generate_plot )
if (use_subprocesses): subprocess_manager.wait_for_finished_processes()
####################################################################### test ###
with_refine_lst = []
if (do_plot_disp_error_vs_mesh_size ): with_refine_lst += [False]
if (do_plot_disp_error_vs_mesh_size_with_refine): with_refine_lst += [True ]
for with_refine in with_refine_lst :
for deformation_type in deformation_type_lst:
for texture_type in texture_type_lst :
for regul_type in regul_type_lst :
structure_type = "heart"
res_basename = structure_type
res_basename += "-"+deformation_type
res_basename += "-"+texture_type
res_basename += "-"+regul_type
if (with_refine):
res_basename += "-with_refine"
test.test(res_basename)
#coding=utf8
################################################################################
import os
import myPythonLibrary as mypy
import dolfin_warp as dwarp
################################################################################
res_folder = "plot_disp_error_vs_regul_strength"
test = mypy.Test(
res_folder=res_folder,
perform_tests=1,
stop_at_failure=1,
clean_after_tests=1,
qois_suffix="")
################################################################################
images_folder = "generate_images"
n_voxels = 100
deformation_type_lst = [ ]
deformation_type_lst += ["contractandtwist"]
texture_type_lst = [ ]
texture_type_lst += ["tagging"]
noise_level_lst = [ ]
noise_level_lst += [0.0]
noise_level_lst += [0.1]
noise_level_lst += [0.2]
noise_level_lst += [0.3]
n_runs_for_noisy_images = 10
working_folder = "run_warp"
mesh_size_lst = [ ]
mesh_size_lst += [0.1 ]
# mesh_size_lst += [0.1/2**1] # 0.05
# mesh_size_lst += [0.1/2**2] # 0.025
# mesh_size_lst += [0.1/2**3] # 0.0125
# mesh_size_lst += [0.1/2**4] # 0.00625
regul_type_lst = []
regul_type_lst += ["continuous-linear-elastic" ]
regul_type_lst += ["continuous-linear-equilibrated" ]
regul_type_lst += ["continuous-elastic" ]
regul_type_lst += ["continuous-equilibrated" ]
regul_type_lst += ["discrete-simple-elastic" ]
regul_type_lst += ["discrete-simple-equilibrated" ]
regul_type_lst += ["discrete-linear-equilibrated" ]
regul_type_lst += ["discrete-linear-equilibrated-tractions-normal" ]
regul_type_lst += ["discrete-linear-equilibrated-tractions-tangential" ]
regul_type_lst += ["discrete-linear-equilibrated-tractions-normal-tangential"]
regul_type_lst += ["discrete-equilibrated" ]
regul_type_lst += ["discrete-equilibrated-tractions-normal" ]
regul_type_lst += ["discrete-equilibrated-tractions-tangential" ]
regul_type_lst += ["discrete-equilibrated-tractions-normal-tangential" ]
regul_level_lst = [ ]
regul_level_lst += [0.99 ]
regul_level_lst += [0.1*2**3] # 0.8
regul_level_lst += [0.1*2**2] # 0.4
regul_level_lst += [0.1*2**1] # 0.2
regul_level_lst += [0.1 ]
regul_level_lst += [0.1/2**1] # 0.05
regul_level_lst += [0.1/2**2] # 0.025
regul_level_lst += [0.1/2**3] # 0.0125
regul_level_lst += [0.0 ]
do_generate_images = 1
do_generate_meshes = 1
do_run_warp = 1
do_plot_disp_error_vs_regul_strength = 1
use_subprocesses = 1
write_subprocesses_output_to_files = 1
################################################################################
if (use_subprocesses):
subprocess_manager = mypy.SubprocessManager()
else:
from generate_images_and_meshes_from_HeartSlice import generate_images_and_meshes_from_HeartSlice
from plot_disp_error_vs_regul_strength import plot_disp_error_vs_regul_strength
############################################################ generate_images ###
if (do_generate_images):
for deformation_type in deformation_type_lst:
# Need to run the model before generating all images in parallel
print("*** running model ***" )
print("deformation_type:", deformation_type)
texture_type = "no"
noise_level = 0
run_model = True
generate_images = False
if (use_subprocesses):
command_lst = []
command_lst += ["python", "generate_images_and_meshes_from_HeartSlice.py"]
command_lst += ["--n_voxels" , str(n_voxels) ]
command_lst += ["--deformation_type", deformation_type ]
command_lst += ["--texture_type" , texture_type ]
command_lst += ["--noise_level" , str(noise_level) ]
command_lst += ["--run_model" , str(run_model) ]
command_lst += ["--generate_images" , str(generate_images)]
if (write_subprocesses_output_to_files):
stdout_folder = "generate_images"
if not os.path.exists(stdout_folder): os.mkdir(stdout_folder)
stdout_basename = "heart"
stdout_basename += "-"+deformation_type
stdout_filename = stdout_folder+"/"+stdout_basename+".out"
else:
stdout_filename = None
subprocess_manager.start_new_process_when_available(
command_lst = command_lst,
stdout_filename = stdout_filename)
subprocess_manager.wait_for_finished_processes()
else:
generate_images_and_meshes_from_HeartSlice(
n_voxels = n_voxels ,
deformation_type = deformation_type,
texture_type = texture_type ,
noise_level = noise_level ,
run_model = run_model ,
generate_images = generate_images )
for texture_type in texture_type_lst:
for noise_level in noise_level_lst :
n_runs = n_runs_for_noisy_images if (noise_level > 0) else 1
run_model = False
generate_images = True
for k_run in range(1, n_runs+1):
print("*** generate_images ***" )
print("deformation_type:", deformation_type)
print("texture_type:" , texture_type )
print("noise_level:" , noise_level )
print("k_run:" , k_run )
if (use_subprocesses):
command_lst = []
command_lst += ["python", "generate_images_and_meshes_from_HeartSlice.py"]
command_lst += ["--n_voxels" , str(n_voxels) ]
command_lst += ["--deformation_type", deformation_type ]
command_lst += ["--texture_type" , texture_type ]
command_lst += ["--noise_level" , str(noise_level) ]
if (n_runs > 1):
command_lst += ["--k_run" , str(k_run) ]
command_lst += ["--run_model" , str(run_model) ]
command_lst += ["--generate_images" , str(generate_images)]
if (write_subprocesses_output_to_files):
stdout_folder = "generate_images"
if not os.path.exists(stdout_folder): os.mkdir(stdout_folder)
stdout_basename = "heart"
stdout_basename += "-"+deformation_type
stdout_basename += "-"+texture_type
stdout_basename += "-noise="+str(noise_level)
if (n_runs > 1):
stdout_basename += "-run="+str(k_run).zfill(2)
stdout_filename = stdout_folder+"/"+stdout_basename+".out"
else:
stdout_filename = None
subprocess_manager.start_new_process_when_available(
command_lst = command_lst,
stdout_filename = stdout_filename)
else:
generate_images_and_meshes_from_HeartSlice(
n_voxels = n_voxels ,
deformation_type = deformation_type ,
texture_type = texture_type ,
noise_level = noise_level ,
k_run = k_run if (n_runs > 1) else None,
run_model = run_model ,
generate_images = generate_images )
if (use_subprocesses): subprocess_manager.wait_for_finished_processes()
############################################################ generate_meshes ###
if (do_generate_meshes):
for deformation_type in deformation_type_lst:
for mesh_size in mesh_size_lst :
print("*** generate_meshes ***" )
print("deformation_type:", deformation_type)
print("mesh_size:" , mesh_size )
texture_type = "no"
noise_level = 0
run_model = True
generate_images = False
if (use_subprocesses):
command_lst = []
command_lst += ["python", "generate_images_and_meshes_from_HeartSlice.py"]
command_lst += ["--n_voxels" , str(n_voxels) ]
command_lst += ["--deformation_type", deformation_type ]
command_lst += ["--texture_type" , texture_type ]
command_lst += ["--noise_level" , str(noise_level) ]
command_lst += ["--run_model" , str(run_model) ]
command_lst += ["--generate_images" , str(generate_images)]
command_lst += ["--mesh_size" , str(mesh_size) ]
if (write_subprocesses_output_to_files):
stdout_folder = "generate_images"
if not os.path.exists(stdout_folder): os.mkdir(stdout_folder)
stdout_basename = "heart"
stdout_basename += "-"+deformation_type
stdout_basename += "-h="+str(mesh_size)
stdout_filename = stdout_folder+"/"+stdout_basename+".out"
else:
stdout_filename = None
subprocess_manager.start_new_process_when_available(
command_lst = command_lst,
stdout_filename = stdout_filename)
else:
generate_images_and_meshes_from_HeartSlice(
n_voxels = n_voxels ,
deformation_type = deformation_type,
texture_type = texture_type ,
noise_level = noise_level ,
run_model = run_model ,
generate_images = generate_images ,
mesh_size = mesh_size )
if (use_subprocesses): subprocess_manager.wait_for_finished_processes()
################################################################### run_warp ###
if (do_run_warp):
for deformation_type in deformation_type_lst:
for texture_type in texture_type_lst :
for noise_level in noise_level_lst :
n_runs = n_runs_for_noisy_images if (noise_level > 0) else 1
for k_run in range(1, n_runs+1):
for mesh_size in mesh_size_lst :
for regul_type in regul_type_lst :
for regul_level in regul_level_lst :
if any([_ in regul_type for _ in ["linear", "simple"]]):
regul_model = "hooke"
else:
regul_model = "ogdenciarletgeymonatneohookean"
regul_poisson = 0.3
print("*** run_warp ***" )
print("deformation_type:", deformation_type)
print("texture_type:" , texture_type )
print("noise_level:" , noise_level )
print("k_run:" , k_run )
print("mesh_size:" , mesh_size )
print("regul_type:" , regul_type )
print("regul_model:" , regul_model )
print("regul_level:" , regul_level )
print("regul_poisson:" , regul_poisson )
images_basename = "heart"
images_basename += "-"+deformation_type
images_basename += "-"+texture_type
images_basename += "-noise="+str(noise_level)
if (n_runs > 1):
images_basename += "-run="+str(k_run).zfill(2)
mesh_folder = images_folder
mesh_basename = "heart"
mesh_basename += "-"+deformation_type
mesh_basename += "-h="+str(mesh_size)
mesh_basename += "-mesh"
working_basename = images_basename
working_basename += "-h="+str(mesh_size)
working_basename += "-"+regul_type
working_basename += "-regul="+str(regul_level)
relax_type = "backtracking"
tol_dU = 1e-2
n_iter_max = 100
normalize_energies = 1
continue_after_fail = 1
write_VTU_files = 1
write_VTU_files_with_preserved_connectivity = 1
if (use_subprocesses):
command_lst = []
command_lst += ["python", "../../dolfin_warp/warp.py"]
command_lst += ["--working_folder" , working_folder ]
command_lst += ["--working_basename" , working_basename ]
command_lst += ["--images_folder" , images_folder ]
command_lst += ["--images_basename" , images_basename ]
command_lst += ["--mesh_folder" , mesh_folder ]
command_lst += ["--mesh_basename" , mesh_basename ]
command_lst += ["--regul_type" , regul_type ]
command_lst += ["--regul_model" , regul_model ]
command_lst += ["--regul_level" , str(regul_level) ]
command_lst += ["--regul_poisson" , str(regul_poisson) ]
command_lst += ["--relax_type" , relax_type ]
command_lst += ["--normalize_energies" , str(normalize_energies) ]
command_lst += ["--tol_dU" , str(tol_dU) ]
command_lst += ["--n_iter_max" , str(n_iter_max) ]
command_lst += ["--continue_after_fail" , str(continue_after_fail) ]
command_lst += ["--write_VTU_files" , str(write_VTU_files) ]
command_lst += ["--write_VTU_files_with_preserved_connectivity", str(write_VTU_files_with_preserved_connectivity)]
if (write_subprocesses_output_to_files):
if not os.path.exists(working_folder): os.mkdir(working_folder)
stdout_filename = working_folder+"/"+working_basename+".out"
else:
stdout_filename = None
subprocess_manager.start_new_process_when_available(
command_lst = command_lst,
stdout_filename = stdout_filename)
else:
dwarp.warp(
working_folder = working_folder ,
working_basename = working_basename ,
images_folder = images_folder ,
images_basename = images_basename ,
mesh_folder = mesh_folder ,
mesh_basename = mesh_basename ,
regul_type = regul_type ,
regul_model = regul_model ,
regul_level = regul_level ,
regul_poisson = regul_poisson ,
relax_type = relax_type ,
normalize_energies = normalize_energies ,
tol_dU = tol_dU ,
n_iter_max = n_iter_max ,
continue_after_fail = continue_after_fail ,
write_VTU_files = write_VTU_files ,
write_VTU_files_with_preserved_connectivity = write_VTU_files_with_preserved_connectivity)
if (use_subprocesses): subprocess_manager.wait_for_finished_processes()
########################################## plot_disp_error_vs_regul_strength ###
if (do_plot_disp_error_vs_regul_strength):
for deformation_type in deformation_type_lst:
for texture_type in texture_type_lst :
for regul_type in regul_type_lst :
print("*** plot_disp_error_vs_regul_strength ***")
print("deformation_type:", deformation_type)
print("texture_type:" , texture_type )
print("regul_type:" , regul_type )
structure_type = "heart"
regul_level_for_zero = 1e-3
generate_datafile = 1
generate_datafile_with_limited_precision = 1
generate_plotfile = 1
generate_plot = 1
if (use_subprocesses):
command_lst = []
command_lst += ["python", "plot_disp_error_vs_regul_strength.py"]
command_lst += ["--images_folder" , images_folder ]
command_lst += ["--sol_folder" , working_folder ]
command_lst += ["--structure_type" , structure_type ]
command_lst += ["--deformation_type" , deformation_type ]
command_lst += ["--texture_type" , texture_type ]
command_lst += ["--regul_type" , regul_type ]
command_lst += ["--noise_level_lst" , str(noise_level_lst).replace(" ", "") ]
command_lst += ["--n_runs_for_noisy_images" , str(n_runs_for_noisy_images) ]
command_lst += ["--regul_level_lst" , str(regul_level_lst).replace(" ", "") ]
command_lst += ["--regul_level_for_zero" , str(regul_level_for_zero) ]
command_lst += ["--generate_datafile" , str(generate_datafile) ]
command_lst += ["--generate_datafile_with_limited_precision", str(generate_datafile_with_limited_precision)]
command_lst += ["--generate_plotfile" , str(generate_plotfile) ]
command_lst += ["--generate_plot" , str(generate_plot) ]
if (write_subprocesses_output_to_files):
stdout_folder = "plot_disp_error_vs_regul_strength"
if not os.path.exists(stdout_folder): os.mkdir(stdout_folder)
stdout_basename = structure_type
stdout_basename += "-"+deformation_type
stdout_basename += "-"+texture_type
stdout_basename += "-"+regul_type
stdout_filename = stdout_folder+"/"+stdout_basename+".out"
else:
stdout_filename = None
subprocess_manager.start_new_process_when_available(
command_lst = command_lst,
stdout_filename = stdout_filename)
else:
plot_disp_error_vs_regul_strength(
images_folder = images_folder ,
sol_folder = working_folder ,
structure_type = structure_type ,
deformation_type = deformation_type ,
texture_type = texture_type ,
regul_type = regul_type ,
noise_level_lst = noise_level_lst ,
n_runs_for_noisy_images = n_runs_for_noisy_images ,
regul_level_lst = regul_level_lst ,
regul_level_for_zero = regul_level_for_zero ,
generate_datafile = generate_datafile ,
generate_datafile_with_limited_precision = generate_datafile_with_limited_precision,
generate_plotfile = generate_plotfile ,
generate_plot = generate_plot )
if (use_subprocesses): subprocess_manager.wait_for_finished_processes()
####################################################################### test ###
for deformation_type in deformation_type_lst:
for texture_type in texture_type_lst :
for regul_type in regul_type_lst :
structure_type = "heart"
res_basename = structure_type
res_basename += "-"+deformation_type
res_basename += "-"+texture_type
res_basename += "-"+regul_type
test.test(res_basename)
#coding=utf8
################################################################################
import os
import myPythonLibrary as mypy
import dolfin_warp as dwarp
################################################################################
res_folder = "plot_disp_error_vs_regul_strength"
test = mypy.Test(
res_folder=res_folder,
perform_tests=1,
stop_at_failure=1,
clean_after_tests=1,
qois_suffix="")
################################################################################
n_dim = 2
images_folder = "generate_images"
n_voxels = 100
structure_deformation_type_lst = [ ]
structure_deformation_type_lst += [["square", "translation"]]
structure_deformation_type_lst += [["square", "rotation" ]]
structure_deformation_type_lst += [["square", "compression"]]
structure_deformation_type_lst += [["square", "shear" ]]
texture_type_lst = [ ]
texture_type_lst += ["tagging"]
noise_level_lst = [ ]
noise_level_lst += [0.0]
noise_level_lst += [0.1]
noise_level_lst += [0.2]
noise_level_lst += [0.3]
n_runs_for_noisy_images = 10
working_folder = "run_warp"
mesh_size_lst = [ ]
mesh_size_lst += [0.1 ]
# mesh_size_lst += [0.1/2**1] # 0.05
# mesh_size_lst += [0.1/2**2] # 0.025
# mesh_size_lst += [0.1/2**3] # 0.0125
# mesh_size_lst += [0.1/2**4] # 0.00625
regul_type_lst = [ ]
regul_type_lst += ["continuous-linear-elastic" ]
regul_type_lst += ["continuous-linear-equilibrated" ]
regul_type_lst += ["continuous-elastic" ]
regul_type_lst += ["continuous-equilibrated" ]
regul_type_lst += ["discrete-simple-elastic" ]
regul_type_lst += ["discrete-simple-equilibrated" ]
regul_type_lst += ["discrete-linear-equilibrated" ]
regul_type_lst += ["discrete-linear-equilibrated-tractions-normal" ]
regul_type_lst += ["discrete-linear-equilibrated-tractions-tangential" ]
regul_type_lst += ["discrete-linear-equilibrated-tractions-normal-tangential"]
regul_type_lst += ["discrete-equilibrated" ]
regul_type_lst += ["discrete-equilibrated-tractions-normal" ]
regul_type_lst += ["discrete-equilibrated-tractions-tangential" ]
regul_type_lst += ["discrete-equilibrated-tractions-normal-tangential" ]
regul_level_lst = [ ]
regul_level_lst += [0.99 ]
regul_level_lst += [0.1*2**3] # 0.8
regul_level_lst += [0.1*2**2] # 0.4
regul_level_lst += [0.1*2**1] # 0.2
regul_level_lst += [0.1 ]
regul_level_lst += [0.1/2**1] # 0.05
regul_level_lst += [0.1/2**2] # 0.025
regul_level_lst += [0.1/2**3] # 0.0125
regul_level_lst += [0.0 ]
do_generate_images = 1
do_generate_meshes = 1
do_run_warp = 1
do_plot_disp_error_vs_regul_strength = 1
use_subprocesses = 1
write_subprocesses_output_to_files = 1
################################################################################
if (use_subprocesses):
subprocess_manager = mypy.SubprocessManager()
else:
from generate_images_and_meshes_from_Struct import generate_images_and_meshes_from_Struct
from plot_disp_error_vs_regul_strength import plot_disp_error_vs_regul_strength
############################################################ generate_images ###
if (do_generate_images):
for structure_type, deformation_type in structure_deformation_type_lst:
for texture_type in texture_type_lst :
for noise_level in noise_level_lst :
n_runs = n_runs_for_noisy_images if (noise_level > 0) else 1
for k_run in range(1, n_runs+1):
print("*** generate_images ***" )
print("structure_type:" , structure_type )
print("deformation_type:", deformation_type)
print("texture_type:" , texture_type )
print("noise_level:" , noise_level )
print("k_run:" , k_run )
generate_images = True
compute_meshes = False
if (use_subprocesses):
command_lst = []
command_lst += ["python", "generate_images_and_meshes_from_Struct.py"]
command_lst += ["--n_dim" , str(n_dim) ]
command_lst += ["--n_voxels" , str(n_voxels) ]
command_lst += ["--structure_type" , structure_type ]
command_lst += ["--deformation_type", deformation_type ]
command_lst += ["--texture_type" , texture_type ]
command_lst += ["--noise_level" , str(noise_level) ]
if (n_runs > 1):
command_lst += ["--k_run" , str(k_run) ]
command_lst += ["--generate_images" , str(generate_images)]
command_lst += ["--compute_meshes" , str(compute_meshes) ]
if (write_subprocesses_output_to_files):
stdout_folder = "generate_images"
if not os.path.exists(stdout_folder): os.mkdir(stdout_folder)
stdout_basename = structure_type
stdout_basename += "-"+deformation_type
stdout_basename += "-"+texture_type
stdout_basename += "-noise="+str(noise_level)
if (n_runs > 1):
stdout_basename += "-run="+str(k_run).zfill(2)
stdout_filename = stdout_folder+"/"+stdout_basename+".out"
else:
stdout_filename = None
subprocess_manager.start_new_process_when_available(
command_lst = command_lst,
stdout_filename = stdout_filename)
else:
generate_images_and_meshes_from_Struct(
n_dim = n_dim ,
n_voxels = n_voxels ,
structure_type = structure_type ,
deformation_type = deformation_type ,
texture_type = texture_type ,
noise_level = noise_level ,
k_run = k_run if (n_runs > 1) else None,
generate_images = generate_images ,
compute_meshes = compute_meshes )
if (use_subprocesses): subprocess_manager.wait_for_finished_processes()
############################################################ generate_meshes ###
if (do_generate_meshes):
for structure_type, deformation_type in structure_deformation_type_lst:
for mesh_size in mesh_size_lst :
print("*** generate_meshes ***" )
print("structure_type:" , structure_type )
print("deformation_type:", deformation_type)
print("mesh_size:" , mesh_size )
texture_type = "no"
noise_level = 0
generate_images = False
compute_meshes = True
if (use_subprocesses):
command_lst = []
command_lst += ["python", "generate_images_and_meshes_from_Struct.py"]
command_lst += ["--n_dim" , str(n_dim) ]
command_lst += ["--n_voxels" , str(n_voxels) ]
command_lst += ["--structure_type" , structure_type ]
command_lst += ["--deformation_type", deformation_type ]
command_lst += ["--texture_type" , texture_type ]
command_lst += ["--noise_level" , str(noise_level) ]
command_lst += ["--mesh_size" , str(mesh_size) ]
command_lst += ["--generate_images" , str(generate_images)]
command_lst += ["--compute_meshes" , str(compute_meshes) ]
if (write_subprocesses_output_to_files):
stdout_folder = "generate_images"
if not os.path.exists(stdout_folder): os.mkdir(stdout_folder)
stdout_basename = structure_type
stdout_basename += "-"+deformation_type
stdout_basename += "-h="+str(mesh_size)
stdout_filename = stdout_folder+"/"+stdout_basename+".out"
else:
stdout_filename = None
subprocess_manager.start_new_process_when_available(
command_lst = command_lst,
stdout_filename = stdout_filename)
else:
generate_images_and_meshes_from_Struct(
n_dim = n_dim ,
n_voxels = n_voxels ,
structure_type = structure_type ,
deformation_type = deformation_type,
texture_type = texture_type ,
noise_level = noise_level ,
mesh_size = mesh_size ,
generate_images = generate_images ,
compute_meshes = compute_meshes )
if (use_subprocesses): subprocess_manager.wait_for_finished_processes()
################################################################### run_warp ###
if (do_run_warp):
for structure_type, deformation_type in structure_deformation_type_lst:
for texture_type in texture_type_lst :
for noise_level in noise_level_lst :
n_runs = n_runs_for_noisy_images if (noise_level > 0) else 1
for k_run in range(1, n_runs+1):
for mesh_size in mesh_size_lst :
for regul_type in regul_type_lst :
for regul_level in regul_level_lst :
if any([_ in regul_type for _ in ["linear", "simple"]]):
regul_model = "hooke"
else:
regul_model = "ogdenciarletgeymonatneohookean"
regul_poisson = 0.0
print("*** run_warp ***" )
print("structure_type:" , structure_type )
print("deformation_type:", deformation_type)
print("texture_type:" , texture_type )
print("noise_level:" , noise_level )
print("k_run:" , k_run )
print("mesh_size:" , mesh_size )
print("regul_type:" , regul_type )
print("regul_model:" , regul_model )
print("regul_level:" , regul_level )
print("regul_poisson:" , regul_poisson )
images_basename = structure_type
images_basename += "-"+deformation_type
images_basename += "-"+texture_type
images_basename += "-noise="+str(noise_level)
if (n_runs > 1):
images_basename += "-run="+str(k_run).zfill(2)
mesh_folder = images_folder
mesh_basename = structure_type
mesh_basename += "-"+deformation_type
mesh_basename += "-h="+str(mesh_size)
if (structure_type == "heart"):
mesh_basename += "-mesh"
working_basename = images_basename
working_basename += "-h="+str(mesh_size)
working_basename += "-"+regul_type
working_basename += "-regul="+str(regul_level)
relax_type = "backtracking"
normalize_energies = 1
tol_dU = 1e-2
n_iter_max = 100
continue_after_fail = 1
write_VTU_files = 1
write_VTU_files_with_preserved_connectivity = 1
if (use_subprocesses):
command_lst = []
command_lst += ["python", "../../dolfin_warp/warp.py"]
command_lst += ["--working_folder" , working_folder ]
command_lst += ["--working_basename" , working_basename ]
command_lst += ["--images_folder" , images_folder ]
command_lst += ["--images_basename" , images_basename ]
command_lst += ["--mesh_folder" , mesh_folder ]
command_lst += ["--mesh_basename" , mesh_basename ]
command_lst += ["--regul_type" , regul_type ]
command_lst += ["--regul_model" , regul_model ]
command_lst += ["--regul_level" , str(regul_level) ]
command_lst += ["--regul_poisson" , str(regul_poisson) ]
command_lst += ["--relax_type" , relax_type ]
command_lst += ["--normalize_energies" , str(normalize_energies) ]
command_lst += ["--tol_dU" , str(tol_dU) ]
command_lst += ["--n_iter_max" , str(n_iter_max) ]
command_lst += ["--continue_after_fail" , str(continue_after_fail) ]
command_lst += ["--write_VTU_files" , str(write_VTU_files) ]
command_lst += ["--write_VTU_files_with_preserved_connectivity", str(write_VTU_files_with_preserved_connectivity)]
if (write_subprocesses_output_to_files):
if not os.path.exists(working_folder): os.mkdir(working_folder)
stdout_filename = working_folder+"/"+working_basename+".out"
else:
stdout_filename = None
subprocess_manager.start_new_process_when_available(
command_lst = command_lst,
stdout_filename = stdout_filename)
else:
dwarp.warp(
working_folder = working_folder ,
working_basename = working_basename ,
images_folder = images_folder ,
images_basename = images_basename ,
mesh_folder = mesh_folder ,
mesh_basename = mesh_basename ,
regul_type = regul_type ,
regul_model = regul_model ,
regul_level = regul_level ,
regul_poisson = regul_poisson ,
relax_type = relax_type ,
normalize_energies = normalize_energies ,
tol_dU = tol_dU ,
n_iter_max = n_iter_max ,
continue_after_fail = continue_after_fail ,
write_VTU_files = write_VTU_files ,
write_VTU_files_with_preserved_connectivity = write_VTU_files_with_preserved_connectivity)
if (use_subprocesses): subprocess_manager.wait_for_finished_processes()
########################################## plot_disp_error_vs_regul_strength ###
if (do_plot_disp_error_vs_regul_strength):
for structure_type, deformation_type in structure_deformation_type_lst:
for texture_type in texture_type_lst :
for regul_type in regul_type_lst :
print("*** plot_disp_error_vs_regul_strength ***")
print("structure_type:" , structure_type )
print("deformation_type:", deformation_type)
print("texture_type:" , texture_type )
print("regul_type:" , regul_type )
regul_level_for_zero = 1e-3
generate_datafile = 1
generate_datafile_with_limited_precision = 1
generate_plotfile = 1
generate_plot = 1
if (use_subprocesses):
command_lst = []
command_lst += ["python", "plot_disp_error_vs_regul_strength.py"]
command_lst += ["--images_folder" , images_folder ]
command_lst += ["--sol_folder" , working_folder ]
command_lst += ["--structure_type" , structure_type ]
command_lst += ["--deformation_type" , deformation_type ]
command_lst += ["--texture_type" , texture_type ]
command_lst += ["--regul_type" , regul_type ]
command_lst += ["--noise_level_lst" , str(noise_level_lst).replace(" ", "") ]
command_lst += ["--n_runs_for_noisy_images" , str(n_runs_for_noisy_images) ]
command_lst += ["--regul_level_lst" , str(regul_level_lst).replace(" ", "") ]
command_lst += ["--regul_level_for_zero" , str(regul_level_for_zero) ]
command_lst += ["--generate_datafile" , str(generate_datafile) ]
command_lst += ["--generate_datafile_with_limited_precision", str(generate_datafile_with_limited_precision)]
command_lst += ["--generate_plotfile" , str(generate_plotfile) ]
command_lst += ["--generate_plot" , str(generate_plot) ]
if (write_subprocesses_output_to_files):
stdout_folder = "plot_disp_error_vs_regul_strength"
if not os.path.exists(stdout_folder): os.mkdir(stdout_folder)
stdout_basename = structure_type
stdout_basename += "-"+deformation_type
stdout_basename += "-"+texture_type
stdout_basename += "-"+regul_type
stdout_filename = stdout_folder+"/"+stdout_basename+".out"
else:
stdout_filename = None
subprocess_manager.start_new_process_when_available(
command_lst = command_lst,
stdout_filename = stdout_filename)
else:
plot_disp_error_vs_regul_strength(
images_folder = images_folder ,
sol_folder = working_folder ,
structure_type = structure_type ,
deformation_type = deformation_type ,
texture_type = texture_type ,
regul_type = regul_type ,
noise_level_lst = noise_level_lst ,
n_runs_for_noisy_images = n_runs_for_noisy_images ,
regul_level_lst = regul_level_lst ,
regul_level_for_zero = regul_level_for_zero ,
generate_datafile = generate_datafile ,
generate_datafile_with_limited_precision = generate_datafile_with_limited_precision,
generate_plotfile = generate_plotfile ,
generate_plot = generate_plot )
if (use_subprocesses): subprocess_manager.wait_for_finished_processes()
####################################################################### test ###
for structure_type, deformation_type in structure_deformation_type_lst:
for texture_type in texture_type_lst :
for regul_type in regul_type_lst :
res_basename = structure_type
res_basename += "-"+deformation_type
res_basename += "-"+texture_type
res_basename += "-"+regul_type
test.test(res_basename)
#coding=utf8
################################################################################
### ###
### Created by Martin Genet, 2016-2024 ###
### ###
### École Polytechnique, Palaiseau, France ###
### ###
################################################################################
import os
import shutil
import sys
import myPythonLibrary as mypy
import dolfin_mech as dmech
import dolfin_warp as dwarp
################################################################################
res_folder = sys.argv[0][:-3]
if not os.path.exists(res_folder): os.mkdir(res_folder)
# test = mypy.Test(
# res_folder=res_folder,
# perform_tests=0,
# stop_at_failure=0,
# clean_after_tests=0,
# qois_suffix="")
images = {
"T":1.,
"n_frames":2}
X0 = [0.5,0.5]
R = 0.35
structure = {"type":"disc", "X0":X0, "R":R}
# deformation = {"type":"homogeneous", "X0":X0[0], "Y0":X0[1], "Fxx":-0.9}
deformation = {"type":"homogeneous", "X0":X0[0], "Y0":X0[1], "Exx":+0.1, "Eyy":+0.1}
evolution = {"type":"linear"}
N = 10
mesh_basename = "mesh"
mesh, _, _, _, _, _, _, _ = dmech.run_Disc_Mesh(params={"X0":X0[0], "Y0":X0[1], "R":R, "l":R/N, "mesh_filebasename":res_folder+"/"+mesh_basename})
dwarp.compute_warped_mesh(
working_folder=res_folder,
working_basename=mesh_basename,
images=images,
structure=structure,
deformation=deformation,
evolution=evolution,
mesh=mesh,
mesh_ext="vtu",
verbose=1)
regul_type_lst = []
regul_type_lst += ["continuous-linear-elastic" ]
regul_type_lst += ["continuous-linear-equilibrated" ]
regul_type_lst += ["continuous-elastic" ]
regul_type_lst += ["continuous-equilibrated" ]
regul_type_lst += ["discrete-simple-elastic" ]
regul_type_lst += ["discrete-simple-equilibrated" ]
regul_type_lst += ["discrete-linear-equilibrated" ]
regul_type_lst += ["discrete-linear-tractions" ]
regul_type_lst += ["discrete-linear-tractions-normal" ]
regul_type_lst += ["discrete-linear-tractions-tangential"]
regul_type_lst += ["discrete-equilibrated" ]
regul_type_lst += ["discrete-tractions" ]
regul_type_lst += ["discrete-tractions-normal" ]
regul_type_lst += ["discrete-tractions-tangential" ]
dwarp.compute_regularization_energies(
dim = 2,
working_folder = res_folder,
working_basename = mesh_basename,
working_ext = "vtu",
working_displacement_array_name = "displacement",
noise_type = None,
noise_level = 0.,
regul_types = regul_type_lst,
regul_model_for_lin = "hooke",
regul_model_for_nl = "ogdenciarletgeymonatneohookean",
regul_poisson = 0.,
normalize_energies = True,
write_regularization_energy_file = True,
plot_regularization_energy = False,
verbose = 1)
# test.test(mesh_basename+"-regul_ener")
shutil.rmtree(res_folder, ignore_errors=1)
#coding=utf8
################################################################################
### ###
### Created by Martin Genet, 2016-2024 ###
### ###
### École Polytechnique, Palaiseau, France ###
### ###
################################################################################
import math
import os
import shutil
import sys
import myPythonLibrary as mypy
import myVTKPythonLibrary as myvtk
import dolfin_mech as dmech
import dolfin_warp as dwarp
################################################################################
res_folder = sys.argv[0][:-3]
if not os.path.exists(res_folder): os.mkdir(res_folder)
# test = mypy.Test(
# res_folder=res_folder,
# perform_tests=0,
# clean_after_tests=1)
working_basename = "heart"
dmech.run_HeartSlice_Hyperelasticity(
incomp = 0,
mesh_params = {"X0":0.5, "Y0":0.5, "Ri":0.2, "Re":0.4, "l":0.1, "mesh_filebasename":res_folder+"/"+working_basename+"-mesh"},
mat_params = {"model":"CGNH", "parameters":{"E":1., "nu":0.3}},
step_params = {"dt_ini":1/10},
load_params = {"type":"disp", "dRi":-0.10, "dRe":-0.05, "dTi":-math.pi/4, "dTe":-math.pi/8},
res_basename = res_folder+"/"+working_basename,
write_vtus_with_preserved_connectivity = True,
verbose = 1)
ref_image = myvtk.createImageFromSizeAndRes(
dim = 2 ,
size = 1.,
res = 10,
up = 1 )
s = [0.1]*2
ref_image_model = lambda X:math.sqrt(abs(math.sin(math.pi*X[0]/s[0]))
* abs(math.sin(math.pi*X[1]/s[1])))
noise_params = {"type":"no"}
dwarp.compute_warped_images(
working_folder = res_folder,
working_basename = working_basename,
working_ext = "vtu",
working_displacement_field_name = "U",
ref_image = ref_image,
ref_frame = 0,
ref_image_model = ref_image_model,
noise_params = noise_params,
print_warped_mesh = 0,
verbose = 0)
shutil.rmtree(res_folder, ignore_errors=1)
#coding=utf8
################################################################################
### ###
### Created by Martin Genet, 2016-2024 ###
### ###
### École Polytechnique, Palaiseau, France ###
### ###
################################################################################
import math
import os
import shutil
import sys
import myPythonLibrary as mypy
import dolfin_warp as dwarp
################################################################################
res_folder = sys.argv[0][:-3]
if not os.path.exists(res_folder): os.mkdir(res_folder)
# test = mypy.Test(
# res_folder=res_folder,
# perform_tests=0,
# clean_after_tests=1)
n_dim_lst = [ ]
n_dim_lst += [2]
# n_dim_lst += [3]
structure_deformation_type_lst = []
structure_deformation_type_lst += [["box" , "translation"]]
structure_deformation_type_lst += [["box" , "rotation" ]]
structure_deformation_type_lst += [["box" , "compression"]]
structure_deformation_type_lst += [["box" , "shear" ]]
structure_deformation_type_lst += [["ring", "heart" ]]
texture_type_lst = []
texture_type_lst += ["no"]
texture_type_lst += ["tagging"]
texture_type_lst += ["tagging-addComb"]
texture_type_lst += ["tagging-diffComb"]
texture_type_lst += ["tagging-signed"]
texture_type_lst += ["tagging-signed-addComb"]
texture_type_lst += ["tagging-signed-diffComb"]
upsampling_factor_lst = [ ]
upsampling_factor_lst += [1]
upsampling_factor_lst += [2]
noise_level_lst = []
noise_level_lst += [0]
noise_level_lst += [0.1]
for n_dim in n_dim_lst :
for structure_type, deformation_type in structure_deformation_type_lst:
for texture_type in texture_type_lst :
for upsampling_factor in upsampling_factor_lst :
for noise_level in noise_level_lst :
images = {
"n_dim":n_dim,
"L":[1.]*n_dim,
"n_voxels": [10]*n_dim,
"upsampling_factors": [upsampling_factor]*n_dim,
"T":1.,
"n_frames":3,
"data_type":"float",
"folder":res_folder}
images_basename = str(n_dim)+"D"
images_basename += "-"+structure_type
images_basename += "-"+deformation_type
images_basename += "-"+texture_type
images_basename += "-"+"x".join([str(n) for n in images["n_voxels"]])
if (upsampling_factor != 1):
images_basename += "-"+"x".join([str(n) for n in images["upsampling_factors"]])
if (noise_level != 0):
images_basename += "-noise="+str(noise_level)
images["basename"] = images_basename
if (structure_type == "box"):
if (deformation_type == "translation"):
Xmin = [0.1]+[0.2]*(n_dim-1)
Xmax = [0.7]+[0.8]*(n_dim-1)
elif (deformation_type in ("rotation", "compression", "shear")):
Xmin = [0.2]*n_dim
Xmax = [0.8]*n_dim
else: assert (0)
structure = {"type":"box", "Xmin":Xmin, "Xmax":Xmax}
elif (structure_type == "disc"):
if (deformation_type == "translation"):
X0 = [0.4]+[0.5]*(n_dim-1)
elif (deformation_type in ("rotation", "compression", "shear")):
X0 = [0.5]*n_dim
else: assert (0)
R = 0.35
structure = {"type":"disc", "X0":X0, "R":R}
elif (structure_type == "ring"):
if (deformation_type == "translation"):
X0 = [0.4]+[0.5]*(n_dim-1)
elif (deformation_type in ("rotation", "compression", "shear", "heart")):
X0 = [0.5]*n_dim
else: assert (0)
Ri = 0.15
Re = 0.35
structure = {"type":"heart", "X0":X0, "Ri":Ri, "Re":Re}
texture = {"type":texture_type, "s":0.5}
if (noise_level == 0):
noise = {"type":"no"}
else:
noise = {"type":"normal", "stdev":noise_level}
if (deformation_type == "no"):
deformation = {"type":"no"}
elif (deformation_type == "translation"):
deformation = {"type":"translation", "Dx":0.2, "Dy":0.}
elif (deformation_type == "rotation"):
deformation = {"type":"rotation", "Cx":0.5, "Cy":0.5, "Rz":90.}
elif (deformation_type == "compression"):
deformation = {"type":"homogeneous", "X0":0.5, "Y0":0.5, "Z0":0.5, "Exx":-0.20}
elif (deformation_type == "shear"):
deformation = {"type":"homogeneous", "X0":0.5, "Y0":0.5, "Z0":0.5, "Fxy":+0.20}
elif (deformation_type == "heart"):
deformation = {"type":"heart", "dRi":-0.10, "dRe":-0.05, "dTi":-math.pi/4, "dTe":-math.pi/8}
evolution = {"type":"linear"}
dwarp.generate_images(
images=images,
structure=structure,
texture=texture,
noise=noise,
deformation=deformation,
evolution=evolution,
verbose=1)
shutil.rmtree(res_folder, ignore_errors=1)
#k_frame Err_avg Err_std Ecc_avg Ecc_std Ell_avg Ell_std Erc_avg Erc_std Erl_avg Erl_std Ecl_avg Ecl_std
0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
1 0.004629702772945166 0.0 0.003407413139939308 0.0 0.0016850474057719111 0.0 -0.0012902331072837114 0.0 0.00011935704242205247 0.0 0.0001694990787655115 0.0
2 0.0024934762623161077 0.0 0.0027501643635332584 0.0 0.001840141718275845 0.0 -0.0012133653508499265 0.0 -0.0005730708944611251 0.0 -0.00043151932186447084 0.0
3 0.00337977334856987 0.0 0.0022687693126499653 0.0 0.0017218717839568853 0.0 -0.00039677266613580287 0.0 -0.0002957665710709989 0.0 -0.0010454701259732246 0.0
4 0.0035385838709771633 0.0 0.0028843453619629145 0.0 0.0017311685951426625 0.0 -0.0021433313377201557 0.0 -0.00029201165307313204 0.0 -0.00012462609447538853 0.0
5 0.0015430341009050608 0.0 0.0027987295761704445 0.0 0.0012578798923641443 0.0 -0.0004460901254788041 0.0 -0.00020644141477532685 0.0 -0.0004581794491969049 0.0
6 0.003166780574247241 0.0 0.002939527155831456 0.0 0.0016164116095751524 0.0 -0.0005895877256989479 0.0 3.6184726923238486e-05 0.0 -0.0005750684067606926 0.0
7 0.0026378529146313667 0.0 0.0018884214805439115 0.0 0.0018579739844426513 0.0 -0.0019291063072159886 0.0 -0.00031296093948185444 0.0 -0.0001308170467382297 0.0
8 0.002505834912881255 0.0 0.0020912201143801212 0.0 0.0016387715004384518 0.0 -0.0011261244071647525 0.0 -0.00020224634499754757 0.0 -0.0002808494318742305 0.0
9 0.0020054327324032784 0.0 0.0016470839036628604 0.0 0.0018844997975975275 0.0 -0.0010187539737671614 0.0 -0.00024658828624524176 0.0 -0.0004892792203463614 0.0
10 0.0003206762485206127 0.0 0.000568015209864825 0.0 0.000319346523610875 0.0 -0.0032576974481344223 0.0 -0.0017955085495486856 0.0 -0.0021377485245466232 0.0
#k_frame Err_avg Err_std Ecc_avg Ecc_std Ell_avg Ell_std Erc_avg Erc_std Erl_avg Erl_std Ecl_avg Ecl_std
0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
1 -1.676215610757481e-08 0.0 8.810070006859405e-09 0.0 1.7777892935555428e-08 0.0 1.0039198361511126e-09 0.0 6.278449982133338e-13 0.0 -2.714760360955637e-10 0.0
2 -1.1134595467865438e-08 0.0 6.602142832434765e-09 0.0 -3.5246507934516558e-09 0.0 4.0946818158360543e-10 0.0 1.0910434777855471e-09 0.0 -1.6101424638037543e-09 0.0
3 -8.635846704407868e-09 0.0 1.790180803595831e-08 0.0 -1.5966572064485263e-08 0.0 1.88267290646138e-09 0.0 4.0906772413862313e-10 0.0 -1.407592264968116e-09 0.0
4 -1.361421753109937e-09 0.0 6.0532676648961115e-09 0.0 -2.563485956841305e-08 0.0 1.2802909843401267e-09 0.0 1.8615646801833918e-09 0.0 6.414080377936671e-10 0.0
5 1.003583971481703e-08 0.0 -2.9389196853912836e-08 0.0 -1.1582512726704408e-08 0.0 -1.4466401410118124e-09 0.0 4.042536583259704e-10 0.0 -3.2454566811779273e-10 0.0
6 -1.8583316219178414e-08 0.0 -1.7025714171836626e-08 0.0 2.6417806608947103e-08 0.0 1.0555503138220956e-09 0.0 -5.09403963455668e-10 0.0 5.013615078652833e-10 0.0
7 -1.2131830651185282e-08 0.0 8.284130714741877e-09 0.0 6.595098689388124e-09 0.0 2.1396515670346616e-09 0.0 -7.439872329317865e-11 0.0 -8.103669818515513e-11 0.0
8 2.2741312832863514e-08 0.0 -2.2131908750111506e-08 0.0 -2.3900601497928164e-09 0.0 1.1001345390226902e-09 0.0 7.472911872641319e-11 0.0 1.6393322810337452e-10 0.0
9 2.4566505274492556e-08 0.0 3.247324853461464e-09 0.0 -1.7395906937167638e-08 0.0 -2.0489480945240501e-10 0.0 -3.189172190221079e-11 0.0 -1.005237212914345e-11 0.0
10 -9.44877731612337e-10 0.0 2.4172916113229803e-08 0.0 2.4693775912965066e-08 0.0 2.4043136925833153e-10 0.0 -4.117866117536728e-11 0.0 1.7973265237225533e-11 0.0
#k_frame Err_avg Err_std Ecc_avg Ecc_std Ell_avg Ell_std Erc_avg Erc_std Erl_avg Erl_std Ecl_avg Ecl_std
0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
1 0.024251069873571396 0.0 0.00018869031919166446 0.0 0.0001891673164209351 0.0 0.0003573070571292192 0.0 0.0003571710840333253 0.0 -0.00014842009113635868 0.0
2 0.04381919652223587 0.0 0.0005194715340621769 0.0 0.000520187197253108 0.0 0.00038145744474604726 0.0 0.00038120115641504526 0.0 -0.00012791478366125375 0.0
3 0.054514314979314804 0.0 0.0006071278476156294 0.0 0.0006070085801184177 0.0 0.0004917706246487796 0.0 0.0004917973419651389 0.0 -0.0001064796160790138 0.0
4 0.08838944882154465 0.0 0.0003158355539198965 0.0 0.00031678954837843776 0.0 0.000300459039863199 0.0 0.0003001783916261047 0.0 -2.7250584025750868e-05 0.0
5 0.10377706587314606 0.0 0.00015749224985484034 0.0 0.00015796917432453483 0.0 5.500734914676286e-05 0.0 5.487778253154829e-05 0.0 -2.1641300918417983e-05 0.0
6 0.1221187636256218 0.0 -0.00012282967509236187 0.0 -0.00012247210543137044 0.0 -0.0005718281026929617 0.0 -0.0005719048203900456 0.0 4.901972260995535e-06 0.0
7 0.14686228334903717 0.0 0.00033710733987390995 0.0 0.0003374650259502232 0.0 0.00030292762676253915 0.0 0.0003027931961696595 0.0 -0.00012013605009997264 0.0
8 0.1613456755876541 0.0 0.0005728825926780701 0.0 0.0005727633251808584 0.0 0.00048060022527351975 0.0 0.00048067214083857834 0.0 -0.00016298347327392548 0.0
9 0.1878327578306198 0.0 0.0004683669831138104 0.0 0.00046848627971485257 0.0 -7.232871666928986e-06 0.0 -7.30867805032176e-06 0.0 -5.731832789024338e-05 0.0
10 0.210282564163208 0.0 0.0002953586808871478 0.0 0.0002954779483843595 0.0 0.00016746979963500053 0.0 0.0001674335217103362 0.0 -5.108838377054781e-05 0.0
#k_frame Err_avg Err_std Ecc_avg Ecc_std Ell_avg Ell_std Erc_avg Erc_std Erl_avg Erl_std Ecl_avg Ecl_std
0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
1 0.0007633498171344399 0.0 8.821526535029989e-06 0.0 8.821526535029989e-06 0.0 -2.4930607585121195e-20 2.3900980262647657e-19 4.1766888830776847e-20 2.8087838493962063e-19 4.548061169980118e-21 7.54314945656091e-21
2 0.0012282513780519366 0.0 1.8835246009984985e-05 0.0 1.8835246009984985e-05 0.0 4.2863053864067426e-19 6.712947696596968e-19 2.7204889734488126e-19 7.381715176751782e-19 5.6717185624379045e-21 1.059095481115188e-20
3 0.0013420038158074021 0.0 2.098105505865533e-05 0.0 2.098105505865533e-05 0.0 1.5960047314896903e-19 5.546033955281438e-19 2.520709879024525e-19 5.315669826709992e-19 4.020475959029307e-21 8.872061809066259e-21
4 0.0013420038158074021 0.0 2.098105505865533e-05 0.0 2.098105505865533e-05 0.0 1.5960047314896903e-19 5.546033955281438e-19 2.520709879024525e-19 5.315669826709992e-19 4.020475959029307e-21 8.872061809066259e-21
5 0.0013322156155481935 0.0 3.707477662828751e-05 0.0 3.707477662828751e-05 0.0 3.5164430116606613e-19 5.770468865191415e-19 4.670181820764171e-19 5.502073870628987e-19 1.695623064704377e-20 1.6999634876379305e-20
6 0.0005363471573218703 0.0 2.217317342001479e-05 0.0 2.217317342001479e-05 0.0 2.16836114484421e-19 2.6046080872283215e-19 2.134289208540239e-19 2.471086960638387e-19 3.769280928940308e-21 1.1303444123342549e-20
7 0.00013471556303557009 0.0 4.482369695324451e-05 0.0 4.482369695324451e-05 0.0 -1.2572272355224675e-20 6.24861679598019e-20 1.5039333685402677e-21 7.025485669864979e-20 1.0666934784894322e-20 3.456392772109667e-20
8 -8.27874246169813e-05 0.0 5.209581649978645e-05 0.0 5.209581649978645e-05 0.0 -5.530862204725572e-20 6.262034037900384e-20 -2.1184225272982796e-20 7.09196751464924e-20 5.759037933653762e-21 1.767562988398584e-20
9 -0.00021646064124070108 0.0 5.281110861687921e-05 0.0 5.281110861687921e-05 0.0 -4.0463259051638594e-20 6.838315958763958e-20 -7.71011922799573e-20 4.655898357410454e-20 4.1802010887274105e-20 2.9316814944802825e-20
10 -0.00022116837499197572 0.0 4.386997898109257e-05 0.0 4.386997898109257e-05 0.0 -6.111967968201756e-20 9.650599757037411e-20 -4.4245010571447675e-20 8.571607835783233e-20 -1.1411705105541053e-20 1.9048673855468837e-20
#k_frame Err_avg Err_std Ecc_avg Ecc_std Ell_avg Ell_std Erc_avg Erc_std Erl_avg Erl_std Ecl_avg Ecl_std
0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
1 0.0015760191017761827 0.0 0.0014094975776970387 0.0 0.0007018222822807729 0.0 0.00873907096683979 0.0 -0.0012684104731306434 0.0 0.0001568022125866264 0.0
2 0.002485415665432811 0.0 0.001865185098722577 0.0 0.0010101775405928493 0.0 0.02007833868265152 0.0 -0.0003372591454535723 0.0 -7.634237408638e-05 0.0
3 0.0013952646404504776 0.0 0.002403463702648878 0.0 0.0008439959492534399 0.0 0.030142245814204216 0.0 -0.0005258704768493772 0.0 -1.9818769942503422e-05 0.0
4 0.0019215154461562634 0.0 0.004831505008041859 0.0 0.001012773485854268 0.0 0.038591962307691574 0.0 -0.00014276737056206912 0.0 0.00018820347031578422 0.0
5 0.0027436933014541864 0.0 0.005478160455822945 0.0 0.0010710024507716298 0.0 0.05031273141503334 0.0 -0.00016119118663482368 0.0 0.00011698674643412232 0.0
6 0.0017302865162491798 0.0 0.007503930479288101 0.0 0.000944039726164192 0.0 0.060097698122262955 0.0 -0.00035081393434666097 0.0 -8.4738785517402e-06 0.0
7 0.0018660752102732658 0.0 0.010501072742044926 0.0 0.0008832640014588833 0.0 0.06935440748929977 0.0 -0.00036415865179151297 0.0 -8.066733425948769e-05 0.0
8 0.0016556695336475968 0.0 0.013376965187489986 0.0 0.0008932583150453866 0.0 0.08010581880807877 0.0 -0.0007228960748761892 0.0 -0.00010390155512141064 0.0
9 0.0023497033398598433 0.0 0.017182201147079468 0.0 0.0008597864652983844 0.0 0.09013061970472336 0.0 -0.0006973639829084277 0.0 1.0846622899407521e-05 0.0
10 0.0017641617450863123 0.0 0.021204449236392975 0.0 0.0008993680239655077 0.0 0.10073516517877579 0.0 -0.0009805990848690271 0.0 -1.0382949767517857e-05 0.0
#k_frame Err_avg Err_std Ecc_avg Ecc_std Ell_avg Ell_std Erc_avg Erc_std Erl_avg Erl_std Ecl_avg Ecl_std
0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
1 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
2 1.4436153605856816e-07 0.0 1.8181528105287725e-07 0.0 4.661113806037065e-08 0.0 0.0005287258536554873 0.0 9.561759361531585e-05 0.0 -0.0002899141691159457 0.0
3 2.0777056306542363e-06 0.0 2.527588094380917e-06 0.0 5.452030222841131e-07 0.0 0.002014812780544162 0.0 0.0003077355504501611 0.0 -0.0009972285479307175 0.0
4 6.364090495480923e-06 0.0 7.929843377496582e-06 0.0 2.8880849640700035e-06 0.0 0.0033760410733520985 0.0 0.0011463634436950088 0.0 -0.0021084698382765055 0.0
5 7.018138148850994e-06 0.0 8.682566658535507e-06 0.0 3.1372351259051356e-06 0.0 0.0035431687720119953 0.0 0.001209709094837308 0.0 -0.002189118880778551 0.0
6 2.041014886344783e-05 0.0 2.431027860438917e-05 0.0 1.218486977450084e-05 0.0 0.005698223132640123 0.0 0.0028668842278420925 0.0 -0.004002401605248451 0.0
7 3.040155570488423e-05 0.0 3.5268105420982465e-05 0.0 1.7695398128125817e-05 0.0 0.00691783893853426 0.0 0.0035652879159897566 0.0 -0.004737537819892168 0.0
8 4.52482963737566e-05 0.0 5.258948294795118e-05 0.0 2.8258204110898077e-05 0.0 0.008327793329954147 0.0 0.004548627883195877 0.0 -0.005947447847574949 0.0
9 5.7199311413569376e-05 0.0 6.614323501707986e-05 0.0 4.1006449464475736e-05 0.0 0.009053914807736874 0.0 0.005630312487483025 0.0 -0.007041867822408676 0.0
10 7.605634891660884e-05 0.0 8.670828538015485e-05 0.0 5.897500159335323e-05 0.0 0.010158717632293701 0.0 0.00690897461026907 0.0 -0.008308866061270237 0.0
#k_frame Err_avg Err_std Ecc_avg Ecc_std Ell_avg Ell_std Erc_avg Erc_std Erl_avg Erl_std Ecl_avg Ecl_std
0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
1 -0.00015221824287436903 0.0 -1.658805922488682e-05 0.0 -3.977211599703878e-05 0.0 0.000126482336781919 0.0 0.00013803268666379154 0.0 -7.061025826260448e-05 0.0
2 0.0007110999431461096 0.0 -0.0002579033316578716 0.0 -0.00026845018146559596 0.0 9.933335240930319e-05 0.0 0.00010482743527973071 0.0 -4.0571776480646804e-05 0.0
3 0.0009617827599868178 0.0 -0.0002933713549282402 0.0 -0.0003008191997651011 0.0 0.00012775535287801176 0.0 0.0001320139563176781 0.0 -7.941939838929102e-05 0.0
4 0.0006279574590735137 0.0 -0.00036654528230428696 0.0 -0.00037011964013800025 0.0 0.00039829922025091946 0.0 0.00040021102176979184 0.0 -3.679627843666822e-05 0.0
5 0.0009850148344412446 0.0 -0.000442153075709939 0.0 -0.00040605111280456185 0.0 0.0019382548052817583 0.0 0.0019244187278673053 0.0 1.099831843021093e-05 0.0
6 0.0013084618840366602 0.0 -0.0005643574404530227 0.0 -0.000534325372427702 0.0 0.00021147537336219102 0.0 0.0001976003113668412 0.0 0.00026569177862256765 0.0
7 0.0026170113123953342 0.0 -0.00046847216435708106 0.0 -0.00045279625919647515 0.0 -0.0011098399991169572 0.0 -0.0011127819307148457 0.0 0.00019407272338867188 0.0
8 0.0016963909147307277 0.0 -0.0005772102740593255 0.0 -0.0005624337936751544 0.0 -0.0010721749858930707 0.0 -0.0010735822143033147 0.0 0.00019450760737527162 0.0
9 0.00016012291598599404 0.0 -0.0004621776461135596 0.0 -0.000451333966339007 0.0 -0.0003539089811965823 0.0 -0.00035387210664339364 0.0 0.00013646006118506193 0.0
10 0.00032676715636625886 0.0 -0.0016220191027969122 0.0 -0.0015659781638532877 0.0 -0.00029433303279802203 0.0 -0.00030956161208450794 0.0 0.00108127121347934 0.0
#k_frame Err_avg Err_std Ecc_avg Ecc_std Ell_avg Ell_std Erc_avg Erc_std Erl_avg Erl_std Ecl_avg Ecl_std
0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
1 0.0 0.0 0.0 0.0 0.0 0.0 2.1688984475235738e-17 3.966478607443651e-17 1.734864648134683e-17 4.958596012793192e-17 1.0587911840678754e-20 3.3770847045420073e-20
2 0.0 0.0 0.0 0.0 0.0 0.0 4.0468410776652954e-17 2.948172374742575e-17 4.048111627086177e-17 3.421243087474464e-17 -1.4823076576949856e-20 1.7759098354666472e-20
3 0.0 0.0 0.0 0.0 0.0 0.0 1.2142252591929863e-16 1.0972381407518629e-16 1.214172319633783e-16 7.757477294571234e-17 -2.99990835485898e-20 1.0259292600064135e-20
4 0.0 0.0 0.0 0.0 0.0 0.0 9.830170283280845e-17 8.358866891634244e-17 1.1565740792204905e-16 8.177315371086983e-17 1.1999633419435921e-20 1.9624961093673728e-20
5 0.0 0.0 0.0 0.0 0.0 0.0 8.674005603318193e-17 4.8035251125499536e-17 8.673193863410408e-17 6.254301672767973e-17 -8.823259867232295e-21 1.129928582180873e-20
6 0.0 0.0 0.0 0.0 0.0 0.0 2.3139528397408727e-17 8.654285724737189e-17 5.783823308168114e-17 5.171315273979857e-17 3.670476104768635e-20 6.237189797250588e-20
7 0.0 0.0 0.0 0.0 0.0 0.0 2.7758257886628554e-16 1.2667469267497996e-16 3.469291662579951e-16 6.941153469552917e-17 1.552893736632884e-20 5.856518079211547e-20
8 0.0 0.0 0.0 0.0 0.0 0.0 4.623670514745474e-17 1.0343008490111075e-16 -5.783682136010239e-17 1.2296643711861665e-16 -3.952820420520068e-20 4.604896433306682e-20
9 0.0 0.0 0.0 0.0 0.0 0.0 6.942705552169873e-17 6.93762423352665e-17 3.470435157058744e-17 7.75596287941662e-17 3.529303946892918e-20 3.640490279608693e-20
10 0.0 0.0 0.0 0.0 0.0 0.0 3.0067552045159526e-16 2.9072649896781113e-16 2.659951681478467e-16 3.724188006327362e-16 2.8234431574661863e-21 3.376346947088595e-20