import eofs
from eofs.standard import Eof
import pandas as pd
import numpy as np
import glob
import datetime
from matplotlib import pyplot as plt
import copy
import re
import time
from pylab import *
import matplotlib.dates as mdate
import matplotlib.patches as patches
import matplotlib.ticker as ticker
import xarray as ax
import copy
import geopandas as gpd
from pykrige.ok import OrdinaryKriging
from pykrige.kriging_tools import write_asc_grid
import pykrige.kriging_tools as kt
from matplotlib.colors import LinearSegmentedColormap
from matplotlib.patches import Path, PathPatch
from shapely.geometry import LineString
from cartopy.mpl.ticker import LongitudeFormatter, LatitudeFormatter
from cartopy.mpl.ticker import LongitudeFormatter, LatitudeFormatter
time_parse1 = lambda date: datetime.datetime.strptime(date, '%Y/%m/%d %H:%M')
df = pd.read_csv('./water_level_baozhen_1.csv',parse_dates=['date'],date_parser=time_parse1,encoding='utf-8')
# time_p = str(df.iat[-1,0]).split()[0] + ' ' + '0' + ':' + '00' + ':' + '00'
# print(time_p)
time_list_1 = []
time_list_2 = []
list_1 = []
for i in range(24):
time_list_1.append('start_time' + str(i))
time_list_2.append('start_time' + str(i))
list_1.append('df' + str(i))
time_list_1[0] = datetime.datetime.strptime("0:00:00", "%H:%M:%S").time()
time_list_2[0] = datetime.datetime.strptime("0:00:09", "%H:%M:%S").time()
for i in range(1, 24):
time_list_1[i] = (datetime.datetime.strptime("00:00:00", "%H:%M:%S") + datetime.timedelta(
hours=int(i))).time()
time_list_2[i] = (datetime.datetime.strptime("00:00:09", "%H:%M:%S") + datetime.timedelta(
hours=int(i))).time()
# print(time_list_1)
# print(time_list_2)
list_1[0] = df[
(df['date'].dt.time >= time_list_1[0]) & (df['date'].dt.time <= time_list_2[0])]
t = list_1[0]
# print(list_1[0])
for x1 in range(1, 24):
list_1[x1] = df[
(df['date'].dt.time >= time_list_1[x1]) & (df['date'].dt.time <= time_list_2[x1])]
for i in range(1,24):
t = t.append(list_1[i])
t1 = copy.deepcopy(t)
t1 = t1.reset_index(drop=True)
t1 =t1.sort_values(by = 'date')
t2 = t1.reset_index(drop=True)
t2.to_csv('./baozhen_hour.csv')