import okean
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 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
import netCDF4
import netcdftime
from pyd3d.output1 import processNetCDF
import xarray as xr
import netCDF4
import netcdftime
from netcdftime import utime
import os,sys
import okean.calc as calc
from plotting import plot_settings as ps
from plotting import angles
from processing_2d import vector_sum
import ipywidgets as widgets
from glob import glob
tick2_spacing = 0.1
tick3_spacing = 0.1
xs = xr.open_dataset(r'F:\model\trim-a_jan-feb_1.nc')
fg = gpd.read_file(r'.\xinqiao_outline.shp')
fg1 = fg.to_crs(crs = 'EPSG:4326')
u_arr1 = xs.U1.values[1205][0]
u_arr = xs.U1.values[1210][0]
v_arr1 =xs.V1.values[1205][0]
v_arr =xs.V1.values[1210][0]
x = xs.XCOR.values
y = xs.YCOR.values
fig = plt.figure(figsize=(16,8))
plt.rcParams['font.sans-serif'] = 'Times New Roman'
plt.rcParams['font.size'] = 15
subplots_adjust(left=0.1,bottom=0.15,top=0.95,right=0.95,hspace=0.15,wspace=0.15)
lat_formatter = LatitudeFormatter()
lon_formatter = LongitudeFormatter()
ax = fig.add_subplot(121)
fg1.geometry.plot(facecolor='white',edgecolor='black',alpha=0.5,ax =ax)
ax.quiver(x,y,u_arr,v_arr,scale = 40)
ax.set_ylim(31.49,31.705)
ax.set_xlim(121.274,121.605)
ax.yaxis.set_major_locator(ticker.MultipleLocator(tick2_spacing))
ax.xaxis.set_major_locator(ticker.MultipleLocator(tick3_spacing))
ax.yaxis.set_major_formatter(lat_formatter)
ax.xaxis.set_major_formatter(lon_formatter)
ax.tick_params(labelsize=15,axis='y',rotation=90)
ax.tick_params(labelsize=15,axis='x',rotation=0)
ax1 = fig.add_subplot(122)
ax1.quiver(x,y,u_arr1,v_arr1,scale = 40)
fg1.geometry.plot(facecolor='white',edgecolor='black',alpha=0.5,ax =ax1)
ax1.set_ylim(31.49,31.705)
ax1.set_xlim(121.274,121.605)
ax1.yaxis.set_major_locator(ticker.MultipleLocator(tick2_spacing))
ax1.xaxis.set_major_locator(ticker.MultipleLocator(tick3_spacing))
ax1.yaxis.set_major_formatter(lat_formatter)
ax1.xaxis.set_major_formatter(lon_formatter)
ax1.tick_params(labelsize=15,axis='y',rotation=90)
ax1.tick_params(labelsize=15,axis='x',rotation=0)
plt.savefig(r'./ku_xiaochao.svg',dpi = 200)
plt.show()