Beispiel #1
0
def get_coastal_region():
    """
	海岸付近の海域はTrue(1)、それ以外はFalse
	"""
    """
	def distance_from_coast(lon,lat,resolution='l',degree_in_km=111.12):
	    plt.ioff()
	    m = Basemap(projection='robin',lon_0=0,resolution=resolution)
	    coast = m.drawcoastlines()
	    coordinates = np.vstack(coast.get_segments())
	    lons,lats = m(coordinates[:,0],coordinates[:,1],inverse=True)
	    dists = np.sqrt((lons-lon)**2+(lats-lat)**2)
	    if np.min(dists)*degree_in_km<1:
	      return True
	    else:
	      return False
	"""
    #print(distance_from_coast(-117.2547,32.8049,resolution="i"))
    latlon145_file_name = calc_data.latlon145_file_name
    latlon900_file_name = calc_data.latlon900_file_name
    grid900to145_file_name = calc_data.grid900to145_file_name
    ocean_grid_file = calc_data.ocean_grid_file
    ocean_grid_145 = calc_data.ocean_grid_145
    ocean_idx = calc_data.ocean_idx

    latlon_ex = calc_data.get_lonlat_data()

    is_near_coastal = np.zeros(145**2)
    ocean_grid_145 = ocean_grid_145.values
    ocean_grid_145 *= -1
    ocean_grid_145 += 1
    ocean_grid_145 = np.reshape(ocean_grid_145, (145, 145), order="F")
    #print(ocean_grid_145)
    ocean_x_pos_1 = np.hstack((np.ones((145, 1)), ocean_grid_145))[:, :-1]
    ocean_x_pos_2 = np.hstack((np.ones((145, 1)), ocean_x_pos_1))[:, :-1]
    ocean_x_pos_3 = np.hstack((np.ones((145, 1)), ocean_x_pos_2))[:, :-1]
    ocean_x_neg_1 = np.hstack((ocean_grid_145, np.ones((145, 1))))[:, 1:]
    ocean_x_neg_2 = np.hstack((ocean_x_neg_1, np.ones((145, 1))))[:, 1:]
    ocean_x_neg_3 = np.hstack((ocean_x_neg_2, np.ones((145, 1))))[:, 1:]
    ocean_y_pos_1 = np.vstack((np.ones((1, 145)), ocean_grid_145))[:-1, :]
    ocean_y_pos_2 = np.vstack((np.ones((1, 145)), ocean_y_pos_1))[:-1, :]
    ocean_y_pos_3 = np.vstack((np.ones((1, 145)), ocean_y_pos_2))[:-1, :]
    ocean_y_neg_1 = np.vstack((ocean_grid_145, np.ones((1, 145))))[1:, :]
    ocean_y_neg_2 = np.vstack((ocean_y_neg_1, np.ones((1, 145))))[1:, :]
    ocean_y_neg_3 = np.vstack((ocean_y_neg_2, np.ones((1, 145))))[1:, :]
    coastal_region_1 = ocean_x_pos_1 + ocean_x_neg_1 + ocean_y_pos_1 + ocean_y_neg_1
    #print(coastal_region_1)
    coastal_region_1[ocean_grid_145 == 1] = -1
    coastal_region_1 = coastal_region_1 > 0
    #coastal_region_1 = coastal_region_1.T.ravel()
    coastal_region_2 = ocean_x_pos_1 + ocean_x_pos_2 + ocean_x_neg_1 + ocean_x_neg_2 + ocean_y_pos_1 + ocean_y_pos_2 + ocean_y_neg_1 + ocean_y_neg_2
    coastal_region_2[ocean_grid_145 == 1] = -1
    coastal_region_2 = coastal_region_2 > 0
    #coastal_region_2 = coastal_region_2.T.ravel()
    """
	coastal_region_3 = ocean_x_pos_1 + ocean_x_pos_2 + ocean_x_pos_3 + ocean_x_neg_1 + ocean_x_neg_2 + ocean_x_neg_3 + ocean_y_pos_1 + ocean_y_pos_2 + ocean_y_pos_3 + ocean_y_neg_1 + ocean_y_neg_2 + ocean_y_neg_3
	coastal_region_3[ocean_grid_145==1] = -1
	coastal_region_3 = coastal_region_3>0
	"""
    """
	for i in range(1,143):
		for j in range(1,143):
			if coastal_region > 0:
	"""
    """
	m = Basemap(lon_0=180, boundinglat=50, resolution='h', projection='npstere')
	fig = plt.figure(figsize=(7.5, 7.5))
	m.drawcoastlines(color = '0.15')
	m.fillcontinents(color='#555555')
	x, y = m(np.array(latlon_ex.Lon), np.array(latlon_ex.Lat), inverse=False)
	x1 = np.reshape(x, (145,145), order="F")
	y1 = np.reshape(y, (145,145), order="F")
	dx1 = (x1[1,0]-x1[0,0])/2
	dy1 = (y1[0,1]-y1[0,0])/2
	x2 = np.linspace(x1[0,0], x1[144,0], 145)
	y2 = np.linspace(y1[0,0], y1[0,144], 145)
	xx, yy = np.meshgrid(x2, y2)
	xx, yy = xx.T, yy.T
	xx = np.hstack([xx, xx[:,0].reshape(145,1)])
	xx_ex = np.vstack([xx, (xx[144,:] + (xx[1,0]-xx[0,0]))])
	yy = np.vstack([yy, yy[0,:]])
	yy_ex = np.hstack([(yy[:,0].reshape(146,1) + (yy[0,0]-yy[0,1])), yy])
	#print((coastal_region_1==True).shape)
	#m.scatter(x1[coastal_region_1==True], y1[coastal_region_1==True], color="b", marker='o', s=2, alpha=0.9)
	m.pcolormesh(xx_ex-dx1, yy_ex+dy1, coastal_region_1==True)
	#m.scatter(x1[coastal_region_2==True], y1[coastal_region_2==True], color="g", marker='o', s=1.2, alpha=0.9)
	m.colorbar(location="bottom")
	plt.show()
	"""
    return coastal_region_1.T.ravel(), coastal_region_2.T.ravel()
