<s> from abcunits import ConversionUnit <EOL> from math import pi <EOL> H = <NUM_LIT> * <NUM_LIT:10> ** - <NUM_LIT> <EOL> eVtoJ = <NUM_LIT> * <NUM_LIT:10> ** - <NUM_LIT> <EOL> C = <NUM_LIT> <EOL> class SpecUnit ( ConversionUnit ) : <EOL> """<STR_LIT>""" <EOL> category = '<STR_LIT>' <EOL> @ property <EOL> def symbol ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . category == '<STR_LIT>' : <EOL> return r'<STR_LIT>' <EOL> elif self . category == '<STR_LIT>' : <EOL> return r'<STR_LIT>' <EOL> elif self . category == '<STR_LIT>' : <EOL> return r'<STR_LIT>' <EOL> elif self . category == '<STR_LIT>' : <EOL> return r'<STR_LIT>' <EOL> elif not self . category : <EOL> return '<STR_LIT>' <EOL> else : <EOL> raise UnitError ( '<STR_LIT>' % self . category ) <EOL> class Meters ( SpecUnit ) : <EOL> short = '<STR_LIT:m>' <EOL> full = '<STR_LIT>' <EOL> category = '<STR_LIT>' <EOL> _canonical = True <EOL> @ staticmethod <EOL> def to_canonical ( x ) : <EOL> return x <EOL> @ staticmethod <EOL> def from_canonical ( x ) : <EOL> return x <EOL> class Centimeters ( SpecUnit ) : <EOL> short = '<STR_LIT>' <EOL> full = '<STR_LIT>' <EOL> category = '<STR_LIT>' <EOL> @ staticmethod <EOL> def to_canonical ( x ) : <EOL> return x / <NUM_LIT> <EOL> @ staticmethod <EOL> def from_canonical ( x ) : <EOL> return <NUM_LIT> * x <EOL> class Micrometers ( SpecUnit ) : <EOL> short = '<STR_LIT>' <EOL> full = '<STR_LIT>' <EOL> category = '<STR_LIT>' <EOL> @ staticmethod <EOL> def to_canonical ( x ) : <EOL> return x / <NUM_LIT> <EOL> @ staticmethod <EOL> def from_canonical ( x ) : <EOL> return <NUM_LIT> * x <EOL> class Nanometers ( SpecUnit ) : <EOL> short = '<STR_LIT>' <EOL> full = '<STR_LIT>' <EOL> category = '<STR_LIT>' <EOL> @ staticmethod <EOL> def to_canonical ( x ) : <EOL> return x / <NUM_LIT> <EOL> @ staticmethod <EOL> def from_canonical ( x ) : <EOL> return <NUM_LIT> * x <EOL> class Metersinverse ( SpecUnit ) : <EOL> """<STR_LIT>""" <EOL> short = '<STR_LIT:k>' <EOL> full = '<STR_LIT>' <EOL> category = '<STR_LIT>' <EOL> @ staticmethod <EOL> def to_canonical ( x ) : <EOL> return <NUM_LIT:1.0> / x <EOL> @ staticmethod <EOL> def from_canonical ( x ) : <EOL> return <NUM_LIT:1.0> / x <EOL> class Centimetersinverse ( SpecUnit ) : <EOL> short = '<STR_LIT>' <EOL> full = '<STR_LIT>' <EOL> category = '<STR_LIT>' <EOL> @ staticmethod <EOL> def to_canonical ( x ) : <EOL> return ( <NUM_LIT:1.0> / x ) * ( <NUM_LIT> ) <EOL> @ staticmethod <EOL> def from_canonical ( x ) : <EOL> return <NUM_LIT:1.0> / ( x * <NUM_LIT> ) <EOL> class Micrometersinverse ( SpecUnit ) : <EOL> short = '<STR_LIT>' <EOL> full = '<STR_LIT>' <EOL> category = '<STR_LIT>' <EOL> class Nanometersinverse ( SpecUnit ) : <EOL> short = '<STR_LIT>' <EOL> full = '<STR_LIT>' <EOL> category = '<STR_LIT>' <EOL> class Frequency ( SpecUnit ) : <EOL> """<STR_LIT>""" <EOL> short = '<STR_LIT:f>' <EOL> full = '<STR_LIT>' <EOL> category = '<STR_LIT>' <EOL> @ staticmethod <EOL> def to_canonical ( x ) : <EOL> meters = Meters . to_canonical ( x ) <EOL> return C / meters <EOL> @ staticmethod <EOL> def from_canonical ( x ) : <EOL> return C / x <EOL> class Angularfrequency ( SpecUnit ) : <EOL> short = '<STR_LIT:w>' <EOL> full = '<STR_LIT>' <EOL> category = '<STR_LIT>' <EOL> @ staticmethod <EOL> def to_canonical ( x ) : <EOL> meters = Meters . to_canonical ( x ) <EOL> return ( <NUM_LIT> * pi * C ) / meters <EOL> @ staticmethod <EOL> def from_canonical ( x ) : <EOL> return ( <NUM_LIT> * pi * C ) / x <EOL> class Electronvolts ( SpecUnit ) : <EOL> short = '<STR_LIT>' <EOL> full = '<STR_LIT>' <EOL> category = '<STR_LIT>' <EOL> @ staticmethod <EOL> def to_canonical ( x ) : <EOL> meters = Meters . to_canonical ( x ) <EOL> return ( H * C / ( eVtoJ ) ) / meters <EOL> @ staticmethod <EOL> def from_canonical ( x ) : <EOL> return ( H * C / ( eVtoJ ) ) / x <EOL> _specunits = ( <EOL> Meters ( ) , <EOL> Metersinverse ( ) , <EOL> Nanometers ( ) , <EOL> Centimeters ( ) , <EOL> Centimetersinverse ( ) , <EOL> Micrometers ( ) , <EOL> Micrometersinverse ( ) , <EOL> Electronvolts ( ) , <EOL> Frequency ( ) , <EOL> Angularfrequency ( ) , <EOL> ) <EOL> SPECUNITS = dict ( ( obj . short , obj ) for obj in _specunits ) </s>
