Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Defining regions and changing their attributes #438

Open
OFR-IIASA opened this issue Mar 2, 2022 · 0 comments
Open

Defining regions and changing their attributes #438

OFR-IIASA opened this issue Mar 2, 2022 · 0 comments

Comments

@OFR-IIASA
Copy link

OFR-IIASA commented Mar 2, 2022

In order to add regions, the function add_region() is used. The respective region name, hierarchy and parent can be defined. If a synonym should be added for a given region, then this must be done using add_region_synonym(). The key is though that the definition of the synonym must be done prior to adding the region.

This can be replicated by carrying out the following code snippet:

import message_ix
import ixmp

mp = ixmp.Platform(name="<database_a>")
mp2 = ixmp.Platform(name="<database_b>")
    
 # Copy units
for u in mp.units():
    mp2.add_unit(u)
        
df = mp.regions()
for i in df.index:
    mp2.add_region(region=df.iloc[i].region,
                              hierarchy=df.iloc[i].hierarchy,
                              parent=df.iloc[i].parent)
    if df.iloc[i].mapped_to is not None:
        mp2.add_region_synonym(region=df.iloc[i].region,
                                                 mapped_to=df.iloc[i].mapped_to)

The correct way of doing this:

import message_ix
import ixmp

mp = ixmp.Platform(name="<database_a>")
mp2 = ixmp.Platform(name="<database_b>")
    
 # Copy units
for u in mp.units():
    mp2.add_unit(u)
        
df = mp.regions()
for i in df.index:
    if df.iloc[i].mapped_to is not None:
        mp2.add_region_synonym(region=df.iloc[i].region,
                                                 mapped_to=df.iloc[i].mapped_to)
    mp2.add_region(region=df.iloc[i].region,
                              hierarchy=df.iloc[i].hierarchy,
                              parent=df.iloc[i].parent)

Note, there is not way of modifying and existing entry using the python api.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant