示例#1
0
from ._version import get_versions
__version__ = get_versions()['version']
del get_versions

import pint
from pint import UnitRegistry
from importlib_resources import files
from distutils.version import LooseVersion

# Create ureg here so it is only created once
if LooseVersion(pint.__version__) < LooseVersion('0.10'):
    # Bohr, unified_atomic_mass_unit not defined in pint 0.9, so load
    # pint 0.16.1 definition file
    ureg = UnitRegistry(str(files('euphonic.data') / 'default_en.txt'))
else:
    ureg = UnitRegistry()
ureg.enable_contexts('spectroscopy')
Quantity = ureg.Quantity

from .spectra import Spectrum1D, Spectrum1DCollection, Spectrum2D
from .crystal import Crystal
from .debye_waller import DebyeWaller
from .qpoint_frequencies import QpointFrequencies
from .structure_factor import StructureFactor
from .qpoint_phonon_modes import QpointPhononModes
from .force_constants import ForceConstants
示例#2
0
 def image(self):
     source = files(
         'jaraco.site') / 'static' / 'images' / f'{self.name}.svg'
     return source.read_text()
示例#3
0
import sys

from deprecated import deprecated

if sys.version_info < (3, 9):
    import importlib_resources as resources
else:
    import importlib.resources as resources

__all__ = ("basepath", "open_text")

basepath = resources.files(__name__)

open_text = deprecated(version="0.12.0",
                       reason="Use decaylanguage.data.basepath instead.")(
                           resources.open_text)
示例#4
0
 def copy_scaffold() -> List[Path]:
     dir_path = ir.files("datapane.resources.templates") / scaffold_name
     copy_tree(dir_path, ".")
     return [Path(x.name) for x in dir_path.iterdir()]
