From 9f0805acca3c4198a651051c5f17a348ed5936d4 Mon Sep 17 00:00:00 2001
From: tomrink <rink@ssec.wisc.edu>
Date: Wed, 3 Feb 2021 14:08:09 -0600
Subject: [PATCH] snapshot...

---
 modules/amv/intercompare.py | 33 ++++++++++++++++-----------------
 1 file changed, 16 insertions(+), 17 deletions(-)

diff --git a/modules/amv/intercompare.py b/modules/amv/intercompare.py
index e069729d..09142c48 100644
--- a/modules/amv/intercompare.py
+++ b/modules/amv/intercompare.py
@@ -79,13 +79,12 @@ def pireps(filename, lon_range=[-180, 180], lat_range=[-55, 55]):
                 continue
 
             # Flight level
-            f_i = report.find('/FL')
-            if f_i >= 0:
-                fl = report[f_i+3:]
-                ti = fl.find('/TP')
-                fl = fl[:ti]
-                fl = fl.rstrip()
-                fl = fl.lstrip()
+            so = re.search(FLT_LVL, report)
+            if so is None:
+                continue
+            else:
+                fl = so.group()
+                fl = (fl[3:].rstrip()).lstrip()
                 if fl.isnumeric():
                     fl = float(fl) * 100 * 0.3048  # conv flight level to meters
                 else:
@@ -94,27 +93,27 @@ def pireps(filename, lon_range=[-180, 180], lat_range=[-55, 55]):
             # Icing
             ii = report.find('/IC')
             if ii >= 0:
-                s = report[ii+3:]
-                ri = s.find('/RM')
+                ice_str = report[ii+3:]
+                ri = ice_str.find('/RM')
 
                 if ri >= 0:
-                    s = s[:ri]
+                    ice_str = ice_str[:ri]
                 else:
-                    ri = s.find(',')
+                    ri = ice_str.find(',')
                     if ri >= 0:
-                        s = s[:ri]
-                s = s.lstrip()
-                if s.find('N/A') >= 0:
+                        ice_str = ice_str[:ri]
+                ice_str = ice_str.lstrip()
+                if ice_str.find('N/A') >= 0:
                     continue
 
                 dto = datetime.datetime.strptime(toks[0], '%Y%m%d%H%M').replace(tzinfo=timezone.utc)
                 timestmp = dto.timestamp()
 
-                if len(re.findall(NO_ICE, s)) != 0:
+                if len(re.findall(NO_ICE, ice_str)) != 0:
                     no_ice_reports.append(cnt)
                 else:
                     ice_reports.append(cnt)
-                    so = re.search(ICE_LVL, s)
+                    so = re.search(ICE_LVL, ice_str)
                     if so is not None:
                         lvl_a, lvl_b = so.group().split('-')
                         if lvl_a.find('FL') >= 0:
@@ -126,7 +125,7 @@ def pireps(filename, lon_range=[-180, 180], lat_range=[-55, 55]):
 
                         fl = max(lvl_a, lvl_b)
 
-                reports.append(s)
+                reports.append(ice_str)
                 lats.append(lat)
                 lons.append(lon)
                 alts.append(fl)
-- 
GitLab