Ticket #8428 (closed: fixed)

Opened 7 years ago

Last modified 5 years ago

Peak Reports PDFs

Reported by: Owen Arnold Owned by: Owen Arnold
Priority: major Milestone: Release 3.1
Component: Diffraction Keywords:
Cc: Blocked By: #8381
Blocking: #8561 Tester: Martyn Gigg

Description

Implementing #8381 actually puts everything in place for long standing ISIS SCD requirment. That is to be able to generate PDF peak reports.

Use the reportlab pdf generating library to create reports. Would be nice to have this as a separate module in CrystalTools.

Attachments

QLabIntegrationReport.pdf (182.9 KB) - added by Owen Arnold 7 years ago.

Change History

Changed 7 years ago by Owen Arnold

comment:1 Changed 7 years ago by Owen Arnold

Tester:

using pips install PIL and reportlab first. You may want to set up a virtual environment for these.

Add this script (may need a little modification) to the end o the SXD_NaCl.py script in the mantid script directory

import CrystalTools.PeakReport 
from PyQt4 import QtGui
reload(CrystalTools.PeakReport)
peakReport = CrystalTools.PeakReport.PeakReport("/Users/spu92482/Desktop/animation/")
peakReport.set_log_scale(True)
peakReport.set_background_color(QtGui.QColor(255, 255,255,255))
peakReport.set_show_background(True)
peakReport.set_foreground_color(QtGui.QColor(0, 0,0,255))
peakReport.make_report(QLab, peaks_qLab_Integrated)

After running the script you should get a pdf generated similar to the one attached to this ticket.

comment:2 Changed 7 years ago by Owen Arnold

  • Status changed from new to inprogress

refs #8428. Reporting module created.

Changeset: 43d979110c905cf9affdf2d9f1953a901a2c624f

comment:3 Changed 7 years ago by Owen Arnold

refs #8428. Loop over entire pks wksp.

Changeset: 258ddad358d45c5883b4e0ac0661ccb240b93d32

comment:4 Changed 7 years ago by Owen Arnold

  • Status changed from inprogress to verify
  • Resolution set to fixed

comment:5 Changed 7 years ago by Martyn Gigg

  • Status changed from verify to verifying
  • Tester set to Martyn Gigg

comment:6 Changed 7 years ago by Martyn Gigg

  • Status changed from verifying to reopened
  • Resolution fixed deleted

This runs & creates the PDF with the expected information in it. On windows though there is an error when trying to delete the final image. All of the other 298 png files are able to be deleted but the final 299th causes a file-access error.

I have written a cutdown version of the script that only has 1 peak so that the failure happens quicker. I think it might be worth looking into this quickly to see if it can be solved easily. If not then we can put it in and create another ticket for the windows issue.

import PyQt4.QtGui
qLab = CreateMDWorkspace(Dimensions='3',EventType='MDEvent',Extents='-10,10,-10,10,-10,10',Names='Q_lab_x,Q_lab_y,Q_lab_z',Units='A,B,C')
FakeMDEventData(InputWorkspace=qLab, PeakParams=[1000, 1, 1, 1, 1])
#qLab = BinMD(InputWorkspace=qLab, AxisAligned=True, AlignedDim0="Q_lab_x,-10,10,100", AlignedDim1="Q_lab_y,-10,10,100", AlignedDim2="Q_lab_z,-10,10,100", IterateEvents="1", Parallel="0")
SetSpecialCoordinates(qLab, 'Q (lab frame)')

pathToInstrument = os.path.join(config["instrumentDefinition.directory"], 'CRISP_Definition.xml') # Note that the instrument doesn't matter. Choose a small one.
instWS = LoadEmptyInstrument(Filename=pathToInstrument) # Only do this so that we can provide the parameter to CreatePeaksWorkspace
pw = CreatePeaksWorkspace(InstrumentWorkspace=instWS, NumberOfPeaks=1)

peak = pw.getPeak(0)
peak.setQLabFrame(V3D(1, 1, 1), 1)

