def get_confint(self, _id): confint = mongo.data(_id) if not len(confint): return [] else: confint = np.array(confint) return confint - confint.mean(1)[:, None]
def get_confint(self, _id): confint = mongo.data(_id) if not len(confint): return [] else: confint = np.array(confint) return confint - confint.mean(1)[:,None]
def generate(self): """Generate the view of differenced production.""" for _id in self._ids: data = mongo.data(_id) degree = mongo.settings(_id)['degree'] self.plot(data, degree) plt.clf()
def generate(self): """Generate the view of smoothed production.""" for _id in self._ids: data = mongo.data(_id) step = mongo.settings(_id)['step'] self.plot(data, step) plt.clf()
def generate(self): """Generate the view of the correlogram.""" for _id in self._ids: data = mongo.data(_id[LABELS['values']]) confint = self.get_confint(_id[LABELS['confint']]) stg = mongo.settings(mongo.parents(_id[LABELS['values']])[0]) title = ' - '.join( ['{} = {}'.format(k, v) for k, v in stg.items()]) self.plot(data, confint, title)
def generate(self): """Generate the view of the correlogram.""" for _id in self._ids: data = mongo.data(_id[LABELS['values']]) confint = self.get_confint(_id[LABELS['confint']]) stg = mongo.settings( mongo.parents(_id[LABELS['values']])[0] ) title = ' - '.join(['{} = {}'.format(k, v) for k, v in stg.items()]) self.plot(data, confint, title)
def wrapper(settings, sources): """Prepare the data for the analysis then run it and save it if necessary. """ parents = sorted([_id for name, _id in sources.items()]) created_ids = {} data = {name: mongo.data(_id) for name, _id in sources.items()} need_analysis = not all([ mongo.is_analysis(type_, label, parents, stg) for label, stg in settings.items() ]) if need_analysis or FORCE_CACHE: data = func(data, settings) for label, stg in settings.items(): saved = mongo.is_analysis(type_, label, parents, stg) if not saved: _id = mongo.db.analysis.insert_one({ 'type': type_, 'label': label, 'parents': parents, 'settings': stg, 'data': data[label], }).inserted_id else: _id = mongo.db.analysis.find_one({ 'type': type_, 'label': label, 'parents': parents, 'settings': stg, })['_id'] if FORCE_CACHE: mongo.db.analysis.update({ '_id': _id, }, { '$set': { 'data': data[label] } }, upsert=False) created_ids[label] = _id return created_ids
def main(): """Launch the analysis.""" for cow in mongo.cows(): # Crude dta = mongo.identity(cow, LABELS['prods']) _id = dta['_id'] views.Crude(_id).render() acf_ids = analysis.acf({ LABELS['values']: {}, LABELS['confint']: {'alpha': 0.05}, }, { 'data': _id, }) views.ACF('production', 'ACF', [acf_ids]).render() pacf_ids = analysis.pacf({ LABELS['values']: {}, LABELS['confint']: {'alpha': 0.05}, }, { 'data': _id, }) views.PACF('production', 'PACF', [pacf_ids]).render() # Smoothing smooth_ids = [] steps = [7, 30] for step in steps: id_ = smoothing(_id, step)[LABELS['values']] smooth_ids.append(id_) # R: TODO if step == 7: sdta = mongo.data(id_) views.Smoothing('production', 'Smoothed production', smooth_ids).render() # Differencing diff_ids = [] acf_ids = [] pacf_ids = [] degrees = [1] for degree in degrees: id_ = differencing(_id, degree)[LABELS['values']] diff_ids.append(id_) acf_ids.append(analysis.acf({ LABELS['values']: {}, LABELS['confint']: {'alpha': 0.05}, }, { 'data': id_, })) pacf_ids.append(analysis.pacf({ LABELS['values']: {}, LABELS['confint']: {'alpha': 0.05}, }, { 'data': id_, })) views.Differencing('production', 'Differenced production', diff_ids).render() views.ACF(join('production', 'differenced'), 'ACF', acf_ids).render() views.PACF(join('production', 'differenced'), 'PACF', pacf_ids).render()
def main(): """Launch the analysis.""" for cow in mongo.cows(): # Crude dta = mongo.identity(cow, LABELS['prods']) _id = dta['_id'] views.Crude(_id).render() acf_ids = analysis.acf( { LABELS['values']: {}, LABELS['confint']: { 'alpha': 0.05 }, }, { 'data': _id, }) views.ACF('production', 'ACF', [acf_ids]).render() pacf_ids = analysis.pacf( { LABELS['values']: {}, LABELS['confint']: { 'alpha': 0.05 }, }, { 'data': _id, }) views.PACF('production', 'PACF', [pacf_ids]).render() # Smoothing smooth_ids = [] steps = [7, 30] for step in steps: id_ = smoothing(_id, step)[LABELS['values']] smooth_ids.append(id_) # R: TODO if step == 7: sdta = mongo.data(id_) views.Smoothing('production', 'Smoothed production', smooth_ids).render() # Differencing diff_ids = [] acf_ids = [] pacf_ids = [] degrees = [1] for degree in degrees: id_ = differencing(_id, degree)[LABELS['values']] diff_ids.append(id_) acf_ids.append( analysis.acf( { LABELS['values']: {}, LABELS['confint']: { 'alpha': 0.05 }, }, { 'data': id_, })) pacf_ids.append( analysis.pacf( { LABELS['values']: {}, LABELS['confint']: { 'alpha': 0.05 }, }, { 'data': id_, })) views.Differencing('production', 'Differenced production', diff_ids).render() views.ACF(join('production', 'differenced'), 'ACF', acf_ids).render() views.PACF(join('production', 'differenced'), 'PACF', pacf_ids).render()