2
\$\begingroup\$

Mostly just looking for a review of my regex and implementation of capture groups. its something I've been working to improve.

The indexes have somewhat of a pattern to them of being....

(<level - not at surface>, <parameter>, <(unit) - not on every parameter>)

indexs

indexs = ('Sfc Prs(mb)', 'Mean SLP (mb)', 'Altimeter (in. Hg)', 'Press Alt (ft)', 'Density Alt (ft)', '2 m agl Tmp (K)', '2 m agl Temp-D (K)', '2 m agl Dpt (K)', '2 m agl WBT (K)', 'Convect. Temp (K)', 'Heat Index (F)', 'Wind Chill (F)', 'FITS (F)', '2 m agl RH (%)', '10 m agl Dir', '10 m agl Spd (kt)', 'X-Wind Spd (kt)', 'NonCv Gust Dir', 'NonCv Gust Spd(kt)', '600m AGL Spd (kt)', '600m AGL Dir', 'LLWS Prob (%)', 'Panofsky Index', 'Max Turbc Blw 10K', '3hr Precip (in)', '3hr ConvPrp (in)', 'NonCv Precip Type', '12 Hour Rain (in)', '12 Snow Accum (in)', '24 Snow Accum (in)', 'Precip Water (in)', 'Fog Point. Temp(K)', 'Fog Threat', 'Fog Stability', 'X-Over Temp (K)', 'X-Over Fog (%)', 'Fog Probability(%)', 'DTA Visibility(sm)', 'Visibility (sm)', 'SFC LCL Temp (K)', 'SFC LCL Press (mb)', 'SFC LCL Height (m)', 'ML-CCL Temp (K)', 'ML-CCL Press (mb)', 'ML-CCL Height (m)', 'Cloud Base1(100ft)', 'Cloud Cover1(oct)', 'Cloud Base2(100ft)', 'Cloud Cover2(oct)', 'Cloud Base3(100ft)', 'Cloud Cover3(oct)', 'Cloud Base4(100ft)', 'Cloud Cover4(oct)', 'Cloud Base5(100ft)', 'Cloud Cover5(oct)', 'Lowest Cig(100ft)', 'Total Clouds(oct)', 'Max Icing Blw 10K', 'Sfc CAPE (J/kg)', 'Sfc CINH (J/kg)', 'Trop Height (m)', 'Trop Press (mb)', 'Trop Temp(K)', '1000-500 THKNS (m)', '1000-700 THKNS (m)', '1000-850 THKNS (m)', '850-700 THKNS (m)', '850-500 THKNS (m)', '0C Height (m)', 'Freezing Level (m)', 'Freezing Press(mb)', '-20C Height (m)', '-20C Pressure(mb)', 'Wet-Bulb Zero (m)', 'Prob FZRA (%)', 'Prob PL (%)', 'Prob MIX (%)', 'Prob SN (%)', 'Prob RA (%)', 'Prob RASN (%)', 'Prob Any Precip(%)', 'TSTM Flag (WRF)', 'MU Level (mb)', 'MU Temperature (K)', 'Parcel Temp (K)', 'MU Height (m)', 'ML CAPE (J/kg)', 'ML CINH (J/kg)', 'MU CAPE (J/kg)', 'MU CINH (J/kg)', 'DCAPE (J/kg)', 'MU-LCL Temp (K)', 'MU-LCL Press (mb)', 'MU-LCL Height (m)', 'MU-LCL P-Temp (K)', 'MU LFC (m)', 'MU LFC Prs (mb)', 'MU LFC Tmp(K)', 'MU EQ LEVEL (m)', 'MU EQ LVL Prs(mb)', 'MU EQ LVL Tmp(K)', 'Max Parcel Hgt (m)', 'Max Parcel Prs(mb)', 'Max Parcel Tmp (K)', 'Lightning Prob (%)', 'MU LI (K)', 'MU TTI (K)', 'MU KI (K)', 'SSI (K)', 'MU KO (K)', 'MU THI (K)', 'Lid Strength (K)', 'Cap Break (%)', 'TSTM Prob (%)', 'FM Hail Index (in)', 'RAM Hail Index(in)', 'VIL-D Hail (in)', 'Sig Hail Parameter', 'Max Hail Size (in)', 'Hail Size (in)', 'Tornado Prob (%)', 'Conv Gust Spd(kt)', 'T1 Gust Index (kt)', 'T2 Gust Index (kt)', 'WINDEX (kt)', 'WMSI-MDPI (kt)', 'Snyder Gusts (kt)', 'VIL-D Gusts (kt)', '0-1KM SRH (m2/s2)', '0-2KM SRH (m2/s2)', '0-3KM SRH (m2/s2)', 'EFF SRH (m2/s2)', '6KM SHEAR (m/s)', 'Sig Torn Parameter', '0-4KM VGP', '0-1KM EHI', 'BRN', 'Moist Cnv(g/kg/hr)', 'ThetaE Adv (K/hr)', 'UL Div (1/s)', 'SWEAT Index', 'Dry Microburst', '1000mb  GPH (m)', '1000mb  GPH DVal(m)', '1000mb  Temp (K)', '1000mb  Temp DVal(K)', '1000mb  Dewpt (K)', '1000mb  RH (%)', '1000mb  Parcel Temp', '1000mb  Theta-E (K)', '1000mb  Dir', '1000mb  Speed(kt)', '1000mb  Clouds(%)', '1000mb  FL-Vis (sm)', '1000mb  Mixing Ratio', '1000mb  CWMR (g/kg)', '1000mb  Icing Type', '1000mb  Turbulence', '1000mb  VVS (-ub/s)', '975mb  GPH (m)', '975mb  GPH DVal(m)', '975mb  Temp (K)', '975mb  Temp DVal(K)', '975mb  Dewpt (K)', '975mb  RH (%)', '975mb  Parcel Temp', '975mb  Theta-E (K)', '975mb  Dir', '975mb  Speed(kt)', '975mb  Clouds(%)', '975mb  FL-Vis (sm)', '975mb  Mixing Ratio', '975mb  CWMR (g/kg)', '975mb  Icing Type', '975mb  Turbulence', '975mb  VVS (-ub/s)', '950mb  GPH (m)', '950mb  GPH DVal(m)', '950mb  Temp (K)', '950mb  Temp DVal(K)', '950mb  Dewpt (K)', '950mb  RH (%)', '950mb  Parcel Temp', '950mb  Theta-E (K)', '950mb  Dir', '950mb  Speed(kt)', '950mb  Clouds(%)', '950mb  FL-Vis (sm)', '950mb  Mixing Ratio', '950mb  CWMR (g/kg)', '950mb  Icing Type', '950mb  Turbulence', '950mb  VVS (-ub/s)', '925mb  GPH (m)', '925mb  GPH DVal(m)', '925mb  Temp (K)', '925mb  Temp DVal(K)', '925mb  Dewpt (K)', '925mb  RH (%)', '925mb  Parcel Temp', '925mb  Theta-E (K)', '925mb  Dir', '925mb  Speed(kt)', '925mb  Clouds(%)', '925mb  FL-Vis (sm)', '925mb  Mixing Ratio', '925mb  CWMR (g/kg)', '925mb  Icing Type', '925mb  Turbulence', '925mb  VVS (-ub/s)', '900mb  GPH (m)', '900mb  GPH DVal(m)', '900mb  Temp (K)', '900mb  Temp DVal(K)', '900mb  Dewpt (K)', '900mb  RH (%)', '900mb  Parcel Temp', '900mb  Theta-E (K)', '900mb  Dir', '900mb  Speed(kt)', '900mb  Clouds(%)', '900mb  FL-Vis (sm)', '900mb  Mixing Ratio', '900mb  CWMR (g/kg)', '900mb  Icing Type', '900mb  Turbulence', '900mb  VVS (-ub/s)', '875mb  GPH (m)', '875mb  GPH DVal(m)', '875mb  Temp (K)', '875mb  Temp DVal(K)', '875mb  Dewpt (K)', '875mb  RH (%)', '875mb  Parcel Temp', '875mb  Theta-E (K)', '875mb  Dir', '875mb  Speed(kt)', '875mb  Clouds(%)', '875mb  FL-Vis (sm)', '875mb  Mixing Ratio', '875mb  CWMR (g/kg)', '875mb  Icing Type', '875mb  Turbulence', '875mb  VVS (-ub/s)', '850mb  GPH (m)', '850mb  GPH DVal(m)', '850mb  Temp (K)', '850mb  Temp DVal(K)', '850mb  Dewpt (K)', '850mb  RH (%)', '850mb  Parcel Temp', '850mb  Theta-E (K)', '850mb  Dir', '850mb  Speed(kt)', '850mb  Clouds(%)', '850mb  FL-Vis (sm)', '850mb  Mixing Ratio', '850mb  CWMR (g/kg)', '850mb  Icing Type', '850mb  Turbulence', '850mb  VVS (-ub/s)', '825mb  GPH (m)', '825mb  GPH DVal(m)', '825mb  Temp (K)', '825mb  Temp DVal(K)', '825mb  Dewpt (K)', '825mb  RH (%)', '825mb  Parcel Temp', '825mb  Theta-E (K)', '825mb  Dir', '825mb  Speed(kt)', '825mb  Clouds(%)', '825mb  FL-Vis (sm)', '825mb  Mixing Ratio', '825mb  CWMR (g/kg)', '825mb  Icing Type', '825mb  Turbulence', '825mb  VVS (-ub/s)', '800mb  GPH (m)', '800mb  GPH DVal(m)', '800mb  Temp (K)', '800mb  Temp DVal(K)', '800mb  Dewpt (K)', '800mb  RH (%)', '800mb  Parcel Temp', '800mb  Theta-E (K)', '800mb  Dir', '800mb  Speed(kt)', '800mb  Clouds(%)', '800mb  FL-Vis (sm)', '800mb  Mixing Ratio', '800mb  CWMR (g/kg)', '800mb  Icing Type', '800mb  Turbulence', '800mb  VVS (-ub/s)', '775mb  GPH (m)', '775mb  GPH DVal(m)', '775mb  Temp (K)', '775mb  Temp DVal(K)', '775mb  Dewpt (K)', '775mb  RH (%)', '775mb  Parcel Temp', '775mb  Theta-E (K)', '775mb  Dir', '775mb  Speed(kt)', '775mb  Clouds(%)', '775mb  FL-Vis (sm)', '775mb  Mixing Ratio', '775mb  CWMR (g/kg)', '775mb  Icing Type', '775mb  Turbulence', '775mb  VVS (-ub/s)', '750mb  GPH (m)', '750mb  GPH DVal(m)', '750mb  Temp (K)', '750mb  Temp DVal(K)', '750mb  Dewpt (K)', '750mb  RH (%)', '750mb  Parcel Temp', '750mb  Theta-E (K)', '750mb  Dir', '750mb  Speed(kt)', '750mb  Clouds(%)', '750mb  FL-Vis (sm)', '750mb  Mixing Ratio', '750mb  CWMR (g/kg)', '750mb  Icing Type', '750mb  Turbulence', '750mb  VVS (-ub/s)', '725mb  GPH (m)', '725mb  GPH DVal(m)', '725mb  Temp (K)', '725mb  Temp DVal(K)', '725mb  Dewpt (K)', '725mb  RH (%)', '725mb  Parcel Temp', '725mb  Theta-E (K)', '725mb  Dir', '725mb  Speed(kt)', '725mb  Clouds(%)', '725mb  FL-Vis (sm)', '725mb  Mixing Ratio', '725mb  CWMR (g/kg)', '725mb  Icing Type', '725mb  Turbulence', '725mb  VVS (-ub/s)', '700mb  GPH (m)', '700mb  GPH DVal(m)', '700mb  Temp (K)', '700mb  Temp DVal(K)', '700mb  Dewpt (K)', '700mb  RH (%)', '700mb  Parcel Temp', '700mb  Theta-E (K)', '700mb  Dir', '700mb  Speed(kt)', '700mb  Clouds(%)', '700mb  FL-Vis (sm)', '700mb  Mixing Ratio', '700mb  CWMR (g/kg)', '700mb  Icing Type', '700mb  Turbulence', '700mb  VVS (-ub/s)', '675mb  GPH (m)', '675mb  GPH DVal(m)', '675mb  Temp (K)', '675mb  Temp DVal(K)', '675mb  Dewpt (K)', '675mb  RH (%)', '675mb  Parcel Temp', '675mb  Theta-E (K)', '675mb  Dir', '675mb  Speed(kt)', '675mb  Clouds(%)', '675mb  FL-Vis (sm)', '675mb  Mixing Ratio', '675mb  CWMR (g/kg)', '675mb  Icing Type', '675mb  Turbulence', '675mb  VVS (-ub/s)', '650mb  GPH (m)', '650mb  GPH DVal(m)', '650mb  Temp (K)', '650mb  Temp DVal(K)', '650mb  Dewpt (K)', '650mb  RH (%)', '650mb  Parcel Temp', '650mb  Theta-E (K)', '650mb  Dir', '650mb  Speed(kt)', '650mb  Clouds(%)', '650mb  FL-Vis (sm)', '650mb  Mixing Ratio', '650mb  CWMR (g/kg)', '650mb  Icing Type', '650mb  Turbulence', '650mb  VVS (-ub/s)', '625mb  GPH (m)', '625mb  GPH DVal(m)', '625mb  Temp (K)', '625mb  Temp DVal(K)', '625mb  Dewpt (K)', '625mb  RH (%)', '625mb  Parcel Temp', '625mb  Theta-E (K)', '625mb  Dir', '625mb  Speed(kt)', '625mb  Clouds(%)', '625mb  FL-Vis (sm)', '625mb  Mixing Ratio', '625mb  CWMR (g/kg)', '625mb  Icing Type', '625mb  Turbulence', '625mb  VVS (-ub/s)', '600mb  GPH (m)', '600mb  GPH DVal(m)', '600mb  Temp (K)', '600mb  Temp DVal(K)', '600mb  Dewpt (K)', '600mb  RH (%)', '600mb  Parcel Temp', '600mb  Theta-E (K)', '600mb  Dir', '600mb  Speed(kt)', '600mb  Clouds(%)', '600mb  FL-Vis (sm)', '600mb  Mixing Ratio', '600mb  CWMR (g/kg)', '600mb  Icing Type', '600mb  Turbulence', '600mb  VVS (-ub/s)', '575mb  GPH (m)', '575mb  GPH DVal(m)', '575mb  Temp (K)', '575mb  Temp DVal(K)', '575mb  Dewpt (K)', '575mb  RH (%)', '575mb  Parcel Temp', '575mb  Theta-E (K)', '575mb  Dir', '575mb  Speed(kt)', '575mb  Clouds(%)', '575mb  FL-Vis (sm)', '575mb  Mixing Ratio', '575mb  CWMR (g/kg)', '575mb  Icing Type', '575mb  Turbulence', '575mb  VVS (-ub/s)', '550mb  GPH (m)', '550mb  GPH DVal(m)', '550mb  Temp (K)', '550mb  Temp DVal(K)', '550mb  Dewpt (K)', '550mb  RH (%)', '550mb  Parcel Temp', '550mb  Theta-E (K)', '550mb  Dir', '550mb  Speed(kt)', '550mb  Clouds(%)', '550mb  FL-Vis (sm)', '550mb  Mixing Ratio', '550mb  CWMR (g/kg)', '550mb  Icing Type', '550mb  Turbulence', '550mb  VVS (-ub/s)', '525mb  GPH (m)', '525mb  GPH DVal(m)', '525mb  Temp (K)', '525mb  Temp DVal(K)', '525mb  Dewpt (K)', '525mb  RH (%)', '525mb  Parcel Temp', '525mb  Theta-E (K)', '525mb  Dir', '525mb  Speed(kt)', '525mb  Clouds(%)', '525mb  FL-Vis (sm)', '525mb  Mixing Ratio', '525mb  CWMR (g/kg)', '525mb  Icing Type', '525mb  Turbulence', '525mb  VVS (-ub/s)', '500mb  GPH (m)', '500mb  GPH DVal(m)', '500mb  Temp (K)', '500mb  Temp DVal(K)', '500mb  Dewpt (K)', '500mb  RH (%)', '500mb  Parcel Temp', '500mb  Theta-E (K)', '500mb  Dir', '500mb  Speed(kt)', '500mb  Clouds(%)', '500mb  FL-Vis (sm)', '500mb  Mixing Ratio', '500mb  CWMR (g/kg)', '500mb  Icing Type', '500mb  Turbulence', '500mb  VVS (-ub/s)', '475mb  GPH (m)', '475mb  GPH DVal(m)', '475mb  Temp (K)', '475mb  Temp DVal(K)', '475mb  Dewpt (K)', '475mb  RH (%)', '475mb  Parcel Temp', '475mb  Theta-E (K)', '475mb  Dir', '475mb  Speed(kt)', '475mb  Clouds(%)', '475mb  FL-Vis (sm)', '475mb  Mixing Ratio', '475mb  CWMR (g/kg)', '475mb  Icing Type', '475mb  Turbulence', '475mb  VVS (-ub/s)', '450mb  GPH (m)', '450mb  GPH DVal(m)', '450mb  Temp (K)', '450mb  Temp DVal(K)', '450mb  Dewpt (K)', '450mb  RH (%)', '450mb  Parcel Temp', '450mb  Theta-E (K)', '450mb  Dir', '450mb  Speed(kt)', '450mb  Clouds(%)', '450mb  FL-Vis (sm)', '450mb  Mixing Ratio', '450mb  CWMR (g/kg)', '450mb  Icing Type', '450mb  Turbulence', '450mb  VVS (-ub/s)', '425mb  GPH (m)', '425mb  GPH DVal(m)', '425mb  Temp (K)', '425mb  Temp DVal(K)', '425mb  Dewpt (K)', '425mb  RH (%)', '425mb  Parcel Temp', '425mb  Theta-E (K)', '425mb  Dir', '425mb  Speed(kt)', '425mb  Clouds(%)', '425mb  FL-Vis (sm)', '425mb  Mixing Ratio', '425mb  CWMR (g/kg)', '425mb  Icing Type', '425mb  Turbulence', '425mb  VVS (-ub/s)', '400mb  GPH (m)', '400mb  GPH DVal(m)', '400mb  Temp (K)', '400mb  Temp DVal(K)', '400mb  Dewpt (K)', '400mb  RH (%)', '400mb  Parcel Temp', '400mb  Theta-E (K)', '400mb  Dir', '400mb  Speed(kt)', '400mb  Clouds(%)', '400mb  FL-Vis (sm)', '400mb  Mixing Ratio', '400mb  CWMR (g/kg)', '400mb  Icing Type', '400mb  Turbulence', '400mb  VVS (-ub/s)', '375mb  GPH (m)', '375mb  GPH DVal(m)', '375mb  Temp (K)', '375mb  Temp DVal(K)', '375mb  Dewpt (K)', '375mb  RH (%)', '375mb  Parcel Temp', '375mb  Theta-E (K)', '375mb  Dir', '375mb  Speed(kt)', '375mb  Clouds(%)', '375mb  FL-Vis (sm)', '375mb  Mixing Ratio', '375mb  CWMR (g/kg)', '375mb  Icing Type', '375mb  Turbulence', '375mb  VVS (-ub/s)', '350mb  GPH (m)', '350mb  GPH DVal(m)', '350mb  Temp (K)', '350mb  Temp DVal(K)', '350mb  Dewpt (K)', '350mb  RH (%)', '350mb  Parcel Temp', '350mb  Theta-E (K)', '350mb  Dir', '350mb  Speed(kt)', '350mb  Clouds(%)', '350mb  FL-Vis (sm)', '350mb  Mixing Ratio', '350mb  CWMR (g/kg)', '350mb  Icing Type', '350mb  Turbulence', '350mb  VVS (-ub/s)', '325mb  GPH (m)', '325mb  GPH DVal(m)', '325mb  Temp (K)', '325mb  Temp DVal(K)', '325mb  Dewpt (K)', '325mb  RH (%)', '325mb  Parcel Temp', '325mb  Theta-E (K)', '325mb  Dir', '325mb  Speed(kt)', '325mb  Clouds(%)', '325mb  FL-Vis (sm)', '325mb  Mixing Ratio', '325mb  CWMR (g/kg)', '325mb  Icing Type', '325mb  Turbulence', '325mb  VVS (-ub/s)', '300mb  GPH (m)', '300mb  GPH DVal(m)', '300mb  Temp (K)', '300mb  Temp DVal(K)', '300mb  Dewpt (K)', '300mb  RH (%)', '300mb  Parcel Temp', '300mb  Theta-E (K)', '300mb  Dir', '300mb  Speed(kt)', '300mb  Clouds(%)', '300mb  FL-Vis (sm)', '300mb  Mixing Ratio', '300mb  CWMR (g/kg)', '300mb  Icing Type', '300mb  Turbulence', '300mb  VVS (-ub/s)', '275mb  GPH (m)', '275mb  GPH DVal(m)', '275mb  Temp (K)', '275mb  Temp DVal(K)', '275mb  Dewpt (K)', '275mb  RH (%)', '275mb  Parcel Temp', '275mb  Theta-E (K)', '275mb  Dir', '275mb  Speed(kt)', '275mb  Clouds(%)', '275mb  FL-Vis (sm)', '275mb  Mixing Ratio', '275mb  CWMR (g/kg)', '275mb  Icing Type', '275mb  Turbulence', '275mb  VVS (-ub/s)', '250mb  GPH (m)', '250mb  GPH DVal(m)', '250mb  Temp (K)', '250mb  Temp DVal(K)', '250mb  Dewpt (K)', '250mb  RH (%)', '250mb  Parcel Temp', '250mb  Theta-E (K)', '250mb  Dir', '250mb  Speed(kt)', '250mb  Clouds(%)', '250mb  FL-Vis (sm)', '250mb  Mixing Ratio', '250mb  CWMR (g/kg)', '250mb  Icing Type', '250mb  Turbulence', '250mb  VVS (-ub/s)', '225mb  GPH (m)', '225mb  GPH DVal(m)', '225mb  Temp (K)', '225mb  Temp DVal(K)', '225mb  Dewpt (K)', '225mb  RH (%)', '225mb  Parcel Temp', '225mb  Theta-E (K)', '225mb  Dir', '225mb  Speed(kt)', '225mb  Clouds(%)', '225mb  FL-Vis (sm)', '225mb  Mixing Ratio', '225mb  CWMR (g/kg)', '225mb  Icing Type', '225mb  Turbulence', '225mb  VVS (-ub/s)', '200mb  GPH (m)', '200mb  GPH DVal(m)', '200mb  Temp (K)', '200mb  Temp DVal(K)', '200mb  Dewpt (K)', '200mb  RH (%)', '200mb  Parcel Temp', '200mb  Theta-E (K)', '200mb  Dir', '200mb  Speed(kt)', '200mb  Clouds(%)', '200mb  FL-Vis (sm)', '200mb  Mixing Ratio', '200mb  CWMR (g/kg)', '200mb  Icing Type', '200mb  Turbulence', '200mb  VVS (-ub/s)', '175mb  GPH (m)', '175mb  GPH DVal(m)', '175mb  Temp (K)', '175mb  Temp DVal(K)', '175mb  Dewpt (K)', '175mb  RH (%)', '175mb  Parcel Temp', '175mb  Theta-E (K)', '175mb  Dir', '175mb  Speed(kt)', '175mb  Clouds(%)', '175mb  FL-Vis (sm)', '175mb  Mixing Ratio', '175mb  CWMR (g/kg)', '175mb  Icing Type', '175mb  Turbulence', '175mb  VVS (-ub/s)', '150mb  GPH (m)', '150mb  GPH DVal(m)', '150mb  Temp (K)', '150mb  Temp DVal(K)', '150mb  Dewpt (K)', '150mb  RH (%)', '150mb  Parcel Temp', '150mb  Theta-E (K)', '150mb  Dir', '150mb  Speed(kt)', '150mb  Clouds(%)', '150mb  FL-Vis (sm)', '150mb  Mixing Ratio', '150mb  CWMR (g/kg)', '150mb  Icing Type', '150mb  Turbulence', '150mb  VVS (-ub/s)', '125mb  GPH (m)', '125mb  GPH DVal(m)', '125mb  Temp (K)', '125mb  Temp DVal(K)', '125mb  Dewpt (K)', '125mb  RH (%)', '125mb  Parcel Temp', '125mb  Theta-E (K)', '125mb  Dir', '125mb  Speed(kt)', '125mb  Clouds(%)', '125mb  FL-Vis (sm)', '125mb  Mixing Ratio', '125mb  CWMR (g/kg)', '125mb  Icing Type', '125mb  Turbulence', '125mb  VVS (-ub/s)', '100mb  GPH (m)', '100mb  GPH DVal(m)', '100mb  Temp (K)', '100mb  Temp DVal(K)', '100mb  Dewpt (K)', '100mb  RH (%)', '100mb  Parcel Temp', '100mb  Theta-E (K)', '100mb  Dir', '100mb  Speed(kt)', '100mb  Clouds(%)', '100mb  FL-Vis (sm)', '100mb  Mixing Ratio', '100mb  CWMR (g/kg)', '100mb  Icing Type', '100mb  Turbulence', '100mb  VVS (-ub/s)', '75mb  GPH (m)', '75mb  GPH DVal(m)', '75mb  Temp (K)', '75mb  Temp DVal(K)', '75mb  Dewpt (K)', '75mb  RH (%)', '75mb  Parcel Temp', '75mb  Theta-E (K)', '75mb  Dir', '75mb  Speed(kt)', '75mb  Clouds(%)', '75mb  FL-Vis (sm)', '75mb  Mixing Ratio', '75mb  CWMR (g/kg)', '75mb  Icing Type', '75mb  Turbulence', '75mb  VVS (-ub/s)', '50mb  GPH (m)', '50mb  GPH DVal(m)', '50mb  Temp (K)', '50mb  Temp DVal(K)', '50mb  Dewpt (K)', '50mb  RH (%)', '50mb  Parcel Temp', '50mb  Theta-E (K)', '50mb  Dir', '50mb  Speed(kt)', '50mb  Clouds(%)', '50mb  FL-Vis (sm)', '50mb  Mixing Ratio', '50mb  CWMR (g/kg)', '50mb  Icing Type', '50mb  Turbulence', '50mb  VVS (-ub/s)')

