# Path: pylinac/core/pdf.py
# class PylinacCanvas:
# 
#     def __init__(self, filename: str, page_title: str, font: str="Helvetica", metadata: dict=None, metadata_location: tuple=(2, 25.5)):
#         self.canvas = Canvas(filename, pagesize=A4)
#         self._font = font
#         self._title = page_title
#         self._metadata = metadata
#         self._metadata_location = metadata_location
#         self._generate_pylinac_template_theme()
#         self._add_metadata()
# 
#     def add_new_page(self) -> None:
#         self.canvas.showPage()
#         self._generate_pylinac_template_theme()
#         self._add_metadata()
# 
#     def _add_metadata(self) -> None:
#         if self._metadata is None:
#             return
#         else:
#             text = ['Metadata:']
#             for key, value in self._metadata.items():
#                 text.append(f"{key}: {value}")
#             self.add_text(text=text, location=self._metadata_location)
# 
#     def _generate_pylinac_template_theme(self) -> None:
#         # draw logo and header separation line
#         self.canvas.drawImage(osp.join(osp.dirname(osp.dirname(osp.abspath(__file__))), 'files', 'Pylinac Full cropped.png'),
#                          1 * cm, 26.5 * cm, width=5 * cm, height=3 * cm, preserveAspectRatio=True)
#         self.canvas.line(1 * cm, 26.5 * cm, 20 * cm, 26.5 * cm)
#         # draw title
#         self.add_text(text=self._title, location=(7, 28), font_size=24)
#         # draw "generated by pylinac" tag
#         date = datetime.now().strftime("%B %d, %Y, %H:%M")
#         self.add_text(f"Generated with Pylinac v{__version__} on {date}", location=(0.5, 0.5), font_size=8)
# 
#     def add_text(self, text: Union[str, List[str]], location: Tuple[NumberLike, NumberLike], font_size: int=10) -> None:
#         """Generic text drawing function.
# 
#         Parameters
#         ----------
#         location : Sequence of two numbers
#             The first item is the distance from left edge in cm
#             The second item is the distance from bottom edge in cm.
#         text : str, list of strings
#             Text data; if str, prints single line.
#             If list of strings, each list item is printed on its own line.
#         font_size : int
#             Text font size.
#         """
#         textobj = self.canvas.beginText()
#         textobj.setTextOrigin(location[0]*cm, location[1]*cm)
#         textobj.setFont(self._font, int(font_size))
#         if isinstance(text, str):
#             textobj.textLine(text)
#         elif isinstance(text, list):
#             for line in text:
#                 textobj.textLine(line)
#         self.canvas.drawText(textobj)
# 
#     def add_image(self, image_data: io.BytesIO, location: Sequence, dimensions: Sequence, preserve_aspect_ratio: bool=True) -> None:
#         image_data.seek(0)
#         image = ImageReader(Image.open(image_data))
#         self.canvas.drawImage(image, location[0]*cm, location[1]*cm, width=dimensions[0]*cm,
#                               height=dimensions[1]*cm, preserveAspectRatio=preserve_aspect_ratio)
# 
#     def finish(self) -> None:
#         self.canvas.showPage()
#         self.canvas.save()
# 
# Path: pylinac/core/typing.py

# 
# Path: pylinac/core/utilities.py
# class Structure:
#     """A simple structure that assigns the arguments to the object."""
#     def __init__(self, **kwargs):
#         self.__dict__.update(**kwargs)
# 
#     def update(self, **kwargs):
#         self.__dict__.update(**kwargs)
# 
# def open_path(path: str) -> None:
#     """Open the specified path in the system default viewer."""
# 
#     if os.name == 'darwin':
#         launcher = "open"
#     elif os.name == 'posix':
#         launcher = "xdg-open"
#     elif os.name == 'nt':
#         launcher = "explorer"
#     subprocess.call([launcher, path])


from datetime import datetime
from typing import Optional
from ..core.pdf import PylinacCanvas
from ..core.typing import NumberLike, NumberOrArray
from ..core.utilities import Structure, open_path
import argue
import numpy as np
}

LEAD_OPTIONS = {
    'None': None,
    '30cm': '30cm',
    '50cm': '50cm'
}


def mmHg2kPa(mmHg: float) -> float:
    """Utility function to convert from mmHg to kPa."""
    return mmHg*101.33/760


def mbar2kPa(mbar: float) -> float:
    """Utility function to convert from millibars to kPa."""
    return mbar/10


def fahrenheit2celsius(f: float) -> float:
    """Utility function to convert from Fahrenheit to Celsius."""
    return (f - 32) * 5/9


@argue.bounds(pdd2010=(0.5, 1))
def tpr2010_from_pdd2010(*, pdd2010: float) -> float:
    """Calculate TPR20,10 from PDD20,10. From TRS-398 pg 62 and Followill et al 1998 eqn 1."""
    return 1.2661*pdd2010 - 0.0595



