def inputLayerRange(defaultMin=None, defaultMax=None): if not defaultMin: defaultMin = 600 if not defaultMax: defaultMax = 700 rangeMin = -1 rangeMax = -1 text = 'Enter the minimum range of the layer.\t\t\t' getRangeMin = '%s\n' \ 'If no units are specified, %s will be assumed.\n' \ 'Other valid units are %s . If no value given, default will be %s: ' % \ (util.underlineCyan(text), util.limeText('cm-1'), util.limeText('um'), util.limeText('%scm' % defaultMin)) while rangeMin < 0: rangeMin = receiveInput(getRangeMin, validRange, default=defaultMin) if rangeMin < 0: print('Range min must be %s than zero' % util.magentaText('greater')) text = 'Enter the maximum range of the layer.\t\t\t' getRangeMax = '%s\n' \ 'If no units are specified, %s will be assumed.\n' \ 'Other valid units are %s . If no value given, default will be %s: ' % \ (util.underlineCyan(text), util.limeText('cm-1'), util.limeText('um'), util.limeText('%scm' % defaultMax)) while rangeMax <= rangeMin: rangeMax = receiveInput(getRangeMax, validRange, default=defaultMax) if rangeMax <= rangeMin: print('Range min must be %s than range min of %s' % (util.magentaText('greater'), util.cyanText(rangeMin))) return rangeMin, rangeMax
def createLayer(atmosphere): defaultLayerName = atmosphere.nextLayerName() getLayerName = '\n%s\n' \ 'If no value given, default will be %s : ' \ % (util.underlineCyan('Enter the name of the layer.\t\t'), util.limeText(defaultLayerName)) depth = inputLayerDepth() pressure = inputLayerPressure() temperature = inputLayerTemperature() rangeMin, rangeMax = inputLayerRange() validName = False while not validName: layerName = input(getLayerName) if layerName not in genericAtmosphere: validName = True else: print('Name already taken. Please try again.') layer = atmosphere.addLayer(depth, temperature, pressure, rangeMin, rangeMax, name=layerName) createMolecule(layer) return
def inputPlanckTemps(): text = 'Enter the temperature of the planck curves.\t\t\t' tempList = receiveMultiInput( '%s\n' 'If no units entered, temperature will be assumed %s.\n' 'Other valid units are %s .Multiple temperatures can be separated with a comma: ' % (util.underlineCyan(text), util.limeText('K'), util.limeText('C and F')), validTemperature) return tempList
def inputPlanckRange(units): rangeMin = -1 rangeMax = -1 text = '%s\nUnits are %s. Scientific notation is accepted (1e14):' \ % (util.underlineCyan('Enter the minimum range of the planck spectrum.'),util.limeText(units)) while rangeMin < 0: rangeMin = receiveInput(text, validNumber) if rangeMin < 0: print('Range min must be %s than zero' % util.magentaText('greater')) text = '%s\nUnits are %s. Scientific notation is accepted (1e14):' \ % (util.underlineCyan('Enter the maximum range of the planck spectrum.'), util.limeText(units)) while rangeMax <= rangeMin: rangeMax = receiveInput(text, validNumber) if rangeMax <= rangeMin: print('Range min must be %s than range min of %s' % (util.magentaText('greater'), util.cyanText(rangeMin))) return rangeMin, rangeMax
def inputMoleculeName(default=None): if not default: default = 'co2' text = 'Enter the short molecule name.\t\t\t' moleculeName = receiveInput( '%s\n' 'For a full list of options, type %s. For a list of cross-section only molecules, type %s. If no value given, %s will be used: ' % (util.underlineCyan(text), util.magentaText('help'), util.magentaText('xsc'), util.limeText(default)), validMoleculeName, default=default) return moleculeName
def inputLayerPressure(default=None): if not default: default = 1013.25 text = 'Enter the pressure of the layer.\t\t\t' getPressure = '%s\n' \ 'If no units are specified, %s will be assumed.\n' \ 'Other valid units are %s . If no value given, default will be %s: ' % \ (util.underlineCyan(text), util.limeText('mBar'), util.limeText('pa, bar, and atm.'), util.limeText('%smbar' % default)) pressure = receiveInput(getPressure, validPressure, default=default) return pressure
def inputLayerDepth(default=None): if not default: default = 10 text = 'Enter the thickness of the layer.\t\t\t' getDepth = '%s\n' \ 'If no units are specified, %s will be assumed.\n' \ 'Other valid units are %s . If no value given, default will be %s: ' % \ (util.underlineCyan(text), util.limeText('cm'), util.limeText('m, in, ft.'), util.limeText('%scm' % default)) depth = receiveInput(getDepth, validDepth, default=default) return depth
def displayMenu(self): titleStr = '\t' + self.title while len(titleStr) < 60: titleStr += ' ' print('\n%s' % util.underlineCyan(titleStr)) i = 1 validEntry = ['x'] for entry in self.entries: if entry.selectionKey: validEntry.append(entry.selectionKey.lower()) print( ' %s) %s' % (util.magentaText(entry.selectionKey.upper()), entry.name)) else: validEntry.append(str(i)) print(' %s) %s' % (util.magentaText(i), entry.name)) i += 1 if 'Main' not in self.title: print(' %s Previous menu' % util.magentaText('B)')) validEntry.append('b') print(' %s Exit' % util.magentaText('X)')) validChoice = False if self.hint: print(util.limeText('**' + self.hint)) while not validChoice: userInput = input('Choose an option: ') if userInput.lower() == 'x': print('Goodbye') exit(1) elif userInput.lower() == 'b' and 'Main' not in self.title: return elif userInput in validEntry: try: userChoice = self.entries[int(userInput) - 1] except ValueError: # this means the user entered a letter but it is in the valid choices # roll through the entries to find the matching choice userChoice = next( filter( lambda x: x.selectionKey and x.selectionKey.lower( ) == userInput.lower(), self.entries)) if userChoice.nextFunction: userChoice.nextFunction(userChoice.functionParams) validChoice = True elif userChoice.nextMenu: userChoice.nextMenu.displayMenu() validChoice = True else: print('Invalid entry. Try again.')
def inputLayerTemperature(default=None): if not default: default = 300 text = 'Enter the temperature of the layer.\t\t\t' getTemperature = '%s\n' \ 'If no units are specified, %s will be assumed.\n' \ 'Other valid units are %s . If no value given, default will be %s: ' % \ (util.underlineCyan(text), util.limeText('K'), util.limeText('C or F'), util.limeText('%sK' % default)) temperature = receiveInput(getTemperature, validTemperature, default=default) return temperature
def inputMoleculeComposition(obj=None, default=None): if not default: default = '400ppm' text = 'Enter the molecule composition.\t\t\t' composition, units = receiveInput( '%s\n' 'If no units entered, composition will be assumed %s.\n' 'Other valid units are %s . If no value given, %s will be used: ' % (util.underlineCyan(text), util.limeText('parts per 1'), util.limeText('ppm, ppb, or percentage'), util.limeText(default)), validComposition, default=default) if obj: if units == 'ppm': obj.setPPM(composition) elif units == 'ppb': obj.setPPB(composition) elif 'perc' in units or units == '%': obj.setPercentage(composition) else: obj.setConcentrationPercentage(composition) return else: return composition, units