Пример #1
0
 def timed(*args, **kw):
     ts = time.time()
     result = method(*args, **kw)
     te = time.time()
     sys.stdout.write('{} : {} ms\n'.format(method.__name__,
                                            (te - ts) * 1000))
     return result
Пример #2
0
 def make_gui(self):
     """  Setups the general structure of the gui, the first function called """
     #print(self.config.QD_classes, self.config.QD_class_index)
     self.option_window = Toplevel()
     self.option_window.protocol("WM_DELETE_WINDOW", self.on_exit)
     self.canvas_frame = tk.Frame(self, height=500)
     self.option_frame = tk.Frame(self.option_window, height=300)
     self.canvas_frame.pack(side=tk.LEFT, fill=tk.BOTH, expand=True)
     self.option_frame.pack(side=tk.RIGHT, fill=None, expand=False)
     self.make_options_frame()
     a = time.time()
     self.make_canvas_frame()
     print(time.time() - a)
     self.disable_singlecolor()
Пример #3
0
def make_positions():

    ##########################################  PSP

    starttime =datetime(2018, 8,13)
    endtime = datetime(2025, 8, 31)
    psp_time = []
    while starttime < endtime:
        psp_time.append(starttime)
        starttime += timedelta(days=res_in_days)
    psp_time_num=mdates.date2num(psp_time)     

    spice.furnish(spicedata.get_kernel('psp_pred'))
    psp=spice.Trajectory('SPP')
    psp.generate_positions(psp_time,'Sun',frame)
    print('PSP pos')

    psp.change_units(astropy.units.AU)  
    [psp_r, psp_lat, psp_lon]=cart2sphere(psp.x,psp.y,psp.z)
    print('PSP conv')


    ############################################## BepiColombo

    starttime =datetime(2018, 10, 21)
    endtime = datetime(2025, 11, 2)
    bepi_time = []
    while starttime < endtime:
        bepi_time.append(starttime)
        starttime += timedelta(days=res_in_days)
    bepi_time_num=mdates.date2num(bepi_time) 

    spice.furnish(spicedata.get_kernel('bepi_pred'))
    bepi=spice.Trajectory('BEPICOLOMBO MPO') # or BEPICOLOMBO MMO
    bepi.generate_positions(bepi_time,'Sun',frame)
    bepi.change_units(astropy.units.AU)  
    [bepi_r, bepi_lat, bepi_lon]=cart2sphere(bepi.x,bepi.y,bepi.z)
    print('Bepi')



    #################################################### Solar Orbiter

    starttime = datetime(2020, 3, 1)
    endtime = datetime(2026, 1, 1)
    solo_time = []
    while starttime < endtime:
        solo_time.append(starttime)
        starttime += timedelta(days=res_in_days)
    solo_time_num=mdates.date2num(solo_time) 

    spice.furnish(spicedata.get_kernel('solo_2020'))
    solo=spice.Trajectory('Solar Orbiter')
    solo.generate_positions(solo_time, 'Sun',frame)
    solo.change_units(astropy.units.AU)
    [solo_r, solo_lat, solo_lon]=cart2sphere(solo.x,solo.y,solo.z)
    print('Solo')






    plt.figure(1, figsize=(12,9))
    plt.plot_date(psp_time,psp_r,'-', label='R')
    plt.plot_date(psp_time,psp_lat,'-',label='lat')
    plt.plot_date(psp_time,psp_lon,'-',label='lon')
    plt.ylabel('AU / RAD')
    plt.legend()




    plt.figure(2, figsize=(12,9))
    plt.plot_date(bepi_time,bepi_r,'-', label='R')
    plt.plot_date(bepi_time,bepi_lat,'-',label='lat')
    plt.plot_date(bepi_time,bepi_lon,'-',label='lon')
    plt.title('Bepi Colombo position '+frame)
    plt.ylabel('AU / RAD')
    plt.legend()




    plt.figure(3, figsize=(12,9))
    plt.plot_date(solo_time,solo_r,'-', label='R')
    plt.plot_date(solo_time,solo_lat,'-',label='lat')
    plt.plot_date(solo_time,solo_lon,'-',label='lon')
    plt.title('Solar Orbiter position '+frame)
    plt.ylabel('AU / RAD')
    plt.legend()


    ########### plots


    ######## R with all three
    plt.figure(4, figsize=(16,10))
    plt.plot_date(psp_time,psp.r,'-',label='PSP')
    plt.plot_date(bepi_time,bepi.r,'-',label='Bepi Colombo')
    plt.plot_date(solo_time,solo.r,'-',label='Solar Orbiter')
    plt.legend()
    plt.title('Heliocentric distance of heliospheric observatories')
    plt.ylabel('AU')
    plt.savefig('results/positions_plots/bepi_psp_solo_R.png')

    ##### Longitude all three
    plt.figure(5, figsize=(16,10))
    plt.plot_date(psp_time,psp_lon*180/np.pi,'-',label='PSP')
    plt.plot_date(bepi_time,bepi_lon*180/np.pi,'-',label='Bepi Colombo')
    plt.plot_date(solo_time,solo_lon*180/np.pi,'-',label='Solar Orbiter')
    plt.legend()
    plt.title(frame+' longitude')
    plt.ylabel('DEG')
    plt.savefig('results/positions_plots/bepi_psp_solo_longitude_'+frame+'.png')


    ############# Earth for mercury, venusus, STA
    #https://docs.heliopy.org/en/stable/data/spice.html


    planet_kernel=spicedata.get_kernel('planet_trajectories')

    starttime =datetime(2018, 1, 1)
    endtime = datetime(2028, 12, 31)
    earth_time = []
    while starttime < endtime:
        earth_time.append(starttime)
        starttime += timedelta(days=res_in_days)
    earth_time_num=mdates.date2num(earth_time)     

    earth=spice.Trajectory('399')  #399 for Earth, not barycenter (because of moon)
    earth.generate_positions(earth_time,'Sun',frame)
    earth.change_units(astropy.units.AU)  
    [earth_r, earth_lat, earth_lon]=cart2sphere(earth.x,earth.y,earth.z)
    print('Earth')

    ################ mercury
    mercury_time_num=earth_time_num
    mercury=spice.Trajectory('1')  #barycenter
    mercury.generate_positions(earth_time,'Sun',frame)  
    mercury.change_units(astropy.units.AU)  
    [mercury_r, mercury_lat, mercury_lon]=cart2sphere(mercury.x,mercury.y,mercury.z)
    print('mercury') 

    ################# venus
    venus_time_num=earth_time_num
    venus=spice.Trajectory('2')  
    venus.generate_positions(earth_time,'Sun',frame)  
    venus.change_units(astropy.units.AU)  
    [venus_r, venus_lat, venus_lon]=cart2sphere(venus.x,venus.y,venus.z)
    print('venus') 


    ############### Mars

    mars_time_num=earth_time_num
    mars=spice.Trajectory('4')  
    mars.generate_positions(earth_time,'Sun',frame)  
    mars.change_units(astropy.units.AU)  
    [mars_r, mars_lat, mars_lon]=cart2sphere(mars.x,mars.y,mars.z)
    print('mars') 

    #############stereo-A
    sta_time_num=earth_time_num
    spice.furnish(spicedata.get_kernel('stereo_a_pred'))
    sta=spice.Trajectory('-234')  
    sta.generate_positions(earth_time,'Sun',frame)  
    sta.change_units(astropy.units.AU)  
    [sta_r, sta_lat, sta_lon]=cart2sphere(sta.x,sta.y,sta.z)
    print('STEREO-A') 



    #save positions 
    if high_res_mode:
     pickle.dump([psp_time,psp_time_num,psp_r,psp_lon,psp_lat,bepi_time,bepi_time_num,bepi_r,bepi_lon,bepi_lat,solo_time,solo_time_num,solo_r,solo_lon,solo_lat], open( 'positions_plots/psp_solo_bepi_'+frame+'_1min.p', "wb" ) )
     sys.exit()
    else: 
     psp=np.rec.array([psp_time_num,psp_r,psp_lon,psp_lat, psp.x, psp.y,psp.z],dtype=[('time','f8'),('r','f8'),('lon','f8'),('lat','f8'),('x','f8'),('y','f8'),('z','f8')])
     bepi=np.rec.array([bepi_time_num,bepi_r,bepi_lon,bepi_lat,bepi.x, bepi.y,bepi.z],dtype=[('time','f8'),('r','f8'),('lon','f8'),('lat','f8'),('x','f8'),('y','f8'),('z','f8')])
     solo=np.rec.array([solo_time_num,solo_r,solo_lon,solo_lat,solo.x, solo.y,solo.z],dtype=[('time','f8'),('r','f8'),('lon','f8'),('lat','f8'),('x','f8'),('y','f8'),('z','f8')])
     sta=np.rec.array([sta_time_num,sta_r,sta_lon,sta_lat,sta.x, sta.y,sta.z],dtype=[('time','f8'),('r','f8'),('lon','f8'),('lat','f8'),('x','f8'),('y','f8'),('z','f8')])
     earth=np.rec.array([earth_time_num,earth_r,earth_lon,earth_lat, earth.x, earth.y,earth.z],dtype=[('time','f8'),('r','f8'),('lon','f8'),('lat','f8'),('x','f8'),('y','f8'),('z','f8')])
     venus=np.rec.array([venus_time_num,venus_r,venus_lon,venus_lat, venus.x, venus.y,venus.z],dtype=[('time','f8'),('r','f8'),('lon','f8'),('lat','f8'),('x','f8'),('y','f8'),('z','f8')])
     mars=np.rec.array([mars_time_num,mars_r,mars_lon,mars_lat, mars.x, mars.y,mars.z],dtype=[('time','f8'),('r','f8'),('lon','f8'),('lat','f8'),('x','f8'),('y','f8'),('z','f8')])
     mercury=np.rec.array([mercury_time_num,mercury_r,mercury_lon,mercury_lat,mercury.x, mercury.y,mercury.z],dtype=[('time','f8'),('r','f8'),('lon','f8'),('lat','f8'),('x','f8'),('y','f8'),('z','f8')])
     pickle.dump([psp, bepi, solo, sta, earth, venus, mars, mercury,frame], open( 'results/positions_psp_solo_bepi_sta_planets_'+frame+'_2hours.p', "wb" ) )
     #load with [psp, bepi, solo, sta, earth, venus, mars, mercury,frame]=pickle.load( open( 'positions_psp_solo_bepi_sta_planets_HCI_6hours_2018_2025.p', "rb" ) )
 
 
    end=time.time()
    print( 'generate position took time in seconds:', round((end-start),1) )
