def test_find_unit(): assert find_unit('coulomb') == ['coulomb', 'coulombs', 'coulomb_constant'] assert find_unit(coulomb) == [ 'C', 'coulomb', 'coulombs', 'planck_charge', 'elementary_charge' ] assert find_unit(charge) == [ 'C', 'coulomb', 'coulombs', 'planck_charge', 'elementary_charge' ] assert find_unit(inch) == [ 'm', 'au', 'cm', 'dm', 'ft', 'km', 'ly', 'mi', 'mm', 'nm', 'pm', 'um', 'yd', 'nmi', 'feet', 'foot', 'inch', 'mile', 'yard', 'meter', 'miles', 'yards', 'inches', 'meters', 'micron', 'microns', 'decimeter', 'kilometer', 'lightyear', 'nanometer', 'picometer', 'centimeter', 'decimeters', 'kilometers', 'lightyears', 'micrometer', 'millimeter', 'nanometers', 'picometers', 'centimeters', 'micrometers', 'millimeters', 'nautical_mile', 'planck_length', 'nautical_miles', 'astronomical_unit', 'astronomical_units' ] assert find_unit(inch**-1) == ['D', 'dioptre', 'optical_power'] assert find_unit(length**-1) == ['D', 'dioptre', 'optical_power'] assert find_unit(inch**3) == [ 'L', 'l', 'cL', 'cl', 'dL', 'dl', 'mL', 'ml', 'liter', 'quart', 'liters', 'quarts', 'deciliter', 'centiliter', 'deciliters', 'milliliter', 'centiliters', 'milliliters', 'planck_volume' ] assert find_unit('voltage') == [ 'V', 'v', 'volt', 'volts', 'planck_voltage' ]
def _get_unitName(self, id): global units if hasattr(units, id): return id if hasattr(units, id.lower()): return id.lower() candidates = units.find_unit(id) if len(candidates) == 0: raise ValueError("cannot find unit with name " + id) if len(candidates) > 1: raise ValueError("multiple possible units found for " + id) return candidates[0]
def test_find_unit(): assert find_unit('coulomb') == ['coulomb', 'coulombs', 'coulomb_constant'] assert find_unit(coulomb) == [ 'C', 'coulomb', 'coulombs', 'planck_charge', 'elementary_charge' ] assert find_unit(charge) == [ 'C', 'coulomb', 'coulombs', 'planck_charge', 'elementary_charge' ] assert find_unit(inch) == [ 'm', 'au', 'cm', 'dm', 'ft', 'km', 'ly', 'mi', 'mm', 'nm', 'pm', 'um', 'yd', 'nmi', 'feet', 'foot', 'inch', 'mile', 'yard', 'meter', 'miles', 'yards', 'inches', 'meters', 'micron', 'microns', 'decimeter', 'kilometer', 'lightyear', 'nanometer', 'picometer', 'centimeter', 'decimeters', 'kilometers', 'lightyears', 'micrometer', 'millimeter', 'nanometers', 'picometers', 'centimeters', 'micrometers', 'millimeters', 'nautical_mile', 'planck_length', 'nautical_miles', 'astronomical_unit', 'astronomical_units' ] assert find_unit(inch**-1) == ['D', 'dioptre', 'optical_power'] assert find_unit(length**-1) == ['D', 'dioptre', 'optical_power'] assert find_unit(inch**2) == ['ha', 'hectare', 'planck_area'] assert find_unit(inch**3) == [ 'L', 'l', 'cL', 'cl', 'dL', 'dl', 'mL', 'ml', 'liter', 'quart', 'liters', 'quarts', 'deciliter', 'centiliter', 'deciliters', 'milliliter', 'centiliters', 'milliliters', 'planck_volume' ] assert find_unit('voltage') == [ 'V', 'v', 'volt', 'volts', 'planck_voltage' ] assert find_unit(grams) == [ 'g', 't', 'Da', 'kg', 'mg', 'ug', 'amu', 'mmu', 'amus', 'gram', 'mmus', 'grams', 'pound', 'tonne', 'dalton', 'pounds', 'kilogram', 'kilograms', 'microgram', 'milligram', 'metric_ton', 'micrograms', 'milligrams', 'planck_mass', 'milli_mass_unit', 'atomic_mass_unit', 'atomic_mass_constant' ]
def test_find_unit(): assert find_unit('coulomb') == ['coulomb', 'coulombs', 'coulomb_constant'] assert find_unit(coulomb) == ['C', 'coulomb', 'coulombs', 'planck_charge'] assert find_unit(charge) == ['C', 'coulomb', 'coulombs', 'planck_charge'] assert find_unit(inch) == [ 'm', 'au', 'cm', 'dm', 'ft', 'km', 'ly', 'mi', 'mm', 'nm', 'pm', 'um', 'yd', 'nmi', 'feet', 'foot', 'inch', 'mile', 'yard', 'meter', 'miles', 'yards', 'inches', 'meters', 'micron', 'microns', 'decimeter', 'kilometer', 'lightyear', 'nanometer', 'picometer', 'centimeter', 'decimeters', 'kilometers', 'lightyears', 'micrometer', 'millimeter', 'nanometers', 'picometers', 'centimeters', 'micrometers', 'millimeters', 'nautical_mile', 'planck_length', 'nautical_miles', 'astronomical_unit', 'astronomical_units'] assert find_unit(inch**-1) == ['D', 'dioptre', 'optical_power'] assert find_unit(length**-1) == ['D', 'dioptre', 'optical_power'] assert find_unit(inch ** 3) == [ 'l', 'cl', 'dl', 'ml', 'liter', 'quart', 'liters', 'quarts', 'deciliter', 'centiliter', 'deciliters', 'milliliter', 'centiliters', 'milliliters', 'planck_volume'] assert find_unit('voltage') == ['V', 'v', 'volt', 'volts', 'planck_voltage']
from sympy.physics import units # Convert 12 inches to meters D = 12*float(units.inch/units.meter) # Covert 0.2 mg/L to kg/m3 C = 0.2*float((units.mg/units.l)/(units.kg/units.m**3)) # Convert 30 psi to m (assuming density = 1000 kg/m3 and gravity = 9.81 m/s2) if not units.find_unit('waterpressure'): units.waterpressure = 9810*units.Pa P = 30*float(units.psi/units.waterpressure) # Convert 200 gallons/day to m3/day if not units.find_unit('gallon'): units.gallon = 4*units.quart R = 200*float(units.gallon/units.m**3)
def test_find_unit(): assert find_unit('charge') == ['charge'] assert find_unit(charge) == ['C', 'charge', 'coulomb', 'coulombs']
from sympy.physics import units as u a = 12. * u.inch / u.m print(a) ##====================================================================== u.BTU = 1055.05585 * u.J a = u.BTU print('\n') print(a) ##====================================================================== ## find_unit('search_things') ##====================================================================== a = u.find_unit('coul') print('{} {} {}'.format('u.find_unit_coul = ', a, '')) b = u.find_unit(u.charge) print('\n') print(b) ##====================================================================== print("\n") print(u.A.name) print(u.ampere.abbrev) print(u.find_unit('magnet')) ##====================================================================== print("\n")
def test_find_unit(): assert find_unit("charge") == ["charge"] assert find_unit(charge) == ["C", "charge", "coulomb", "coulombs"]
from sympy.physics import units # Convert 12 inches to meters D = 12 * float(units.inch / units.meter) # Covert 0.2 mg/L to kg/m3 C = 0.2 * float((units.mg / units.l) / (units.kg / units.m**3)) # Convert 30 psi to m (assuming density = 1000 kg/m3 and gravity = 9.81 m/s2) if not units.find_unit('waterpressure'): units.waterpressure = 9810 * units.Pa P = 30 * float(units.psi / units.waterpressure) # Convert 200 gallons/day to m3/day if not units.find_unit('gallon'): units.gallon = 4 * units.quart R = 200 * float(units.gallon / units.m**3)
from sympy.physics import units # Convert 12 inches to meters D = units.convert_to(12 * units.inch, units.meter) # Convert 0.2 mg/L to kg/m3 C = units.convert_to(0.2 * units.mg / units.l, units.kg / units.m**3) # Convert 30 psi to m (assuming density = 1000 kg/m3 and gravity = 9.81 m/s2) P = 30 * units.psi P = units.convert_to(P, units.Pa) # convert psi to pascal waterpressure = 9810 * units.Pa / units.m H = P / waterpressure # convert pascal to m # Convert 200 gallons/day to m3/day if not 'gallon' in units.find_unit('volume'): units.gallon = 4 * units.quart R = units.convert_to(200 * units.gallon / units.day, units.m**3 / units.day)
class _storage: USgal = units.Quantity('US gallon', 'USgal') # units.systems.SI.set_quantity_scale_factor(USgal, 231*units.inch**3) # USgal.set_scale_factor(231*units.inch**3) # USgal.set_dimension(units.length**3) units.systems.SI.set_quantity_dimension(USgal, units.length**3) UKgal = units.Quantity('UK gallon', 'UKgal') # units.systems.SI.set_quantity_scale_factor(UKgal, 4.54609*units.liter) # UKgal.set_scale_factor(4.54609*units.liter) # UKgal.set_dimension(units.length**3) units.systems.SI.set_quantity_dimension(UKgal, units.length**3) lbf = units.Quantity('pound_force', 'lbf') # lbf.set_dimension(units.force) units.systems.SI.set_quantity_dimension(lbf, units.force) # units.systems.SI.set_quantity_scale_factor(lbf, units.pound.scale_factor) # lbf.set_scale_factor(units.pound.scale_factor) MPa = megapascal = megapascals = units.Quantity('megapascal', 'MPa') # MPa.set_dimension(units.pressure) units.systems.SI.set_quantity_dimension(MPa, units.pressure) # units.systems.SI.set_quantity_scale_factor(MPa, 1000*units.kPa) # MPa.set_scale_factor(1000*units.kPa) GPa = gigapascal = gigapascals = units.Quantity('gigapascal', 'GPa') # GPa.set_dimension(units.pressure) units.systems.SI.set_quantity_dimension(GPa, units.pressure) # units.systems.SI.set_quantity_scale_factor(GPa, 1e6*units.kPa) # GPa.set_scale_factor(1e6*units.kPa) kN = kilonewton = kilonewtons = units.Quantity('kilonewton', 'kN') # kN.set_dimension(units.force) units.systems.SI.set_quantity_dimension(kN, units.force) # units.systems.SI.set_quantity_scale_factor(kN, 1000*units.newton) # kN.set_scale_factor(1000*units.newton) weight = units.force density = units.mass / units.volume area = units.length**2 sec = units.second min = units.minute hr = units.hour lbm = units.pound distance = units.length Hertz = units.hertz for k, v in locals().copy().items(): if isinstance(v, (units.Quantity, units.Dimension)): setattr(units, k, v) del locals()[k] lengths = distances = { k: getattr(units, k) for k in units.find_unit(units.inch) } areas = {k + '^2': v**2 for k, v in lengths.items()} accelerations = {k: getattr(units, k) for k in units.find_unit(units.gee)} pressures = {k: getattr(units, k) for k in units.find_unit(units.pascal)} masses = {k: getattr(units, k) for k in units.find_unit(units.gram)} forces = weights = { k: getattr(units, k) for k in units.find_unit(units.newton) } times = {k: getattr(units, k) for k in units.find_unit(units.minute)} angles = {k: getattr(units, k) for k in units.find_unit(units.radian)} # velocities = {k: getattr(units, k) for k in units.find_unit(units.speed)} # frequencies = {k: getattr(units, k) for k in units.find_unit(units.hertz)} # information = {k: getattr(units, k) for k in units.find_unit(units.byte)} # powers = {k: getattr(units, k) for k in units.find_unit(units.power)} # voltages = {k: getattr(units, k) for k in units.find_unit(units.volts)} # currents = {k: getattr(units, k) for k in units.find_unit(units.ampere)} # charges = {k: getattr(units, k) for k in units.find_unit(units.coulomb)} # lights = {k: getattr(units, k) for k in units.find_unit(units.luminosity)} # resistances = {k: getattr(units, k) for k in units.find_unit(units.ohm)} # amounts = {k: getattr(units, k) for k in units.find_unit(units.mol)} # temperatures = {k: getattr(units, k) for k in units.find_unit(units.kelvin)} # magneticdensities = {k: getattr(units, k) for k in units.find_unit(units.tesla)} # magneticfluxes = {k: getattr(units, k) for k in units.find_unit(units.weber)} # energies = {k: getattr(units, k) for k in units.find_unit(units.electronvolt)} # capacitances = {k: getattr(units, k) for k in units.find_unit(units.farad)} # inductances = {k: getattr(units, k) for k in units.find_unit(units.henry)} volumes = {k: getattr(units, k) for k in units.find_unit(units.liter)} volumes.update({k + '^3': v**3 for k, v in lengths.items()}) unit_subs = dict() for name, d in locals().copy().items(): if not isinstance(d, dict) or name == 'unit_subs': continue for k, v in d.items(): if isinstance(v, (units.Dimension, units.Quantity)): unit_subs[k] = v del d, k, v dimensions = { k: v for k, v in vars(units).items() if isinstance(v, units.Dimension) } units.One = S.One
def test_find_unit(): assert find_unit("coulomb") == ["coulomb", "coulombs", "coulomb_constant"] assert find_unit(coulomb) == [ "C", "coulomb", "coulombs", "planck_charge", "elementary_charge", ] assert find_unit(charge) == [ "C", "coulomb", "coulombs", "planck_charge", "elementary_charge", ] assert find_unit(inch) == [ "m", "au", "cm", "dm", "ft", "km", "ly", "mi", "mm", "nm", "pm", "um", "yd", "nmi", "feet", "foot", "inch", "mile", "yard", "meter", "miles", "yards", "inches", "meters", "micron", "microns", "decimeter", "kilometer", "lightyear", "nanometer", "picometer", "centimeter", "decimeters", "kilometers", "lightyears", "micrometer", "millimeter", "nanometers", "picometers", "centimeters", "micrometers", "millimeters", "nautical_mile", "planck_length", "nautical_miles", "astronomical_unit", "astronomical_units", ] assert find_unit(inch**-1) == ["D", "dioptre", "optical_power"] assert find_unit(length**-1) == ["D", "dioptre", "optical_power"] assert find_unit(inch**3) == [ "l", "cl", "dl", "ml", "liter", "quart", "liters", "quarts", "deciliter", "centiliter", "deciliters", "milliliter", "centiliters", "milliliters", "planck_volume", ] assert find_unit("voltage") == [ "V", "v", "volt", "volts", "planck_voltage" ]