mirror of
				https://github.com/Telecominfraproject/oopt-gnpy.git
				synced 2025-10-31 01:57:54 +00:00 
			
		
		
		
	Refactoring: conversion functions instead of gnpy.core.units.UNITS
The TL;DR behind this patch is that it's better to have a utility conversion function instead of having multiplier LUT and open code which implements the conversion. The FiberParams handling looked fishy -- apparently, it was keeping the multiplier around, but it was unconditionally setting the units to meters, anyway. Given that the units were not being preserved anyway (everything got converted to meters), and that the multipler was not used anywhere, let's refactor the code to just convert to meters using our new utility function, and remove the unused argument. Change-Id: Id886d409a4046f980eed569265baefd97db841bd
This commit is contained in:
		| @@ -15,6 +15,7 @@ from csv import writer | ||||
| import numpy as np | ||||
| from numpy import pi, cos, sqrt, log10 | ||||
| from scipy import constants | ||||
| from gnpy.core.exceptions import ConfigurationError | ||||
|  | ||||
|  | ||||
| def load_json(filename): | ||||
| @@ -282,3 +283,29 @@ def automatic_fmax(f_min, spacing, nch): | ||||
|     196125000000000.0 | ||||
|     """ | ||||
|     return f_min + spacing * nch | ||||
|  | ||||
|  | ||||
| def convert_length(value, units): | ||||
|     """Convert length into basic SI units | ||||
|  | ||||
|     >>> convert_length(1, 'km') | ||||
|     1000.0 | ||||
|     >>> convert_length(2.0, 'km') | ||||
|     2000.0 | ||||
|     >>> convert_length(123, 'm') | ||||
|     123.0 | ||||
|     >>> convert_length(123.0, 'm') | ||||
|     123.0 | ||||
|     >>> convert_length(42.1, 'km') | ||||
|     42100.0 | ||||
|     >>> convert_length(666, 'yards') | ||||
|     Traceback (most recent call last): | ||||
|         ... | ||||
|     gnpy.core.exceptions.ConfigurationError: Cannot convert length in "yards" into meters | ||||
|     """ | ||||
|     if units == 'm': | ||||
|         return value * 1e0 | ||||
|     elif units == 'km': | ||||
|         return value * 1e3 | ||||
|     else: | ||||
|         raise ConfigurationError(f'Cannot convert length in "{units}" into meters') | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Jan Kundrát
					Jan Kundrát