def test_years_active(test_mp): test_mp.add_unit('year') scen = Scenario(test_mp, *msg_args, version='new') scen.add_set('node', 'foo') scen.add_set('technology', 'bar') # Periods of uneven length years = [1990, 1995, 2000, 2005, 2010, 2020, 2030] # First period length is immaterial duration = [1900, 5, 5, 5, 5, 10, 10] scen.add_horizon({'year': years, 'firstmodelyear': years[-1]}) scen.add_par('duration_period', pd.DataFrame(zip(years, duration), columns=['year', 'value'])) # 'bar' built in period '1995' with 25-year lifetime: # - is constructed in 1991-01-01. # - by 1995-12-31, has operated 5 years. # - operates until 2015-12-31. This is within the period '2020'. scen.add_par('technical_lifetime', pd.DataFrame(dict( node_loc='foo', technology='bar', unit='year', value=25, year_vtg=years[1]), index=[0])) result = scen.years_active('foo', 'bar', years[1]) # Correct return type assert isinstance(years, list) assert isinstance(years[0], int) # Years 1995 through 2020 npt.assert_array_equal(result, years[1:-1])
def test_years_active_extend3(test_mp): test_mp.add_unit("year") scen = Scenario(test_mp, **SCENARIO["dantzig"], version="new") scen.add_set("node", "foo") scen.add_set("technology", "bar") # Periods of uneven length years = [1990, 1995, 2000, 2005, 2010, 2020, 2030] scen.add_horizon(year=years, firstmodelyear=2010) scen.add_set("year", [1992]) scen.add_par("duration_period", "1992", 2, "y") scen.add_par("duration_period", "1995", 3, "y") scen.add_par( "technical_lifetime", pd.DataFrame( dict( node_loc="foo", technology="bar", unit="year", value=[20], year_vtg=1990, ), ), ) obs = scen.years_active("foo", "bar", 1990) assert obs == [1990, 1992, 1995, 2000, 2005]
def test_years_active_extend(test_mp): scen = Scenario(test_mp, *msg_multiyear_args) scen = scen.clone(keep_solution=False) scen.check_out() scen.add_set('year', ['2040', '2050']) scen.add_par('duration_period', '2040', 10, 'y') scen.add_par('duration_period', '2050', 10, 'y') df = scen.years_active('seattle', 'canning_plant', '2020') npt.assert_array_equal(df, [2020, 2030, 2040]) scen.discard_changes()
def test_years_active_extend(test_mp): scen = Scenario(test_mp, *msg_multiyear_args) # Existing time horizon years = [2010, 2020, 2030] result = scen.years_active('seattle', 'canning_plant', years[1]) npt.assert_array_equal(result, years[1:]) # Add years to the scenario years.extend([2040, 2050]) scen.check_out() scen.add_set('year', years[-2:]) scen.add_par('duration_period', '2040', 10, 'y') scen.add_par('duration_period', '2050', 10, 'y') # technical_lifetime of seattle/canning_plant/2020 is 30 years. # - constructed in 2011-01-01. # - by 2020-12-31, has operated 10 years. # - operates until 2040-12-31. # - is NOT active within the period '2050' (2041-01-01 to 2050-12-31) result = scen.years_active('seattle', 'canning_plant', '2020') npt.assert_array_equal(result, years[1:-1])
def test_years_active_extend(message_test_mp): scen = Scenario(message_test_mp, **SCENARIO["dantzig multi-year"]) # Existing time horizon years = [1963, 1964, 1965] result = scen.years_active("seattle", "canning_plant", years[1]) npt.assert_array_equal(result, years[1:]) # Add years to the scenario years.extend([1993, 1995]) scen.check_out() scen.add_set("year", years[-2:]) scen.add_par("duration_period", "1993", 28, "y") scen.add_par("duration_period", "1995", 2, "y") # technical_lifetime of seattle/canning_plant/1964 is 30 years. # - constructed in 1964-01-01. # - by 1964-12-31, has operated 1 year. # - by 1965-12-31, has operated 2 years. # - operates until 1993-12-31. # - is NOT active within the period '1995' (1994-01-01 to 1995-12-31) result = scen.years_active("seattle", "canning_plant", 1964) npt.assert_array_equal(result, years[1:-1])
def test_years_active_extended2(test_mp): test_mp.add_unit("year") scen = Scenario(test_mp, **SCENARIO["dantzig"], version="new") scen.add_set("node", "foo") scen.add_set("technology", "bar") # Periods of uneven length years = [1990, 1995, 2000, 2005, 2010, 2020, 2030] # First period length is immaterial duration = [1900, 5, 5, 5, 5, 10, 10] scen.add_horizon(year=years, firstmodelyear=years[-1]) scen.add_par( "duration_period", pd.DataFrame(zip(years, duration), columns=["year", "value"]) ) # 'bar' built in period '2020' with 10-year lifetime: # - is constructed in 2011-01-01. # - by 2020-12-31, has operated 10 years. # - operates until 2020-12-31. This is within the period '2020'. # The test ensures that the correct lifetime value is retrieved, # i.e. the lifetime for the vintage 2020. scen.add_par( "technical_lifetime", pd.DataFrame( dict( node_loc="foo", technology="bar", unit="year", value=[20, 20, 20, 20, 20, 10, 10], year_vtg=years, ), ), ) result = scen.years_active("foo", "bar", years[-2]) # Correct return type assert isinstance(result, list) assert isinstance(result[0], int) # Years 2020 npt.assert_array_equal(result, years[-2])
def test_years_active(test_mp): test_mp.add_unit("year") scen = Scenario(test_mp, **SCENARIO["dantzig"], version="new") scen.add_set("node", "foo") scen.add_set("technology", "bar") # Periods of uneven length years = [1990, 1995, 2000, 2005, 2010, 2020, 2030] # First period length is immaterial duration = [1900, 5, 5, 5, 5, 10, 10] scen.add_horizon(year=years, firstmodelyear=years[-1]) scen.add_par( "duration_period", pd.DataFrame(zip(years, duration), columns=["year", "value"]) ) # 'bar' built in period '1995' with 25-year lifetime: # - is constructed in 1991-01-01. # - by 1995-12-31, has operated 5 years. # - operates until 2015-12-31. This is within the period '2020'. scen.add_par( "technical_lifetime", pd.DataFrame( dict( node_loc="foo", technology="bar", unit="year", value=25, year_vtg=years[1], ), index=[0], ), ) result = scen.years_active("foo", "bar", years[1]) # Correct return type assert isinstance(result, list) assert isinstance(result[0], int) # Years 1995 through 2020 npt.assert_array_equal(result, years[1:-1])
def test_years_active(test_mp): scen = Scenario(test_mp, *msg_multiyear_args) df = scen.years_active('seattle', 'canning_plant', '2020') npt.assert_array_equal(df, [2020, 2030])
def test_years_active(test_mp): scen = Scenario(test_mp, *msg_multiyear_args) years = scen.years_active('seattle', 'canning_plant', '2020') assert isinstance(years, list) assert isinstance(years[0], int) npt.assert_array_equal(years, [2020, 2030])