示例#5
0
def template_to_head(info,
                     space,
                     coord_frame='auto',
                     unit='auto',
                     verbose=None):
    """Transform a BIDS standard template montage to the head coordinate frame.

    Parameters
    ----------
    %(info_not_none)s The info is modified in place.
    space : str
        The name of the BIDS standard template. See
        https://bids-specification.readthedocs.io/en/stable/99-appendices/08-coordinate-systems.html#standard-template-identifiers
        for a list of acceptable spaces.
    coord_frame : 'mri' | 'mri_voxel' | 'ras'
        BIDS template coordinate systems do not specify a coordinate frame,
        so this must be determined by inspecting the documentation for the
        dataset or the ``electrodes.tsv`` file.  If ``'auto'``, the coordinate
        frame is assumed to be ``'mri_voxel'`` if the coordinates are strictly
        positive, and ``'ras'`` (``"scanner RAS"``) otherwise.

        .. warning::

            ``scanner RAS`` and ``surface RAS`` coordinates frames are similar
            so be very careful not to assume a BIDS dataset's coordinates are
            in one when they are actually in the other. The only way to tell
            for template coordinate systems, currently, is if it is specified
            in the dataset documentation.

    unit : 'm' | 'mm' | 'auto'
        The unit that was used in the coordinate system specification.
        If ``'auto'``, ``'m'`` will be inferred if the montage
        spans less than ``-1`` to ``1``, and ``'mm'`` otherwise. If the
        ``coord_frame`` is ``'mri_voxel'``, ``unit`` will be ignored.
    %(verbose)s

    Returns
    -------
    %(info_not_none)s The modified ``Info`` object.
    trans : mne.transforms.Transform
        The data transformation matrix from ``'head'`` to ``'mri'``
        coordinates.

    """
    _validate_type(info, mne.io.Info)
    _check_option('space', space, BIDS_STANDARD_TEMPLATE_COORDINATE_SYSTEMS)
    _check_option('coord_frame', coord_frame,
                  ('auto', 'mri', 'mri_voxel', 'ras'))
    _check_option('unit', unit, ('auto', 'm', 'mm'))
    # XXX: change to after 0.11 release
    # montage = info.get_montage()
    montage = _get_montage(info)
    if montage is None:
        raise RuntimeError('No montage found in the `raw` object')
    montage.remove_fiducials()  # we will add fiducials so remove any
    pos = montage.get_positions()
    if pos['coord_frame'] not in ('mni_tal', 'unknown'):
        raise RuntimeError(
            "Montage coordinate frame '{}' not expected for a template "
            "montage, should be 'unknown' or 'mni_tal'".format(
                pos['coord_frame']))
    locs = np.array(list(pos['ch_pos'].values()))
    locs = locs[~np.any(np.isnan(locs), axis=1)]  # only channels with loc
    if locs.size == 0:
        raise RuntimeError('No channel locations found in the montage')
    if unit == 'auto':
        unit = 'm' if abs(locs - locs.mean(axis=0)).max() < 1 else 'mm'
    if coord_frame == 'auto':
        coord_frame = 'mri_voxel' if locs.min() >= 0 else 'ras'
    # transform montage to head
    data_dir = files('mne_bids.data')
    # set to the right coordinate frame as specified by the user
    for d in montage.dig:  # ensure same coordinate frame
        d['coord_frame'] = MNE_STR_TO_FRAME[coord_frame]
    # do the transforms, first ras -> vox if needed
    if montage.get_positions()['coord_frame'] == 'ras':
        ras_vox_trans = mne.read_trans(data_dir /
                                       f'space-{space}_ras-vox_trans.fif')
        if unit == 'm':  # must be in mm here
            for d in montage.dig:
                d['r'] *= 1000
        montage.apply_trans(ras_vox_trans)
    if montage.get_positions()['coord_frame'] == 'mri_voxel':
        vox_mri_trans = mne.read_trans(data_dir /
                                       f'space-{space}_vox-mri_trans.fif')
        montage.apply_trans(vox_mri_trans)
    assert montage.get_positions()['coord_frame'] == 'mri'
    if not (unit == 'm' and coord_frame == 'mri'):  # if so, already in m
        for d in montage.dig:
            d['r'] /= 1000  # mm -> m
    # now add fiducials (in mri coordinates)
    fids = mne.io.read_fiducials(data_dir / f'space-{space}_fiducials.fif')[0]
    montage.dig = fids + montage.dig  # add fiducials
    for fid in fids:  # ensure also in mri
        fid['coord_frame'] = MNE_STR_TO_FRAME['mri']
    info.set_montage(montage)  # transform to head
    # finally return montage
    return info, mne.read_trans(data_dir / f'space-{space}_trans.fif')
示例#6
0
文件: reddit.py 项目: lippirk/uwb
from psaw import PushshiftAPI
from typing import Iterator, List
from pathlib import Path
import importlib_resources
import re
import praw

import uwb.src.util as u

T = PushshiftAPI
_test_posts_folder = (importlib_resources.files(
    'uwb') / "resources" / "test_posts")


def eprint(x: str) -> None:
    u.eprint(f"reddit.py: {x}")


class Post:
    def __init__(self, *, _id: str, subreddit: str, title: str, content: str):
        self._id = _id
        self.subreddit = subreddit
        self.title = title
        self.content = content


def init(test=False) -> T:
    if test:
        return None
    return PushshiftAPI()
示例#7
0
    True,
    'server.socket_port':
    int(os.environ.get('PORT', 8080)),
    'server.socket_host':
    os.environ.get('SOCKET_HOST', '::'),
    'tools.encode.on':
    True,
    'tools.encode.encoding':
    'utf-8',
    'tools.decode.on':
    True,
    'tools.sessions.on':
    True,
    'tools.trailing_slash.on':
    True,
    'tools.staticdir.root':
    os.fspath(files('jaraco.site')),
    'tools.proxy.on':
    True,
})

config = {
    '/static': {
        'tools.staticdir.on': True,
        'tools.staticdir.dir': 'static',
        'tools.staticdir.content_types': dict(svg='image/svg+xml'),
    }
}

app = cherrypy.tree.mount(Root(), '/', config)