from ..si.base import * from ..si.derived import * from unum import new_unit __all__ = [ 'kN', 'MN', 'kNm', 'MNm', 'kNcm', 'kG', 'T', 'kPa', 'MPa', 'GPa' ] kN = new_unit('kN', N * 1e3, 'kilonewton') MN = new_unit('MN', N * 1e6, 'meganewton') gravity = 9.81 * m / s ** 2 gf = new_unit('gf', g * gravity, 'gram force') kgf = kG = new_unit('kgf', kg * gravity, 'kilogram force') tf = new_unit('tf', kg * 10e3 * gravity, 'tone force') kPa = new_unit('kPa', Pa * 1e3, 'kilopascal') MPa = new_unit('MPa', Pa * 1e6, 'megapascal') GPa = new_unit('GPa', Pa * 1e9, 'gigapascal') kNm = new_unit('kNm', kN * m, 'kilonewton meter') MNm = new_unit('MNm', MN * m, 'meganewton meter') kNcm = new_unit('kNcm', kN * cm, 'kilonewton centimeter')
def test_NewUnit_NameConflict_Throws(self): unum.new_unit("a_unit", 0, "my_new_unit") with self.assertRaises(unum.NameConflictError): unum.new_unit("a_unit", 0, "my_new_unit")
from unum import new_unit from unum.units import g lb = pound = new_unit("lb", 453.59237 * g, "Pound") gr = grain = new_unit("gr", 0.06479891 * g, "Grain") dr = dram = new_unit("dr", lb / 256, "Dram") #dram now meant only avoirdupois drams, which were 1⁄16 of an avoirdupois ounce of 437.5 grains, thus equal to 27.34 grains #drachm now meant only apothecaries' drachms, which were 1⁄8 of an apothecaries' ounce of 480 grains, thus equal to 60 grains oz = ounce = new_unit("oz", lb / 16, "Ounce") st = stone = new_unit("st", 14 * lb, "Stone") qr = qtr = quarter = new_unit("qtr", 28 * lb, "Quarter") cwt = hundredweight = new_unit("cwt", 112 * lb, "Long Hundredweight") cwt_s = short_hundredweight = new_unit("s cwt", 100 * lb, "Short Hundredweight") t = ton = new_unit("ton", 2240 * lb, "Long Ton") t_s = short_ton = new_unit("short ton", 2000 * lb, "Short Ton") slug = new_unit("slug", 32.17404856 * lb, "Slug")
""" US Customary units. Author: L Selter, 2020 Maintainer: L Selter https://github.com/Tirpitz93 Much of these units are based off: https://upload.wikimedia.org/wikipedia/commons/thumb/9/9e/English_Length_Units_Graph.svg/348px-English_Length_Units_Graph.svg.png and its parent page: https://www.wikiwand.com/en/Imperial_units as well as: https://www.britannica.com/topic/Imperial-unit """ from unum import new_unit from unum.units import cm from unum.units.imp_UK import short_ton as ton_s_UK from unum.units.imp_UK import short_hundredweight as hundred_weight_s_UK fl_dr_US = us_fluid_dram = new_unit("fl dr (US)", 3.6966911953125 * cm**3, "Fluid Dram (US)") ton = ton_s_UK hundredweight = hundred_weight_s_UK
from unum import new_unit from unum.units import g ounce = oz_t = new_unit("oz t", 31.1034768 * g, "Troy ounce") pound = lb_t = new_unit("lb t", 12 * oz_t, "Troy Pound") pennyweight = pwt = new_unit("pwt", oz_t / 20, "Troy Pennyweight") grain = gr_t = new_unit("gr t", pwt / 24, "Troy Grain")
""" This is one of those lovely confusing messes we are left with when people try to standardise. https://www.wikiwand.com/en/Pound_(mass)#Metric_pounds """ from unum import new_unit from unum.units import g metric_pound = lb_m = new_unit("lb m", 500 * g, "Metric Pound")
""" https://www.wikiwand.com/en/Troy_weight#Mint_masses """ from unum import new_unit from unum.units.imp_UK.troy import gr_t mite = new_unit("mite", gr_t / 20, "Mint Mite") droit = new_unit("droit", mite / 24, "Mint Droit") perit = new_unit("perit", droit / 20, "Mint Perit") blank = new_unit("blank", perit / 24, "Mint blank")
""" https://www.britannica.com/topic/Imperial-unit """ ## Apothecary from unum import new_unit from unum.units.imp_UK import fl_oz from unum.units.imp_UK.troy import lb_t, oz_t, gr_t ##Volume apothecary_fluid_drachm = fl_dr_ap = new_unit("fl drachm ap", fl_oz / 8, "Fluid Drachm") fl_s_ap = apothecary_fl_scruple = new_unit("fl scruple ap", fl_dr_ap / 3, "Fluid Scruple") min_ap = apothecary_minim = new_unit("minim ap", fl_s_ap / 20, "Minim") ##Mass/Weight apothecary_pound = lb_ap = new_unit( "lb ap", lb_t, "Apothecary Pound" ) # some sources state that apothecary weight measure are a set of subdivisions of the troy system apothecary_ounce = oz_ap = new_unit("oz ap", oz_t, "Apothecary Ounce") gr_ap = apothecary_grain = new_unit("gr ap", gr_t, "Apothecary Grain") s_ap = apothecary_scruple = new_unit("s ap", 20 * gr_ap, "Apothecary Scruple") dr_ap = apothecary_drachm = drachm = new_unit("dr ap", apothecary_ounce / 8, "Apothecary Drachm") #dram now meant only avoirdupois drams, which were 1⁄16 of an avoirdupois ounce of 437.5 grains, thus equal to 27.34 grains #drachm now meant only apothecaries' drachms, which were 1⁄8 of an apothecaries' ounce of 480 grains, thus equal to 60 grains
""" from unum import new_unit from unum.units import m, mg, g, s from unum.units.others import g0 # << define your units hereafter, e.g. # M = new_unit( 'm' , 0 , 'meter' ) # KM = new_unit( 'km' , 1000. * M , 'kilometer' ) >> ## Length ###length inch = new_unit('inch', 0.0254 * m, 'Inch') th = thou = new_unit('th', inch / 1000, 'Thousandth Inch') ft = foot = new_unit("ft", 12 * inch, "Foot") yd = yard = new_unit("yd", 3 * ft, "Yard") ch = chain = new_unit("ch", 22 * yd, "Chain") fur = furlong = new_unit("fur", 10 * ch, "Furlong") mi = mile = new_unit("mi", 8 * fur, "Mile (statute") lea = league = new_unit("lea", 3 * mi, "League") ftm = fathom = new_unit("ftm", 6.08 * ft, "Fathom") cable = new_unit("cable", 100 * ftm, "Cable") link = new_unit("link", chain / 100, "Link") rod = pole = new_unit("rod", 25 * link, "Rod") namile = british_nautical_mile = admirality_mile = new_unit( "namile", 10 * cable, "British Nautical Mile") line = new_unit("line", inch / 12, "Line") point = new_unit("point", 6 * line, "Point")