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 editLayerPressure(layer): print('Current %s for %s is : %s\n' % (util.limeText('pressure'), util.limeText( layer.name), util.cyanText('%smbar' % layer.P))) pressure = inputLayerPressure(default=layer.P) layer.changePressure(pressure) menuEditLayerParam(layer)
def editLayerTemperature(layer): print('Current %s for %s is : %s\n' % (util.limeText('temperature'), util.limeText( layer.name), util.cyanText('%sK' % layer.T))) temperature = inputLayerTemperature(default=layer.T) layer.changeTemperature(temperature) menuEditLayerParam(layer)
def editLayerDepth(layer): print('Current %s for %s is : %s\n' % (util.limeText('depth'), util.limeText( layer.name), util.cyanText('%scm' % layer.depth))) depth = inputLayerDepth(default=layer.depth) layer.changeDepth(depth) menuEditLayerParam(layer)
def editLayerRange(layer): print('Current %s for %s is %s\n' % (util.limeText('range'), util.limeText(layer.name), util.cyanText('%s-%scm-1' % (layer.rangeMin, layer.rangeMax)))) rangeMin, rangeMax = inputLayerRange(defaultMin=layer.rangeMin, defaultMax=layer.rangeMax) layer.changeRange(rangeMin, rangeMax) menuEditLayerParam(layer)
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 selectXscFile(params): def relevanceScore(layerT, layerP, fileT, fileP, weightedT=1, weightedP=1.1): tDiff = abs(layerT - fileT) * weightedT pDiff = abs(layerP - fileP) * weightedP total = tDiff + pDiff return total layer = params['layer'] xsc = params['xsc'] if 'sort' not in params: params['sort'] = 'RELEVANT_P' sort = params['sort'] entries = [] unsortedFiles = util.returnXscFilesInDirectory(xsc) if unsortedFiles is False or unsortedFiles == []: question = "Either that directory doesn't exist or it was empty. Would you like to try downloading the data from HITRAN?" if receiveInput(question, validYorN) == 'y': filepath = util.downloadXscZipFile(xsc) util.unzipFile(filepath) util.mergeXsc(xsc) selectXscFile(params) else: return else: hintText = "Layer P and T will be adjusted according to the xsc file" unsortedValues = list( map(lambda file: util.parseXscFileName(file), unsortedFiles)) if sort == 'TEMP': sortedValues = sorted(unsortedValues, key=lambda i: (float(i['TEMP']), float(i['PRESSURE']))) sortedValues.reverse() hintText += '\nCurrently sorted by temperature with largest values at bottom' elif sort == 'PRESSURE': sortedValues = sorted(unsortedValues, key=lambda i: (float(i['PRESSURE']), float(i['TEMP']))) sortedValues.reverse() hintText += '\nCurrently sorted by pressure with largest values at bottom' elif sort == 'RELEVANT_P': sortedValues = sorted( unsortedValues, key=lambda i: (relevanceScore(layer.T, layer.P, float(i['TEMP']), float(i['PRESSURE']) * 1.31579))) sortedValues.reverse() hintText += '\nCurrently sorted closest minimizing pressure difference, with closest match at bottom' elif sort == 'RELEVANT_T': sortedValues = sorted( unsortedValues, key=lambda i: (relevanceScore(layer.T, layer.P, float(i['TEMP']), float(i['PRESSURE']) * 1.31579, weightedP=1, weightedT=1.1))) hintText += '\nCurrently sorted closest minimizing temperature difference, with closest match at bottom' sortedValues.reverse() for v in sortedValues: if sort == 'TEMP' or sort == 'RELEVANT_T': displayName = 'Temp: %s -- Pressure: %s -- Range: %s' % ( util.limeText(v['TEMP'] + 'K'), util.cyanText(v['PRESSURE'] + 'Torr'), util.magentaText(v['RANGE'] + 'cm-1')) elif sort == 'PRESSURE' or sort == 'RELEVANT_P': displayName = 'Pressure: %s -- Temp: %s -- Range: %s' % ( util.cyanText(v['PRESSURE'] + 'Torr'), util.limeText(v['TEMP'] + 'K'), util.magentaText(v['RANGE'] + 'cm-1')) entries.append( Entry(displayName, nextFunction=addXscToLayer, functionParams={ 'layer': layer, 'file': v['LONG_FILENAME'], 'xsc': xsc })) pressureParams = params.copy() pressureParams.update({'sort': 'PRESSURE'}) entries.append( Entry('Sort by pressure', nextFunction=selectXscFile, functionParams=pressureParams, selectionKey='P')) tempParams = params.copy() tempParams.update({'sort': 'TEMP'}) entries.append( Entry('Sort by temperature', nextFunction=selectXscFile, functionParams=tempParams, selectionKey='T')) tempParams = params.copy() tempParams.update({'sort': 'RELEVANT_T'}) entries.append( Entry('Sort by closest temperature', nextFunction=selectXscFile, functionParams=tempParams, selectionKey='minT')) tempParams = params.copy() tempParams.update({'sort': 'RELEVANT_P'}) entries.append( Entry('Sort by closest pressure', nextFunction=selectXscFile, functionParams=tempParams, selectionKey='minP')) menu = Menu('Choose file to use', entries, hint=hintText) menu.displayMenu() return