main.py

import re
from typing import Iterable, Union
import pandas as pd

indexs=...


def make_index_tuples() -> Iterable[tuple[str, str, Union[str, None]]]:
    pattern = r"""
            (?:(\d{2,4}mb)\s+)?   # capture group 1: match level if any
            ([A-Za-z0-9\s-]*)     # capture group 2: match parameter between
            (?:\s\(|\((.*)\))?    # capture group 3: matching anything between(UNIT) if any
            """
    # sometimes there is a space between the parameter and unit sometimes not
    for index in indexs:
        level, param, unit = re.search(pattern, index, re.VERBOSE).groups()
        if level is None:
            level = "surface"

        param = param.strip().replace(" ", "_").lower()

        yield level, param, unit

def start():
    df_index = pd.MultiIndex.from_tuples(
            tuple(make_index_tuples()),
            names=("level", "parameter", "unit"),
        )

if __name__ == "__main__":
    start()


results

MultiIndex([('surface',        'sfc_prs',     'mb'),
            ('surface',       'mean_slp',     'mb'),
            ('surface',      'altimeter', 'in. Hg'),
            ('surface',      'press_alt',     'ft'),
            ('surface',    'density_alt',     'ft'),
            ('surface',    '2_m_agl_tmp',      'K'),
            ('surface', '2_m_agl_temp-d',      'K'),
            ('surface',    '2_m_agl_dpt',      'K'),
            ('surface',    '2_m_agl_wbt',      'K'),
            ('surface',        'convect',      nan),
            ...
            (   '50mb',        'theta-e',      'K'),
            (   '50mb',            'dir',      nan),
            (   '50mb',          'speed',     'kt'),
            (   '50mb',         'clouds',      '%'),
            (   '50mb',         'fl-vis',     'sm'),
            (   '50mb',   'mixing_ratio',      nan),
            (   '50mb',           'cwmr',   'g/kg'),
            (   '50mb',     'icing_type',      nan),
            (   '50mb',     'turbulence',      nan),
            (   '50mb',            'vvs',  '-ub/s')],
           names=['level', 'parameter', 'unit'], length=805)
