Exemplo n.º 1
0
def great(m, startlon, startlat, azimuth,*args, **kwargs):
    """
    function to draw great circle, takes into account crossing the border
    by: Thomas Lecocq
    """
    glon1 = startlon
    glat1 = startlat
    glon2 = glon1
    glat2 = glat1
 
    step = 50
 
    glon2, glat2, baz = shoot(glon1, glat1, azimuth, step)
    if azimuth-180 >= 0:
        while glon2 <= startlon:
            line = m.drawgreatcircle(glon1, glat1, glon2, glat2,del_s=50,**kwargs)
            azimuth = baz + 180.
            glat1, glon1 = (glat2, glon2)
 
            glon2, glat2, baz = shoot(glon1, glat1, azimuth, step)
    elif azimuth-180 < 0:
        while glon2 >= startlon:
            line = m.drawgreatcircle(glon1, glat1, glon2, glat2,del_s=50,**kwargs)
            azimuth = baz + 180.
            glat1, glon1 = (glat2, glon2)
 
            glon2, glat2, baz = shoot(glon1, glat1, azimuth, step)
    return line
 def plt_range_circles(self,lon,lat,azi=None):
     'program to plot range circles starting from the last point selected on the map, with principal plane identified'        
     if self.circlesoff:
         return
     diam = [50.0,100.0,200.0,500.0,1000.0]
     colors = ['lightgrey','lightgrey','lightgrey','lightsalmon','crimson']
     line = []
     an = []
     for i,d in enumerate(diam):
         ll, = equi(self.m,lon,lat,d,color=colors[i])
         line.append(ll)
         slon,slat,az = shoot(lon,lat,0.0,d)
         x,y = self.m(slon,slat)
         ano = self.line.axes.annotate('%i km' %(d),(x,y),color='silver')
         an.append(ano)
     if azi:
         slon,slat,az = shoot(lon,lat,azi,diam[-1])
         mlon,mlat,az = shoot(lon,lat,azi+180.0,diam[-1])
         lazi1, = self.m.plot([slon],[slat],'--*',color='grey',markeredgecolor='#BBBB00',markerfacecolor='#EEEE00',markersize=20)
         lazi2, = self.m.plot([mlon,lon,slon],[mlat,lat,slat],'--',color='grey')
         line.append(lazi1)
         line.append(lazi2)
     for deg in [0,90,180,270]:
         dlo,dla,az = shoot(lon,lat,deg,diam[-1])
         elo,ela,az = shoot(lon,lat,deg,diam[-1]*0.85)
         ll, = self.m.plot([elo,dlo],[ela,dla],'-',color='grey')
         line.append(ll)
         for dd in [22.5,45.0,67.5]:
             dlo,dla,az = shoot(lon,lat,deg+dd,diam[-1])
             elo,ela,az = shoot(lon,lat,deg+dd,diam[-1]*0.93)
             ll, = self.m.plot([elo,dlo],[ela,dla],'-',color='grey')
             line.append(ll)
     return line,an
Exemplo n.º 3
0
    def newpoint(self,
                 Bearing,
                 distance,
                 alt=None,
                 last=True,
                 feet=False,
                 km=True,
                 insert=False,
                 insert_i=-1):
        """
        program to add a new point at the end of the current track with a bearing and distance, optionally an altitude
        if feet is set, altitude is defined in feet not the defautl meters.
        if km is set to True, distance is defined in kilometers (default), if False, it uses nautical miles (nm)
        update to use insert keyword for placing a point in the middle of the line, at the position of insert_i
        """
        if not km:
            dist = distance * 2.02  #need to check this value.
        else:
            dist = distance
        newlon, newlat, baz = shoot(self.lons[insert_i],
                                    self.lats[insert_i],
                                    Bearing,
                                    maxdist=distance)
        if self.verbose:
            print 'New points at lon: %f, lat: %f' % (newlon, newlat)
        if self.m:
            x, y = self.m(newlon, newlat)
            if not insert:
                self.lons.append(newlon)
                self.lats.append(newlat)
            else:
                self.lons.insert(insert_i + 1, newlon)
                self.lats.insert(insert_i + 1, newlat)
        else:
            x, y = newlon, newlat
        if not insert:
            self.xs.append(x)
            self.ys.append(y)
        else:
            self.xs.insert(insert_i + 1, x)
            self.ys.insert(insert_i + 1, y)
        self.line.set_data(self.xs, self.ys)

        if self.ex:
            if alt:
                if feet:
                    alt = alt / 3.28084
            if not insert:
                self.ex.appends(self.lats[-1], self.lons[-1], alt=alt)
            else:
                self.ex.inserts(insert_i + 1, newlat, newlon, alt=alt)
            self.ex.calculate()
            self.ex.write_to_excel()
        self.update_labels()
        self.draw_canvas()
