djgroen / flee

flee agent-based modelling code
BSD 3-Clause "New" or "Revised" License
6 stars 7 forks source link

Default Column for Location Attributes #99

Open lauraharbach opened 9 months ago

lauraharbach commented 9 months ago

Add default column functionality to location attributes.

For example, add a default "flood_level" attribute for locations not specified in the flood_level.csv file.

e.g. flood_level.csv should look like this.

Day, Default, F1, F2, F3

0,0,1,3,2 1,0,2,1,3 2,0,1,2,3 3,0,1,1,1

Code currently works by defaulting dynamic attributes to 0 in UpdateLocationAttributes:

def UpdateLocationAttributes(self, e, attribute_name: str, time: int) -> None:

    attrlist = self.attributes[attribute_name]

    for i in range(0, len(e.locations)):
        loc_name = e.locations[i].name
        if loc_name in attrlist:
            e.locations[i].attributes[attribute_name] = attrlist[loc_name][time]
            print(e.time, loc_name, e.locations[i].attributes, attrlist[loc_name][time], file=sys.stderr)
        else:
            e.locations[i].attributes[attribute_name] = 0
            print(e.time, loc_name, e.locations[i].attributes, file=sys.stderr)

There are two types of location attributes. Static ones and dynamic ones. The dynamic ones are only added when UpdateLocationAttributes is called, not before that. Once default column is working, remove the e.locations[i].attributes[attribute_name] = 0 else statement above which defaults dynamic attributes to zero.