Beispiel #2
0
import seaborn as sns
import matplotlib.gridspec as gridspec

import pandas.plotting._converter as pandacnv
pandacnv.register()

import calc_data

latlon145_file_name = calc_data.latlon145_file_name
latlon900_file_name = calc_data.latlon900_file_name
grid900to145_file_name = calc_data.grid900to145_file_name
ocean_grid_file = calc_data.ocean_grid_file
ocean_grid_145 = calc_data.ocean_grid_145
ocean_idx = calc_data.ocean_idx

latlon_ex = calc_data.get_lonlat_data()

start_list = []
n = 20000000
y_list = [3, 4, 5, 6, 7, 8, 9, 10, 13, 14, 15, 16]
for i in y_list:
    m = n + i * 10000
    for j in range(12):
        start_list.append(m + (j + 1) * 100 + 1)
start_ex_list = [
    20170101, 20170201, 20170301, 20170401, 20170501, 20170601, 20170701,
    20170801
]
start_list = np.sort(np.array(list(set(start_list)
                                   | set(start_ex_list)))).tolist()
M = len(start_list)
Beispiel #3
0
import pandas as pd
import seaborn as sns

import calc_data

latlon145_file_name = calc_data.latlon145_file_name
latlon900_file_name = calc_data.latlon900_file_name
grid900to145_file_name = calc_data.grid900to145_file_name
ocean_grid_file = calc_data.ocean_grid_file
ocean_grid_145 = calc_data.ocean_grid_145
ocean_idx = calc_data.ocean_idx

g = np.arange(0, 145, 1)
points = np.meshgrid(g, g)

df_lonlat = calc_data.get_lonlat_data()
lon, lat = np.array(df_lonlat["Lon"]), np.array(df_lonlat["Lat"])


#####################################################################
#自分で定義したカラーマップを返す
def generate_cmap(colors):
    values = range(len(colors))

    vmax = np.ceil(np.max(values))
    color_list = []
    for v, c in zip(values, colors):
        color_list.append((v / vmax, c))
    return LinearSegmentedColormap.from_list('custom_cmap', color_list)