from rumi.viz import dataquery
import altair as alt
import altair as alt
import pandas as pd


model_instance ="/home/vikrant/programming/work/github/PIER/"

modelmanager_ = dataquery.ModelInstance(model_instance)
Process Process-2:
Traceback (most recent call last):
  File "/usr/lib/python3.13/multiprocessing/process.py", line 313, in _bootstrap
    self.run()
    ~~~~~~~~^^
  File "/usr/lib/python3.13/multiprocessing/process.py", line 108, in run
    self._target(*self._args, **self._kwargs)
    ~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/vikrant/programming/work/github/Rumi-dev/rumi/io/logger.py", line 68, in listener_process
    sleep(1)
    ~~~~~^^^
KeyboardInterrupt
scenario = "1_Ref"

multi = dataquery.MultiScenarioData("1_Ref","2_Vikasit","3_Vichalit")

total_demand = multi.get_aggregated_demand(demand_sector='ALL',
                                           energy_service='ALL',
                                           energy_carrier='ALL',
                                           service_tech=None,
                                           geogroupby=['ModelGeography'],
                                           timegroupby=['Year'])
total_demand
Year ModelGeography DemandSector EnergyService EnergyCarrier EnergyUnit EnergyDemand Scenario
0 2024 INDIA D_RES RES_OTHER ELECTRICITY PJ 273.112773 1_Ref
1 2025 INDIA D_RES RES_OTHER ELECTRICITY PJ 283.843427 1_Ref
2 2026 INDIA D_RES RES_OTHER ELECTRICITY PJ 295.100336 1_Ref
3 2027 INDIA D_RES RES_OTHER ELECTRICITY PJ 306.896993 1_Ref
4 2028 INDIA D_RES RES_OTHER ELECTRICITY PJ 319.251024 1_Ref
... ... ... ... ... ... ... ... ...
1075 2037 INDIA D_TRANS IntFreight HSD PJ 26.470467 3_Vichalit
1076 2038 INDIA D_TRANS IntFreight HSD PJ 27.379369 3_Vichalit
1077 2039 INDIA D_TRANS IntFreight HSD PJ 28.333561 3_Vichalit
1078 2040 INDIA D_TRANS IntFreight HSD PJ 29.343345 3_Vichalit
1079 2041 INDIA D_TRANS IntFreight HSD PJ 30.420763 3_Vichalit

3240 rows × 8 columns

total_demand
Year ModelGeography DemandSector EnergyService EnergyCarrier EnergyUnit EnergyDemand Scenario
0 2024 INDIA D_RES RES_OTHER ELECTRICITY PJ 273.112773 1_Ref
1 2025 INDIA D_RES RES_OTHER ELECTRICITY PJ 283.843427 1_Ref
2 2026 INDIA D_RES RES_OTHER ELECTRICITY PJ 295.100336 1_Ref
3 2027 INDIA D_RES RES_OTHER ELECTRICITY PJ 306.896993 1_Ref
4 2028 INDIA D_RES RES_OTHER ELECTRICITY PJ 319.251024 1_Ref
... ... ... ... ... ... ... ... ...
1075 2037 INDIA D_TRANS IntFreight HSD PJ 26.470467 3_Vichalit
1076 2038 INDIA D_TRANS IntFreight HSD PJ 27.379369 3_Vichalit
1077 2039 INDIA D_TRANS IntFreight HSD PJ 28.333561 3_Vichalit
1078 2040 INDIA D_TRANS IntFreight HSD PJ 29.343345 3_Vichalit
1079 2041 INDIA D_TRANS IntFreight HSD PJ 30.420763 3_Vichalit

3240 rows × 8 columns

import altair as alt
from rumi.viz import ploting
alt.Chart(total_demand).mark_bar().encode(
    y = alt.Y('EnergyDemand:Q'),
    x = alt.X("Year"),
    column = "Scenario",
    color = 'Scenario')
