From 32c3b6844d04601a2c53f375a0c68cc962ee88b4 Mon Sep 17 00:00:00 2001
From: tomrink <rink@ssec.wisc.edu>
Date: Sun, 14 Feb 2021 21:57:25 -0600
Subject: [PATCH] add inverse transforms

---
 modules/util/geos_nav.py | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)

diff --git a/modules/util/geos_nav.py b/modules/util/geos_nav.py
index a7217e8f..58e8dfa6 100644
--- a/modules/util/geos_nav.py
+++ b/modules/util/geos_nav.py
@@ -211,6 +211,31 @@ class GEOSNavigation:
 
         return geographic_lon, geographic_lat
 
+    def sat_to_earth(self, x, y):
+        if self.scan_geom == 'GOES':
+            x, y = goes_to_geos(x, y)
+
+        c1 = (h * np.cos(x) * np.cos(y)) * (h * np.cos(x) * np.cos(y))
+        c2 = (np.cos(y) * np.cos(y) + fp * np.sin(y) * np.sin(y)) * d
+
+        if c1 < c2:
+            return np.nan, np.nan
+
+        s_d = np.sqrt(c1 - c2)
+        s_n = (h * np.cos(x) * np.cos(y) - s_d) / (np.cos(y) * np.cos(y) + fp * np.sin(y) * np.sin(y))
+        s_1 = h - s_n * np.cos(x) * np.cos(y)
+        s_2 = s_n * np.sin(x) * np.cos(y)
+        s_3 = s_n * np.sin(y)
+        s_xy = np.sqrt(s_1 * s_1 + s_2 * s_2)
+
+        geographic_lon = np.arctan(s_2 / s_1) + self.sub_lon
+        geographic_lat = np.arctan(fp * (s_3 / s_xy))
+
+        geographic_lon *= RAD_TO_DEG
+        geographic_lat *= RAD_TO_DEG
+
+        return geographic_lon, geographic_lat
+
 # def compute_scale_offset(lon_a, lat_a, col_a, line_a, lon_b, lat_b, col_b, line_b):
 #     lamda_a, theta_a = earth_to_sat(lon_a, lat_a)
 #     lamda_b, theta_b = earth_to_sat(lon_b, lat_b)
-- 
GitLab