1818import pytz
1919import requests
2020
21+ from .plots .environment_plots import _EnvironmentPlots
2122from .prints .environment_prints import _EnvironmentPrints
2223
24+
2325try :
2426 import netCDF4
2527except ImportError :
@@ -401,6 +403,9 @@ def __init__(
401403 # Recalculate Earth Radius
402404 self .earthRadius = self .calculateEarthRadius (self .lat , self .datum ) # in m
403405
406+ # Initialize plots and prints object
407+ self .plots = _EnvironmentPlots (self )
408+
404409 return None
405410
406411 def setDate (self , date , timeZone = "UTC" ):
@@ -2865,53 +2870,7 @@ def info(self):
28652870
28662871 # Plot graphs
28672872 print ("\n \n Atmospheric Model Plots" )
2868- # Create height grid
2869- grid = np .linspace (self .elevation , self .maxExpectedHeight )
2870-
2871- # Create figure
2872- plt .figure (figsize = (9 , 4.5 ))
2873-
2874- # Create wind speed and wind direction subplot
2875- ax1 = plt .subplot (121 )
2876- ax1 .plot (
2877- [self .windSpeed (i ) for i in grid ], grid , "#ff7f0e" , label = "Speed of Sound"
2878- )
2879- ax1 .set_xlabel ("Wind Speed (m/s)" , color = "#ff7f0e" )
2880- ax1 .tick_params ("x" , colors = "#ff7f0e" )
2881- ax1up = ax1 .twiny ()
2882- ax1up .plot (
2883- [self .windDirection (i ) for i in grid ],
2884- grid ,
2885- color = "#1f77b4" ,
2886- label = "Density" ,
2887- )
2888- ax1up .set_xlabel ("Wind Direction (°)" , color = "#1f77b4" )
2889- ax1up .tick_params ("x" , colors = "#1f77b4" )
2890- ax1up .set_xlim (0 , 360 )
2891- ax1 .set_ylabel ("Height Above Sea Level (m)" )
2892- ax1 .grid (True )
2893-
2894- # Create density and speed of sound subplot
2895- ax2 = plt .subplot (122 )
2896- ax2 .plot (
2897- [self .speedOfSound (i ) for i in grid ],
2898- grid ,
2899- "#ff7f0e" ,
2900- label = "Speed of Sound" ,
2901- )
2902- ax2 .set_xlabel ("Speed of Sound (m/s)" , color = "#ff7f0e" )
2903- ax2 .tick_params ("x" , colors = "#ff7f0e" )
2904- ax2up = ax2 .twiny ()
2905- ax2up .plot (
2906- [self .density (i ) for i in grid ], grid , color = "#1f77b4" , label = "Density"
2907- )
2908- ax2up .set_xlabel ("Density (kg/m³)" , color = "#1f77b4" )
2909- ax2up .tick_params ("x" , colors = "#1f77b4" )
2910- ax2 .set_ylabel ("Height Above Sea Level (m)" )
2911- ax2 .grid (True )
2912-
2913- plt .subplots_adjust (wspace = 0.5 )
2914- plt .show ()
2873+ self .plots .atmospheric_model ()
29152874
29162875 def allInfo (self ):
29172876 """Prints out all data and graphs available about the Environment.
@@ -2928,165 +2887,7 @@ def allInfo(self):
29282887 self .prints .all ()
29292888
29302889 # Plot graphs
2931- print ("\n \n Atmospheric Model Plots" )
2932- # Create height grid
2933- grid = np .linspace (self .elevation , self .maxExpectedHeight )
2934-
2935- # Create figure
2936- plt .figure (figsize = (9 , 9 ))
2937-
2938- # Create wind speed and wind direction subplot
2939- ax1 = plt .subplot (221 )
2940- ax1 .plot (
2941- [self .windSpeed (i ) for i in grid ], grid , "#ff7f0e" , label = "Speed of Sound"
2942- )
2943- ax1 .set_xlabel ("Wind Speed (m/s)" , color = "#ff7f0e" )
2944- ax1 .tick_params ("x" , colors = "#ff7f0e" )
2945- ax1up = ax1 .twiny ()
2946- ax1up .plot (
2947- [self .windDirection (i ) for i in grid ],
2948- grid ,
2949- color = "#1f77b4" ,
2950- label = "Density" ,
2951- )
2952- ax1up .set_xlabel ("Wind Direction (°)" , color = "#1f77b4" )
2953- ax1up .tick_params ("x" , colors = "#1f77b4" )
2954- ax1up .set_xlim (0 , 360 )
2955- ax1 .set_ylabel ("Height Above Sea Level (m)" )
2956- ax1 .grid (True )
2957-
2958- # Create density and speed of sound subplot
2959- ax2 = plt .subplot (222 )
2960- ax2 .plot (
2961- [self .speedOfSound (i ) for i in grid ],
2962- grid ,
2963- "#ff7f0e" ,
2964- label = "Speed of Sound" ,
2965- )
2966- ax2 .set_xlabel ("Speed of Sound (m/s)" , color = "#ff7f0e" )
2967- ax2 .tick_params ("x" , colors = "#ff7f0e" )
2968- ax2up = ax2 .twiny ()
2969- ax2up .plot (
2970- [self .density (i ) for i in grid ], grid , color = "#1f77b4" , label = "Density"
2971- )
2972- ax2up .set_xlabel ("Density (kg/m³)" , color = "#1f77b4" )
2973- ax2up .tick_params ("x" , colors = "#1f77b4" )
2974- ax2 .set_ylabel ("Height Above Sea Level (m)" )
2975- ax2 .grid (True )
2976-
2977- # Create wind u and wind v subplot
2978- ax3 = plt .subplot (223 )
2979- ax3 .plot ([self .windVelocityX (i ) for i in grid ], grid , label = "Wind U" )
2980- ax3 .plot ([self .windVelocityY (i ) for i in grid ], grid , label = "Wind V" )
2981- ax3 .legend (loc = "best" ).set_draggable (True )
2982- ax3 .set_ylabel ("Height Above Sea Level (m)" )
2983- ax3 .set_xlabel ("Wind Speed (m/s)" )
2984- ax3 .grid (True )
2985-
2986- # Create pressure and temperature subplot
2987- ax4 = plt .subplot (224 )
2988- ax4 .plot (
2989- [self .pressure (i ) / 100 for i in grid ], grid , "#ff7f0e" , label = "Pressure"
2990- )
2991- ax4 .set_xlabel ("Pressure (hPa)" , color = "#ff7f0e" )
2992- ax4 .tick_params ("x" , colors = "#ff7f0e" )
2993- ax4up = ax4 .twiny ()
2994- ax4up .plot (
2995- [self .temperature (i ) for i in grid ],
2996- grid ,
2997- color = "#1f77b4" ,
2998- label = "Temperature" ,
2999- )
3000- ax4up .set_xlabel ("Temperature (K)" , color = "#1f77b4" )
3001- ax4up .tick_params ("x" , colors = "#1f77b4" )
3002- ax4 .set_ylabel ("Height Above Sea Level (m)" )
3003- ax4 .grid (True )
3004-
3005- plt .subplots_adjust (wspace = 0.5 , hspace = 0.3 )
3006- plt .show ()
3007-
3008- # Plot ensemble member comparison
3009- if self .atmosphericModelType != "Ensemble" :
3010- return None
3011-
3012- print ("\n \n Ensemble Members Comparison" )
3013- currentMember = self .ensembleMember
3014-
3015- # Create figure
3016- plt .figure (figsize = (9 , 13.5 ))
3017-
3018- # Create wind u subplot
3019- ax5 = plt .subplot (321 )
3020- for i in range (self .numEnsembleMembers ):
3021- self .selectEnsembleMember (i )
3022- ax5 .plot ([self .windVelocityX (i ) for i in grid ], grid , label = i )
3023- # ax5.legend(loc='best').set_draggable(True)
3024- ax5 .set_ylabel ("Height Above Sea Level (m)" )
3025- ax5 .set_xlabel ("Wind Speed (m/s)" )
3026- ax5 .set_title ("Wind U - Ensemble Members" )
3027- ax5 .grid (True )
3028-
3029- # Create wind v subplot
3030- ax6 = plt .subplot (322 )
3031- for i in range (self .numEnsembleMembers ):
3032- self .selectEnsembleMember (i )
3033- ax6 .plot ([self .windVelocityY (i ) for i in grid ], grid , label = i )
3034- # ax6.legend(loc='best').set_draggable(True)
3035- ax6 .set_ylabel ("Height Above Sea Level (m)" )
3036- ax6 .set_xlabel ("Wind Speed (m/s)" )
3037- ax6 .set_title ("Wind V - Ensemble Members" )
3038- ax6 .grid (True )
3039-
3040- # Create wind speed subplot
3041- ax7 = plt .subplot (323 )
3042- for i in range (self .numEnsembleMembers ):
3043- self .selectEnsembleMember (i )
3044- ax7 .plot ([self .windSpeed (i ) for i in grid ], grid , label = i )
3045- # ax7.legend(loc='best').set_draggable(True)
3046- ax7 .set_ylabel ("Height Above Sea Level (m)" )
3047- ax7 .set_xlabel ("Wind Speed (m/s)" )
3048- ax7 .set_title ("Wind Speed Magnitude - Ensemble Members" )
3049- ax7 .grid (True )
3050-
3051- # Create wind direction subplot
3052- ax8 = plt .subplot (324 )
3053- for i in range (self .numEnsembleMembers ):
3054- self .selectEnsembleMember (i )
3055- ax8 .plot ([self .windDirection (i ) for i in grid ], grid , label = i )
3056- # ax8.legend(loc='best').set_draggable(True)
3057- ax8 .set_ylabel ("Height Above Sea Level (m)" )
3058- ax8 .set_xlabel ("Degrees True (°)" )
3059- ax8 .set_title ("Wind Direction - Ensemble Members" )
3060- ax8 .grid (True )
3061-
3062- # Create pressure subplot
3063- ax9 = plt .subplot (325 )
3064- for i in range (self .numEnsembleMembers ):
3065- self .selectEnsembleMember (i )
3066- ax9 .plot ([self .pressure (i ) for i in grid ], grid , label = i )
3067- # ax9.legend(loc='best').set_draggable(True)
3068- ax9 .set_ylabel ("Height Above Sea Level (m)" )
3069- ax9 .set_xlabel ("Pressure (P)" )
3070- ax9 .set_title ("Pressure - Ensemble Members" )
3071- ax9 .grid (True )
3072-
3073- # Create temperature subplot
3074- ax10 = plt .subplot (326 )
3075- for i in range (self .numEnsembleMembers ):
3076- self .selectEnsembleMember (i )
3077- ax10 .plot ([self .temperature (i ) for i in grid ], grid , label = i )
3078- # ax10.legend(loc='best').set_draggable(True)
3079- ax10 .set_ylabel ("Height Above Sea Level (m)" )
3080- ax10 .set_xlabel ("Temperature (K)" )
3081- ax10 .set_title ("Temperature - Ensemble Members" )
3082- ax10 .grid (True )
3083-
3084- # Display plot
3085- plt .subplots_adjust (wspace = 0.5 , hspace = 0.3 )
3086- plt .show ()
3087-
3088- # Clean up
3089- self .selectEnsembleMember (currentMember )
2890+ self .plots .all ()
30902891
30912892 return None
30922893
0 commit comments