def test_17(self): """TestFILMCfgXML.test_17(): "Resistivity_3Track_Logrithmic.xml" test retFILMDest().""" myFcxr = FILMCfgXML.FilmCfgXMLRead() self.assertEqual(29, len(myFcxr)) self.assertTrue( myFcxr.retFILMDest("Resistivity_3Track_Logrithmic.xml", Mnem.Mnem('BS')) is not None)
def test_04(self): """TestFILMCfgXML.test_04(): "Micro_Resistivity_3Track.xml" tracks.""" myFcxr = FILMCfgXML.FilmCfgXMLRead() self.assertEqual(29, len(myFcxr)) self.assertTrue("Micro_Resistivity_3Track.xml" in myFcxr) # print() # print('Micro Res:', myFcxr["Micro_Resistivity_3Track.xml"]) # Four tracks self.assertEqual(4, len(myFcxr["Micro_Resistivity_3Track.xml"])) # for i, t in enumerate(myFcxr["Micro_Resistivity_3Track.xml"].genTracks()): # print(i, t) # print(myFcxr["Micro_Resistivity_3Track.xml"][0].left) self.assertEqual(Coord.Dim(0, 'in'), myFcxr["Micro_Resistivity_3Track.xml"][0].left) leftRight = [ (t.left, t.right) for t in myFcxr["Micro_Resistivity_3Track.xml"].genTracks() ] # print(leftRight) expResult = [ (Coord.Dim(value=0.0, units='in'), Coord.Dim(value=2.4, units='in')), (Coord.Dim(value=2.4, units='in'), Coord.Dim(value=3.2, units='in')), (Coord.Dim(value=3.2, units='in'), Coord.Dim(value=5.6, units='in')), (Coord.Dim(value=5.6, units='in'), Coord.Dim(value=8.0, units='in')), ] self.assertEqual(expResult, leftRight)
def test_16(self): """TestFILMCfgXML.test_16(): "Resistivity_3Track_Logrithmic.xml" test retAllFILMDestS() fails.""" myFcxr = FILMCfgXML.FilmCfgXMLRead() self.assertEqual(29, len(myFcxr)) # print(myFcxr._chOutpMnemFilmMap) self.assertRaises(FILMCfgXML.ExceptionFILMCfgXMLReadLookUp, myFcxr.retAllFILMDestS, Mnem.Mnem('NOTBS', len_mnem=0))
def main(): print ('Cmd: %s' % ' '.join(sys.argv)) # TODO: Option to treat files with -f, --format as LAS, LIS, AUTO # TODO: Depth scale overrides -s, --scale ? optParser = CmnCmdOpts.argParserInOut( 'Generates SVG plot(s) from input LIS & LAS file/directory to an output file/directory.', prog=None, version=__version__, ) optParser.add_argument("-A", "--API", action="store_true", dest="apiHeader", default=False, help="Put an API header on each plot. [default: False]") optParser.add_argument("-x", "--xml", action="append", dest="LgFormat", default=[], help="Use XML LgFormat UniqueId to use for plotting (additive)." \ +" Use -x? to see what LgFormats (UniqueID+Description) are available." \ +" Use -x?? to see what curves each format can plot. See also -X. [default: []]") optParser.add_argument( "-X", "--XML", type=int, dest="LgFormat_min", default=0, help="Use any LgFormat XML plots that use n or more outputs. If -x option present limited by those LgFormats [default: 0]" ) # optParser.add_argument("-f", "--file-type", choices=['LAS', 'LIS', 'AUTO'], # help="File format to assume for the input, AUTO will do it's best. [default: \"AUTO\"].") optParser.add_argument("-s", "--scale", action="append", type=int, dest="scale", default=0, help="Scale of X axis to use (an integer). [default: 0].") myOptNs = optParser.parse_args() clkStart = time.clock() timStart = time.time() # Initialise logging etc. logging.basicConfig(level=myOptNs.logLevel, format='%(asctime)s %(levelname)-8s %(message)s', #datefmt='%y-%m-%d % %H:%M:%S', stream=sys.stdout) # Your code here if '?' in ''.join(myOptNs.LgFormat): # Handle -x? here and exit myFg = FILMCfgXML.FilmCfgXMLRead() print('XML LgFormats available: [{:d}]'.format(len(myFg.keys()))) print(myFg.longStr(''.join(myOptNs.LgFormat).count('?'))) return 1 if myOptNs.jobs == CmnCmdOpts.DEFAULT_OPT_MP_JOBS: myPlp = PlotLogPasses( myOptNs.pathIn, myOptNs.pathOut, myOptNs, ) myResult = myPlp.plotLogInfo else: myResult = plotLogPassesMP( myOptNs.pathIn, myOptNs.pathOut, myOptNs, ) if os.path.isdir(myOptNs.pathOut): myResult.writeHTML(os.path.join(myOptNs.pathOut, 'index.html'), myOptNs.pathIn) print('plotLogInfo', str(myResult)) print(' CPU time = %8.3f (S)' % (time.clock() - clkStart)) print('Exec. time = %8.3f (S)' % (time.time() - timStart)) print('Bye, bye!') return 0
def test_11(self): """TestFILMCfgXML.test_12(): "Resistivity_3Track_Logrithmic.xml" tracks chOutpMnemInFilmId() returns False.""" myFcxr = FILMCfgXML.FilmCfgXMLRead() self.assertEqual(29, len(myFcxr)) myFilmID = 'Resistivity_3Track_Logrithmic.xml' # print() # pprint.pprint(myFcxr._chOutpMnemFilmMap) self.assertTrue(myFilmID in myFcxr) # Not a Mnem.Mnem object self.assertFalse(myFcxr.chOutpMnemInFilmId('NOTBS', myFilmID))
def test_18(self): """TestFILMCfgXML.test_18(): "Resistivity_3Track_Logrithmic.xml" test retFILMDest() fails.""" myFcxr = FILMCfgXML.FilmCfgXMLRead() self.assertEqual(29, len(myFcxr)) self.assertRaises( FILMCfgXML.ExceptionFILMCfgXMLReadLookUp, myFcxr.retFILMDest, "Resistivity_3Track_Logrithmic.xml", Mnem.Mnem('NOTBS', len_mnem=0), )
def test_10(self): """TestFILMCfgXML.test_10(): "Resistivity_3Track_Logrithmic.xml" tracks chOutpMnemInFilmId().""" myFcxr = FILMCfgXML.FilmCfgXMLRead() self.assertEqual(29, len(myFcxr)) myFilmID = 'Resistivity_3Track_Logrithmic.xml' # print() # pprint.pprint(myFcxr._chOutpMnemFilmMap) self.assertTrue(myFilmID in myFcxr) for aCuOutp in (Mnem.Mnem(c, len_mnem=-Mnem.LEN_MNEM) for c in ( 'BS', 'ROP5', 'CALI', 'PCAL', 'HCAL', 'SP', 'GR', 'ATR', 'PSR', 'AHT10', 'AHT20', 'AHT30', 'AHT60', 'AHT90', 'AHO10', 'AHO20', 'AHO30', 'AHO60', 'AHO90', 'AHF10', 'AHF20', 'AHF30', 'AHF60', 'AHF90', 'RLA0', 'RLA1', 'RLA2', 'RLA3', 'RLA4', 'RLA5', 'SFL', 'ILM', 'ILD', 'MSFL', 'RXO', 'LLM', 'LLD', 'A22H', 'A34H', 'P16H_RT', 'P28H_RT', 'P34H_RT', 'TENS', )): self.assertTrue(myFcxr.chOutpMnemInFilmId(aCuOutp, myFilmID), 'aCuOutp="{!r:s}"'.format(aCuOutp))
def _plotUsingLgFormats(self, theFi, theLpIdx, thePrs, theFpOut): """Plots a LogPass from a LIS file using the LgFormat XML files specify the plot. theFi - the LIS File object. theLpIdx - integer for the LogPass in the LIS File. thePrs - a PlotRecord Set that holds the seek positions of the appropriate LIS Logical Records (we only use CONS records here for the API header). theFpOut - Output file path for the SVG file(s), one per FILM ID. """ assert(len(self._lgFormatS) > 0) _p, myLogPass, myCONSRecS = self._retPlotFromPlotRecordSet(theFi, thePrs) myFilm = FILMCfgXML.FilmCfgXMLRead() for aUniqueId in self._lgFormatS: logging.info('PlotLogPasses._plotUsingLgFormats(): UniqueId={:s}.'.format(aUniqueId)) # Create a PRES like object from the UniqueId myRoot = myFilm.rootNode(aUniqueId) if myRoot is not None: myPres = PRESCfgXML.PresCfgXMLRead(myRoot, myFilm) myPlot = Plot.PlotReadXML(myFilm, myPres) if myPlot.hasDataToPlotLIS(myLogPass, aUniqueId): # Create output path and plot it myOutFilePath = '{:s}_{:04d}_{:s}.svg'.format(theFpOut, theLpIdx, aUniqueId) myCurvIDs, numPoints = myPlot.plotLogPassLIS( theFi, myLogPass, myLogPass.xAxisFirstEngVal, myLogPass.xAxisLastEngVal, aUniqueId, open(myOutFilePath, 'w'), frameStep=1, title="Plot: {:s} LogPass: {:d} FILM ID={:s}".format( os.path.abspath(myOutFilePath), theLpIdx, aUniqueId, ), lrCONS=myCONSRecS, ) assert(myCurvIDs is not None and numPoints is not None) # So here the essential data that we have to put in the index.html is: # Key: myOutFilePath or input file fp, lpIdx, aFilmId, # Value: (myPlot.xScale(aFilmId), myLogPass.xAxisFirstEngVal, myLogPass.xAxisLastEngVal, myCurvIDs) self.plotLogInfo.addPlotResult( theFi.fileId, myOutFilePath, theLpIdx, aUniqueId, myPlot.xScale(aUniqueId), myLogPass.xAxisFirstEngVal, myLogPass.xAxisLastEngVal, theCurveS=myCurvIDs, ptsPlotted=numPoints) else: logging.error('PlotLogPasses._plotUsingLgFormats(): No root node for UniqueId: "{:s}"'.format(aUniqueId)) else: logging.info('PlotLogPasses._plotUsingLgFormats(): No data to plot for FILM ID {:s}'.format(aUniqueId))
def test_15(self): """TestFILMCfgXML.test_15(): "Resistivity_3Track_Logrithmic.xml" test retAllFILMDestS().""" myFcxr = FILMCfgXML.FilmCfgXMLRead() self.assertEqual(29, len(myFcxr)) # print('') # pprint.pprint(myFcxr._chOutpMnemFilmMap) self.assertEquals( [ 'Azimuthal_Density_3Track.xml', 'Azimuthal_Resistivity_3Track.xml', 'Micro_Resistivity_3Track.xml', 'Porosity_GR_3Track', 'Resistivity_3Track_Correlation.xml', 'Resistivity_3Track_Logrithmic.xml', 'Resistivity_Investigation_Image.xml', 'Sonic_3Track.xml', 'Triple_Combo', ], sorted(myFcxr.retAllFILMDestS(Mnem.Mnem('BS'))), )
def test_14(self): """TestFILMCfgXML.test_14(): "Resistivity_3Track_Logrithmic.xml" test rootNode() returns None.""" myFcxr = FILMCfgXML.FilmCfgXMLRead() self.assertEqual(29, len(myFcxr)) self.assertRaises(KeyError, myFcxr.rootNode, "")
def test_13(self): """TestFILMCfgXML.test_13(): "Resistivity_3Track_Logrithmic.xml" test rootNode().""" myFcxr = FILMCfgXML.FilmCfgXMLRead() self.assertEqual(29, len(myFcxr)) self.assertTrue( myFcxr.rootNode("Resistivity_3Track_Logrithmic.xml") is not None)
def test_12(self): """TestFILMCfgXML.test_12(): "Resistivity_3Track_Logrithmic.xml" exercise longStr().""" myFcxr = FILMCfgXML.FilmCfgXMLRead() self.assertEqual(29, len(myFcxr)) myFcxr.longStr()
def setUp(self): self._fcxr = FILMCfgXML.FilmCfgXMLRead() self.assertEqual(28, len(self._fcxr)) self.assertTrue(self.TEST_FILM_ID in self._fcxr)
def test_01(self): """TestFILMCfgXML.test_01(): Test construction.""" myFcxr = FILMCfgXML.FilmCfgXMLRead() self.assertEqual(29, len(myFcxr))
def test_02(self): """TestXMLMatchesRHDT.test_01(): Which XML LgFormat files with RPS1 (RepCode 130, 80 bytes) channel and a LIS LogPass.""" # DIPMETER_EDIT_TAPE_REP_CODE myF = self._retFileSinglePr( # LRH for DFSR bytes([64, 0]) # EB 4, up/down value 0 (down) + bytes([4, 1, 66, 0]) # EB 12, absent value -153.0 + bytes([12, 4, 68]) + b'\xbb\xb3\x80\x00' # EB 0 terminates read + bytes([0, 1, 66, 0]) # # Sensor 0 # Mnemonic Service ID Serv ord No Units API 45,310,01,1 File No: 256 + b'DEPT' + b'ServID' + b'ServOrdN' + b'FEET' + b'\x02\xb3\x60\x3b' + bytes([1, 0]) # 4 LIS bytes Pad 1 super Rep code Process indicators + bytes([0, 4]) + b'000' + b'\x01' + bytes([ 68, ]) + bytes([0, 1, 2, 3, 4]) # Sensor 1 + b'RPS1' + b'ServID' + b'ServOrdN' + b' ' + b'\x02\xb3\x60\x3b' + bytes([1, 0]) + bytes([0, 80]) + b'000' + b'\x01' + bytes([ 130, ]) + bytes([0, 1, 2, 3, 4]) # Sensor 2 + b'P1AZ' + b'ServID' + b'ServOrdN' + b' ' + b'\x02\xb3\x60\x3b' + bytes([1, 0]) + bytes([0, 4]) + b'000' + b'\x01' + bytes([ 68, ]) + bytes([0, 1, 2, 3, 4]) # Sensor 3 + b'DEVI' + b'ServID' + b'ServOrdN' + b' ' + b'\x02\xb3\x60\x3b' + bytes([1, 0]) + bytes([0, 4]) + b'000' + b'\x01' + bytes([ 68, ]) + bytes([0, 1, 2, 3, 4]) # Sensor 4 + b'HAZI' + b'ServID' + b'ServOrdN' + b' ' + b'\x02\xb3\x60\x3b' + bytes([1, 0]) + bytes([0, 4]) + b'000' + b'\x01' + bytes([ 68, ]) + bytes([0, 1, 2, 3, 4]) # Sensor 5 + b'C1 ' + b'ServID' + b'ServOrdN' + b' ' + b'\x02\xb3\x60\x3b' + bytes([1, 0]) + bytes([0, 4]) + b'000' + b'\x01' + bytes([ 68, ]) + bytes([0, 1, 2, 3, 4]) # Sensor 6 + b'C2 ' + b'ServID' + b'ServOrdN' + b' ' + b'\x02\xb3\x60\x3b' + bytes([1, 0]) + bytes([0, 4]) + b'000' + b'\x01' + bytes([ 68, ]) + bytes([0, 1, 2, 3, 4]) # Sensor 7 + b'FEP ' + b'ServID' + b'ServOrdN' + b' ' + b'\x02\xb3\x60\x3b' + bytes([1, 0]) + bytes([0, 4]) + b'000' + b'\x01' + bytes([ 68, ]) + bytes([0, 1, 2, 3, 4]) # Sensor 8 + b'RB ' + b'ServID' + b'ServOrdN' + b' ' + b'\x02\xb3\x60\x3b' + bytes([1, 0]) + bytes([0, 4]) + b'000' + b'\x01' + bytes([ 68, ]) + bytes([0, 1, 2, 3, 4])) myLp = LogPass.LogPass(LogiRec.LrDFSRRead(myF), 'FileID') myFilmCfg = FILMCfgXML.FilmCfgXMLRead('') myFilmCfg.addXMLRoot(etree.fromstring( TestLgFormatXMLData.LGFORMAT_HDT)) filmMap = XMLMatches.fileCurveMapFromFILM(myLp, myFilmCfg) # print() # print('myLp._chMap:') # pprint.pprint(myLp._chMap) # print(myLp.longStr()) # pprint.pprint(sorted(myLp.outpMnemS())) # print('filmMap:') # pprint.pprint(filmMap) # pprint.pprint(sorted(filmMap['HDT'])) self.assertEqual( [ Mnem.Mnem(b'C1\x00\x00'), Mnem.Mnem(b'C2\x00\x00'), Mnem.Mnem(b'DEPT'), Mnem.Mnem(b'DEVI'), # Mnem.Mnem(b'EMEX'), Mnem.Mnem(b'FC0\x00'), Mnem.Mnem(b'FC1\x00'), Mnem.Mnem(b'FC2\x00'), Mnem.Mnem(b'FC3\x00'), Mnem.Mnem(b'FC4\x00'), Mnem.Mnem(b'FEP\x00'), # Mnem.Mnem(b'FEP1'), # Mnem.Mnem(b'FEP2'), Mnem.Mnem(b'HAZI'), Mnem.Mnem(b'P1AZ'), # Mnem.Mnem(b'PADP'), # Mnem.Mnem(b'RAC1'), # Mnem.Mnem(b'RAC2'), Mnem.Mnem(b'RB\x00\x00'), # Mnem.Mnem(b'REF\x00'), # Mnem.Mnem(b'REFC'), # Mnem.Mnem(b'STAT'), # Mnem.Mnem(b'TEMP'), ], sorted(myLp.outpMnemS()), ) self.assertEqual(1, len(filmMap)) self.assertTrue('HDT' in filmMap) self.assertEqual([ Mnem.Mnem(b'C1\x00\x00'), Mnem.Mnem(b'C2\x00\x00'), Mnem.Mnem(b'DEVI'), Mnem.Mnem(b'FC0\x00'), Mnem.Mnem(b'FC1\x00'), Mnem.Mnem(b'FC2\x00'), Mnem.Mnem(b'FC3\x00'), Mnem.Mnem(b'FC4\x00'), Mnem.Mnem(b'HAZI'), Mnem.Mnem(b'P1AZ'), Mnem.Mnem(b'RB\x00\x00'), ], sorted(filmMap['HDT']))
def main(): usage = """usage: %prog [options] in out Generates plot(s) from input LIS file or directory to an output destination.""" print('Cmd: %s' % ' '.join(sys.argv)) optParser = OptionParser(usage, version='%prog ' + __version__) optParser.add_option( "-A", "--API", action="store_true", dest="apiHeader", default=False, help="Include and API header on top of each plot. [default: %default]") optParser.add_option( "-k", "--keep-going", action="store_true", dest="keepGoing", default=False, help="Keep going as far as sensible. [default: %default]") optParser.add_option("-r", "--recursive", action="store_true", dest="recursive", default=False, help="Process input recursively. [default: %default]") optParser.add_option( "-j", "--jobs", type="int", dest="jobs", default=-1, help="Max processes when multiprocessing. Zero uses number of native CPUs [%d]. -1 disables multiprocessing." \ % multiprocessing.cpu_count() \ + " [default: %default]" ) optParser.add_option( "-l", "--loglevel", type="int", dest="loglevel", default=40, help= "Log Level (debug=10, info=20, warning=30, error=40, critical=50) [default: %default]" ) optParser.add_option( "-x", "--xml", action="append", dest="LgFormat", default=[], help= "Add an XML LgFormat to use for plotting. Value is the UniqueId. Use -x? to see what LgFormats are available. [default: %default]" ) opts, args = optParser.parse_args() clkStart = time.clock() timStart = time.time() # Initialise logging etc. logging.basicConfig( level=opts.loglevel, format='%(asctime)s %(levelname)-8s %(message)s', #datefmt='%y-%m-%d % %H:%M:%S', stream=sys.stdout) # Your code here # Handle -x? if '?' in opts.LgFormat: myFg = FILMCfgXML.FilmCfgXMLRead() print('XML LgFormats available: [{:d}]'.format(len(myFg.keys()))) print(myFg.longStr()) while '?' in opts.LgFormat: opts.LgFormat.remove('?') return 1 if len(args) != 2: optParser.print_help() optParser.error( "I can't do much without an input path to LIS file(s) and an output path." ) return 1 if opts.jobs == -1: myPlp = PlotLogPasses(args[0], args[1], opts.recursive, opts.keepGoing, opts.LgFormat, opts.apiHeader) myResult = myPlp.plotLogInfo else: myResult = plotLogPassesMP(args[0], args[1], None, opts.recursive, opts.keepGoing, opts.LgFormat, opts.apiHeader, opts.jobs) myResult.writeHTML(os.path.join(args[1], 'index.html'), args[0]) print('plotLogInfo', str(myResult)) print(' CPU time = %8.3f (S)' % (time.clock() - clkStart)) print('Exec. time = %8.3f (S)' % (time.time() - timStart)) print('Bye, bye!') return 0
def setUp(self): self._fcxr = FILMCfgXML.FilmCfgXMLRead() self.assertEqual(28, len(self._fcxr))
def test_03(self): """TestFILMCfgXML.test_03(): Test construction has key "Micro_Resistivity_3Track.xml".""" myFcxr = FILMCfgXML.FilmCfgXMLRead() self.assertEqual(29, len(myFcxr)) self.assertTrue("Micro_Resistivity_3Track.xml" in myFcxr)
def fileCurveMap(theLpOrLasFile, dir=None): """Returns a map of ``{FilmID : [OUTP, ...], ...}`` which is a list of OUTP in theLpOrLasFile that could be plotted with that film ID.""" myFilmCfg = FILMCfgXML.FilmCfgXMLRead(dir) return fileCurveMapFromFILM(theLpOrLasFile, myFilmCfg)
def _retPlotFromXML(self, theFi, theIdxLogPass, theUniqueId): assert (len(self._lgFormatS) > 0) assert (theUniqueId in self._lgFormatS) myFcfg = FILMCfgXML.FilmCfgXMLRead() return Plot.PlotReadXML(myFcfg[theUniqueId], self._scale), theIdxLogPass.logPass
def main(): print('Cmd: %s' % ' '.join(sys.argv)) # TODO: Option to treat files with -f, --format as LAS, LIS, AUTO # TODO: Depth scale overrides -s, --scale ? parser = cmn_cmd_opts.path_in_out( 'Generates SVG plot(s) from input LIS & LAS file/directory to an output file/directory.', prog=None, version=__version__, ) cmn_cmd_opts.add_log_level(parser) cmn_cmd_opts.add_multiprocessing(parser) parser.add_argument( "-A", "--API", action="store_true", dest="apiHeader", default=False, help="Put an API header on each plot. [default: False]") parser.add_argument("-x", "--xml", action="append", dest="LgFormat", default=[], help="Use XML LgFormat UniqueId to use for plotting (additive)." \ +" Use -x? to see what LgFormats (UniqueID+Description) are available." \ +" Use -x?? to see what curves each format can plot. See also -X. [default: []]") parser.add_argument( "-X", "--XML", type=int, dest="LgFormat_min", default=0, help= "Use any LgFormat XML plots that use n or more outputs. If -x option present limited by those LgFormats [default: 0]" ) parser.add_argument("-g", "--glob", action="store_true", dest="glob", default=None, help="File match pattern. Default: %(default)s.") # parser.add_argument("-f", "--file-type", choices=['LAS', 'LIS', 'AUTO'], # help="File format to assume for the input, AUTO will do it's best. [default: \"AUTO\"].") parser.add_argument( "-s", "--scale", action="append", type=int, dest="scale", default=0, help="Scale of X axis to use (an integer). [default: 0].") args = parser.parse_args() # Initialise logging etc. cmn_cmd_opts.set_log_level(args) # print('args', args) # return 0 start_clock = time.clock() start_time = time.time() # Your code here if '?' in ''.join(args.LgFormat): # Handle -x? here and exit myFg = FILMCfgXML.FilmCfgXMLRead() print('XML LgFormats available: [{:d}]'.format(len(myFg.keys()))) print(myFg.longStr(''.join(args.LgFormat).count('?'))) return 1 if cmn_cmd_opts.multiprocessing_requested(args): myPlp = PlotLogPasses( args.path_in, args.path_out, args, ) myResult = myPlp.plotLogInfo else: myResult = plotLogPassesMP( args.path_in, args.path_out, args, ) if os.path.isdir(args.path_out): myResult.writeHTML(os.path.join(args.path_out, 'index.html'), args.path_in) print('plotLogInfo', str(myResult)) print(' CPU time = %8.3f (S)' % (time.clock() - start_clock)) print('Exec. time = %8.3f (S)' % (time.time() - start_time)) print('Bye, bye!') return 0