Exemplo n.º 4
0
 def calc_move_from_rot(self,i,angle,lat0,lon0):
     """
     Program to calculate a bearing and angle to rotate the point i based on the lat lon points lat0 and lon0
     Returns a bearing and a distance of the point i to get the correct position
     """
     dist = spherical_dist([lat0,lon0],[self.lats[i],self.lons[i]])
     bearing_start = bearing([lat0,lon0],[self.lats[i],self.lons[i]])
     newlon,newlat,baz = shoot(lon0,lat0,bearing_start+angle,maxdist=dist)
     dist_end = spherical_dist([self.lats[i],self.lons[i]],[newlat,newlon])
     bearing_end = bearing([self.lats[i],self.lons[i]],[newlat,newlon])
     return bearing_end,dist_end        
Exemplo n.º 5
0
 def calc_move_from_rot(self, i, angle, lat0, lon0):
     """
     Program to calculate a bearing and angle to rotate the point i based on the lat lon points lat0 and lon0
     Returns a bearing and a distance of the point i to get the correct position
     """
     dist = spherical_dist([lat0, lon0], [self.lats[i], self.lons[i]])
     bearing_start = bearing([lat0, lon0], [self.lats[i], self.lons[i]])
     newlon, newlat, baz = shoot(lon0,
                                 lat0,
                                 bearing_start + angle,
                                 maxdist=dist)
     dist_end = spherical_dist([self.lats[i], self.lons[i]],
                               [newlat, newlon])
     bearing_end = bearing([self.lats[i], self.lons[i]], [newlat, newlon])
     return bearing_end, dist_end
Exemplo n.º 6
0
 def newpoint(self,Bearing,distance,alt=None,last=True,feet=False,km=True,insert=False,insert_i=-1):
     """
     program to add a new point at the end of the current track with a bearing and distance, optionally an altitude
     if feet is set, altitude is defined in feet not the defautl meters.
     if km is set to True, distance is defined in kilometers (default), if False, it uses nautical miles (nm)
     update to use insert keyword for placing a point in the middle of the line, at the position of insert_i
     """
     if not km:
         dist = distance*2.02 #need to check this value.
     else:
         dist = distance
     newlon,newlat,baz = shoot(self.lons[insert_i],self.lats[insert_i],Bearing,maxdist=distance)
     if self.verbose:
         print 'New points at lon: %f, lat: %f' %(newlon,newlat)
     if self.m:
         x,y = self.m(newlon,newlat)
         if not insert:
             self.lons.append(newlon)
             self.lats.append(newlat)
         else:
             self.lons.insert(insert_i+1,newlon)
             self.lats.insert(insert_i+1,newlat)
     else:
         x,y = newlon,newlat
     if not insert:
         self.xs.append(x)
         self.ys.append(y)
     else:
         self.xs.insert(insert_i+1,x)
         self.ys.insert(insert_i+1,y)
     self.line.set_data(self.xs, self.ys)
     
     if self.ex:
         if alt:
             if feet:
                 alt = alt/3.28084
         if not insert:
             self.ex.appends(self.lats[-1],self.lons[-1],alt=alt)
         else:
             self.ex.inserts(insert_i+1,newlat,newlon,alt=alt)
         self.ex.calculate()
         self.ex.write_to_excel()
     self.update_labels()
     self.draw_canvas()
