I am very new to python and am working on the Jupyter notebook. I Have the following packages imported:
import warnings
import numpy as np
import xarray as xr
import pandas as pd
import matplotlib.pyplot as plt
import cartopy.crs as ccrs
import cartopy.mpl.ticker as cticker
from cartopy.util import add_cyclic_point
I have data with a monthly frequency and units per second and I'm trying to get them to be per year. Any help would be appreciated. I tried to resample the data before but have decided I cant rely on the inner functions of python.
#Constants
DayPerYear=360 # Calendars vary by modelling group
path='C:/mypath/'
PercipFile='myfile'
ds=xr.open_dataset(path+PercipFile)
ds
Time_raw=ds.variables['time'][:]
print(Time_raw)
tt = np.size("time")
Time_m = np.zeros((tt))
SAT_m = np.zeros((tt))
ty = int(tt / 12)
# Time in years
Time_y = np.arange(1911, 1911 + ty, 1) + 0.5
SAT_y = np.zeros((ty))
yc = 0 # year count
Months = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
Months_leap = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
for j in range(0, tt, 12):
# Get year length, need to change if leap years
if (j + 12 < tt):
lyear = Time_raw[j + 12] - Time_raw[j] # length of year
else:
lyear = Time_raw[-1] - Time_raw[j - 1] # Works BC leap is in
February
# Set pre count variables
YearSum = 0
# Enter year loop
for k in range(0, 12):
if (lyear == 360):
lmonth = 30
elif (lyear == 365):
lmonth = Months[k]
elif (lyear == 366):
lmonth = Months_leap[k]
else:
print('Year check')
lmonth = 30 # set a default value
YearSum = YearSum + SAT_m[j + k] * 1month
# Exit month loop divide by year length
SAT_y[yc] = YearSum / year
# Increase year counter
yc = yc + 1
Im getting IndexError: index 1 is out of bounds for axis 0 with size 1 on line 38 if that helps. thank you!