alt.Chart(total_demand.query("(Year==2024)| (Year==2035) | (Year == 2041)")).mark_bar().encode(
    y = alt.Y('EnergyDemand:Q'),
    x = alt.X("Scenario"),
    color = 'EnergyService').facet(
    column=alt.Column("Year:N", title=None, header=alt.Header(labelOrient="bottom"))
)
from rumi.viz import ploting
p = ploting.DemandSectorWise(scenario=scenario,name="Demand Sector Wise")
p.plot(data=total_demand).facet(
    column=alt.Column("Scenario:N", title=None, header=alt.Header(labelOrient="bottom"))
)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[16], line 1
----> 1 p.plot(data=total_demand).facet(
      2     column=alt.Column("Scenario:N", title=None, header=alt.Header(labelOrient="bottom"))
      3 )

File ~/usr/local/rumiviz/lib/python3.13/site-packages/altair/vegalite/v6/api.py:3995, in _EncodingMixin.facet(self, facet, row, column, data, columns, **kwargs)
   3992     r: Any = row
   3993     f = FacetMapping(row=r, column=column)
-> 3995 return FacetChart(spec=self, facet=f, data=data, columns=columns, **kwargs)

File ~/usr/local/rumiviz/lib/python3.13/site-packages/altair/vegalite/v6/api.py:4927, in FacetChart.__init__(self, data, spec, facet, params, **kwargs)
   4925     msg = f"{type(self).__name__!r} requires a `spec`, but got: {spec!r}"
   4926     raise TypeError(msg)
-> 4927 _check_if_valid_subspec(spec, "FacetChart")
   4928 _spec_as_list = [spec]
   4929 params, _spec_as_list = _combine_subchart_params(params, _spec_as_list)

File ~/usr/local/rumiviz/lib/python3.13/site-packages/altair/vegalite/v6/api.py:4281, in _check_if_valid_subspec(spec, classname)
   4276 if spec._get(attr) is not Undefined:
   4277     msg = (
   4278         f"Objects with {attr!r} attribute cannot be used within {classname}. "
   4279         f"Consider defining the {attr} attribute in the {classname} object instead."
   4280     )
-> 4281     raise TypeError(msg)

TypeError: Objects with 'config' attribute cannot be used within FacetChart. Consider defining the config attribute in the FacetChart object instead.
p1 = ploting.DemandDrillDownSectorCarrierNormalisedBarPlot(scenario=scenario,name="Demand Sector Wise Normalised")
p1.plot()
/tmp/ipykernel_62627/2990898309.py:2: UserWarning: Automatically deduplicated selection parameter with identical configuration. If you want independent parameters, explicitly name them differently (e.g., name='param1', name='param2'). See https://github.com/vega/altair/issues/3891
  p1.plot()
/home/vikrant/usr/local/rumiviz/lib/python3.13/site-packages/altair/vegalite/v6/api.py:3801: UserWarning: Automatically deduplicated selection parameter with identical configuration. If you want independent parameters, explicitly name them differently (e.g., name='param1', name='param2'). See https://github.com/vega/altair/issues/3891
  dct = self.to_dict(context={"pre_transform": False})
class DemandSectorWise(ploting.SingleScenarioDemandBarPlot):
    chart_id = "DemandSectorWise"

    def plot(self, data=None, save=False):
        chart = super().plot(data, save)
        props = self.get_plot_specs().get("properties", {})
        return self.configure_title(chart.mark_bar().encode(
            # cluster by sector
            xOffset=alt.XOffset("DemandSector:N", title="Demand Sector"),
            color=alt.Color("DemandSector:N", title="Demand Sector",
                            scale=self.sectors_scale()),
            tooltip=[
                alt.Tooltip('Year:O'),
                alt.Tooltip('DemandSector:N'),
                alt.Tooltip(f'{self.quantity}:Q', title=self.description)
            ]
        ).facet(
    column=alt.Column("Scenario:N", title=None, header=alt.Header(labelOrient="bottom"))
        ))
p = DemandSectorWise(scenario='1_REF', name="multi", data=total_demand)
p.plot()