\$\endgroup\$
3
  • 1
    \$\begingroup\$ Separating the level and parameter into a multi index is an excellent idea. Separating the unit is not. The unit is closely tied with the parameter and should not be separated. \$\endgroup\$
    – Reinderien
    Apr 24 at 15:25
  • 1
    \$\begingroup\$ The unit gets set as a column, purpose being to mask the DataFrame for example df[df.unit =="K"] and convert all Kelvin values to Celsius \$\endgroup\$ Apr 24 at 15:38
  • 1
    \$\begingroup\$ Fine, but then the unit shouldn't land in the index. \$\endgroup\$
    – Reinderien
    Apr 24 at 15:42

1 Answer 1

2
\$\begingroup\$

indexs should be spelled indices.

Your implementation is non-vectorised and should make use of the Pandas str.extract function, which is perfectly suited to this task.

I think your parameter section of the regex is a little too strict, and can basically match anything that isn't a paren.

You should be using named capturing groups.

You say:

sometimes there is a space between the parameter and unit sometimes not

So then why is there an unconditional \s at the beginning of your third group?

level is a real number, perhaps a millibar differential quantity inferring the elevation. So don't write surface! Write 0.

Only the first two columns should be made part of a multi-index.

Suggested

import re
import pandas as pd

INDEX_PAT = re.compile(
    r"""
        ^                        # start
        (?:                      # non-capture: optional level wrapper
            (?P<level>\d+)       # capture: level 
            mb\s+                # strip millibar suffix
        )?   
        (?P<param>[^()]*?)       # capture: parameter, non-parens, lazy
        (?:                      # non-capture: optional unit wrapper
            \s*                  # greedy whitespace from previous field
            \(
                (?P<unit>        # capture: unit
                    [^()]+?      # non-parens, lazy
                )
            \)
        )?
        $                        # end
        (?x)                     # verbose
    """
)