Exemplo n.º 7
0
 def movepoint(self,i,Bearing,distance,last=False):
     'Program to move a point a certain distance and bearing'
     newlon,newlat,baz = shoot(self.lons[i],self.lats[i],Bearing,maxdist=distance)
     if self.m:
         x,y = self.m(newlon,newlat)
         self.lons[i] = newlon
         self.lats[i] = newlat
     else:
         x,y = newlon,newlat
     self.xs[i] = x
     self.ys[i] = y
     self.line.set_data(self.xs, self.ys)
     if self.ex: self.ex.mods(i,self.lats[i],self.lons[i])
     if last:
         if self.ex:
             self.ex.calculate()
             self.ex.write_to_excel()
         self.update_labels()
         self.draw_canvas()
 def movepoint(self,i,bearing,distance,last=False):
     'Program to move a point a certain distance and bearing'
     newlon,newlat,baz = shoot(self.lons[i],self.lats[i],bearing,maxdist=distance)
     if self.m:
         x,y = self.m(newlon,newlat)
         self.lons[i] = newlon
         self.lats[i] = newlat
     else:
         x,y = newlon,newlat
     self.xs[i] = x
     self.ys[i] = y
     self.line.set_data(self.xs, self.ys)
     if self.ex: self.ex.mods(i,self.lats[i],self.lons[i])
     if last:
         if self.ex:
             self.ex.calculate()
             self.ex.write_to_excel()
         self.update_labels()
         self.draw_canvas()
 def newpoint(self,bearing,distance):
     'program to add a new point at the end of the current track with a bearing and distance'
     newlon,newlat,baz = shoot(self.lons[-1],self.lats[-1],bearing,maxdist=distance)
     if self.verbose:
         print 'New points at lon: %f, lat: %f' %(newlon,newlat)
     if self.m:
         x,y = self.m(newlon,newlat)
         self.lons.append(newlon)
         self.lats.append(newlat)
     else:
         x,y = newlon,newlat
     self.xs.append(x)
     self.ys.append(y)
     self.line.set_data(self.xs, self.ys)
     if self.ex:
         self.ex.appends(self.lats[-1],self.lons[-1])
         self.ex.calculate()
         self.ex.write_to_excel()
     self.update_labels()
     self.draw_canvas()
Exemplo n.º 10
0
def equi(m, centerlon, centerlat, radius, *args, **kwargs):
    """
    plot a single circle on a map
    uses the shoot function below
    from: http://www.geophysique.be/2011/02/20/matplotlib-basemap-tutorial-09-drawing-circles/
    by: Thomas Lecocq
    """
    from map_utils import shoot
    glon1 = centerlon
    glat1 = centerlat
    X = []
    Y = []
    for azimuth in range(0, 360):
        glon2, glat2, baz = shoot(glon1, glat1, azimuth, radius)
        X.append(glon2)
        Y.append(glat2)
    X.append(X[0])
    Y.append(Y[0])

    #m.plot(X,Y,**kwargs) #Should work, but doesn't...
    X,Y = m(X,Y)
    line = m.ax.plot(X,Y,**kwargs)
    return line
Exemplo n.º 11
0
 def plt_range_circles(self,lon,lat,azi=None):
     'program to plot range circles starting from the last point selected on the map, with principal plane identified'        
     if self.circlesoff:
         return
     if self.large:
         diam = [50.0,100.0,200.0,500.0,1000.0]
     else:
         diam = [25.0,50.0,100.0,200.0,500.0]
     colors = ['lightgrey','lightgrey','lightgrey','lightsalmon','crimson']
     line = []
     an = []
     for i,d in enumerate(diam):
         ll, = equi(self.m,lon,lat,d,color=colors[i])
         line.append(ll)
         slon,slat,az = shoot(lon,lat,0.0,d)
         x,y = self.m(slon,slat)
         ano = self.line.axes.annotate('%i km' %(d),(x,y),color='silver')
         an.append(ano)
     if azi:
         slon,slat,az = shoot(lon,lat,azi,diam[-1])
         mlon,mlat,az = shoot(lon,lat,azi+180.0,diam[-1])
         lazi1, = self.m.plot([slon],[slat],'--*',color='grey',markeredgecolor='#BBBB00',markerfacecolor='#EEEE00',markersize=20)
         lazi2, = self.m.plot([mlon,lon,slon],[mlat,lat,slat],'--',color='grey')
         line.append(lazi1)
         line.append(lazi2)
     # plot angle points on the line
     for deg in [0,90,180,270]:
         dlo,dla,az = shoot(lon,lat,deg,diam[-1])
         elo,ela,az = shoot(lon,lat,deg,diam[-1]*0.85)
         ll, = self.m.plot([elo,dlo],[ela,dla],'-',color='grey')
         line.append(ll)
         for dd in [22.5,45.0,67.5]:
             dlo,dla,az = shoot(lon,lat,deg+dd,diam[-1])
             elo,ela,az = shoot(lon,lat,deg+dd,diam[-1]*0.93)
             ll, = self.m.plot([elo,dlo],[ela,dla],'-',color='grey')
             line.append(ll)
     return line,an
