def _build_norms(vals, days, yr_days): mth_days = get_md_array(days[DATE]) # Build 15-day norms for every day in days day_nums = np.arange(yr_days.size) # Column 0: mean, Column 1: std norms = np.ones([yr_days.size, 2]) * np.NAN fin_mask = np.isfinite(vals) for x in day_nums: date = yr_days[x] srt_date = date - A_WEEK end_date = date + A_WEEK date_range = get_date_array(srt_date, end_date) mth_days_range = get_md_array(date_range) date_mask = np.in1d(mth_days, mth_days_range) vals_rng = vals[np.logical_and(fin_mask, date_mask)] if vals_rng.size >= MIN_NORM_VALUES: norms[x, 0], norms[x, 1] = _biweight_mean_std(vals_rng) return norms
def _build_percentiles(vals, days, yr_days): mth_days = get_md_array(days[DATE]) # Build 29-day percentiles for every day in yr_days day_nums = np.arange(yr_days.size) # Columns: 30th,50th,70th,90th,95th percentiles = np.ones([yr_days.size, 5]) * np.NAN for x in day_nums: date = yr_days[x] srt_date = date - TWO_WEEKS end_date = date + TWO_WEEKS date_range = get_date_array(srt_date, end_date) mth_days_range = get_md_array(date_range) date_mask = np.in1d(mth_days, mth_days_range) vals_rng = vals[np.logical_and( np.logical_and(_not_nan(vals), vals > 0), date_mask)] if vals_rng.size >= MIN_PERCENTILE_VALUES: percentiles[x, :] = [ np.percentile(vals_rng, 30), np.percentile(vals_rng, 50), np.percentile(vals_rng, 70), np.percentile(vals_rng, 90), np.percentile(vals_rng, 95) ] return percentiles
def _get_pctiles_md_masks(days, yr_days): mth_days = get_md_array(days[DATE]) day_nums = np.arange(yr_days.size) pctile_masks = np.zeros((yr_days.size, mth_days.size), dtype=np.bool) for x in day_nums: mth_day = yr_days[x] srt_mth_day = mth_day - TWO_WEEKS end_mth_day = mth_day + TWO_WEEKS date_range = get_date_array(srt_mth_day, end_mth_day) mth_days_range = get_md_array(date_range) pctile_masks[x, :] = np.in1d(mth_days, mth_days_range) return pctile_masks
def _get_norms_md_masks(days, yr_days): mth_days = get_md_array(days[DATE]) # For non-leap years day_nums = np.arange(yr_days.size) norm_masks = np.zeros((yr_days.size, mth_days.size), dtype=np.bool) for x in day_nums: mth_day = yr_days[x] srt_mth_day = mth_day - A_WEEK end_mth_day = mth_day + A_WEEK date_range = get_date_array(srt_mth_day, end_mth_day) mth_days_range = get_md_array(date_range) norm_masks[x, :] = np.in1d(mth_days, mth_days_range) return norm_masks
NGH_CORR = 0.8 NGH_RESID_CUTOFF = 8.0 NGH_RESID_STD_CUTOFF = 4.0 ANOMALY_CUTOFF = 10.0 MIN_DAYS_MTH_WINDOW = 40 MIN_NGHS = 3 MAX_NGHS = 7 NGH_STNS_ID = "NGH_STNS_ID" NGH_STNS_MASK_OVERLAP = "NGH_STNS_MASK_OVERLAP" NGH_STNS_WGHTS = "NGH_STNS_WGHTS" NGH_STNS_MODEL = "NGH_STNS_MODEL" NGH_STNS_OBS = "NGH_STNS_OBS" # Constants for building Tmin/Tmax normals MONTHS = np.arange(1, 13) DATES_366 = get_date_array(datetime(2004, 1, 1), datetime(2004, 12, 31)) DATES_365 = get_date_array(datetime(2003, 1, 1), datetime(2003, 12, 31)) MIN_NORM_VALUES = 100 TWX_TO_GHCN_FLAGS_MAP = { QA_OK: "", QA_MISSING: "", DUP: "D", QA_DUP_YEAR: "D", QA_DUP_MONTH: "D", QA_DUP_YEAR_MONTH: "D", QA_DUP_WITHIN_MONTH: "D", QA_GAP: "G", QA_INTERNAL_INCONSIST: "I", QA_STREAK: "K", QA_MEGA_INCONSIST: "M",