Code vapor

mail@pastecode.io avatar
unknown
plain_text
7 months ago
1.7 kB
4
Indexable
Never
"""
Extracción de una serie de tiempo con WRF-python
"""
import numpy as  np
import xarray as xa

from matplotlib import pyplot as plt
from glob import glob
from netCDF4 import Dataset
import wrf
import pandas as pd
from datetime import datetime
import sys
from datetime import datetime, timedelta

df = pd.read_csv('vismet_centrosur_pp_upto_20230627.csv', index_col="Fecha", parse_dates=True)

files = [ Dataset(x) for x in sorted(glob('wrfout_d04_2023-04-26_00:00:00')) ]

pr  = wrf.getvar(files,'RAINNC', timeidx=wrf.ALL_TIMES)
pc  = wrf.getvar(files,'RAINC' , timeidx=wrf.ALL_TIMES)

pos = wrf.ll_to_xy(files[0], -37.91, -71.45).values
lon = pos[0]
lat = pos[1]

pr = pr.interp(  west_east=lon, south_north=lat )
pc = pc.interp(  west_east=lon, south_north=lat )

fig, ax = plt.subplots(2,1)

plt.sca(ax[0])
plt.plot(pr.Time, pr+pc, label="Precipitación total")
plt.plot(pr.Time, pc, label="Pprecipitación convectiva")
plt.grid()
plt.ylabel('mm')
plt.legend()

plt.sca(ax[1])
plt.plot(pr.Time[1:], np.diff(pr+pc), label="Tasa precipitación total")
plt.plot(pr.Time[1:], np.diff(pc), label="Tasa precipitación convectiva")
plt.ylabel('mm/hora')
plt.grid()
plt.legend()

df = pd.read_csv('vismet_centrosur_pp_upto_20230627.csv', index_col="Fecha", parse_dates=True)
df = df[datetime(2023,4,26):datetime(2023,4,29)]
df = df["08313002-4"]

df[np.isnan(df)] = 0


df.index = df.index - timedelta(hours=-3)

plt.sca(ax[0])
plt.plot(df.index, df.cumsum(),'ko-',markersize=3, label="Precipitacion observada")
plt.legend()

plt.sca(ax[1])
plt.plot(df.index, df,'ko-',markersize=3, label="Tasa para la observacion")
plt.legend()
plt.show()
Leave a Comment