The sequence of days on February 29 in a leap year in a certain period of time

  Data, Data Analytics, Python, Worknotes

The following code is used to count the order of the date of February 29 in leap years for a period.


import sys
import warnings
if not sys.warnoptions:
    warnings.simplefilter('ignore')
#Process data    
import numpy as np
import matplotlib.pyplot as plt
#Process data    
import numpy as np
import xarray as xr
#Writing data files
import pandas as pd
import calendar

The extent of the subset of data from the global dataset.


min_lon = -100 
min_lat = 37 
max_lon = -80 
max_lat = 47 

Order of February 29 for a period.


idfeb29=np.empty(shape=(1,11),dtype='int16')
i0=0
idays=0
for iy in np.arange(2006,2050):
    yd=365
    if(calendar.isleap(iy)):
        idfeb29[0,i0]=idays+60
        print(iy,idays+60)
        i0=i0+1
        yd=366
        
    idays=idays+yd

Read 5 data sets, slice the data, concatenate and delete Februrary 29 data


f0='data/rsds_day_GFDL-ESM2M_rcp26_r1i1p1_EWEMBI_20060101-20101231.nc4'
f1='data/rsds_day_GFDL-ESM2M_rcp26_r1i1p1_EWEMBI_20110101-20201231.nc4'
f2='data/rsds_day_GFDL-ESM2M_rcp26_r1i1p1_EWEMBI_20210101-20301231.nc4'
f3='data/rsds_day_GFDL-ESM2M_rcp26_r1i1p1_EWEMBI_20310101-20401231.nc4'
f4='data/rsds_day_GFDL-ESM2M_rcp26_r1i1p1_EWEMBI_20410101-20501231.nc4'

ds0=xr.open_dataset(f0,decode_times=False)
ds1=xr.open_dataset(f1,decode_times=False)
ds2=xr.open_dataset(f2,decode_times=False)
ds3=xr.open_dataset(f3,decode_times=False)
ds4=xr.open_dataset(f4,decode_times=False)

cropped_ds0 = ds0.sel(lat=slice(max_lat,min_lat), lon=slice(min_lon,max_lon))
cropped_ds1 = ds1.sel(lat=slice(max_lat,min_lat), lon=slice(min_lon,max_lon))
cropped_ds2 = ds2.sel(lat=slice(max_lat,min_lat), lon=slice(min_lon,max_lon))
cropped_ds3 = ds3.sel(lat=slice(max_lat,min_lat), lon=slice(min_lon,max_lon))
cropped_ds4 = ds4.sel(lat=slice(max_lat,min_lat), lon=slice(min_lon,max_lon))

X0=cropped_ds0['rsds']
X1=cropped_ds1['rsds']
X2=cropped_ds2['rsds']
X3=cropped_ds3['rsds']
X4=cropped_ds4['rsds']

X=np.concatenate((X0,X1,X2,X3,X4), axis=0)
X=np.delete(X,np.flip(idfeb29[0,:]-1),axis=0)