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
from sklearn.linear_model import LinearRegression
tick1_spacing = 0.1
tick2_spacing = 0.1
so1 = [1,1,0]
font1 = {'family': 'Times New Roman',
'weight': 'normal',
'size': 15,
}
d1 = ['Unnamed: 0','hb', 'h', 'value', 'date']
s = np.full([1, 5], np.nan)
s1 = pd.DataFrame(s, columns=d1)
op = ['Unnamed: 0']
v1 = []
v2 = []
dfg = pd.read_csv('./1_sudu.csv')
df = pd.read_csv(r'./6月xq表层1.csv')
z1 = df['黏土']
z2 = df['粉砂']
z3 = df['砂']
bds = []
ads = dfg.groupby('date')
tt =list(ads)
adt = []
for i in range(len(tt)):
tt1 = tt[i][1]
adt.append(tt[i][0])
st = s1.append(tt1, ignore_index=True)
st1 = st.append(s1, ignore_index=True)
st1.drop(op, inplace=True, axis=1)
len_1 = len(st1['hb'])
st1.iat[0, 0] = 0
st1.iat[0, 1] = st1.iat[1, 1]
st1.iat[0, 2] = st1.iat[1, 2] * 1.02
st1.iat[0, 3] = st1.iat[1, 3]
st1.iat[-1, 0] = 1
st1.iat[-1, 1] = st1.iat[-2, 1]
st1.iat[-1, 2] = st1.iat[-2, 2] * 0.795
st1.iat[-1, 3] = st1.iat[-2, 3]
v_1 = abs((st1.iat[1, 2] - st1.iat[-2, 2]))/ ( st1.iat[1, 1])
# print(v_1)
v1.append(v_1)
v_2 = st1.iat[-2, 2]
v2.append(v_2)
vv1 = pd.Series(np.array(v1))
vv2 = pd.Series(np.array(v2))
dc = pd.DataFrame(vv2,columns=['tidu1'])
dc['date'] = pd.Series(adt)
dc1 = copy.deepcopy(dc)
dc1.to_csv('./dicengliusu.csv')
dh = pd.DataFrame(vv1,columns=['tidu1'])
# dh['niantu'] = z1
# dh['fensha'] = z2
# dh['sha'] = z3
dh['date'] = pd.Series(adt)
print(dh)
dh1 = copy.deepcopy(dh)
dh1.to_csv('./tiudu_bdnihe1.csv')
# if len(st1) <= 3:
# # print(st1)
# v_1 = abs((st1.iat[-2, 2] - st1.iat[-1, 2])) / (0.2 * st1.iat[-1, 1])
# v1.append(v_1)
# else:
#
# if 3<len(st1) <= 7:
# # print(st1)
# v_1 = abs((st1.iat[-3, 2] - st1.iat[-2, 2])) / (0.2 * st1.iat[-1, 1])
# v1.append(v_1)
# elif 7< len(st1)<=10:
# # print(st1)
# for x1 in range(len(st1['hb'])):
# at = st1.iat[x1, 0]
# h = st1.iat[-1, 1]
# if at ==4.41:
# id_1 = st1.loc[st1['hb'] == at]
# # print(id_1)
# id_2 = st1.loc[st1['hb'] == 1]
# # print(id_1)
# # print(id_2)
# v_1 = (abs(id_1.iat[0, 2]-id_2.iat[0, 2]))/(0.2*id_2.iat[-1, 1])
# # print(v_1)
# v1.append(v_1)
# elif 10 < len(st1) <= 18:
# # print(st1)
# for x1 in range(len(st1['hb'])):
# at = st1.iat[x1, 0]
# h = st1.iat[-1, 1]
# if 0.735 * h < at < 0.789 * h:
# id_1 = st1.loc[st1['hb'] == at]
# # print(id_1)
# id_2 = st1.loc[st1['hb'] == 1]
# v_1 = (abs(id_1.iat[0, 2] - id_2.iat[0, 2])) / (0.2 * id_2.iat[-1, 1])
# # print(v_1)
# v1.append(v_1)
# elif 18 < len(st1) <= 22:
# # print(st1)
# for x1 in range(len(st1['hb'])):
# at = st1.iat[x1, 0]
# h = st1.iat[-1, 1]
# if 0.8 * h < at < 0.84 * h:
# id_1 = st1.loc[st1['hb'] == at]
# # print(id_1)
# id_2 = st1.loc[st1['hb'] == 1]
# v_1 = (abs(id_1.iat[0, 2] - id_2.iat[0, 2])) / (0.2 * id_2.iat[-1, 1])
# v1.append(v_1)
# elif len(st1)>22:
# for x1 in range(len(st1['hb'])):
# at = st1.iat[x1, 0]
# h = st1.iat[-1, 1]
# if 0.8 * h < at < 0.835 * h:
# id_1 = st1.loc[st1['hb'] == at]
# # print(id_1)
# id_2 = st1.loc[st1['hb'] == 1]
# v_1 = (abs(id_1.iat[0, 2] - id_2.iat[0, 2])) / (0.2 * id_2.iat[-1, 1])
# v1.append(v_1)
# print(v1)
# vv1 = pd.Series(np.array(v1))
# # print(adt)
# print(vv1)
# dh = pd.DataFrame(vv1,columns=['tidu1'])
# dh['niantu'] = z1
# dh['fensha'] = z2
# dh['sha'] = z3
# dh['date'] = pd.Series(adt)
# print(dh)
# dh1 = copy.deepcopy(dh)
# dh1.to_csv('./tiudu_nihe.csv')
# print(st1)
# if len(st1)<=3:
# v_1 =(st1.iat[-2, 2]-st1.iat[-1, 2])/(0.2*st1.iat[-1, 1])
# v1.append(v_1)
# else:
# v_1 = abs(st1.iat[-3, 2] - st1.iat[-2, 2]) / (0.2 * st1.iat[-1, 1])
# v1.append(v_1)
# vv1 = pd.Series(np.array(v1))
#
# dh = pd.DataFrame(vv1,columns=['tidu1'])
# dh['niantu'] = z1
# dh['fensha'] = z2
# dh['sha'] = z3
#
# dh1 = copy.deepcopy(dh)
# # dh1.to_csv('./tiud_nihe.csv')
# x = dh1[['tidu1']]
# y1 = dh1[['niantu']]
# # print(x)
# # print(y1)
#
# lm1 = LinearRegression()
# ft1 = lm1.fit(x,y1)
# ct1 = ft1.score(x,y1)
# dy1 =ct1**0.5
# print(dy1)