def parse_indices(strings: pd.Series) -> pd.DataFrame:
    df = strings.str.extract(INDEX_PAT)
    df.level = df.level.fillna(0).astype(int)
    return df


if __name__ == "__main__":
    print(parse_indices(pd.DataFrame(indices)[0]))

Output

     level         param    unit
0        0       Sfc Prs      mb
1        0      Mean SLP      mb
2        0     Altimeter  in. Hg
3        0     Press Alt      ft
4        0   Density Alt      ft
..     ...           ...     ...
800     50  Mixing Ratio     NaN
801     50          CWMR    g/kg
802     50    Icing Type     NaN
803     50    Turbulence     NaN
804     50           VVS   -ub/s

[805 rows x 3 columns]
\$\endgroup\$
2
  • \$\begingroup\$ So then why is there an unconditional \s at the beginning of your third group? A mistake on my behalf, still learning (?:\s\(|\((.*)\))? I guess I assumed that equated \s\( or \(. \$\endgroup\$ Apr 28 at 0:43
  • \$\begingroup\$ On a related note. I'm working on some more complex regex to tokenize more complicated patterns. My coworker insist using a PEG. The string data I'm talking about is a TAF. TAF format and units vary by station. For example... KSYR 280016Z 2800/2824 29012G22KT P6SM SCT025 OVC040 TEMPO 2800/2802 30014G25KT P6SM -RASN OVC025 FM281500 31013G23KT P6SM SCT040 FM281900 31016G28KT P6SM SKC \$\endgroup\$ Apr 28 at 0:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.