Ejemplo n.º 1
0
 def __init__(self, save_folder, ini_file=None):
     config = configparser.RawConfigParser()
     if ini_file is not None:
         config_file = ini_file
     elif len(sys.argv) > 1:
         config_file = sys.argv[1]
     else:
         config_file = getModelFile('SIREN.ini')
     config.read(config_file)
     technologies = config.get('Power', 'technologies')
     technologies += ' ' + config.get('Power', 'fossil_technologies')
     technologies = technologies.split()
     for i in range(len(technologies)):
         technologies[i] = techClean(technologies[i])
     technologies = sorted(technologies)
     tech_dict = {}
     for technology in technologies:
         area = 0.
         capital_cost = ''
         o_m_cost = ''
         try:
             area = float(config.get(technology, 'area'))
         except:
             pass
         try:
             capital_cost = config.get(technology, 'capital_cost')
             if capital_cost[-1] == 'K':
                 capital_cost = float(capital_cost[:-1]) * pow(10, 3)
             elif capital_cost[-1] == 'M':
                 capital_cost = float(capital_cost[:-1]) * pow(10, 6)
             else:
                 capital_cost = float(capital_cost)
         except:
             pass
         try:
             o_m_cost = config.get(technology, 'o_m_cost')
             if o_m_cost[-1] == 'K':
                 o_m_cost = float(o_m_cost[:-1]) * pow(10, 3)
             elif o_m_cost[-1] == 'M':
                 o_m_cost = float(o_m_cost[:-1]) * pow(10, 6)
             else:
                 o_m_cost = float(o_m_cost)
         except:
             pass
         tech_dict[technology] = [area, capital_cost, o_m_cost]
     dialog = Table(
         tech_dict,
         fields=['technology', 'area', 'capital_cost', 'o_m_cost'],
         save_folder=save_folder,
         title='Technologies',
         edit=True)
     dialog.exec_()
     values = dialog.getValues()
     if values is None:
         return
     SaveIni(values)
Ejemplo n.º 2
0
 def nice(self, string):
     if string == '':
         strout = string
     else:
         strout = techClean(string, full=True)
         if string != '' and string in self.units:
             i = self.units.find(string)
             j = self.units.find(' ', i)
             if j < 0:
                 j = len(self.units)
             strout = strout + ' (' + self.units[i + 1 + len(string):j] + ')'
     self.hdrs[strout] = string
     return strout
Ejemplo n.º 3
0
 def __init__(self):
     config = configparser.RawConfigParser()
     if len(sys.argv) > 1:
         config_file = sys.argv[1]
     else:
         config_file = getModelFile('SIREN.ini')
     config.read(config_file)
     self.icons = {
         'Biomass': 'biomass_g.png',
         'CST': 'solar_g.png',
         'Fossil': 'fossil_g.png',
         'Geothermal': 'hot_rocks_g.png',
         'Hydro': 'hydro_g.png',
         'Other': 'question.png',
         'PV': 'solar_pv_g.png',
         'Solar Thermal': 'solar_g.png',
         'Wave': 'wave_g.png',
         'Wind': 'wind_g.png'
     }
     try:
         technologies = config.get('Power', 'technologies').split()
         for tec in technologies:
             tec = techClean(tec)
             try:
                 self.icons[tec] = config.get(tec, 'icon')
             except:
                 pass
         technologies = config.get('Power', 'fossil_technologies').split()
         for tec in technologies:
             tec = techClean(tec)
             try:
                 self.icons[tec] = config.get(tec, 'icon')
             except:
                 pass
     except:
         pass
