<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Build names mapping
To make it a little easier to check that I'm using the correct guids, construct a mapping from names back to guid.
Note
Step1:  Pikov sprite editor classes
These classes are the core resources used in defining a "Pikov" file.
Note
Step2:  Gamekitty
Create instances of the Pikov classes to define a concrete Pikov graph, based on my "gamekitty" animations.
Step3:  Chop image into 8x8 sprites
By creating an array of 8x8 images, we make it easier to map from PICO-8 sprite number (from my original gamekitty cart) to a Bitmap.
<ASSISTANT_TASK:>
Python Code:
names = {}
for node in graph:
    for edge in node:
        if edge.guid == "169a81aefca74e92b45e3fa03c7021df":
            value = node[edge].value
            if value in names:
                raise ValueError('name: "{}" defined twice'.format(value))
            names[value] = node
     
names["ctor"]
# {name: names[name].guid for name in sorted(names) if '[' not in name}
def name_to_guid(name):
    if name not in names:
        return None
    node = names[name]
    if not hasattr(node, "guid"):
        return None
    return node.guid
Explanation: Build names mapping
To make it a little easier to check that I'm using the correct guids, construct a mapping from names back to guid.
Note: this adds a constraint that no two nodes have the same name, which should not be enforced for general semantic graphs.
End of explanation
from pikov.sprite import Resource, Rectangle, Point, Bitmap
Explanation: Pikov sprite editor classes
These classes are the core resources used in defining a "Pikov" file.
Note: ideally these classes could be derived from the graph itself, but I
don't (yet) encode type or field information in the pikov.json semantic
graph.
End of explanation
resource = Resource(graph, guid=name_to_guid("spritesheet"))
resource.name = "spritesheet"
resource.relative_path = "./gamekitty.png"
resource
resource.image
Explanation: Gamekitty
Create instances of the Pikov classes to define a concrete Pikov graph, based on my "gamekitty" animations.
End of explanation
spritesheet = []
for row in range(16):
    for column in range(16):
        sprite_number = row * 16 + column
        
        crop_name = "crop[{}]".format(sprite_number)
        crop = Rectangle(graph, guid=name_to_guid(crop_name))
        crop.name = crop_name
        
        anchor_name = "anchor[{}]".format(sprite_number)
        anchor = Point(graph, guid=name_to_guid(anchor_name))
        anchor.name = anchor_name
        anchor.x = column * 8
        anchor.y = row * 8
        crop.anchor = anchor
        crop.width = 8
        crop.height = 8
        
        bitmap_name = "bitmap[{}]".format(sprite_number)
        bitmap = Bitmap(graph, guid=name_to_guid(bitmap_name))
        bitmap.name = bitmap_name
        bitmap.resource = resource
        bitmap.crop = crop
        
        spritesheet.append(bitmap)
list(graph.get_labels(spritesheet[4]))
spritesheet[1].image
# Save our work!
graph.save()
Explanation: Chop image into 8x8 sprites
By creating an array of 8x8 images, we make it easier to map from PICO-8 sprite number (from my original gamekitty cart) to a Bitmap.
End of explanation
<END_TASK>