Beispiel #1
0
def reset_units(seed=None, length=None, mass=None, time=None, energy=None, charge=None):
    """Allows the working units to be reset to random values or specified accoring to dimensions."""
    
    if length is None and time is None and mass is None and energy is None and charge is None:
        nu.reset_units(seed)
    
    else:
        try:
            length = unit[length]
        except:
            pass
        try:
            mass = unit[mass]
        except:
            pass
        try:
            time = unit[time]
        except:
            pass        
        try:
            energy = unit[energy]
        except:
            pass    
        try:
            charge = unit[charge]
        except:
            pass      
    
        m = 1.
        kg = 1.
        s = 1.
        C = 1.
        K = 1.
        
        if length is not None:
            m = nu.m / length
        if mass is not None:
            kg = nu.kg / mass
        if time is not None:
            s = nu.s / time
        if charge is not None:
            C = nu.C / charge
        if energy is not None:
            J = nu.J / energy
            if mass is None:
                kg = J * s**2 / m**2
            elif time is None:
                s = (kg * m**2 / J)**0.5
            elif length is None:
                m = (J * s**2 / kg)
            else:
                raise ValueError('length, mass, time and energy cannot all be defined')
        
        nu.m = m
        nu.kg = kg
        nu.s = s
        nu.C = C
        nu.K = K
        
        nu.set_derived_units_and_constants()
    build_unit()    
Beispiel #2
0
def reset_units(seed=None, length=None, mass=None, time=None, energy=None, charge=None):
    """Allows the working units to be reset to random values or specified accoring to dimensions."""
    
    if length is None and time is None and mass is None and energy is None and charge is None:
        nu.reset_units(seed)
    
    else:
        try:
            length = unit[length]
        except:
            pass
        try:
            mass = unit[mass]
        except:
            pass
        try:
            time = unit[time]
        except:
            pass        
        try:
            energy = unit[energy]
        except:
            pass    
        try:
            charge = unit[charge]
        except:
            pass      
    
        m = 1.
        kg = 1.
        s = 1.
        C = 1.
        K = 1.
        
        if length is not None:
            m = nu.m / length
        if mass is not None:
            kg = nu.kg / mass
        if time is not None:
            s = nu.s / time
        if charge is not None:
            C = nu.C / charge
        if energy is not None:
            J = nu.J / energy
            if mass is None:
                kg = J * s**2 / m**2
            elif time is None:
                s = (kg * m**2 / J)**0.5
            elif length is None:
                m = (J * s**2 / kg)
            else:
                raise ValueError('length, mass, time and energy cannot all be defined')
        
        nu.m = m
        nu.kg = kg
        nu.s = s
        nu.C = C
        nu.K = K
        
        nu.set_derived_units_and_constants()
    build_unit()    
Beispiel #3
0
def reset_units(seed=None, **kwargs):
    """
    Extends numericalunits.reset_units() by allowing for working units to be
    defined.  If no working units are specified, then random working units are
    used just like the default numericalunits behavior.  Otherwise, use the
    specified working units and SI.
    
    Parameters
    ----------
    seed : int, optional
        random number seed to use in generating random working units.
        seed='SI' will use SI units.  Cannot be given with the other
        parameters.
    length : str, optional
        Unit of length to use for the working units.
    mass : str, optional
        Unit of mass to use for the working units.
    time : str, optional
        Unit of time to use for the working units.
    energy : str, optional
        Unit of energy to use for the working units.
    charge : str, optional
        Unit of charge to use for the working units.
        
    Raises
    ------
    ValueError
        If seed is given with any other parameters, or if more than four of
        the working unit parameters are given.
    """

    # Generate random base working units
    if (len(kwargs) == 0):

        nu.reset_units(seed)
        build_unit()

    # Generate SI + defined working units
    elif seed is None:

        # Check that no more than 4 working units are defined
        if len(kwargs) > 4:
            raise ValueError('Only four working units can be defined')

        # Set base units to 1 (working units to SI)
        nu.reset_units('SI')
        build_unit()

        # Scale base units by working units
        if 'length' in kwargs:
            nu.m = unit['m'] / unit[kwargs['length']]

        if 'mass' in kwargs:
            nu.kg = unit['kg'] / unit[kwargs['mass']]

        if 'time' in kwargs:
            nu.s = unit['s'] / unit[kwargs['time']]

        if 'charge' in kwargs:
            nu.C = unit['C'] / unit[kwargs['charge']]

        # Scale derived units by working units
        if 'energy' in kwargs:
            J = unit['J'] / unit[kwargs['energy']]

            # Scale base units by derived units
            if 'mass' not in kwargs:
                nu.kg = J * nu.s**2 / nu.m**2
            elif 'time' not in kwargs:
                nu.s = (nu.kg * nu.m**2 / J)**0.5
            elif 'length' not in kwargs:
                nu.m = (J * nu.s**2 / nu.kg)

        # Rebuild derived units and unit dictionary
        nu.set_derived_units_and_constants()
        build_unit()

    else:
        raise ValueError('seed cannot be given with any other parameters')