Ejemplo n.º 4
0
 def add_item(self, key, value, i):
     if i < 0:
         i = self.grid.rowCount(
         )  # could possibly use this always just not sure about colour groups
         screen = QtWidgets.QDesktopWidget().availableGeometry()
         if self.height[1] + self.height[0] < int(screen.height() * .9):
             width = max(self.width[1], self.frameGeometry().width())
             self.height[1] += self.height[0]
             self.resize(width, self.height[1])
     wht = techClean(key, full=True)
     self.grid.addWidget(QtWidgets.QLabel(wht), i, 0)
     if self.map != '':
         self.btn.append(QtWidgets.QPushButton(key, self))
         self.btn[-1].clicked.connect(self.showDialog)
         if value[0] != '':
             self.btn[-1].setStyleSheet(
                 'QPushButton {background-color: %s; color: %s;}' %
                 (value[0].name(), value[0].name()))
         self.grid.addWidget(self.btn[-1], i, 1)
         metrics = self.btn[-1].fontMetrics()
         if metrics.boundingRect(
                 self.btn[-1].text()).width() > self.width[0]:
             self.width[0] = metrics.boundingRect(
                 self.btn[-1].text()).width()
         if metrics.boundingRect(
                 self.btn[-1].text()).height() > self.height[0]:
             self.height[0] = metrics.boundingRect(self.btn[-1].text(
             )).height() + self.grid.verticalSpacing() * 2
     self.btn.append(QtWidgets.QPushButton(key + '_base', self))
     metrics = self.btn[-1].fontMetrics()
     if i < 2:
         self.default_style = self.btn[-1].styleSheet()
     self.btn[-1].clicked.connect(self.showDialog)
     if value[1] != '':
         self.btn[-1].setStyleSheet(
             'QPushButton {background-color: %s; color: %s;}' %
             (value[1].name(), value[1].name()))
     self.grid.addWidget(self.btn[-1], i, self.default_col)
     if metrics.boundingRect(self.btn[-1].text()).width() > self.width[0]:
         self.width[0] = metrics.boundingRect(self.btn[-1].text()).width()
     if metrics.boundingRect(self.btn[-1].text()).height() > self.height[0]:
         self.height[0] = metrics.boundingRect(
             self.btn[-1].text()).height() + self.grid.verticalSpacing() * 2
Ejemplo n.º 5
0
 def get_config(self):
     config = configparser.RawConfigParser()
     if len(sys.argv) > 1:
         config_file = sys.argv[1]
     else:
         config_file = getModelFile('SIREN.ini')
     config.read(config_file)
     try:
         self.base_year = config.get('Base', 'year')
     except:
         self.base_year = '2012'
     parents = []
     try:
         parents = getParents(config.items('Parents'))
     except:
         pass
     try:
         self.sam_file = config.get('Files', 'sam_turbines')
         for key, value in parents:
             self.sam_file = self.sam_file.replace(key, value)
         self.sam_file = self.sam_file.replace('$USER$', getUser())
         self.sam_file = self.sam_file.replace('$YEAR$', self.base_year)
     except:
         self.sam_file = ''
     try:
         self.pow_dir = config.get('Files', 'pow_files')
         for key, value in parents:
             self.pow_dir = self.pow_dir.replace(key, value)
         self.pow_dir = self.pow_dir.replace('$USER$', getUser())
         self.pow_dir = self.pow_dir.replace('$YEAR$', self.base_year)
     except:
         self.pow_dir = ''
     try:
         self.map = config.get('Map', 'map_choice')
     except:
         self.map = ''
     self.upper_left = [0., 0.]
     self.lower_right = [-90., 180.]
     try:
          upper_left = config.get('Map', 'upper_left' + self.map).split(',')
          self.upper_left[0] = float(upper_left[0].strip())
          self.upper_left[1] = float(upper_left[1].strip())
          lower_right = config.get('Map', 'lower_right' + self.map).split(',')
          self.lower_right[0] = float(lower_right[0].strip())
          self.lower_right[1] = float(lower_right[1].strip())
     except:
          try:
              lower_left = config.get('Map', 'lower_left' + self.map).split(',')
              upper_right = config.get('Map', 'upper_right' + self.map).split(',')
              self.upper_left[0] = float(upper_right[0].strip())
              self.upper_left[1] = float(lower_left[1].strip())
              self.lower_right[0] = float(lower_left[0].strip())
              self.lower_right[1] = float(upper_right[1].strip())
          except:
              pass
     self.technologies = ['']
     self.areas = {}
     try:
         technologies = config.get('Power', 'technologies')
         for item in technologies.split():
             itm = techClean(item)
             self.technologies.append(itm)
             try:
                 self.areas[itm] = float(config.get(itm, 'area'))
             except:
                 self.areas[itm] = 0.
     except:
         pass
     self.cst_tshours = 0
     try:
         self.cst_tshours = float(config.get('CST', 'tshours'))
     except:
         pass
     self.st_tshours = 0
     try:
         self.st_tshours = float(config.get('Solar Thermal', 'tshours'))
     except:
         pass