Exemplo n.º 12
0
def get_MODIS_surf_albedo(fp,doy,lat,lon,year_of_MODIS=2007):
    """
    Purpose:
        helper function to get the details of the surface albedo from MODIS albedo 
    
    Input: 
        fp: path to get the saved files
        doy: day of year of the requested data
        lat: latitude of the surface albedo to get
        lon: longitude of the surface albedo to get
        
    Output:
        modis_albedo: dict containing the values used to create the albedo from a subset of aod, and sza
                      mean_geo, mean_iso, mean_vol : mean values within the lat and lon space
                      std_geo, std_iso, std_vol: standard deviation of the values within the lat and lon space
                      table_AOD: lut tabel of fractional diffuse proportion, value of the AODs
                      table_SZA: lut table value of sza
                      table_fracdiffuse: lut table of the fractional diffuse proportion linked to AOD and SZA                      
                          
    Keywords: 
        year_of_MODIS: (default to 2007) year as integer of the MODIS albedo files to use
    
    Dependencies:
        numpy
        Run_fuliou (this file)
        map_utils

    
    Required files:
        skyl_lut_bbshortwave.dat file 
        MODIS albedo files for the correct day:
            MCD43GF_geo_shortwave_%03d_2007.hdf
            MCD43GF_iso_shortwave_%03d_2007.hdf
            MCD43GF_vol_shortwave_%03d_2007.hdf
    
    Example:
        
        ...
        
    Modification History:
    
        Written (v1.0): Samuel LeBlanc, 2017-03-22, Santa Cruz, CA
                        migrated to python from matlab based on codes in read_FuLiou_input_file_Calipso_revFeb2015.m
                        originally written by John Livingston
    """
    import numpy as np
    from map_utils import shoot
    from Run_fuliou import load_hdf_spec
    
    MODIS_start_days = np.append(np.arange(1,367,8),367)
    modis_albedo = {}
    
    # read file of the fractional diffuse for bbshortwave per aod and sza
    f = fp+'skyl_lut_bbshortwave.dat'
    modis_albedo['table_AOD'] = np.arange(0,0.99,0.02)
    r = np.genfromtxt(f,skip_header=2)
    modis_albedo['table_SZA'] = r[:,0]
    modis_albedo['table_fracdiffuse'] = r[:,1:]
    
    # get the MODIS file day
    MODIS_select_day = MODIS_start_days[(doy-MODIS_start_days)>=0][-1]
    # get the lat lon range from the center point
    lats,lons = np.arange(4).astype(float),np.arange(4).astype(float)
    for i in range(4): lons[i],lats[i],_ = shoot(lon,lat,45.0+i*90.0,maxdist=20.000*np.sqrt(2.0))
    if len(np.unique(lons))<2: lons[0],lons[1] = lons[0]-0.1,lons[1]+0.1
    if len(np.unique(lats))<2: lats[0],lats[1] = lats[0]-0.1,lats[1]+0.1
        
    # Select the proper grid points to load from the MCD43GF gapfilled albedo files
    latgrid = np.arange(90,-90,-30.0/3600.0)
    longrid = np.arange(-180.0,180,30.0/3600.0)
    ix = np.where((latgrid>=lats.min())&(latgrid<=lats.max()))[0]
    iy = np.where((longrid>=lons.min())&(longrid<=lons.max()))[0]
    
    # assure that all the grid points are within the lats/lons
    # not used for now
    
    # Load the modis gap filled albedo files
    buffer_geo = load_hdf_spec(fp+'MCD43GF_geo_shortwave_%03d_%d.hdf'%(MODIS_select_day,year_of_MODIS),ix,iy)
    buffer_iso = load_hdf_spec(fp+'MCD43GF_iso_shortwave_%03d_%d.hdf'%(MODIS_select_day,year_of_MODIS),ix,iy)
    buffer_vol = load_hdf_spec(fp+'MCD43GF_vol_shortwave_%03d_%d.hdf'%(MODIS_select_day,year_of_MODIS),ix,iy)
    
    modis_albedo['mean_geo'] = np.nanmean(buffer_geo)
    modis_albedo['mean_iso'] = np.nanmean(buffer_iso)
    modis_albedo['mean_vol'] = np.nanmean(buffer_vol)
    modis_albedo['std_geo'] = np.nanstd(buffer_geo)
    modis_albedo['std_iso'] = np.nanstd(buffer_geo)
    modis_albedo['std_vol'] = np.nanstd(buffer_geo)
    
    return modis_albedo