Beispiel #4
0
def reset_units(seed=None, **kwargs):
    """
    Extends numericalunits.reset_units() by allowing for working units to be
    defined.  If no working units are specified, then random working units are
    used just like the default numericalunits behavior.  Otherwise, use the
    specified working units and SI.
    
    Parameters
    ----------
    seed : int, optional
        random number seed to use in generating random working units.
        seed='SI' will use SI units.  Cannot be given with the other
        parameters.
    length : str, optional
        Unit of length to use for the working units.
    mass : str, optional
        Unit of mass to use for the working units.
    time : str, optional
        Unit of time to use for the working units.
    energy : str, optional
        Unit of energy to use for the working units.
    charge : str, optional
        Unit of charge to use for the working units.
        
    Raises
    ------
    ValueError
        If seed is given with any other parameters, or if more than four of
        the working unit parameters are given.
    """
    
    # Generate random base working units
    if (len(kwargs) == 0):
        
        nu.reset_units(seed)
        build_unit()
    
    # Generate SI + defined working units
    elif seed is None:
        
        # Check that no more than 4 working units are defined
        if len(kwargs) > 4:
            raise ValueError('Only four working units can be defined')
        
        # Set base units to 1 (working units to SI)
        nu.reset_units('SI')
        build_unit()
        
        # Scale base units by working units
        if 'length' in kwargs:
            nu.m = unit['m'] / unit[kwargs['length']]
        
        if 'mass' in kwargs:
            nu.kg = unit['kg'] / unit[kwargs['mass']]
        
        if 'time' in kwargs:
            nu.s = unit['s'] / unit[kwargs['time']]
        
        if 'charge' in kwargs:
            nu.C = unit['C'] / unit[kwargs['charge']]
        
        # Scale derived units by working units
        if 'energy' in kwargs:
            J = unit['J'] / unit[kwargs['energy']]
            
            # Scale base units by derived units
            if 'mass' not in kwargs:
                nu.kg = J * nu.s**2 / nu.m**2
            elif 'time' not in kwargs:
                nu.s = (nu.kg * nu.m**2 / J)**0.5
            elif 'length' not in kwargs:
                nu.m = (J * nu.s**2 / nu.kg)
        
        # Rebuild derived units and unit dictionary
        nu.set_derived_units_and_constants()
        build_unit()
        
    else:
        raise ValueError('seed cannot be given with any other parameters')
Beispiel #5
0
import logging
import numericalunits as nu
import os
from datetime import *
import StringIO
import gzip

nu.reset_units()
nu.set_derived_units_and_constants()

from google.appengine.api import urlfetch
import json


class WeatherError(Exception):
    def __init__(self, value, details):
        self.value = value
        self.details = details.rstrip()

    def __str__(self):
        return repr(self.value) + ' ' + repr(self.details)


class WeatherCalculator:
    def __init__(self, session):
        self.min_latitude = 90
        self.min_longitude = 180
        self.max_latitude = -90
        self.max_longitude = -180
        self.error = False
        self.name = None