diff --git a/to_mongo.py b/to_mongo.py index ec86643c2fb03ed7ebd261a86c0e89d46e075516..dcf98b0b89109b5ad45f09d20f51c7e546fbba2c 100644 --- a/to_mongo.py +++ b/to_mongo.py @@ -62,16 +62,16 @@ for year in years: tmaxs = data.tmax.data - if is_leap_year(year): # extra day in leap year screws everything up + # if is_leap_year(year): # extra day in leap year screws everything up - tmin_1 = tmins[:59] - tmin_2 = tmins[60:] + # tmin_1 = tmins[:59] + # tmin_2 = tmins[60:] - tmax_1 = tmaxs[:59] - tmin_2 = tmaxs[60:] + # tmax_1 = tmaxs[:59] + # tmin_2 = tmaxs[60:] - tmins = np.concatenate([tmin_1, tmin_2], axis=0) - tmaxs = np.concatenate([tmax_1, tmin_2], axis=0) + # tmins = np.concatenate([tmin_1, tmin_2], axis=0) + # tmaxs = np.concatenate([tmax_1, tmin_2], axis=0) locs = [] @@ -127,30 +127,52 @@ gdd = db["normals"] resp = gdd.create_index([ ("location", "2dsphere") ]) resp = gdd.create_index([ ("year", 1) ]) -single_year_min = np.zeros((365, 621, 1405)) -single_year_max = np.zeros((365, 621, 1405)) +single_year_min = np.zeros((366, 621, 1405)) +single_year_max = np.zeros((366, 621, 1405)) + +ld_min = np.zeros((single_year_min.shape[-2], single_year_min.shape[-1])) +ld_max = np.zeros((single_year_min.shape[-2], single_year_min.shape[-1]) ) +ld_count = 0 for year in range(1981, 2010+1): print (year) data = xr.open_dataset("data/temps_%s.nc" % year) tmins = data.tmin.data - tmaxs = data.tmax.data + tmaxs = data.tmax.data + + ## idx 59 is leap day + + if not is_leap_year(year): # extra day in leap year screws everything up - if is_leap_year(year): # extra day in leap year screws everything up + insert = np.zeros((1, tmins.shape[-2], tmins.shape[-1])) + insert[:] = np.nan tmin_1 = tmins[:59] - tmin_2 = tmins[60:] + tmin_2 = tmins[59:] tmax_1 = tmaxs[:59] - tmin_2 = tmaxs[60:] + tmin_2 = tmaxs[59:] + + tmins = np.concatenate([tmin_1, insert, tmin_2], axis=0) + tmaxs = np.concatenate([tmax_1, insert, tmin_2], axis=0) + + else: + + ld_min += tmins[59] + ld_max += tmaxs[59] + ld_count += 1 - tmins = np.concatenate([tmin_1, tmin_2], axis=0) - tmaxs = np.concatenate([tmax_1, tmin_2], axis=0) single_year_max += tmaxs/30 single_year_min += tmins/30 +ld_min = ld_min/ld_count +ld_max = ld_max/ld_count + +single_year_min[59] = ld_min +single_year_max[59] = ld_max + x = np.where(~np.isnan(np.nanmean(single_year_max, axis=0))) # x = [(a, b) for a, b in zip(x[0], x[1])]