iiasa / message_ix

The integrated assessment and energy systems model MESSAGEix
https://docs.messageix.org
Apache License 2.0
112 stars 149 forks source link

Enhancement Proposal: Input of data using string - A Simplified Approach to Inputting Data into MESSAGEix without MS Excel #778

Closed shreeyashn20 closed 5 months ago

shreeyashn20 commented 5 months ago

Dear Researchers,

I present to you a Simplified Approach to Inputting Data into MESSAGEix without MS Excel.

This improved method for inputting data into MESSAGEix offers a user-friendly tabular format, eliminating the need for MS Excel files and version management of codes and xlsx files separately. It utilizes comma-separated values (CSV) fed to a string, which is then merged with the year_df dataset. The resulting table can be used as input to the parameter, simplifying the data input process for non-coders.

  1. Create a CSV and store it as string in a variable.

    data_var_cost = """
    node_loc,technology,mode,time,value,unit
    India,coal,standard,year,5,$/kWh
    India,gas,standard,year,6,$/kWh
    India,oil,standard,year,7,$/kWh
    """
  2. Read the CSV and String file and store it in new variable. df_var_cost = pd.read_csv(StringIO(data_var_cost))

  3. Now merge the newly created variable with year_df. This step can be modified to merge year_vtg or year_act.

    
    year_df['key'] = 0
    df_var_cost['key'] = 0

merged_var_cost = pd.merge(year_df, df_var_cost, on='key').drop('key', axis=1)


4. Finally, feed the merged table into the parameter function.
```scenario.add_par("var_cost",merged_var_cost)```

This method can be introduced in Westeros tutorials to help new users write and see data as well as code in single ipynb file.  Major advantage over using ```for``` loop mentioned in Westeros tutorial is the ability to change data for future model years. 

This is my small and humble contribution in open-source community of MESSAGEix.

Thank you for patient reading!