<s> """<STR_LIT>""" <EOL> import os <EOL> import warnings <EOL> import pyart <EOL> import numpy as np <EOL> from numpy . testing . decorators import skipif <EOL> try : <EOL> import cvxopt <EOL> cvxopt_available = True <EOL> except ImportError : <EOL> cvxopt_available = False <EOL> try : <EOL> import glpk <EOL> glpk_available = True <EOL> except ImportError : <EOL> glpk_available = False <EOL> try : <EOL> import cylp . cy <EOL> cylp_available = True <EOL> except ImportError : <EOL> cylp_available = False <EOL> PATH = os . path . dirname ( __file__ ) <EOL> REFERENCE_RAYS_FILE = os . path . join ( PATH , '<STR_LIT>' ) <EOL> @ skipif ( not glpk_available ) <EOL> def test_phase_proc_lp_glpk ( ) : <EOL> radar , phidp , kdp = perform_phase_processing ( ) <EOL> ref = np . load ( REFERENCE_RAYS_FILE ) <EOL> assert _ratio ( ref [ '<STR_LIT>' ] , phidp [ '<STR_LIT:data>' ] ) <= <NUM_LIT> <EOL> assert _ratio ( ref [ '<STR_LIT>' ] , kdp [ '<STR_LIT:data>' ] ) <= <NUM_LIT> <EOL> assert _ratio ( ref [ '<STR_LIT>' ] , <EOL> radar . fields [ '<STR_LIT>' ] [ '<STR_LIT:data>' ] ) <= <NUM_LIT> <EOL> @ skipif ( not cvxopt_available ) <EOL> def test_phase_proc_lp_cvxopt ( ) : <EOL> from cvxopt import solvers <EOL> solvers . options [ '<STR_LIT>' ] = <NUM_LIT:0> <EOL> radar , phidp , kdp = perform_phase_processing ( '<STR_LIT>' ) <EOL> ref = np . load ( REFERENCE_RAYS_FILE ) <EOL> assert _ratio ( ref [ '<STR_LIT>' ] , phidp [ '<STR_LIT:data>' ] ) <= <NUM_LIT> <EOL> assert _ratio ( ref [ '<STR_LIT>' ] , kdp [ '<STR_LIT:data>' ] ) <= <NUM_LIT> <EOL> assert _ratio ( ref [ '<STR_LIT>' ] , <EOL> radar . fields [ '<STR_LIT>' ] [ '<STR_LIT:data>' ] ) <= <NUM_LIT> <EOL> @ skipif ( not cylp_available ) <EOL> def test_phase_proc_lp_cylp ( ) : <EOL> with warnings . catch_warnings ( ) : <EOL> warnings . simplefilter ( "<STR_LIT:ignore>" , category = FutureWarning ) <EOL> radar , phidp , kdp = perform_phase_processing ( '<STR_LIT>' ) <EOL> ref = np . load ( REFERENCE_RAYS_FILE ) <EOL> assert _ratio ( ref [ '<STR_LIT>' ] , phidp [ '<STR_LIT:data>' ] ) <= <NUM_LIT> <EOL> assert _ratio ( ref [ '<STR_LIT>' ] , kdp [ '<STR_LIT:data>' ] ) <= <NUM_LIT> <EOL> assert _ratio ( ref [ '<STR_LIT>' ] , <EOL> radar . fields [ '<STR_LIT>' ] [ '<STR_LIT:data>' ] ) <= <NUM_LIT> <EOL> @ skipif ( not cylp_available ) <EOL> def test_phase_proc_lp_cylp_mp ( ) : <EOL> with warnings . catch_warnings ( ) : <EOL> warnings . simplefilter ( "<STR_LIT:ignore>" , category = FutureWarning ) <EOL> radar , phidp , kdp = perform_phase_processing ( '<STR_LIT>' ) <EOL> ref = np . load ( REFERENCE_RAYS_FILE ) <EOL> assert _ratio ( ref [ '<STR_LIT>' ] , phidp [ '<STR_LIT:data>' ] ) <= <NUM_LIT> <EOL> assert _ratio ( ref [ '<STR_LIT>' ] , kdp [ '<STR_LIT:data>' ] ) <= <NUM_LIT> <EOL> assert _ratio ( ref [ '<STR_LIT>' ] , <EOL> radar . fields [ '<STR_LIT>' ] [ '<STR_LIT:data>' ] ) <= <NUM_LIT> <EOL> def _ratio ( a1 , a2 ) : <EOL> """<STR_LIT>""" <EOL> abs_residues = np . abs ( a1 - a2 ) . sum ( ) <EOL> avg_abs_sum = <NUM_LIT:0.5> * np . abs ( a1 ) . sum ( ) + <NUM_LIT:0.5> * np . abs ( a2 ) . sum ( ) <EOL> return abs_residues / avg_abs_sum <EOL> def perform_phase_processing ( LP_solver = '<STR_LIT>' ) : <EOL> """<STR_LIT>""" <EOL> radar = pyart . testing . make_single_ray_radar ( ) <EOL> phidp , kdp = pyart . correct . phase_proc_lp ( radar , <NUM_LIT:0.0> , LP_solver = LP_solver ) <EOL> return radar , phidp , kdp <EOL> def save_reference_rays ( radar , phidp , kdp ) : <EOL> """<STR_LIT>""" <EOL> unfolded = radar . fields [ '<STR_LIT>' ] <EOL> np . savez ( <EOL> REFERENCE_RAYS_FILE , <EOL> reference_phidp = phidp [ '<STR_LIT:data>' ] , <EOL> reference_kdp = kdp [ '<STR_LIT:data>' ] , <EOL> reference_unfolded_phidp = unfolded [ '<STR_LIT:data>' ] ) <EOL> def make_plot ( range_km , unfolded_phidp , refl , phidp , kdp , filename ) : <EOL> """<STR_LIT>""" <EOL> from matplotlib import pyplot as plt <EOL> fig = plt . figure ( figsize = [ <NUM_LIT:10> , <NUM_LIT:5> ] ) <EOL> ax = fig . add_subplot ( <NUM_LIT> ) <EOL> p1 , = ax . plot ( range_km , phidp [ '<STR_LIT:data>' ] [ <NUM_LIT:0> ] , '<STR_LIT>' ) <EOL> p2 , = ax . plot ( range_km , unfolded_phidp [ '<STR_LIT:data>' ] [ <NUM_LIT:0> ] , '<STR_LIT>' ) <EOL> ax . set_ylim ( <NUM_LIT:0> , <NUM_LIT> ) <EOL> ax . set_ylabel ( '<STR_LIT>' ) <EOL> ax . set_xlabel ( '<STR_LIT>' ) <EOL> ax2 = ax . twinx ( ) <EOL> p3 , = ax2 . plot ( range_km , kdp [ '<STR_LIT:data>' ] [ <NUM_LIT:0> ] , '<STR_LIT>' ) <EOL> p4 , = ax2 . plot ( range_km , refl [ '<STR_LIT:data>' ] [ <NUM_LIT:0> ] / <NUM_LIT> ) <EOL> ax2 . yaxis . grid ( color = '<STR_LIT>' , linestyle = '<STR_LIT>' ) <EOL> ax . legend ( [ p1 , p2 , p3 , p4 ] , <EOL> [ "<STR_LIT>" , "<STR_LIT>" , '<STR_LIT>' , '<STR_LIT>' ] , <EOL> loc = '<STR_LIT>' ) <EOL> fig . savefig ( filename ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> import sys <EOL> radar , phidp , kdp = perform_phase_processing ( ) <EOL> filename = '<STR_LIT>' <EOL> if sys . argv [ - <NUM_LIT:1> ] == '<STR_LIT>' : <EOL> save_reference_rays ( radar , phidp , kdp ) <EOL> filename = '<STR_LIT>' <EOL> make_plot ( radar . range [ '<STR_LIT:data>' ] / <NUM_LIT> , <EOL> radar . fields [ '<STR_LIT>' ] , <EOL> radar . fields [ '<STR_LIT>' ] , <EOL> phidp , kdp , filename ) </s>
