From 45173c0d8e93b7d30d8ca5f60508a0828d55af2e Mon Sep 17 00:00:00 2001 From: tuckersiegel <siegel.tucker@gmail.com> Date: Mon, 22 Feb 2021 14:33:28 -0500 Subject: [PATCH] normals adjustment --- to_mongo.py | 40 +++++++++++++++++++++++++++++++--------- 1 file changed, 31 insertions(+), 9 deletions(-) diff --git a/to_mongo.py b/to_mongo.py index 3cf477a..415fe4f 100644 --- a/to_mongo.py +++ b/to_mongo.py @@ -98,15 +98,26 @@ for year in years: count += 1 + if len(locs) != 0: + new_result = gdd.insert_many(locs) + ### 30 YEAR NORMALS ### ### Covers from 1981-2010 ### +db = client["gdd_database"] + +gdd = db.normals + +gdd.drop() + +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.nan -single_year_max[:] = np.nan - for year in range(1981, 2010+1): print (year) data = xr.open_dataset("data/temps_%s.nc" % year) @@ -123,16 +134,29 @@ for year in range(1981, 2010+1): tmin_2 = tmaxs[60:] tmins = np.concatenate([tmin_1, tmin_2], axis=0) - tmaxs = 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 - x = np.where(~np.isnan(np.nanmean(single_year_max, axis=0))) -x = [(a, b) for a, b in zip(x[0], x[1])] +# x = [(a, b) for a, b in zip(x[0], x[1])] -lat = lat[::-1] +# FORCE LOCATIONS TO COLLEGE PARK, LAT 38.99 LON -76.94 BECAUSE OF ATLAS LIMIT + +a1 = np.where(38.5 < lat)[0].tolist() +a2 = np.where(lat < 39.5)[0].tolist() +lat_a = np.array(list(set(a1) & set(a2))) + +a1 = np.where(-77 < lon)[0].tolist() +a2 = np.where(lon < -76)[0].tolist() +lon_a = np.array(list(set(a1) & set(a2))) + +x1 = np.array(np.meshgrid(lat_a, lon_a)).T.reshape(len(lat_a) * len(lon_a), 2).tolist() +x1 = [(z[0], z[1]) for z in x1] +x2 = [(a, b) for a, b in zip(x[0], x[1])] # fix to x = [..... (x[0], x[1])] and all limiting stuff above and below when atlas limit removed + +x = list(set(x1) & set(x2)) tmins = single_year_min tmaxs = single_year_max @@ -163,8 +187,6 @@ for i in tqdm.tqdm(x): t["prism_lat"] = int(a[0]) t["prism_lon"] = int(a[1]) - t["last_date"] = 0#datetime.datetime.strptime(str(soy + np.timedelta64(len(tmin_) - 1, "D")) , "%Y-%m-%d") - t["year"] = 0 t["min_temps"] = list([float(a) for a in tmin_]) t["max_temps"] = list([float(a) for a in tmax_]) t["_id"] = _id -- GitLab