import numpy
import datetime
import pandas

class RunTraceRadar(object):
    """
    This is for ARC computers where we cannot 
    use pydarn!!!!
    """
    
    def __init__(self, rad, beam_list,\
                 date_start, date_end,
                 elevbeg, elevend, elevstp,\
                 freq, nhop=1, timestep=1):
        """
        Initialize parameters
        """
        self.date_start = datetime.datetime(2016,12,4)
        self.date_end = datetime.datetime(2016,12,5)
        self.elevbeg = 5.
        self.elevend = 55.
        self.elevstp = 0.5
        self.freq = 11. 
        self.nhop = 1 
        self.timestep = 0.5
        # get some other params!
        self.boresite = -40.0
        self.nbeams = 16
        self.ngates = 75.
        self.txlat = 37.10
        self.txlon = -77.95
        self.beam_sep = 3.24
        
        self.min_beam = 0
        self.max_beam = 16
        
        self.offset = self.nbeams/2. - 0.5
        self.beam_azim = []
        
        self.min_beam_azim = round(self.boresite + (self.min_beam - self.offset)*self.beam_sep,2)
        self.max_beam_azim = round(self.boresite + (self.max_beam - self.offset)*self.beam_sep,2)
        
            
    def run_trace(self):
        """
        Run ray tracing for the parameters
        """
        import ray_trace_mp
        rt_obj = ray_trace_mp.RayTraceMP(self.date_start, self.date_end,\
                             self.txlat, self.txlon,\
                             self.min_beam_azim, self.max_beam_azim,\
                             self.beam_sep, self.elevbeg,\
                             self.elevend, self.elevstp,\
                             self.freq, self.nhop, timestep=self.timestep)
        rdict = rt_obj.trace()
        
#     def get_scatter(self, rt_dict, gnd_sct_file="../gnd_sct.csv",\
#                     iono_sct_file="../iono_sct.csv"):
#         """
#         Convert raytracing results to beam-gate scatter
#         """
#         import rt_sct_utils
        
#         sct_obj = rt_sct_utils.RT_SCT(rt_dict)
#         gnd_df = sct_obj.get_gnd_sct_df()
#         iono_df = sct_obj.get_iono_sct_df()
        
#         gnd_df.to_csv(gnd_sct_file)
#         iono_df.to_csv(iono_sct_file)
        
        
if __name__ == "__main__":
    import time
    start_time = time.time()
    rad = 'bks'
    beam_list = [b for b in range(16)]
    date_start = datetime.datetime(2016,10,12)
    date_end = datetime.datetime(2016,10,13)
    timestep = 0.5
    elevbeg = 5.0
    elevend = 55.0#60.0
    elevstp = 0.5
    freq = 11.
    sr_obj = RunTraceRadar(rad, beam_list,\
                 date_start, date_end,
                 elevbeg, elevend, elevstp, freq,\
                 timestep=timestep)
    rdict = sr_obj.run_trace()
#     sr_obj.get_scatter(rdict)
    end_time = time.time()
    print("execution time (minutes)-->",(end_time-start_time)/60.)
import numpy
import datetime
import pandas

class RunTraceRadar(object):
    """
    This is for ARC computers where we cannot 
    use pydarn!!!!
    """
    
    def __init__(self, rad, beam_list,\
                 date_start, date_end,
                 elevbeg, elevend, elevstp,\
                 freq, nhop=1, timestep=1):
        """
        Initialize parameters
        """
        self.date_start = datetime.datetime(2016,12,4)
        self.date_end = datetime.datetime(2016,12,5)
        self.elevbeg = 5.
        self.elevend = 55.
        self.elevstp = 0.5
        self.freq = 11. 
        self.nhop = 1 
        self.timestep = 0.5
        # get some other params!
        self.boresite = -40.0
        self.nbeams = 16
        self.ngates = 75.
        self.txlat = 37.10
        self.txlon = -77.95
        self.beam_sep = 3.24
        
        self.min_beam = 0
        self.max_beam = 16
        
        self.offset = self.nbeams/2. - 0.5
        self.beam_azim = []
        
        self.min_beam_azim = round(self.boresite + (self.min_beam - self.offset)*self.beam_sep,2)
        self.max_beam_azim = round(self.boresite + (self.max_beam - self.offset)*self.beam_sep,2)
        
            
    def run_trace(self):
        """
        Run ray tracing for the parameters
        """
        import ray_trace_mp
        rt_obj = ray_trace_mp.RayTraceMP(self.date_start, self.date_end,\
                             self.txlat, self.txlon,\
                             self.min_beam_azim, self.max_beam_azim,\
                             self.beam_sep, self.elevbeg,\
                             self.elevend, self.elevstp,\
                             self.freq, self.nhop, timestep=self.timestep)
        rdict = rt_obj.trace()
        
#     def get_scatter(self, rt_dict, gnd_sct_file="../gnd_sct.csv",\
#                     iono_sct_file="../iono_sct.csv"):
#         """
#         Convert raytracing results to beam-gate scatter
#         """
#         import rt_sct_utils
        
#         sct_obj = rt_sct_utils.RT_SCT(rt_dict)
#         gnd_df = sct_obj.get_gnd_sct_df()
#         iono_df = sct_obj.get_iono_sct_df()
        
#         gnd_df.to_csv(gnd_sct_file)
#         iono_df.to_csv(iono_sct_file)
        
        
if __name__ == "__main__":
    import time
    start_time = time.time()
    rad = 'bks'
    beam_list = [b for b in range(16)]
    date_start = datetime.datetime(2016,10,12)
    date_end = datetime.datetime(2016,10,13)
    timestep = 0.5
    elevbeg = 5.0
    elevend = 55.0#60.0
    elevstp = 0.5
    freq = 11.
    sr_obj = RunTraceRadar(rad, beam_list,\
                 date_start, date_end,
                 elevbeg, elevend, elevstp, freq,\
                 timestep=timestep)
    rdict = sr_obj.run_trace()
#     sr_obj.get_scatter(rdict)
    end_time = time.time()
    print("execution time (minutes)-->",(end_time-start_time)/60.)
This is for ARC computers where we cannot      use pydarn!!!! Initialize parameters # get some other params! Run ray tracing for the parameters #     def get_scatter(self, rt_dict, gnd_sct_file="../gnd_sct.csv",\ #                     iono_sct_file="../iono_sct.csv"): #         """ #         Convert raytracing results to beam-gate scatter #         """ #         import rt_sct_utils #         sct_obj = rt_sct_utils.RT_SCT(rt_dict) #         gnd_df = sct_obj.get_gnd_sct_df() #         iono_df = sct_obj.get_iono_sct_df() #         gnd_df.to_csv(gnd_sct_file) #         iono_df.to_csv(iono_sct_file) #60.0 #     sr_obj.get_scatter(rdict)