# -*- coding: utf-8 -*-
"""
Spyder Editor
This is a temporary script file.
"""
# Importar librerias
import fiona, numpy as np
import pylab as pl
from netCDF4 import Dataset
from pyscissor import scissor # pip install pyscissor
from [Link] import ShapelyFeature
import [Link] as cfeature
import pandas as pd
import [Link] as ccrs
ncf = Dataset("D:/NESTOR/PPDIARIA/RAIN4PE_daily_0.1d_1981_2015_v1.[Link]")
cuenca = [Link]("D:/NESTOR/PPDIARIA/cuenca_utm.shp")
print([Link])
#cuenca_s18 = cuenca.to_crs(epsg=32718)
print(ncf)
# Ajustes generales para los plots..
from matplotlib.font_manager import *
from [Link] import *
ioff()
rc(
'lines',
linewidth=1)
rc(
'text',
usetex=False)# Para poder usar 'usetex=True' es necesario haber instalado latex
rc(
'font',
family='Times New Roman')
font_title = FontProperties(size=24)
font_label = FontProperties(size=22)
font_ticks = FontProperties(size=16)
font_legend = FontProperties(size=15)
print([Link]['time'])
lats =[Link]['Latitude'][:]
lons =[Link]['Longitude'][:]
prec =[Link]['pcp'][:]
times =[Link]['time'][:]
# calcular.. mascara para .shp
from [Link] import shape
record = next(iter(cuenca))
shapely_shape = shape(record['geometry'])
[Link]
pys = scissor(shapely_shape,lats,lons)
wg = pys.get_masked_weight()
# Cuadricula ponderada
cart_ft =
ShapelyFeature([shapely_shape],[Link](),facecolor='none',edgecolor='cyan'
,linewidth=2)
# plot
fig =[Link](figsize=(5,5))
ax=[Link](projection=[Link]())
[Link](lons,lats,wg,cmap='ocean',shading='nearest')
[Link]()
ax.set_title("$Cuenca\ Cachi$", fontproperties=font_title)
ax.add_feature(cart_ft)
ax.set_xlim(-74.8, -73.8)
ax.set_ylim(-13.6,-12.8)
[Link]()
# Asignar mascara
[Link]=[Link]
# Plot de precipitación enmascarada del primer paso de tiempo
fig =[Link](figsize=(5,5))
ax=[Link](projection=[Link]())
[Link](lons,lats,prec[-1],cmap='jet')
[Link]()
ax.add_feature(cart_ft)
ax.set_xlim(-74.8, -73.8)
ax.set_ylim(-13.6,-12.8)
[Link]('Calculemos la prec. promedio...\nareal de cuenca!!',
xy=(-74.5,-13.1),#xy=(-74.4,-13.45)
xytext=(-75.5,-12.9),#xytext=(-74.3,-13.35)
arrowprops={'facecolor':'#23bf97','shrink':0.01},fontsize=9.5)
[Link]()
# Serie de precipitación promedio areal de cuenca..
prec_prom = [Link]([Link][0])
for t in range([Link][0]):
prec_prom[t] = [Link](prec[t],weights=wg)
# plot
[Link](figsize=(12,5))
[Link](times,prec_prom,'o-',label='Precipitación promedio areal de cuenca', color=
'blue')
[Link](loc=2, prop=font_legend)
[Link]("$Date\ (meses)$")
[Link]('on', color='.8',linestyle='--')
[Link]()
# Guardas datos!!!
df= [Link](prec_prom)
df
#df.to_csv("D:/T_JONA/TESIS_PISCO/Entrada/Pisco_Pp/Python_PISCO/Prec_areal.csv")