djgroen / flee

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

Fixing ReadLocationsFromCSV flood_level.csv path issue #103

Closed lauraharbach closed 6 months ago

lauraharbach commented 7 months ago

Laura's branch - laura_dflee_flood

Generalising reading the flood_level.csv file in ReadLocationsFromCSV in InputGeography.py, so that both the config and test files pass. Without this the full path needs to be specified so that when AddNewConflictZones in test/test_dflee calls ReadLocationsFromCSV again, the flood_level.csv file can be found. ReadLocationsFromCSV needs to be fixed, SimulationSettings.FloodLevelInputFile is an empty string [WHY?], so the implemented temp fix is to define SimulationSettings.FloodLevelInputFile based on SimulationSettings.ConflictInputFile.

def ReadLocationsFromCSV(self, csv_name: str) -> None:
        """
        Summary:
            Converts a CSV file to a locations information table

        Args:
            csv_name (str): csv file name

        Returns:
            None.
        """
        #These print statements show SimulationSettings.FloodLevelInputFile is an unexpected empty string
        # print("csv_name", csv_name, file=sys.stderr)
        # print("SimulationSettings.ConflictInputFile", SimulationSettings.ConflictInputFile, file=sys.stderr)
        # print("SimulationSettings.FloodLevelInputFile", SimulationSettings.FloodLevelInputFile, file=sys.stderr)

        if "flood_driven_spawning" in SimulationSettings.spawn_rules.keys():
            # Read flood location attributes.
            if SimulationSettings.spawn_rules["flood_driven_spawning"] is True:
                #Works with the dflee_test_laura config file
                # self.ReadAttributeInputCSV("flood_level","int","input_csv/flood_level.csv") 
                # self.ReadAttributeInputCSV("forecast_flood_levels","int","input_csv/flood_level.csv") 

                #Works with the dflee_test.py test case 
                # self.ReadAttributeInputCSV("flood_level","int","/Users/laura/Documents/PhD/Codes/FLEE/flee/test_data/test_data_dflee/test_input_csv/flood_level.csv")
                # self.ReadAttributeInputCSV("forecast_flood_levels","int","/Users/laura/Documents/PhD/Codes/FLEE/flee/test_data/test_data_dflee/test_input_csv/flood_level.csv")

                #Works with both dflee_test.py and dflee_test_laura config file
                flood_level_file = SimulationSettings.FloodLevelInputFile
                if flood_level_file == "":
                    flood_level_file = SimulationSettings.ConflictInputFile[:-13] + "flood_level.csv"
                self.ReadAttributeInputCSV("flood_level","int",flood_level_file)
                self.ReadAttributeInputCSV("forecast_flood_levels","int",flood_level_file)

                #Can't get this to work with dflee_test_laura config file as SimulationSettings.FloodLevelInputFile returns an empty string. 

                # self.ReadAttributeInputCSV("flood_level","int",SimulationSettings.FloodLevelInputFile)
                # self.ReadAttributeInputCSV("forecast_flood_levels","int",SimulationSettings.FloodLevelInputFile)

            elif SimulationSettings.move_rules["FloodRulesEnabled"] is False:
                self.ReadConflictInputCSV(SimulationSettings.ConflictInputFile)