def main(*args): config = cea.config.Configuration() cache = cea.plots.cache.NullPlotCache() # handle arguments if not args: args = sys.argv[1:] # drop the script name (plot_cli.py) from the arguments if len(args) < 2: print_usage(config.plugins) return category_name, plot_id, plot_args = args[0], args[1], args[2:] plot_class = cea.plots.categories.load_plot_by_id(category_name, plot_id, config.plugins) if not plot_class: print("Could not load plot {category_name}/{plot_id}".format(**locals())) print("Choose from:") for plot_category, plot_class in cea.plots.categories.list_plots(config.plugins): print("{category}/{plot}".format(category=plot_category.name, plot=plot_class.id())) return parameters = {k: config.get(v) for k, v in plot_class.expected_parameters.items() } parameters.update(cea.config.parse_command_line_args(plot_args)) plot = plot_class(config.project, parameters, cache) plot.plot(auto_open=True)
def main(config): cache_folder = tempfile.mkdtemp() plot_cache = cea.plots.cache.MemoryPlotCache(cache_folder) with config.ignore_restrictions(): if config.plots_supply_system.system == "_sys_today_": # BUGFIX: _sys_today_ not supported config.plots_supply_system.system = "" try: for category in cea.plots.categories.list_categories(plugins=[]): # create the new dashboard print( "Plotting category {category}".format(category=category.label)) for plot_class in category.plots: print("- Plotting {plot_class}".format( plot_class=plot_class.__name__)) parameters = { k: config.get(v) for k, v in plot_class.expected_parameters.items() } plot = plot_class(config.project, parameters, plot_cache) print(" - plotting to {output_path}".format( output_path=plot.output_path)) plot.plot() print(" - plotting div (len={len})".format( len=len(plot.plot_div()))) finally: shutil.rmtree(cache_folder, ignore_errors=True)
def test_mixed_use_schedules(self): config = cea.config.Configuration(cea.config.DEFAULT_CONFIG) stochastic_occupancy = config.demand.use_stochastic_occupancy gv = GlobalVariables() gv.config = config locator = ReferenceCaseOpenLocator() date = pd.date_range(gv.date_start, periods=8760, freq='H') building_properties = BuildingProperties(locator, gv, False, 'CH', False) bpr = building_properties['B01'] list_uses = ['OFFICE', 'INDUSTRIAL'] bpr.occupancy = {'OFFICE': 0.5, 'INDUSTRIAL': 0.5} # calculate schedules archetype_schedules, archetype_values = schedule_maker( 'CH', date, locator, list_uses) calculated_schedules = calc_schedules(list_uses, archetype_schedules, bpr, archetype_values, stochastic_occupancy) config = ConfigParser.SafeConfigParser() config.read(get_test_config_path()) reference_results = json.loads( config.get('test_mixed_use_schedules', 'reference_results')) for schedule in reference_results: self.assertAlmostEqual( calculated_schedules[schedule][REFERENCE_TIME], reference_results[schedule], places=4, msg="Schedule '%s' at time %s, %f != %f" % (schedule, str(REFERENCE_TIME), calculated_schedules[schedule][REFERENCE_TIME], reference_results[schedule]))
def test_mixed_use_schedules(self): locator = ReferenceCaseOpenLocator() config = cea.config.Configuration(cea.config.DEFAULT_CONFIG) config.scenario = locator.scenario building_properties = BuildingProperties(locator, False) bpr = building_properties['B1011'] bpr.occupancy = {'OFFICE': 0.5, 'SERVERROOM': 0.5} bpr.comfort['mainuse'] = 'OFFICE' # calculate schedules schedule_maker_main(locator, config) calculated_schedules = pd.read_csv(locator.get_schedule_model_file('B1011')).set_index('DATE') config = ConfigParser.SafeConfigParser() config.read(get_test_config_path()) reference_results = json.loads(config.get('test_mixed_use_schedules', 'reference_results')) for schedule in reference_results: if (isinstance(calculated_schedules[schedule][REFERENCE_TIME], str)) and (isinstance( reference_results[schedule], unicode)): self.assertEqual(calculated_schedules[schedule][REFERENCE_TIME], reference_results[schedule], msg="Schedule '{}' at time {}, {} != {}".format(schedule, str(REFERENCE_TIME), calculated_schedules[schedule][ REFERENCE_TIME], reference_results[schedule])) else: self.assertAlmostEqual(calculated_schedules[schedule][REFERENCE_TIME], reference_results[schedule], places=4, msg="Schedule '{}' at time {}, {} != {}".format(schedule, str(REFERENCE_TIME), calculated_schedules[schedule][ REFERENCE_TIME], reference_results[schedule]))
def test_mixed_use_archetype_values(self): # test if a sample mixed use building gets standard results locator = ReferenceCaseOpenLocator() config = ConfigParser.SafeConfigParser() config.read(get_test_config_path()) calculated_results = calculate_mixed_use_archetype_values_results(locator).to_dict() print(calculated_results) # compare to reference values expected_results = json.loads(config.get('test_mixed_use_archetype_values', 'expected_results')) for column, rows in expected_results.items(): self.assertIn(column, calculated_results) for building, value in rows.items(): self.assertIn(building, calculated_results[column]) self.assertAlmostEqual(value, calculated_results[column][building], 4)
def plot_category(cache): for category in list_categories(): if category.label != label: continue print('category:', category.name, ':', category.label) for plot_class in category.plots: print('plot_class:', plot_class) parameters = { k: config.get(v) for k, v in plot_class.expected_parameters.items() } plot = plot_class(config.project, parameters=parameters, cache=cache) assert plot.name, 'plot missing name: %s' % plot assert plot.category_name == category.name print('plot:', plot.name, '/', plot.id(), '/', plot.title) # plot the plot! plot.plot()
def test_mixed_use_schedules(self): locator = ReferenceCaseOpenLocator() config = cea.config.Configuration(cea.config.DEFAULT_CONFIG) config.scenario = locator.scenario stochastic_occupancy = config.demand.use_stochastic_occupancy # get year from weather file weather_path = locator.get_weather_file() weather_data = epwreader.epw_reader(weather_path)[['year']] year = weather_data['year'][0] date = pd.date_range(str(year) + '/01/01', periods=HOURS_IN_YEAR, freq='H') building_properties = BuildingProperties(locator, False) bpr = building_properties['B01'] list_uses = ['OFFICE', 'INDUSTRIAL'] bpr.occupancy = {'OFFICE': 0.5, 'INDUSTRIAL': 0.5} # calculate schedules archetype_schedules, archetype_values = schedule_maker( date, locator, list_uses) calculated_schedules = calc_schedules(list_uses, archetype_schedules, bpr, archetype_values, stochastic_occupancy) config = ConfigParser.SafeConfigParser() config.read(get_test_config_path()) reference_results = json.loads( config.get('test_mixed_use_schedules', 'reference_results')) for schedule in reference_results: self.assertAlmostEqual( calculated_schedules[schedule][REFERENCE_TIME], reference_results[schedule], places=4, msg="Schedule '%s' at time %s, %f != %f" % (schedule, str(REFERENCE_TIME), calculated_schedules[schedule][REFERENCE_TIME], reference_results[schedule]))
def plot_the_whole_category(cache): for category in list_categories(): if category.label != label: # skip other categories continue print('category:', category.name, ':', category.label) for plot_class in category.plots: print('plot_class:', plot_class) parameters = { k: config.get(v) for k, v in plot_class.expected_parameters.items() } plot = plot_class(config.project, parameters=parameters, cache=cache) assert plot.name, 'plot missing name: %s' % plot assert plot.category_name == category.name print('plot:', plot.name, '/', plot.id(), '/', plot.title) missing_input_files = plot.missing_input_files() if missing_input_files: for locator_method, args in missing_input_files: print('Input file not found: {}'.format(locator_method(*args))) else: # plot the plot! plot.plot()
def test_mixed_use_archetype_values(self): # test if a sample mixed use building gets standard results locator = ReferenceCaseOpenLocator() config = ConfigParser.SafeConfigParser() config.read(get_test_config_path()) calculated_results = calculate_test_mixed_use_archetype_values_results( locator).to_dict() # compare to reference values expected_results = json.loads( config.get('test_mixed_use_archetype_values', 'expected_results')) for column, rows in expected_results.items(): self.assertIn(column, calculated_results) for building, value in rows.items(): self.assertIn(building, calculated_results[column]) self.assertAlmostEqual(value, calculated_results[column][building], 4) architecture_DB = get_database(locator.get_archetypes_properties('CH'), 'ARCHITECTURE') architecture_DB['Code'] = architecture_DB.apply( lambda x: x['building_use'] + str(x['year_start']) + str(x[ 'year_end']) + x['standard'], axis=1) self.assertEqual( correct_archetype_areas(prop_architecture_df=pd.DataFrame( data=[['B1', 0.5, 0.5, 0.0, 2006, 2020, 'C'], ['B2', 0.2, 0.8, 0.0, 1000, 1920, 'R']], columns=[ 'Name', 'SERVERROOM', 'PARKING', 'Hs', 'year_start', 'year_end', 'standard' ]), architecture_DB=architecture_DB, list_uses=['SERVERROOM', 'PARKING']), [0.5, 0.2])
yield cls_object if __name__ == '__main__': from pprint import pprint config = cea.config.Configuration() cache = cea.plots.cache.NullPlotCache() errors = [] for category in list_categories(plugins=config.plugins): print('category:', category.name, ':', category.label) for plot_class in category.plots: try: print('plot_class:', plot_class) parameters = { k: config.get(v) for k, v in plot_class.expected_parameters.items() } plot = plot_class(config.project, parameters=parameters, cache=cache) assert plot.name, 'plot missing name: %s' % plot assert plot.category_name == category.name print('plot:', plot.name, '/', plot.id(), '/', plot.title) # plot the plot! plot.plot() # write plot data plot.plot_data_to_file()
def get_default_parameters(cls, config): """Return a dictionary of parameters taken by using the values in the config file""" return {k: config.get(v) for k, v in cls.expected_parameters.items()}
yield cls_object if __name__ == '__main__': from pprint import pprint config = cea.config.Configuration() cache = cea.plots.cache.NullPlotCache() errors = [] for category in list_categories(plugins=config.plugins): print('category:', category.name, ':', category.label) for plot_class in category.plots: try: print('plot_class:', plot_class) parameters = { k: config.get(v) for k, v in plot_class.expected_parameters.items() } plot = plot_class(config.project, parameters=parameters, cache=cache) assert plot.name, 'plot missing name: %s' % plot assert plot.category_name == category.name print('plot:', plot.name, '/', plot.id(), '/', plot.title) # plot the plot! plot.plot() # write plot data plot.plot_data_to_file() except Exception as e: errors.append({'plot': plot_class, 'error': e})