def min_temp_day(): df_out_min = p.DataFrame() df_out_min5 = p.DataFrame() for file in files.lat_lon_files(): df = p.read_csv (file) if len(df) > 0: cols = files.lat_lon_cols(df) lat_lon_5 = cols[0] # make year associated with winter df['year2'] = df['year'].shift(190) df['doy2'] = df['day_of_year'] # make doy be part of previous year in the winter df.loc[(df.doy2 < 190), 'doy2'] = df.doy2 + 365 # lop off the beginning which isn't useful df2 = df.iloc[190:].copy() df = df.set_index('doy2') dfg = df.groupby('year2') for col in cols: df_out_min[col] = dfg[col].idxmin() df_out_min5[lat_lon_5] = dfg['mean'].idxmin() print ('processed ' + lat_lon_5) df_out_min.to_csv(out_dir + 'min_lat_lon.csv') decades(df_out_min).to_csv(out_dir + 'min_lat_lon_dec.csv') df_out_min5.to_csv(out_dir + 'min_lat_lon5.csv') decades(df_out_min5).to_csv(out_dir + 'min_lat_lon5_dec.csv')
def leap_year_delta(): df_out_delta = p.DataFrame() for file in files.lat_lon_files(DIR, SHORT_NAME): df = p.read_csv(file) years = find_full_years(df) if len(years) > 0: cols = files.lat_lon_cols(df) lat_lon = cols[0] df_out_delta[lat_lon] = calc_leap_delta(df, years)['temp'] # print('processed ' + lat_lon) df_out_delta.reset_index(inplace=True) df_out_delta.to_csv(OUT_DIR + 'leap_deltas.csv') out = [] for loc in df_out_delta.columns.to_list().remove('year'): delta = df_out_delta[loc] delta = delta[delta != 0] out.append({'loc': loc, 'mean': delta.mean(), 'max': delta.max()}) return p.DataFrame(out)
def max_temp_day(): df_out_max = p.DataFrame() df_out_max5 = p.DataFrame() for file in files.lat_lon_files(): df = p.read_csv (file) if len(df) > 0: cols = files.lat_lon_cols(df) lat_lon_5 = cols[0] df = df.set_index('day_of_year') dfg = df.groupby('year') for col in cols: df_out_max[col] = dfg[col].idxmax() df_out_max5[lat_lon_5] = dfg['mean'].idxmax() print ('processed ' + lat_lon_5) df_out_max.to_csv(out_dir + 'max_lat_lon.csv') decades(df_out_max).to_csv(out_dir + 'max_lat_lon_dec.csv') df_out_max5.to_csv(out_dir + 'max_lat_lon5.csv') decades(df_out_max5).to_csv(out_dir + 'max_lat_lon5_dec.csv')
def process(): # df_out_norm_mo = p.DataFrame() # df_out_new_leap_mo = p.DataFrame() df_out_norm_yr = p.DataFrame() df_out_new_leap_yr = p.DataFrame() df_out_tropical_yr = p.DataFrame() # = p.DataFrame() for file in files.lat_lon_files(DIR, SHORT_NAME): df = p.read_csv(file) years = find_full_years(df) if len(years) > 0: cols = files.lat_lon_cols(df) # only use the mean of the col # use the first lat_lon as the name for the new column lat_lon = cols[0] # df_out_norm_mo[lat_lon] = calc_normal_leap_mo(df, years)['temp'] # df_out_new_leap_mo[lat_lon] = calc_new_leap_mo(df, years)['temp'] df_out_norm_yr[lat_lon] = calc_normal_leap_yr(df, years)['temp'] df_out_new_leap_yr[lat_lon] = calc_new_leap_yr(df, years)['temp'] df_out_tropical_yr[lat_lon] = calc_tropical_yr(df, years)['temp'] # df_out_no_leap_mo[lat_lon] = no_leap(df, years)['temp'] print('processed ' + lat_lon) # df_out_norm_mo.reset_index(inplace=True) # df_out_new_leap_mo.reset_index(inplace=True) df_out_norm_yr.reset_index(inplace=True) df_out_new_leap_yr.reset_index(inplace=True) df_out_tropical_yr.reset_index(inplace=True) # df_out_no_leap_mo.reset_index(inplace=True) # df_out_norm_mo.to_csv(OUT_DIR + 'normal_mo.csv') # df_out_new_leap_mo.to_csv(OUT_DIR + 'new_leap_mo.csv') # df_out_no_leap_mo.to_csv(OUT_DIR + 'no_leap_mo.csv') df_out_norm_yr.to_csv(OUT_DIR + 'normal_yr.csv') df_out_new_leap_yr.to_csv(OUT_DIR + 'new_leap_yr.csv') df_out_tropical_yr.to_csv(OUT_DIR + 'tropical_yr.csv') # df_out_no_leap_yr = df_out_no_leap_mo.groupby('year').mean() # df_out_no_leap_yr.to_csv(OUT_DIR + 'no_leap_yr.csv') return True