def timeseries(self, iamc=False, regions=None, variables=None, units=None, years=None): """retrieve timeseries data as a pandas.DataFrame Parameters ---------- iamc : boolean, default True returns a pandas.DataFrame either - 'IAMC-style' format (cols: region, variable unit, <years>) - in tabular form (cols: region, variable, unit, year) regions : list of strings filter by regions variables : list of strings filter by variables units : list of strings filter by units years : list of integers filter by years """ # convert filter lists to Java objects regions = ix.to_jlist(regions) variables = ix.to_jlist(variables) units = ix.to_jlist(units) years = ix.to_jlist(years) # retrieve data, convert to pandas.DataFrame data = self._jobj.getTimeseries(regions, variables, units, None, years) dictionary = {} # if in tabular format ts_range = range(data.size()) cols = ['region', 'variable', 'unit'] for i in cols: dictionary[i] = [str(data.get(j).get(i)) for j in ts_range] dictionary['year'] = [data.get(j).get('year').intValue() for j in ts_range] cols.append("year") dictionary['value'] = [data.get(j).get('value').floatValue() for j in ts_range] cols.append("value") df = pd.DataFrame df = df.from_dict(dictionary, orient='columns', dtype=None) df['model'] = self.model df['scenario'] = self.scenario df = df[['model', 'scenario'] + cols] if iamc: df = df.pivot_table(index=iamc_idx_cols, columns='year')['value'] df.reset_index(inplace=True) return df
def add_cat(self, name, cat, keys, is_unique=False): """Map elements from *keys* to category *cat* within set *name*. Parameters ---------- name : str Name of the set. cat : str Name of the category. keys : str or list of str Element keys to be added to the category mapping. is_unique: bool, optional If `True`, then *cat* must have only one element. An exception is raised if *cat* already has an element, or if ``len(keys) > 1``. """ self._jobj.addCatEle(name, str(cat), ixmp.to_jlist(keys), is_unique)