Skip to content

Instantly share code, notes, and snippets.

@habi
Last active August 29, 2015 14:27
Show Gist options
  • Save habi/7a43054c9cf3f1357755 to your computer and use it in GitHub Desktop.
Save habi/7a43054c9cf3f1357755 to your computer and use it in GitHub Desktop.
Logfile-Parser (reading log into a dictionary, easier for searching) and Logfile.
"""
Log file parser, based on http://stackoverflow.com/a/17776027/323100
"""
import re
def str2dict(filename='LogFile.log'):
results = {}
with open(filename, "r") as cache:
# read file into a list of lines
lines = cache.readlines()
# loop through lines
for line in lines:
# skip lines starting with "--".
if not line.startswith("--"):
# '\s*' matches any whitespace zero or more times
# ':\s' matches the colon and the trailing space.
# We thus split the line at 'space(s) colon space(s)' or
# 'colon space(s)'
# Strip the trailing return (\n)
# Split into list using '\t' as the split pattern
# Test RegEx with https://regex101.com/
line = re.sub("\s*:\s*", "\t", line).strip().split('\t')
# use first item in list for the key, join remaining list items
# with ", " for the value.
results[line[0]] = ", ".join(line[1:])
return results
def SearchValueOfKey(dictionary, lookup, verbose=False):
if verbose:
print 'Looking for "%s"' % lookup
for key, value in dictionary.items():
if str(lookup) in str(key):
if verbose:
print 'We found the "%s" to be "%s"' % (key, value)
return value
Parsed = str2dict("A-DMa.log")
# If you know the exact key
print Parsed.get('Number of darks')
# If you don't know it, then search
print SearchValueOfKey(Parsed, 'Magni', True)
User ID : eSomethingSomething
SNAP&STEP-TOMO scan of sample Something started on Mon Jun 8 13:03:50 2015
--------------------Beamline Settings-------------------------
Ring current [mA] : 400.738
Beam energy [keV] : 12.000
Monostripe : Ru/C
FE-Filter : No Filter 100%
OP-Filter 1 : No Filter
OP-Filter 2 : No Filter
OP-Filter 3 : No Filter
--------------------Detector Settings-------------------------
Camera : PCO.Edge 5.5
Microscope : Opt.Peter MB op
Magnification : 20.0
Scintillator : LAG:Ce 20 um
Exposure time [ms] : 170.0
Stabilization time [ms] : 50.0
Millisecond shutter [ms] : not used
X-ROI : 1 - 2560
Y-ROI : 1 - 2160
Actual pixel size [um] : 0.325
------------------------Scan Settings-------------------------
Sample folder : /sls/X02DA/data/eSomethingSomething/Data10/disk1/Someting/
File Prefix : Something
Number of projections : 3001
Number of darks : 10
Number of flats : 100
Number of inter-flats : 0
Flat frequency : 0
Rot Y min position [deg] : -180.0
Rot Y max position [deg] : 180.0
Rotation axis position : Left
Angular step [deg] : 0.120
Sample In [um] : 390
Sample Out [um] : 5000
-----------------------Sample coordinates---------------------
X-coordinate : 1965.15
Y-coordinate : 8500.00
Z-coordinate : 18000.00
XX-coordinate : -2882.40
ZZ-coordinate : -72.50
-----------------------Microscope coordinates---------------------
X-coordinate : -212.21
Y-coordinate : -141.54
Z-coordinate : 47.00
--------------------------------------------------------------
TOMOGRAPHIC SCAN STARTED!!!
TOMOGRAPHIC SCAN FINISHED at Mon Jun 8 13:22:01 2015
Original rotation center : 59.50
Rotation center of stitched sinograms: 2619.50
------------------- Projection Information -------------------------------
Original tif projection 2560x2160 pixels
Total size of Tiff projection 35511091kb
reconstruction was not selected
Original rotation center : 59.50
Rotation center of stitched sinograms: 2619.50
------------------- Projection Information -------------------------------
Original tif projection 2560x2160 pixels
Total size of Tiff projection 35511091kb
reconstruction was not selected
Original rotation center : 59.50
Rotation center of stitched sinograms: 2619.50
------------------- Projection Information -------------------------------
Original tif projection 2560x2160 pixels
Total size of Tiff projection 35511091kb
------------------- Reconstruction Parameters -------------------------------
Used algorithm: Gridrec
Reconstruction Dir /sls/X02DA/Data10/eSomethingSomething/disk1/Something/sin/../rec_8bit_0/
Filter parz
Rotation 0.0
Geometry: Homogenous angular projections distribution between 0 and pi
Binning for reconstruction (X,Y) (1,1)
ROI for reconstruction 0,0,0,0
Output format 8 scaling paramters -0.002,0.002
Padding 0.5
------------------- Reconstruction Information -------------------------------
Size of reconstructed slice [MB] 26.2144
Size of reconstructed dataset [GB] 56.623104
-------------- Paganin phase retrieval -------------------
Delta 5e-8
Beta 1e-9
Distance 10.0 mm
Pixel size 0.325 microns
----------------------------------------------------------
Original rotation center : 59.50
Rotation center of stitched sinograms: 2619.50
------------------- Projection Information -------------------------------
Original tif projection 2560x2160 pixels
Total size of Tiff projection 35511091kb
reconstruction was not selected
Original rotation center : 2622.25
------------------- Projection Information -------------------------------
Original tif projection 5120x2160 pixels
Total size of Tiff projection 33199718kb
reconstruction was not selected
Original rotation center : 2622.40
------------------- Projection Information -------------------------------
Original tif projection 5120x2160 pixels
Total size of Tiff projection 33199718kb
reconstruction was not selected
Original rotation center : 2619.50
------------------- Projection Information -------------------------------
Original tif projection 5120x2160 pixels
Total size of Tiff projection 33199718kb
------------------- Reconstruction Parameters -------------------------------
Used algorithm: Gridrec
Reconstruction Dir /sls/X02DA/Data10/eSomethingSomething/disk1/Something/sin/../rec_16bit_Paganin_0/
Filter ramp
Rotation 0.0
Geometry: Homogenous angular projections distribution between 0 and pi
Binning for reconstruction (X,Y) (1,1)
ROI for reconstruction 0,0,0,0
Output format 16 scaling paramters -5e-06,5e-06
Padding 0.5
------------------- Reconstruction Information -------------------------------
Size of reconstructed slice [MB] 52.4288
Size of reconstructed dataset [GB] 113.246208
Original rotation center : 59.50
Rotation center of stitched sinograms: 2619.50
------------------- Projection Information -------------------------------
Original tif projection 2560x2160 pixels
Total size of Tiff projection 35511091kb
------------------- Reconstruction Parameters -------------------------------
Used algorithm: Gridrec
Reconstruction Dir /sls/X02DA/Data10/eSomethingSomething/disk1/Something/sin/../rec_16bit_0/
Filter parz
Rotation 0.0
Geometry: Homogenous angular projections distribution between 0 and pi
Binning for reconstruction (X,Y) (1,1)
ROI for reconstruction 0,0,0,0
Output format 16 scaling paramters -0.002,0.002
Padding 0.5
------------------- Reconstruction Information -------------------------------
Size of reconstructed slice [MB] 52.4288
Size of reconstructed dataset [GB] 113.246208
<sample><name>SampleName</name><userid>eAccount</userid><pointOfInterest><name>P1</name><coordinates><x>-6926.40</x><y>20500.00</y><z>20479.00</z><xx>-1443.90</xx><zz>2088.25</zz><coordinateSystem>beamline</coordinateSystem></coordinates><scan><scanType>FAST-TOMO</scanType><startDate>Mon Aug 24 09:30:40 2015</startDate><beamlineParameters><parameter name="Ring current" unit="mA">401.983</parameter><parameter name="Beam energy" unit="keV">19.998</parameter><parameter name="Monostripe">Ru/C</parameter><parameter name="FE-Filter">No Filter 100%</parameter><parameter name="OP-Filter1">200um Al</parameter><parameter name="OP-Filter2">50um Al</parameter><parameter name="OP-Filter3">No Filter</parameter></beamlineParameters><detectorParameters><parameter name="Camera">PCO.Edge 4.2</parameter><parameter name="Microscope">Opt.Peter MB op</parameter><parameter name="Objective">20.0</parameter><parameter name="Scintillator">LuAG:Ce 20 um</parameter><parameter name="Exposure time" unit="ms">150</parameter><parameter name="Delay time" unit="ms">0</parameter><parameter name="Millisecond shutter">not used</parameter><parameter name="X-ROI Start">1</parameter><parameter name="X-ROI End">2040</parameter><parameter name="Y-ROI Start">1</parameter><parameter name="Y-ROI End">2048</parameter><parameter name="Actual pixel size" unit="um">0.33</parameter><parameter name="Microscope x position" unit="mm">-232.30</parameter><parameter name="Microscope y position" unit="mm">-157.91</parameter><parameter name="Microscope z position" unit="mm">72.00</parameter></detectorParameters><scanParameters><parameter name="Sample folder">/sls/X02DA/data/eAccount/Data10/disk1/SampleName/</parameter><parameter name="File Prefix">SampleName</parameter><parameter name="Number of projections">1501</parameter><parameter name="Number of darks">30</parameter><parameter name="Number of flats">100</parameter><parameter name="Number of inter-flats">0</parameter><parameter name="Flat frequency">0</parameter><parameter name="Rot Y min position" unit="deg">-0.000</parameter><parameter name="Rot Y max position">180.000</parameter><parameter name="Rotation axis position">Standard</parameter><parameter name="Angular step" unit="deg">0.120</parameter><parameter name="Sample In" unit="um">0</parameter><parameter name="Sample Out" unit="um">-5000</parameter></scanParameters><endDate>Mon Aug 24 09:35:58 2015</endDate></scan></pointOfInterest></sample>
"""
XML file parser, based on Alains input
"""
from xml.dom.minidom import parse
xml = parse('SampleLogfile.xml')
print xml.childNodes
sample = xml.firstChild
print sample.childNodes
poi = sample.childNodes[2]
print poi.childNodes
scan = poi.childNodes[2]
print scan.childNodes
scanparameters = scan.childNodes[4]
print scanparameters.childNodes
for i in scanparameters.childNodes:
print i.toxml()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment