From 7e921f5f3430a16f900520d94441326323f30bc2 Mon Sep 17 00:00:00 2001
From: Philipp Griewank <philipp.griewank@uni-koeln.de>
Date: Fri, 18 Feb 2022 15:40:38 +0100
Subject: [PATCH] Added a new script file

The idea is to avoid to stuffing the da_functions file with lots of stuff that doesn't really belong there.
---
 misc_functions.py | 57 +++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 57 insertions(+)
 create mode 100644 misc_functions.py

diff --git a/misc_functions.py b/misc_functions.py
new file mode 100644
index 0000000..6e7cf63
--- /dev/null
+++ b/misc_functions.py
@@ -0,0 +1,57 @@
+#!/usr/bin/env python
+
+# This is a collection of functions that do not really fit in the model, data assimilation, or plot files. 
+
+import numpy as np
+
+def reflectance_simulator(h,h_c=0.5,window=7,clear_sky=0.3,cloud=0.9):
+    """
+    calculates the "reflectance" which is a fixed clear sky value where h is below h_c, and a cloud  value where h>h_c.
+    As a spatial averaging defined by window, with the total width over the averaging being 2*window+1
+    """
+    c_binary = h*0.0+clear_sky
+    c_binary[h>h_c]=cloud
+    nx =h.shape[0] 
+    index = np.arange(nx)
+    dim = len(h.shape)
+    cf= c_binary * 1.
+    if window>0 and dim==1:
+        for i in range(window):
+            cf += c_binary[(index-i) % nx]
+            cf += c_binary[(index+i) % nx]
+        
+    if window>0 and dim==2:
+        for i in range(window):
+            cf = cf+ c_binary[(index-i) % nx,:]
+            cf = cf+ c_binary[(index+i) % nx,:]
+    cf = cf/(1.+window*2)
+        
+    
+    return cf 
+
+
+def cloud_simulator(h,h_c=0.5,window=7):
+    """
+    First satelitite observation operator. everything above h_c is 1, below is zero, and than an averaging window is applied. The width is defined by window, with the total width over the averaging being 2*window+1.
+    
+    
+    """
+    c_binary = h*0.0
+    c_binary[h>h_c]=1.
+    nx =h.shape[0] 
+    index = np.arange(nx)
+    dim = len(h.shape)
+    cf= c_binary * 1.
+    if window>0 and dim==1:
+        for i in range(window):
+            cf += c_binary[(index-i) % nx]
+            cf += c_binary[(index+i) % nx]
+        
+    if window>0 and dim==2:
+        for i in range(window):
+            cf = cf+ c_binary[(index-i) % nx,:]
+            cf = cf+ c_binary[(index+i) % nx,:]
+    cf = cf/(1.+window*2)
+        
+    
+    return cf 
\ No newline at end of file
-- 
GitLab