peaks_qLab_Integrated = IntegratePeaksMD(InputWorkspace=qLab, PeaksWorkspace=pw, PeakRadius=0.2, BackgroundInnerRadius=0.3, BackgroundOuterRadius=0.4)


import CrystalTools.PeakReport 
from PyQt4 import QtGui

peakReport = CrystalTools.PeakReport.PeakReport("C:/Users/dmn58364/Desktop/animation/")
peakReport.set_log_scale(True)
peakReport.set_background_color(QtGui.QColor(255, 255,255,255))
peakReport.set_show_background(True)
peakReport.set_foreground_color(QtGui.QColor(0, 0,0,255))
peakReport.make_report(qLab, peaks_qLab_Integrated)

comment:7 Changed 7 years ago by Owen Arnold

  • Status changed from reopened to inprogress

refs #8428. Move cleanup to separate method.

Changeset: d9144eecbd79468139f3f5b099d4a4047c098380

comment:8 Changed 7 years ago by Owen Arnold

Move cleanup. Gives the opportunity to either call it via a separate method, or wait for the destructor to be called. This seems to solve the locking issue.

Modified version of above for testing:

import PyQt4.QtGui
qLab = CreateMDWorkspace(Dimensions='3',EventType='MDEvent',Extents='-10,10,-10,10,-10,10',Names='Q_lab_x,Q_lab_y,Q_lab_z',Units='A,B,C')
FakeMDEventData(InputWorkspace=qLab, PeakParams=[1000, 1, 1, 1, 1])
#qLab = BinMD(InputWorkspace=qLab, AxisAligned=True, AlignedDim0="Q_lab_x,-10,10,100", AlignedDim1="Q_lab_y,-10,10,100", AlignedDim2="Q_lab_z,-10,10,100", IterateEvents="1", Parallel="0")
SetSpecialCoordinates(qLab, 'Q (lab frame)')

pathToInstrument = os.path.join(config["instrumentDefinition.directory"], 'CRISP_Definition.xml') # Note that the instrument doesn't matter. Choose a small one.
instWS = LoadEmptyInstrument(Filename=pathToInstrument) # Only do this so that we can provide the parameter to CreatePeaksWorkspace
pw = CreatePeaksWorkspace(InstrumentWorkspace=instWS, NumberOfPeaks=1)

peak = pw.getPeak(0)
peak.setQLabFrame(V3D(1, 1, 1), 1)

peaks_qLab_Integrated = IntegratePeaksMD(InputWorkspace=qLab, PeaksWorkspace=pw, PeakRadius=0.2, BackgroundInnerRadius=0.3, BackgroundOuterRadius=0.4)

def doreport():
        
        import CrystalTools.PeakReport 
        from PyQt4 import QtGui
        reload(CrystalTools.PeakReport)
        peakReport = CrystalTools.PeakReport.PeakReport("C:/Users/spu92482/Desktop/animation/")
        peakReport.set_log_scale(True)
        peakReport.set_background_color(QtGui.QColor(255, 255,255,255))
        peakReport.set_show_background(True)
        peakReport.set_foreground_color(QtGui.QColor(0, 0,0,255))
        peakReport.make_report(qLab, peaks_qLab_Integrated)
        peakReport.clean_files()
doreport()

There has been some tab space formatting here too.

comment:9 Changed 7 years ago by Owen Arnold

  • Status changed from inprogress to verify
  • Resolution set to fixed

comment:10 Changed 7 years ago by Martyn Gigg

  • Status changed from verify to verifying

comment:11 Changed 7 years ago by Martyn Gigg

  • Status changed from verifying to closed

Clean up seems to work fine now.

comment:12 Changed 7 years ago by Martyn Gigg

Merge remote-tracking branch 'origin/feature/8428_reporting'

Full changeset: 23cf94539c75feafd45dd4903ddac1cb9e6faf4c

comment:13 Changed 7 years ago by Owen Arnold

  • Blocking 8561 added

comment:14 Changed 5 years ago by Stuart Campbell

This ticket has been transferred to github issue 9272

Note: See TracTickets for help on using tickets.