Пример #4
0











##################################################### MAIN ###############################


start=time.time()


########## MAKE TRAJECTORIES ############
#make_positions()




file=data_path+'psp_2018_2019_merged.p'
[p,ph]=pickle.load(open(file, "rb" ) )  

file=data_path+'wind_2018_now.p'
[w,wh]=pickle.load(open(file, "rb" ) )  

file=data_path+'sta_2018_now_beacon.p'
Пример #5
0
        1.0,  # b_s (magnetic field scaling parameter)
        15,  # b_1au (magnetic field strength at 1au)
        1.5,  # Gamma (solar wind drag coefficient)
        400,  # v_sw (solar wind speed)
        0  # sigma (measurement noise)
    ]],
    dtype=np.float32)

model_obj = py3dcore.models.ThinTorusGH3DCOREModel(t_launch,
                                                   runs=1,
                                                   use_gpu=False)
model_obj.update_iparams(iparams_arr, seed=42)

############################### measure magnetic field
print()
start = time.time()

#18 is middle
satposindex = 20
print('current satpos measured is ', satposindex)

#t0, btot0, bxyz0, os = measure(model_obj, satpos[6], tm1 - datetime.timedelta(days=3), tm1  + datetime.timedelta(days=20))
t1, btot1, bxyz1, os1 = measure(model_obj, satpos[satposindex],
                                tm1 - datetime.timedelta(days=3),
                                tm1 + datetime.timedelta(days=15))
