Esempio n. 1
0
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
Esempio n. 2
0
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
Esempio n. 3
0
    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.')
Esempio n. 4
0
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
Esempio n. 5
0
def createMolecule(layer):
    addMoleculeLoop = True
    while addMoleculeLoop:
        moleculeName = inputMoleculeName()
        if moleculeName in XSC_LIST:
            params = {'layer': layer, 'xsc': moleculeName}
            selectXscFile(params)
        else:
            concentration, units = inputMoleculeComposition()
            tempdict = {units: concentration}
            molecule = layer.addMolecule(moleculeName, **tempdict)
        while pyrad.totalConcentration(layer) > 1:
            print("%s total concentration exceeds 100%%" %
                  util.magentaText('***\tWARNING\t***'))
            menuEditComposition(layer)
        validInput = False
        while not validInput:
            ask = input("Add another molecule to the layer %s " %
                        util.magentaText('(y/n) :'))
            if ask.strip().lower() == 'y':
                validInput = True
            elif ask.strip().lower() == 'n':
                return
Esempio n. 6
0
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