[docs]defis_tomodir(directory):"""Check if the supplied directory is a tomodir Parameters ---------- directory: string Check if the supplied path is a valid tomodir Returns ------- is_tomodir: bool True if the supplied directory is a tomodir directory """ifos.path.isdir(directory):if(os.path.isdir(directory+"/exe")andos.path.isdir(directory+"/config")andos.path.isdir(directory+"/rho")andos.path.isdir(directory+"/inv")andos.path.isdir(directory+"/mod")):returnTrueelse:returnFalseelse:returnFalse
[docs]deftd_is_finished(tomodir):"""Return the state of modeling and inversion for a given tomodir. The result does not take into account sensitivities or potentials, as optionally generated by CRMod. Parameters ---------- tomodir : string Directory to check Returns ------- crmod_is_finished : bool True if a successful CRMod result is contained in the tomodir directory. crtomo_is_finished : bool True if a successful CRTomo inversion results is contained in the tomodir directory. """ifnotis_tomodir(tomodir):raiseException('Supplied directory is not a tomodir!')# crmod finished is determined by:# config.dat/rho.dat/crmod.cfg are present# volt.dat is presentif(os.path.isfile(tomodir+os.sep+'config/config.dat')andos.path.isfile(tomodir+os.sep+'rho/rho.dat')andos.path.isfile(tomodir+os.sep+'grid/elem.dat')andos.path.isfile(tomodir+os.sep+'grid/elec.dat')andos.path.isfile(tomodir+os.sep+'exe/crmod.cfg')andos.path.isfile(tomodir+os.sep+'mod/volt.dat')):crmod_is_finished=Trueelse:crmod_is_finished=False# crtomo is finished if# crtomo.cfg/volt.dat/elem.dat/elec.dat are present# inv/run.ctr contains the word "CPU" in the last lineif(os.path.isfile(tomodir+os.sep+'grid/elem.dat')andos.path.isfile(tomodir+os.sep+'grid/elec.dat')andos.path.isfile(tomodir+os.sep+'exe/crtomo.cfg')andos.path.isfile(tomodir+os.sep+'inv/inv.ctr')andos.path.isfile(tomodir+os.sep+'inv/run.ctr')andos.path.isfile(tomodir+os.sep+'mod/volt.dat')):withopen(tomodir+os.sep+'inv/run.ctr','r')asfid:lines=fid.readlines()crtomo_is_finished=False# check the last 5 linesforlineinlines[-5:]:test_line=line.strip()regex=re.compile('CPU')result=regex.match(test_line)ifresultisnotNone:crtomo_is_finished=Trueelse:crtomo_is_finished=Falsereturncrmod_is_finished,crtomo_is_finished
[docs]defis_sipdir(directory):""" Simple check if the supplied directory is a SIP directory. Parameters ---------- directory: string Check if the supplied path is a valid SIP directory Returns ------- is_sipdir: bool True if the supplied directory is a SIP directory """is_sipdir=Trueif(notos.path.isfile(directory+os.sep+'frequencies.dat')):is_sipdir=Falseif(notos.path.isdir(directory+os.sep+'invmod')):is_sipdir=Falsereturnis_sipdir
[docs]defsipdir_is_finished(sipdir):"""Return the state of modeling and inversion for a given SIP dir. The result does not take into account sensitivities or potentials, as optionally generated by CRMod. Parameters ---------- sipdir: string Directory to check Returns ------- crmod_is_finished: bool True if all tomodirs of this SIP directory contain finished modeling results. crtomo_is_finished: bool True if all tomodirs of this SIP directory contain finished inversion results. """ifnotis_sipdir(sipdir):raiseException('Directory is not a valid SIP directory!')subdirs_raw=sorted(glob.glob(sipdir+os.sep+'invmod'+os.sep+'*'))subdirs=[xforxinsubdirs_rawifos.path.isdir(x)]crmod_finished=Truecrtomo_finished=Trueforsubdirinsubdirs:subcrmod,subcrtomo=td_is_finished(subdir)ifnotsubcrmod:crmod_finished=Falseifnotsubcrtomo:crtomo_finished=Falsereturncrmod_finished,crtomo_finished