#t2, btot2, bxyz2, os = measure(model_obj, satpos[30], tm1 - datetime.timedelta(days=3), tm1  + datetime.timedelta(days=20))
print('took ', np.round(time.time() - start, 3), '  seconds')
print()
#print(t1)
#print(os1)
Пример #6
0
    sc_time_num = mdates.date2num(sc_time)
    sc.generate_positions(sc_time, 'Sun', frame)
    sc.change_units(astropy.units.AU)
    sc_r, sc_lat, sc_lon = cart2sphere(sc.x, sc.y, sc.z)
    screc = np.rec.array([sc_time_num, sc_r, sc_lon, sc_lat, sc.x, sc.y, sc.z],
                         dtype=[('time', 'f8'), ('r', 'f8'), ('lon', 'f8'),
                                ('lat', 'f8'), ('x', 'f8'), ('y', 'f8'),
                                ('z', 'f8')])

    return screc


##################################################### MAIN ###############################

start = time.time()

############################################ SETTINGS

#Coordinate System
frame = 'HCI'
#frame='HEEQ'
print(frame)

#sidereal solar rotation rate
if frame == 'HCI': sun_rot = 24.47
#synodic
if frame == 'HEEQ': sun_rot = 26.24

#black background on or off
back = True
Пример #7
0
    def make_canvas_frame(self):
        """ Create the data and thematic map images for the first time """
        b = time.time()
        self.fig, (self.imageax, self.previewax) = plt.subplots(ncols=2,
                                                                figsize=self.canvas_size,
                                                                sharex=True, sharey=True,
                                                                gridspec_kw=self.subplot_grid_spec)
        print(time.time() - b)
    
        self.canvas = FigureCanvasTkAgg(self.fig, master=self.canvas_frame)
        self.canvas.mpl_connect('button_press_event', self.onclick)
        self.canvas.mpl_connect('key_press_event', self.onpress)
        # set up the channel data view
        b = time.time()
        #self.configure_threecolor_image()
        self.configure_image()
        print(time.time()-b)
        self.imageplot = self.imageax.imshow(self.image)
        self.imageax.set_xlim([0, self.shape[1]])
        self.imageax.set_ylim([0, self.shape[0]])
        # self.imageax.set_aspect("equal")
        self.imageax.set_axis_off()

        # set up the thematic map view
        self.selection_array = np.zeros(self.shape, dtype=np.uint8)
        if self.blank:
            self.selection_array += self.config.QD_class_index['unlabeled']
        else:
            self.draw_default()
        self.history.append(self.selection_array)
        colortable = [self.config.QD_colors[self.config.QD_class_name[i]]
                      for i in range(len(self.config.QD_classes))]
        cmap = matplotlib.colors.ListedColormap(colortable)
        self.mask = self.previewax.imshow(self.selection_array,
                                          origin='lower',
                                          interpolation='nearest',
                                          cmap=cmap,
                                          vmin=-1, vmax=len(colortable))
        self.previewax.set_xlim([0, self.shape[1]])
        self.previewax.set_ylim([0, self.shape[0]])
        self.previewax.set_aspect("equal")
        self.previewax.set_axis_off()

        # add selection layer for lasso
        #self.pix = np.arange(self.shape[0])  # assumes square image
        #xv, yv = np.meshgrid(self.pix, self.pix)
        self.pix = np.asarray(list(list(reversed(list(elem))) for elem in 
            itertools.product(list(range(self.shape[0])), list(range(self.shape[1])))))

        lineprops = dict(color=self.config.default['lasso_color'],
                         linewidth=self.config.default['lasso_width'])
        self.lasso = LassoSelector(self.imageax, self.onlasso, lineprops=lineprops)

        # display everything
        self.canvas.show()
        self.canvas.get_tk_widget().pack(side=tk.TOP, fill=tk.BOTH, expand=True)
        self.canvas._tkcanvas.pack(side=tk.TOP, fill=tk.BOTH, expand=True)

        # add the tool bar
        self.toolbarcenterframe = tk.LabelFrame(self.canvas_frame,
                                                borderwidth=0,
                                                text="Draw: unlabeled",
                                                relief=tk.FLAT,
                                                labelanchor=tk.N,
                                                background='red')
        toolbarframe = tk.Frame(self.toolbarcenterframe)
        toolbar = CustomToolbar(self.canvas, toolbarframe, self.toolbarcenterframe, self)
        toolbar.update()
        self.fig.canvas.toolbar.set_message = lambda x: ""  # remove state reporting
        toolbarframe.pack()
        self.toolbarcenterframe.pack(side=tk.BOTTOM, fill=tk.X)
Пример #8
0
#go through all wind data and check for each hour whether this is inside a MFR or sheath or background wind

#3 labels: background wind, sheath, MFR
#data: about 1e5 training instances (without test data) with 4 features: average btot, std btot, vtot, vstd

#get the features and labels for ICME classification

get_fl_classify=False
#get_fl_classify=True

interval_hours=1

#takes 22 minutes for full data
if get_fl_classify:
  
  start = time.time()
  print('extract features for classification')

  #test CME extraction April 2010
  #win=win[1690000:1720000]
  #win_time=win_time[1690000:1720000]

  #win=win[1500000:2000000]
  #win_time=win_time[1500000:2000000]

  #win=win[0:2500000]
  #win_time=win_time[0:2500000]


  hour_int_size=round(np.size(win)/(60*interval_hours))-1