backscatter_angle_sampleΒΆ

A sample.

Probably will be moved to script folder.

''' A sample.

Probably will be moved to script folder.
'''
import os
import sys
import logging
logging.basicConfig()
import datetime
import math

import matplotlib.pyplot as plt
from matplotlib.patches import Polygon
import numpy as np
import scipy as sp

from irfpy.cena import backscatter_angle

def main_backscatter_angle():

    # z functions
    fig = plt.figure()

    z0 = fig.add_subplot(411)
    z1 = fig.add_subplot(412)
    z2 = fig.add_subplot(413)
    z3 = fig.add_subplot(414)

    sza = np.linspace(0, 90, 90)

    z0.plot(sza, backscatter_angle.z0(sza))
    z1.plot(sza, backscatter_angle.z1(sza))
    z2.plot(sza, backscatter_angle.z2(sza))
    z3.plot(sza, backscatter_angle.z3(sza))

    # f vs theta (scza) at different sza.
    fig = plt.figure()
    ax = fig.add_subplot(111)
    theta_list = np.arange(0, 91, 10)
    sza_list = np.array([0, 15, 30, 45, 60, 75, 90])
    phi = 0  # For a typical value
    for sza in sza_list:
        f = backscatter_angle.fs(sza, phi, theta_list)
        ax.plot(theta_list, f, label='sza=%d' % sza)
    ax.legend()
    ax.set_title('fs vs theta at phi=0, sza=specified')

    # f vs phi at different sza
    fig = plt.figure()
    ax = fig.add_subplot(111)
    phi_list = np.arange(0, 361, 30)
    theta = 0.
    for sza in sza_list:
        f = backscatter_angle.fs(sza, phi_list, theta)
        ax.plot(phi_list, f, label='sza=%d' % sza)
    ax.legend()
    ax.set_title('fs vs phi at theta=%.1f, sza=specified' % theta)


    sza = 37.5  # to simulate 30-45 in the paper.

    fig = plt.figure()
    ax = fig.add_subplot(111)

    phi = np.linspace(0, 360, 25)[:-1] + 7.5
    theta = np.linspace(0, 90, 7)[:-1] + 7.5

    print(phi)
    print(theta)

    c0 = 0.0
    c1 = 0.012
#    c0 = -0.1
#    c1 = 0.1

    for p in phi:
        for t in theta:
            fpt = backscatter_angle.fs(sza, p, t)

            # To plot
            ps = np.array([p-7.5, p-7.5, p+7.5, p+7.5]) * np.pi / 180.
            ts = np.array([t-7.5, t+7.5, t+7.5, t-7.5])

            # Theta is the distance
            # Phi is the angle
            # x = theta sin(phi)
            # y = -theta cos(phi)
            x = ts * np.sin(ps)
            y = -ts * np.cos(ps)
            xy = np.array([x, y]).T
            clr = (fpt - c0) / (c1 - c0)
            print(p, t, fpt, clr)
            if clr < 0: clr = 0
            if clr > 1: clr = 1
            
            xypol = Polygon(xy, color='%.2f' % clr)

            ax.add_patch(xypol)

    ax.set_xlim(-100, 100)
    ax.set_ylim(-100, 100)
    ax.set_aspect(1)

            


if __name__ == '__main__':
    main_backscatter_angle()