RUFAS.units module#
- class RUFAS.units.MeasurementUnits(*values)#
Bases:
Enum
A list of acceptable units used within the RuFaS model.
- ANIMALS = 'animals'#
- ARTIFICIAL_INSEMINATIONS = 'AI'#
- BYTES = 'bytes'#
- CALENDAR_YEAR = 'calendar year'#
- MCAL_PER_MJ = 'Mcal/MJ'#
- CENTIMETERS = 'cm'#
- CENTIMETERS_PER_MILLIMETER = 'cm/mm'#
- CONCEPTIONS = 'conception'#
- CONCEPTIONS_PER_SERVICE = 'conceptions per service'#
- COWS = 'cows'#
- CUBIC_METERS = 'm^3'#
- CUBIC_METERS_PER_DAY = 'm^3/day'#
- CUBIC_METERS_PER_KILOGRAM = 'm^3/kg'#
- CUBIC_METERS_PER_LITER = 'm^3/L'#
- CUBIC_METERS_PER_CUBIC_MILLIMETER = 'm^3/mm^3'#
- CUBIC_MILLIMETERS_PER_CUBIC_METER = 'mm^3/m^3'#
- DAYS = 'day'#
- DAYS_PER_LEAP_YEAR = 'day/leap year'#
- DAYS_PER_YEAR = 'day/year'#
- DEGREES_CELSIUS = '°C'#
- DRY_KILOGRAMS = 'dry kg'#
- DRY_KILOGRAMS_PER_HECTARE = 'dry kg/ha'#
- DOLLARS = '$'#
- FRACTION = 'fraction'#
- GRAMS = 'g'#
- GRAMS_PER_DAY = 'g/day'#
- GRAMS_PER_KILOGRAM = 'g/kg'#
- GRAMS_PER_LITER = 'g/L'#
- HECTARE = 'ha'#
- HECTARES_PER_SQUARE_CENTIMETER = 'ha/cm^2'#
- HECTARES_PER_SQUARE_KILOMETER = 'ha/km^2'#
- HECTARES_PER_SQUARE_METER = 'ha/m^2'#
- HECTARES_PER_SQUARE_MILLIMETER = 'ha/mm^2'#
- HOURS = 'hour'#
- INJECTIONS = 'injection'#
- JULIAN_DAY = 'julian day'#
- KILOMETERS_PER_METER = 'km/m'#
- KILOGRAMS = 'kg'#
- KILOGRAMS_CARBON_DIOXIDE_PER_KILOGRAM_DRY_MATTER = 'kg CO2 / kg DM'#
- KILOGRAMS_PER_ANIMAL = 'kg/animal'#
- KILOGRAMS_CARBON_DIOXIDE_EQ = 'kg CO2-eq'#
- KILOGRAMS_PER_CUBIC_METER = 'kg/m^3'#
- KILOGRAMS_PER_DAY = 'kg/day'#
- KILOGRAMS_PER_GRAM = 'kg/g'#
- KILOGRAMS_PER_HECTARE = 'kg/ha'#
- KILOGRAMS_PER_LITER = 'kg/L'#
- KILOGRAMS_PER_MEGAGRAM = 'kg/Mg'#
- KILOGRAMS_PER_MILLIGRAM = 'kg/mg'#
- KILOMETERS = 'km'#
- LITERS = 'L'#
- LITERS_PER_CUBIC_METER = 'L/m^3'#
- MEGACALORIES = 'Mcal'#
- MEGACALORIES_PER_KILOGRAM = 'Mcal/kg'#
- MEGAGRAMS_PER_KILOGRAM = 'Mg/kg'#
- MEGAJOULES = 'MJ'#
- MEGAJOULES_PER_CUBIC_METER = 'MJ/m^3'#
- MEGAJOULES_PER_SQUARE_METER = 'MJ/m^2'#
- METERS = 'm'#
- METERS_PER_KILOMETER = 'm/km'#
- METERS_PER_MILLIMETER = 'm/mm'#
- METRIC_TONS = 'metric ton'#
- MILLIMETERS = 'mm'#
- MILLIMETERS_PER_CENTIMETER = 'mm/cm'#
- MILLIMETERS_PER_HECTARE = 'mm/ha'#
- MJ_CH4_PER_G_CH4 = 'MJ/g'#
- ORDINAL_DAY = 'ordinal day'#
- PERCENT = 'percent'#
- PERCENT_OF_DRY_MATTER = 'percent of DM'#
- PREGNANCY_CHECKS = 'preg check'#
- RADIANS_PER_HOUR = 'rad/h'#
- SECONDS = 's'#
- SECONDS_PER_DAY = 's/day'#
- HOURS_PER_DAY = 'h/day'#
- SIMULATION_DAY = 'simulation day'#
- SIMULATION_YEAR = 'simulation year'#
- SQUARE_CENTIMETERS_PER_HECTARE = 'cm^2/ha'#
- SQUARE_KILOMETERS_PER_HECTARE = 'km^2/ha'#
- SQUARE_METERS_PER_HECTARE = 'm^2/ha'#
- SQUARE_METERS = 'm^2'#
- SQUARE_MILLIMETERS_PER_HECTARE = 'mm^2/ha'#
- UNITLESS = 'unitless'#
- WET_KILOGRAMS_PER_HECTARE = 'wet kg/ha'#
- static _parse_unit(unit: str) dict[str, int] #
Parses a unit string to handle units with exponents.
Parameters#
- unitstr
A string representing measurement units.
Returns#
- dict
A dictionary where the keys are unit names (str) and the values are their exponents (int).
- static extract_units(key: str) tuple[dict[str, int], dict[str, int]] #
Extracts the units from a key.
Parameters#
- keystr
The key from which the units are extracted.
Returns#
- tuple[dict, dict]
A tuple of the numerator and denominator units. If there is no denominator, the first element of tuple will have the units and the second will be an empty string. If no units are found, it will return a tuple with two empty strings.
- static adjust_unit_exponents(units1: dict[str, int], units2: dict[str, int]) dict[str, int] #
Combines two unit dictionaries by adding or subtracting their exponents.
Parameters#
- units1dict[str, int]
A dictionary representing the first set of units with keys as unit names and values as exponents.
- units2dict[str, int]
A dictionary representing the second set of units with keys as unit names and values as exponents.
Returns#
- dict[str, int]
The combined units dictionary.
- static simplify_units(numerator: dict[str, int], denominator: dict[str, int]) tuple[dict[str, int], dict[str, int]] #
Simplify the units by cancelling out common units in the numerator and denominator.
Parameters#
- numeratordict[str, int]
A dictionary representing the units in the numerator with keys as unit names and values as exponents.
- denominatordict[str, int]
A dictionary representing the units in the denominator with keys as unit names and values as exponents.
Returns#
- tuple[dict[str, int], dict[str, int]]
A tuple containing two dictionaries: - The first dictionary represents the simplified numerator units with non-zero exponents. - The second dictionary represents the simplified denominator units with non-zero exponents.
- static units_to_string(numerator: dict[str, int], denominator: dict[str, int]) str #
Converts two dictionaries of units (numerator and denominator) back to a single string format.
Parameters#
- numeratordict
A dictionary where the keys are unit names (str) and the values are their exponents (int) for the numerator.
- denominatordict
A dictionary where the keys are unit names (str) and the values are their exponents (int) for the denominator.
Returns#
- str
A string representing the units.