Ejemplo n.º 6
0
 def get_config(self):
     config = configparser.RawConfigParser()
     if __name__ == '__main__':
         for i in range(1, len(sys.argv)):
             if sys.argv[i][-4:] == '.ini':
                 config_file = sys.argv[i]
                 break
     else:
         if len(sys.argv) > 1:
             config_file = sys.argv[1]
         else:
             config_file = getModelFile('SIREN.ini')
     config.read(config_file)
     try:
         self.base_year = config.get('Base', 'year')
     except:
         self.base_year = '2012'
     parents = []
     try:
         parents = getParents(config.items('Parents'))
     except:
         pass
     try:
         self.sam_file = config.get('Files', 'sam_turbines')
         for key, value in parents:
             self.sam_file = self.sam_file.replace(key, value)
         self.sam_file = self.sam_file.replace('$USER$', getUser())
         self.sam_file = self.sam_file.replace('$YEAR$', self.base_year)
     except:
         self.sam_file = ''
     try:
         self.pow_dir = config.get('Files', 'pow_files')
         for key, value in parents:
             self.pow_dir = self.pow_dir.replace(key, value)
         self.pow_dir = self.pow_dir.replace('$USER$', getUser())
         self.pow_dir = self.pow_dir.replace('$YEAR$', self.base_year)
     except:
         self.pow_dir = ''
     self.fac_files = []
     try:
         fac_file = config.get('Files', 'grid_stations')
         for key, value in parents:
             fac_file = fac_file.replace(key, value)
         fac_file = fac_file.replace('$USER$', getUser())
         fac_file = fac_file.replace('$YEAR$', self.base_year)
         self.fac_files.append(fac_file)
     except:
         pass
     if self.stations2:
         try:
             fac_file = config.get('Files', 'grid_stations2')
             for key, value in parents:
                 fac_file = fac_file.replace(key, value)
             fac_file = fac_file.replace('$USER$', getUser())
             fac_file = fac_file.replace('$YEAR$', self.base_year)
             self.fac_files.append(fac_file)
         except:
             pass
     self.ignore_deleted = True
     try:
         if config.get('Grid', 'ignore_deleted_existing').lower() in [
                 'false', 'off', 'no'
         ]:
             self.ignore_deleted = False
     except:
         pass
     self.technologies = ['']
     self.areas = {}
     try:
         technologies = config.get('Power', 'technologies')
         for item in technologies.split():
             itm = techClean(item)
             self.technologies.append(itm)
             try:
                 self.areas[itm] = float(config.get(itm, 'area'))
             except:
                 self.areas[itm] = 0.
     except:
         pass
     try:
         technologies = config.get('Power', 'fossil_technologies')
         technologies = technologies.split()
         for item in technologies:
             itm = techClean(item)
             try:
                 self.areas[itm] = float(config.get(itm, 'area'))
             except:
                 self.areas[itm] = 0.
     except:
         pass
     try:
         mapc = config.get('Map', 'map_choice')
     except:
         mapc = ''
     upper_left = [0., 0.]
     lower_right = [-90., 180.]
     try:
         upper_left = config.get('Map', 'upper_left' + mapc).split(',')
         upper_left[0] = float(upper_left[0].strip())
         upper_left[1] = float(upper_left[1].strip())
         lower_right = config.get('Map', 'lower_right' + mapc).split(',')
         lower_right[0] = float(lower_right[0].strip())
         lower_right[1] = float(lower_right[1].strip())
     except:
         try:
             lower_left = config.get('Map', 'lower_left' + mapc).split(',')
             upper_right = config.get('Map',
                                      'upper_right' + mapc).split(',')
             upper_left[0] = float(upper_right[0].strip())
             upper_left[1] = float(lower_left[1].strip())
             lower_right[0] = float(lower_left[0].strip())
             lower_right[1] = float(upper_right[1].strip())
         except:
             pass
     self.map_polygon = [
         upper_left, [upper_left[0], lower_right[1]], lower_right,
         [lower_right[0], upper_left[1]], upper_left
     ]