def publish_pdf(self, filename: str = None, notes: str = None, open_file: bool = False, metadata: dict = None): """Publish (print) a PDF containing the analysis, images, and quantitative results. Parameters ---------- filename : (str, file-like object} The file to write the results to. notes : str, list of strings Text; if str, prints single line. If list of strings, each list item is printed on its own line. open_file : bool Whether to open the file using the default program after creation. metadata : dict Extra data to be passed and shown in the PDF. The key and value will be shown with a colon. E.g. passing {'Author': 'James', 'Unit': 'TrueBeam'} would result in text in the PDF like: -------------- Author: James Unit: TrueBeam -------------- """ plt.ioff() if filename is None: filename = self.image.pdf_path canvas = pdf.PylinacCanvas(filename, page_title="Picket Fence Analysis", metadata=metadata) data = io.BytesIO() self.save_analyzed_image(data, leaf_error_subplot=True) canvas.add_image(data, location=(3, 8), dimensions=(12, 12)) text = [ 'Picket Fence results:', 'Magnification factor (SID/SAD): {:2.2f}'.format( self.image.metadata.RTImageSID / self.image.metadata.RadiationMachineSAD), 'Tolerance (mm): {}'.format(self.settings.tolerance), 'Leaves passing (%): {:2.1f}'.format(self.percent_passing), 'Absolute median error (mm): {:2.3f}'.format( self.abs_median_error), 'Mean picket spacing (mm): {:2.1f}'.format( self.pickets.mean_spacing), 'Maximum error (mm): {:2.3f} on Picket {}, Leaf {}'.format( self.max_error, self.max_error_picket, self.max_error_leaf), ] text.append('Gantry Angle: {:2.2f}'.format(self.image.gantry_angle)) text.append('Collimator Angle: {:2.2f}'.format( self.image.collimator_angle)) canvas.add_text(text=text, location=(10, 25.5)) if notes is not None: canvas.add_text(text="Notes:", location=(1, 5.5), font_size=14) canvas.add_text(text=notes, location=(1, 5)) canvas.finish() if open_file: open_path(filename)
def publish_pdf(self, filename: str, notes: Union[str, list] = None, open_file: bool = False, metadata: dict = None): """Publish (print) a PDF containing the analysis, images, and quantitative results. Parameters ---------- filename : (str, file-like object} The file to write the results to. notes : str, list of strings Text; if str, prints single line. If list of strings, each list item is printed on its own line. open_file : bool Whether to open the file using the default program after creation. metadata : dict Extra data to be passed and shown in the PDF. The key and value will be shown with a colon. E.g. passing {'Author': 'James', 'Unit': 'TrueBeam'} would result in text in the PDF like: -------------- Author: James Unit: TrueBeam -------------- """ if not self._is_analyzed: raise NotAnalyzed( "Image is not analyzed yet. Use analyze() first.") canvas = pdf.PylinacCanvas(filename, page_title="Flatness & Symmetry Analysis", metadata=metadata, metadata_location=(2, 5)) # draw result text text = self.results(as_str=False) canvas.add_text(text=text, location=(2, 25.5), font_size=14) canvas.add_new_page() # draw flatness & symmetry on two pages for method in (self._plot_symmetry, self._plot_flatness): for height, direction in zip((1, 12.5), ('vertical', 'horizontal')): data = io.BytesIO() self._save_plot(method, data, direction=direction) canvas.add_image(data, location=(-4, height), dimensions=(28, 12)) canvas.add_new_page() # draw image on last page data = io.BytesIO() self._save_plot(self._plot_image, data, title="Image") canvas.add_image(data, location=(1, 2), dimensions=(18, 20)) if notes is not None: canvas.add_text(text="Notes:", location=(1, 5.5), font_size=14) canvas.add_text(text=notes, location=(1, 5)) canvas.finish() if open_file: open_path(filename)
def publish_pdf(self, filename: str, notes=None, open_file=False, metadata=None): """Publish (print) a PDF containing the analysis, images, and quantitative results. Parameters ---------- filename : (str, file-like object} The file to write the results to. notes : str, list of strings Text; if str, prints single line. If list of strings, each list item is printed on its own line. open_file : bool Whether to open the file using the default program after creation. metadata : dict Extra data to be passed and shown in the PDF. The key and value will be shown with a colon. E.g. passing {'Author': 'James', 'Unit': 'TrueBeam'} would result in text in the PDF like: -------------- Author: James Unit: TrueBeam -------------- """ canvas = pdf.PylinacCanvas(filename, page_title=f'{self.common_name} Phantom Analysis', metadata=metadata) # write the text/numerical values text = self.results() canvas.add_text(text=text, location=(1.5, 25), font_size=14) if notes is not None: canvas.add_text(text="Notes:", location=(1, 5.5), font_size=12) canvas.add_text(text=notes, location=(1, 5)) # plot the image data = io.BytesIO() self.save_analyzed_image(data, image=True, low_contrast=False, high_contrast=False) canvas.add_image(data, location=(1, 3.5), dimensions=(19, 19)) # plot the high contrast if self.high_contrast_rois: canvas.add_new_page() data = io.BytesIO() self.save_analyzed_image(data, image=False, low_contrast=False, high_contrast=True) canvas.add_image(data, location=(1, 7), dimensions=(19, 19)) # plot the low contrast if self.low_contrast_rois: canvas.add_new_page() data = io.BytesIO() self.save_analyzed_image(data, image=False, low_contrast=True, high_contrast=False) canvas.add_image(data, location=(1, 7), dimensions=(19, 19)) canvas.finish() if open_file: open_path(filename)
def publish_pdf(self, filename: str, notes: Union[str, list]=None, open_file: bool=False, metadata: dict=None): """Publish (print) a PDF containing the analysis, images, and quantitative results. Parameters ---------- filename : (str, file-like object} The file to write the results to. notes : str, list of strings Text; if str, prints single line. If list of strings, each list item is printed on its own line. open_file : bool Whether to open the file using the default program after creation. metadata : dict Extra data to be passed and shown in the PDF. The key and value will be shown with a colon. E.g. passing {'Author': 'James', 'Unit': 'TrueBeam'} would result in text in the PDF like: -------------- Author: James Unit: TrueBeam -------------- """ if not self._is_analyzed: raise NotAnalyzed("Image is not analyzed yet. Use analyze() first.") canvas = pdf.PylinacCanvas(filename, page_title="Flatness & Symmetry Analysis", metadata=metadata, metadata_location=(2, 5)) # draw result text text = self.results(as_str=False) canvas.add_text(text=text, location=(2, 25.5), font_size=14) canvas.add_new_page() # draw flatness & symmetry on two pages for method in (self._plot_symmetry, self._plot_flatness): for height, direction in zip((1, 12.5), ('vertical', 'horizontal')): data = io.BytesIO() self._save_plot(method, data, direction=direction) canvas.add_image(data, location=(-4, height), dimensions=(28, 12)) canvas.add_new_page() # draw image on last page data = io.BytesIO() self._save_plot(self._plot_image, data, title="Image") canvas.add_image(data, location=(1, 2), dimensions=(18, 20)) if notes is not None: canvas.add_text(text="Notes:", location=(1, 5.5), font_size=14) canvas.add_text(text=notes, location=(1, 5)) canvas.finish() if open_file: open_path(filename)
def publish_pdf(self, filename: str, notes: str=None, open_file: bool=False, metadata: dict=None): """Publish (print) a PDF containing the analysis, images, and quantitative results. Parameters ---------- filename : (str, file-like object} The file to write the results to. notes : str, list of strings Text; if str, prints single line. If list of strings, each list item is printed on its own line. open_file : bool Whether to open the file using the default program after creation. metadata : dict Extra data to be passed and shown in the PDF. The key and value will be shown with a colon. E.g. passing {'Author': 'James', 'Unit': 'TrueBeam'} would result in text in the PDF like: -------------- Author: James Unit: TrueBeam -------------- """ plt.ioff() canvas = pdf.PylinacCanvas(filename, page_title="Picket Fence Analysis", metadata=metadata) data = io.BytesIO() self.save_analyzed_image(data, leaf_error_subplot=True) canvas.add_image(data, location=(3, 8), dimensions=(12, 12)) text = [ 'Picket Fence results:', f'Magnification factor (SID/SAD): {self.image.metadata.RTImageSID/self.image.metadata.RadiationMachineSAD:2.2f}', f'Tolerance (mm): {self.settings.tolerance}', f'Leaves passing (%): {self.percent_passing:2.1f}', f'Absolute median error (mm): {self.abs_median_error:2.3f}', f'Mean picket spacing (mm): {self.pickets.mean_spacing:2.1f}', f'Maximum error (mm): {self.max_error:2.3f} on Picket {self.max_error_picket}, Leaf {self.max_error_leaf}', ] text.append(f'Gantry Angle: {self.image.gantry_angle:2.2f}') text.append(f'Collimator Angle: {self.image.collimator_angle:2.2f}') canvas.add_text(text=text, location=(10, 25.5)) if notes is not None: canvas.add_text(text="Notes:", location=(1, 5.5), font_size=14) canvas.add_text(text=notes, location=(1, 5)) canvas.finish() if open_file: open_path(filename)