def set_variables(self): """ Function that loads and sets the necessary variables. """ root_dir = os.path.dirname(os.path.realpath(__file__)) self.scratch_dir = os.path.join(root_dir, 'scratch') self.input_dir = os.path.join(root_dir, 'input_data') os.chdir(self.scratch_dir) # Input data BIOSAFE self.legal_weights = pd.read_csv(self.pjoin(self.input_dir, 'legalWeights.csv'), index_col=0) self.links_law = pd.read_csv(self.pjoin(self.input_dir, 'linksLaw.csv'), index_col=0) self.links_eco1 = pd.read_csv(self.pjoin(self.input_dir, 'linksEco.csv'), index_col=0) self.lut = pd.read_excel(self.pjoin(self.input_dir, 'BIOSAFE_20190711.xlsx'), sheet_name='lut_RWES').fillna(method='ffill') # this lookup table (lut) has: # ecotope codes of BIOSAFE in the 1st column: oldEcotope # aggregated/translated ectotopes in 2nd column: newEcotope # Ecotopes used in Virtual River self.vr_eco = pd.read_csv(self.pjoin(self.input_dir, 'VR_ecotopes.csv')) # Aggregate BIOSAFE ecotopes into RWES ecotopes self.links_eco2 = bsf.aggregateEcotopes(self.links_eco1, self.lut) return
legalWeights, linksLaw, linksEco = bsIO.from_csv(bio_dir) speciesPresence = pd.DataFrame(np.random.randint(2, size=len(linksLaw)),\ columns=['speciesPresence'], \ index=linksLaw.index) ecotopeArea = pd.DataFrame(np.ones(82) * 1e5,\ columns = ['area_m2'],\ index = linksEco.columns.values[0:-1]) bs = biosafe.biosafe(legalWeights, linksLaw, linksEco, speciesPresence, ecotopeArea) excel_file = os.path.join(bio_dir, 'BIOSAFE_20150629.xlsx') lut1 = pd.read_excel(excel_file, sheetname='lut_RWES').fillna(method='ffill') # this lookup table has: # ecotope codes of BIOSAFE in the first column: oldEcotope # aggregated/translated ectotopes in the second column: newEcotope linksEco1 = biosafe.aggregateEcotopes(linksEco, lut1) bs.linksEco = linksEco1 #%% Initialize cost module # Read input maps dike_length = pcr.readmap(os.path.join(cost_dir, 'dike_length.map')) dike_raise_sections = pcr.readmap( os.path.join(cost_dir, 'dike_raise_sections.map')) pollution_zones = pcr.readmap(os.path.join(cost_dir, 'pollution_zones.map')) smoothing_cost_classes = pcr.readmap( os.path.join(cost_dir, 'smoothing_cost_classes.map')) dem = pcr.readmap(os.path.join(ref_map_dir, 'dem.map')) # Read input distributions road_distr = ec.read_distribution(cost_dir, 'roads') smoothing_distr = ec.read_distribution(cost_dir, 'smoothing')