Exemplo n.º 1
0
def get_time_ticks_zoomed(iday):

    # compute ticks
    t0 = datetime.datetime(2016, 9, 2 + iday, 0)
    t1 = datetime.datetime(2016, 9, 3 + iday, 0)

    # major tick
    tck = []
    tck_label = []
    t = t0
    while t < t1 + datetime.timedelta(hours=1):
        tck.append(t)
        if np.mod(t.hour, 3) == 0:
            tck_label.append(t.strftime('%H'))
        else:
            tck_label.append('')
        t += datetime.timedelta(hours=1)

    # minor tick
    tck_minor = []
    t = t0
    while t < t1 + datetime.timedelta(hours=1):
        tck_minor.append(t)
        t += datetime.timedelta(minutes=15)

    # string of day
    day_str = t0.strftime('%Y-%m-%d')

    return t0, t1, tck, tck_label, day_str, tck_minor
Exemplo n.º 2
0
    def __init__(self, label=None, logline=None, coord_min=True):

        # split string
        l = logline.split()

        # label
        self.label = label

        # time information
        # assumes: 02/09/2016 05:35:00 7 17.124 43 19.866
        self.time = datetime.datetime(int(l[0].split('/')[2]),
                                      int(l[0].split('/')[1]),
                                      int(l[0].split('/')[0]),
                                      int(l[1].split(':')[0]),
                                      int(l[1].split(':')[1]),
                                      int(l[1].split(':')[2]))

        if len(l) > 2:
            # lon, lat data
            if coord_min:
                self.lon = float(l[2]) + float(l[3]) / 60.
                self.lat = float(l[4]) + float(l[5]) / 60.
            else:
                self.lon = float(l[2])
                self.lat = float(l[3])
Exemplo n.º 3
0
def get_time_ticks():

    # for time plotting purposes
    t0 = datetime.datetime(2016, 9, 2, 0)
    t1 = datetime.datetime(2016, 9, 4, 12)

    ### plot time line
    # assign date locator / formatter to the x-axis to get proper labels
    # dloc = mdates.DayLocator()
    # dform = mdates.DateFormatter('%Y-%m-%d')
    # hloc = mdates.HourLocator(interval=6)
    # hform = mdates.DateFormatter('%H:%M')
    # locator = AutoDateLocator(minticks=3)
    # formatter = AutoDateFormatter(locator)
    # formatter = DateFormatter('%Y-%m-%d %H:%M:%S')
    # plt.gcf().axes[0].xaxis.set_major_formatter(formatter)
    # ax.xaxis.set_minor_locator(hloc)
    # ax.xaxis.set_minor_formatter(hform)
    # ax.xaxis.set_major_locator(hloc)
    # ax.xaxis.set_major_formatter(dform)
    # fig.autofmt_xdate()
    tck = []
    tck_label = []
    tdays = []
    t = t0
    while t < t1 + datetime.timedelta(hours=6):
        tck.append(t)
        if t.hour == 12:
            tck_label.append(t.strftime('%Y-%m-%d'))
        else:
            tck_label.append('')
        t += datetime.timedelta(hours=6)
        if t.hour == 0:
            tdays.append(date2num(t))

    return t0, t1, tck, tck_label, tdays
Exemplo n.º 4
0
def parse_nmea_sentence(s, t=None):
    if 'GPRMC' in s.identifier():
        if len(s.fields)>0 and all([s.datestamp, s.timestamp]):
            time = datetime.datetime.combine(s.datestamp, s.timestamp)
    elif 'GPGGA' in s.identifier():
        if t:
            time = datetime.datetime(t.year,
                                     t.month,
                                     t.day,
                                     int(s.data[0][:2]),
                                     int(s.data[0][2:4]),
                                     int(s.data[0][4:6]),
                                     )
            if time<t:
                time+=datetime.timedelta(days=1)
        else:
            time = t
    return dict(lon=s.longitude,
                lat=s.latitude,
                time=time
                )
Exemplo n.º 5
0
ssh_clim_pop = np.concatenate([ssh_clim_pop, ssh_clim_pop, ssh_clim_pop, ssh_clim_pop])


# load wind
file = np.loadtxt(fname='../../winds/wind_mahe_2018_2019.csv', delimiter=',')
year = file[:, 0]
month = file[:, 1]
day = file[:,2]
hour = file[:,3]
dir = file[:, 4]
speed = file[:,5] / 1.94384 # Convert m/s to knots
u_wind1 = speed * np.cos(np.deg2rad(dir))
v_wind1 = speed * np.sin(np.deg2rad(dir))
time1 = np.zeros(year.shape[0])
for ii in range(year.shape[0]):
    time1[ii] = date2num(datetime.datetime(np.int(year[ii]), np.int(month[ii]),
                         np.int(day[ii]), np.int(hour[ii])))
mat = sci.loadmat('../../winds/winds.mat')
wind = mat['wind_MO']
u_wind = wind['u'][0,0]
v_wind = wind['v'][0,0]
time = wind['time'][0,0] - 366 # we need this to change to python time
fi1 = date2num(datetime.datetime.strptime('2016-01', '%Y-%m'))
fi2 = date2num(datetime.datetime.strptime('2018-06-30', '%Y-%m-%d'))
idxa = np.where(time > fi1)[0][0]
idxb = np.where(time > fi2)[0][0]
ui = u_wind[idxa:398789+1].squeeze()
vi = v_wind[idxa:398789+1].squeeze()
ti = time[idxa:398789+1].squeeze()
ui = np.concatenate((ui, u_wind1))
vi = np.concatenate((vi, v_wind1))
ti = np.concatenate((ti, time1))