예제 #1
0
def test_define_unit_error():
    from unyt import define_unit

    with pytest.raises(RuntimeError):
        define_unit('foobar', 'baz')
    with pytest.raises(RuntimeError):
        define_unit('foobar', 12)
예제 #2
0
def _safe_define(symbol: str, *args, **kwargs):
    # unyt occasionally adds new built-ins, and throws an error for already
    # defined symbols. Log the error and keep going.
    try:
        unyt.define_unit(symbol, *args, **kwargs)
    except RuntimeError as exc:
        logger.info(exc)
예제 #3
0
"""
The velociraptor module. 

More information is available in the documnetation.
"""

# First things first, we need to upgrade msun from a symbol to a
# first-class unit.
import unyt

try:
    unyt.define_unit("msun", unyt.msun, tex_repr=r"M_\odot")
except RuntimeError:
    # We've already done that, oops.
    pass

try:
    unyt.define_unit("mh", unyt.hydrogen_mass, tex_repr=r"m_{\rm H}")
except RuntimeError:
    # We've already done that, oops.
    pass

from velociraptor.catalogue.catalogue import VelociraptorCatalogue
from velociraptor.__version__ import __version__

from typing import Union


def load(
    filename: str,
    disregard_units: bool = False,
예제 #4
0
import numpy as np
from scipy.interpolate import interp1d
import unyt as u

from ..ions import Ion

import os

_lda_unit = u.angstrom
_Jnu_unit = u.ergs / (u.s * u.cm**2 * u.Hz * u.sr)

u.define_unit('Ryd', Ion('H I').ionisation_potential)
u.define_unit('photon', 1.0 * u.dimensionless)


def _load_cuba(filename, z):
    cuba_file = open(os.path.join(os.path.dirname(__file__), filename))

    lda = []
    Jnu = []

    counter = 0
    for line in cuba_file:
        # skip comment lines
        if '#' not in line:
            counter += 1
        else:
            continue
        lsplit = line.split()
        if counter == 1:
            # get redshifts from first line
예제 #5
0
"""
The velociraptor module. 

More information is available in the documnetation.
"""

# First things first, we need to upgrade msun from a symbol to a
# first-class unit.
import unyt

try:
    unyt.define_unit("msun", unyt.msun, tex_repr=r"M_\odot")
except RuntimeError:
    # We've already done that, oops.
    pass

from velociraptor.catalogue.catalogue import VelociraptorCatalogue


def load(filename):
    """
    Loads a velociraptor catalogue, producing a VelociraptorCatalogue
    object.
    """

    return VelociraptorCatalogue(filename)
예제 #6
0
"""HA7000D"""
import socket
from unyt import matplotlib_support, define_unit
from ha7000d.common import get_idn
from ha7000d.ha7062d import HA7062D
from ha7000d.version import __version__

__all__ = ["CommChannel", "__version__"]

try:
    define_unit("dBm", (1.0, "dB"))
except RuntimeError:
    pass
try:
    define_unit("dBc", (1.0, "dB"))
except RuntimeError:
    pass
matplotlib_support()
matplotlib_support.label_style = "/"

PORT = 9760


class CommChannel:
    """Connect to a HA7000D series phase noise analyzer

    Parameters
    ----------
        address (str): instrument's TCPIP address

    Returns
예제 #7
0
"""
The velociraptor module. 

More information is available in the documnetation.
"""

# First things first, we need to upgrade msun and mh from a symbol to a
# first-class unit. We also add a dimensionless unit for magnitudes.
import unyt

try:
    unyt.define_unit("msun", 1.0 * unyt.msun, tex_repr=r"M_\odot")
except RuntimeError:
    # We've already done that, oops.
    pass

try:
    unyt.define_unit("mh", 1.0 * unyt.hydrogen_mass, tex_repr=r"m_{\rm H}")
except RuntimeError:
    # We've already done that, oops.
    pass

try:
    unyt.define_unit("mag", 1.0 * unyt.dimensionless, tex_repr=r"mag")
except RuntimeError:
    # We've already done that, oops.
    pass

from velociraptor.catalogue.catalogue import VelociraptorCatalogue
from velociraptor.__version__ import __version__
예제 #8
0
# -*- coding: utf-8 -*-
# Licensed under a 3-clause BSD style license - see LICENSE.rst

"""
This package defines the oceanography-specific units.  They are also
available in the `unyt` namespace.
"""

import numpy as _numpy
import unyt

# Sverdrup
unyt.define_unit('Sverdrup', 1e6*unyt.m**3/unyt.s)
예제 #9
0
# Licensed under a 3-clause BSD style license - see LICENSE.rst
"""
Oceanography constants in SI units.  See :mod:`oceanpy.constants`
for a complete listing of constants defined in Oceanpy.
"""
import numpy as np

import unyt

# May generate a Unit Registry some day

# Earth day
T_earth = 86164 * unyt.s
unyt.define_unit('T_earth', T_earth)

# Rotation rate of the Earth
Omega_earth = 2 * np.pi / T_earth
unyt.define_unit('Omega_earth', Omega_earth)

# Density of water -- T=25 deg C, S=35 g/kg, P = 1 atm
density_seawater = 1023.6 * unyt.kg / unyt.m**3
unyt.define_unit('density_seawater', density_seawater)