Ejemplo n.º 1
0
def _add_logo(fig,
              x=10,
              y=25,
              zorder=100,
              which='metpy',
              size='small',
              **kwargs):
    """Add the MetPy or Unidata logo to a figure.

    Adds an image to the figure.

    Parameters
    ----------
    fig : `matplotlib.figure`
       The `figure` instance used for plotting
    x : int
       x position padding in pixels
    y : float
       y position padding in pixels
    zorder : int
       The zorder of the logo
    which : str
       Which logo to plot 'metpy' or 'unidata'
    size : str
       Size of logo to be used. Can be 'small' for 75 px square or 'large' for
       150 px square.

    Returns
    -------
    `matplotlib.image.FigureImage`
       The `matplotlib.image.FigureImage` instance created

    """
    try:
        from importlib.resources import files as importlib_resources_files
    except ImportError:  # Can remove when we require Python > 3.8
        from importlib_resources import files as importlib_resources_files

    fname_suffix = {'small': '_75x75.png', 'large': '_150x150.png'}
    fname_prefix = {'unidata': 'unidata', 'metpy': 'metpy'}
    try:
        fname = fname_prefix[which] + fname_suffix[size]
    except KeyError:
        raise ValueError('Unknown logo size or selection') from None

    with (importlib_resources_files('metpy.plots') / '_static' /
          fname).open('rb') as fobj:
        logo = imread(fobj)
    return fig.figimage(logo, x, y, zorder=zorder, **kwargs)
Ejemplo n.º 2
0
    def scan_resource(self, pkg, path):
        r"""Scan a resource directory for colortable files and add them to the registry.

        Parameters
        ----------
        pkg : str
            The package containing the resource directory
        path : str
            The path to the directory with the color tables

        """
        try:
            from importlib.resources import files as importlib_resources_files
        except ImportError:  # Can remove when we require Python > 3.8
            from importlib_resources import files as importlib_resources_files

        for entry in (importlib_resources_files(pkg) / path).iterdir():
            if entry.suffix == TABLE_EXT:
                with entry.open() as stream:
                    self.add_colortable(stream, entry.with_suffix('').name)
Ejemplo n.º 3
0
try:
    from importlib.resources import (as_file as importlib_resources_as_file,
                                     files as importlib_resources_files)
except ImportError:  # Can remove when we require Python > 3.8
    from importlib_resources import (files as importlib_resources_files,
                                     as_file as importlib_resources_as_file)

import matplotlib.font_manager as fm
import numpy as np

from ..package_tools import Exporter

exporter = Exporter(globals())

# Create a matplotlib font object pointing to our weather symbol font
fontfile = importlib_resources_files('metpy.plots') / 'fonts/wx_symbols.ttf'
with importlib_resources_as_file(fontfile) as fname:
    # Need to pass str, not Path, for older matplotlib
    wx_symbol_font = fm.FontProperties(fname=str(fname))


@exporter.export
def wx_code_to_numeric(codes):
    """Determine the numeric weather symbol value from METAR code text.

    A robust method to identifies the numeric value for plotting the correct symbol from a
    decoded METAR current weather group. The METAR codes should be strings with no missing
    values or NaN strings (empty strings are okay).

    For example, if from a Pandas Dataframe sfc_df.wxcodes.fillna('')
Ejemplo n.º 4
0
try:
    import importlib.resources as importlib_resources
    from importlib.resources import files as importlib_resources_files
except ImportError:
    # Try backported to PY<37 `importlib_resources`.
    import importlib_resources as importlib_resources
    from importlib_resources import files as importlib_resources_files

from contextlib import ExitStack
import atexit

# We use an exit stack and register it at interpreter exit to cleanup anything needed
file_manager = ExitStack()
atexit.register(file_manager.close)
ref = importlib_resources_files('pygaps.data') / 'default.db'
DATABASE = file_manager.enter_context(importlib_resources.as_file(ref))

# Lists of pygaps data
MATERIAL_LIST = []
ADSORBATE_LIST = []


def load_data():
    """Will proceed with filling the data store."""

    from ..parsing.sqlite import adsorbates_from_db
    from ..parsing.sqlite import materials_from_db

    global MATERIAL_LIST
    global ADSORBATE_LIST