# Path: pylinac/core/pdf.py
# class PylinacCanvas:
# 
#     def __init__(self, filename: str, page_title: str, font: str="Helvetica", metadata: dict=None, metadata_location: tuple=(2, 25.5)):
#         self.canvas = Canvas(filename, pagesize=A4)
#         self._font = font
#         self._title = page_title
#         self._metadata = metadata
#         self._metadata_location = metadata_location
#         self._generate_pylinac_template_theme()
#         self._add_metadata()
# 
#     def add_new_page(self) -> None:
#         self.canvas.showPage()
#         self._generate_pylinac_template_theme()
#         self._add_metadata()
# 
#     def _add_metadata(self) -> None:
#         if self._metadata is None:
#             return
#         else:
#             text = ['Metadata:']
#             for key, value in self._metadata.items():
#                 text.append(f"{key}: {value}")
#             self.add_text(text=text, location=self._metadata_location)
# 
#     def _generate_pylinac_template_theme(self) -> None:
#         # draw logo and header separation line
#         self.canvas.drawImage(osp.join(osp.dirname(osp.dirname(osp.abspath(__file__))), 'files', 'Pylinac Full cropped.png'),
#                          1 * cm, 26.5 * cm, width=5 * cm, height=3 * cm, preserveAspectRatio=True)
#         self.canvas.line(1 * cm, 26.5 * cm, 20 * cm, 26.5 * cm)
#         # draw title
#         self.add_text(text=self._title, location=(7, 28), font_size=24)
#         # draw "generated by pylinac" tag
#         date = datetime.now().strftime("%B %d, %Y, %H:%M")
#         self.add_text(f"Generated with Pylinac v{__version__} on {date}", location=(0.5, 0.5), font_size=8)
# 
#     def add_text(self, text: Union[str, List[str]], location: Tuple[NumberLike, NumberLike], font_size: int=10) -> None:
#         """Generic text drawing function.
# 
#         Parameters
#         ----------
#         location : Sequence of two numbers
#             The first item is the distance from left edge in cm
#             The second item is the distance from bottom edge in cm.
#         text : str, list of strings
#             Text data; if str, prints single line.
#             If list of strings, each list item is printed on its own line.
#         font_size : int
#             Text font size.
#         """
#         textobj = self.canvas.beginText()
#         textobj.setTextOrigin(location[0]*cm, location[1]*cm)
#         textobj.setFont(self._font, int(font_size))
#         if isinstance(text, str):
#             textobj.textLine(text)
#         elif isinstance(text, list):
#             for line in text:
#                 textobj.textLine(line)
#         self.canvas.drawText(textobj)
# 
#     def add_image(self, image_data: io.BytesIO, location: Sequence, dimensions: Sequence, preserve_aspect_ratio: bool=True) -> None:
#         image_data.seek(0)
#         image = ImageReader(Image.open(image_data))
#         self.canvas.drawImage(image, location[0]*cm, location[1]*cm, width=dimensions[0]*cm,
#                               height=dimensions[1]*cm, preserveAspectRatio=preserve_aspect_ratio)
# 
#     def finish(self) -> None:
#         self.canvas.showPage()
#         self.canvas.save()
# 
# Path: pylinac/core/typing.py

# 
# Path: pylinac/core/utilities.py
# class Structure:
#     """A simple structure that assigns the arguments to the object."""
#     def __init__(self, **kwargs):
#         self.__dict__.update(**kwargs)
# 
#     def update(self, **kwargs):
#         self.__dict__.update(**kwargs)
# 
# def open_path(path: str) -> None:
#     """Open the specified path in the system default viewer."""
# 
#     if os.name == 'darwin':
#         launcher = "open"
#     elif os.name == 'posix':
#         launcher = "xdg-open"
#     elif os.name == 'nt':
#         launcher = "explorer"
#     subprocess.call([launcher, path])


# Path: pylinac/calibration/tg51.py
from datetime import datetime
from typing import Optional
from ..core.pdf import PylinacCanvas
from ..core.typing import NumberLike, NumberOrArray
from ..core.utilities import Structure, open_path
import argue
import numpy as np

}

LEAD_OPTIONS = {
    'None': None,
    '30cm': '30cm',
    '50cm': '50cm'
}


def mmHg2kPa(mmHg: float) -> float:
    """Utility function to convert from mmHg to kPa."""
    return mmHg*101.33/760


def mbar2kPa(mbar: float) -> float:
    """Utility function to convert from millibars to kPa."""
    return mbar/10


def fahrenheit2celsius(f: float) -> float:
    """Utility function to convert from Fahrenheit to Celsius."""
    return (f - 32) * 5/9


@argue.bounds(pdd2010=(0.5, 1))
def tpr2010_from_pdd2010(*, pdd2010: float) -> float:
    """Calculate TPR20,10 from PDD20,10. From TRS-398 pg 62 and Followill et al 1998 eqn 1."""
    return 1.2661*pdd2010 - 0.0595



def p_tp(*, temp: NumberLike, press: NumberLike) -> float: