def record_correlation(s, t, overlap=300): """Return the correlation between the monthly anomalies of the two records, where they have common months.""" assert s.first_year == t.first_year a = list(s.series) b = list(t.series) series.anomalize(a) series.anomalize(b) common = [(u,v) for u,v in zip(a, b) if valid(u) and valid(v)] if len(common) < overlap: return None return correlation.pearson(*zip(*common))
def asdict(arg, inp, mode): """`arg` should be a list of 11-digit station identifiers or 12-digit record identifiers. The records from `inp` are extracted and returned as a dictionary (that maps identifiers to (data,begin) pair). If `mode` is 'anom' then data are converted to monthly anomalies. """ # Clear Climate Code, tool directory import v2index v2 = v2index.File(inp) table = {} for id in arg: for id12, series in v2.get(id): data, begin = from_lines(series) if mode == 'anom': # Clear Climate Code, code directory from code.series import anomalize anomalize(data, None) table[id12] = (data, begin) return table
def asdict(arg, inp, mode, axes, offset=None, scale=None): """`arg` should be a list of 11-digit station identifiers or 12-digit record identifiers. The records from `inp` are extracted and returned as a dictionary (that maps identifiers to (data,begin) pair). If `mode` is 'anom' then data are converted to monthly anomalies; if `mode` is 'annual' then data are converted to annual anomalies (using the GISTEMP algorithm that copes with missing months). *offset* can be used to offset each station. The first station in the *arg* list will have no offset, each subsequent station will have its data biased by adding *offset* (the offset increasing arithmetically for each station). All of the duplicates for a given station will be offset by the same amount. The visual effect is to displace stations upward (if the offset is positive). """ # Clear Climate Code, tool directory import ghcnm_index # Clear Climate Code from code import series v2 = ghcnm_index.File(inp) table = {} if not offset: offset = [0.0] * len(arg) for id,axis,off in zip(arg, axes, offset): for id12,rows in v2.get(id): data,begin = from_lines(rows, scale) if mode == 'anom': series.anomalize(data, None) if mode == 'annual': _, data = series.monthly_annual(data) data = apply_data_offset(data, off) table[id12] = (data,begin,axis) return table
def asdict(arg, inp, mode, axes, offset=None, scale=0.1): """`arg` should be a list of 11-digit station identifiers or 12-digit record identifiers. The records from `inp` are extracted and returned as a dictionary (that maps identifiers to (data,begin) pair). If `mode` is 'anom' then data are converted to monthly anomalies; if `mode` is 'annual' then data are converted to annual anomalies (using the GISTEMP algorithm that copes with missing months). *offset* can be used to offset each station. The first station in the *arg* list will have no offset, each subsequent station will have its data biased by adding *offset* (the offset increasing arithmetically for each station). All of the duplicates for a given station will be offset by the same amount. The visual effect is to displace stations upward (if the offset is positive). """ # Clear Climate Code, tool directory import v2index # Clear Climate Code from code import series v2 = v2index.File(inp) table = {} if not offset: offset = [0.0] * len(arg) for id,axis,off in zip(arg, axes, offset): for id12,rows in v2.get(id): data,begin = from_lines(rows, scale) if mode == 'anom': series.anomalize(data, None) if mode == 'annual': _, data = series.monthly_annual(data) data = apply_data_offset(data, off) table[id12] = (data,begin,axis) return table
def asdict(arg, inp, mode): """`arg` should be a list of 11-digit station identifiers or 12-digit record identifiers. The records from `inp` are extracted and returned as a dictionary (that maps identifiers to (data,begin) pair). If `mode` is 'anom' then data are converted to monthly anomalies. """ # Clear Climate Code, tool directory import v2index v2 = v2index.File(inp) table = {} for id in arg: for id12,series in v2.get(id): data,begin = from_lines(series) if mode == 'anom': # Clear Climate Code, code directory from code.series import anomalize anomalize(data, None) table[id12] = (data,begin) return table