How to use test_exclusions method in autotest

Best Python code snippet using autotest_python

01_🌍_Map.py

Source:01_🌍_Map.py Github

copy

Full Screen

1# Dependencies2import streamlit as st3from google.oauth2 import service_account4import json, tempfile5import pandas as pd6import os7# Set page config8st.set_page_config(page_title = "Map output", layout="wide")9from streamlit_folium import folium_static, st_folium10import ee11import geemap.eefolium as geemap12from utils import *13# Load in datasets (that aren't in GEE)14polys_list = load_csv_list("constituencies_names.csv")[1:]15lad_list = load_csv_list("local_authorities_name.csv")[1:]16# service_account = st.secrets['service_account']17junkstring = '''18data = {}19data['type'] = st.secrets['other_keys']['type']20data['project_id'] = st.secrets['other_keys']['project_id']21data['private_key_id'] = st.secrets['other_keys']['private_key_id']22data['private_key'] = st.secrets['other_keys']['private_key']23data['client_email'] = st.secrets['other_keys']['client_email']24data['client_id'] = st.secrets['other_keys']['client_id']25data['auth_uri'] = st.secrets['other_keys']['auth_uri']26data['token_uri'] = st.secrets['other_keys']['token_uri']27data['auth_provider_x509_cert_url'] = st.secrets['other_keys']['auth_provider_x509_cert_url']28data['client_x509_cert_url'] = st.secrets['other_keys']['client_x509_cert_url']29tfile = tempfile.NamedTemporaryFile(mode="w+")30json.dump(data, tfile)31tfile.flush()32credentials = ee.ServiceAccountCredentials(service_account, tfile.name)33ee.Initialize(credentials)34tfile = tempfile.NamedTemporaryFile(mode="w+")35json.dump(data, tfile)36tfile.flush()37credentials = ee.ServiceAccountCredentials(service_account, tfile.name)38ee.Initialize(credentials)'''39#credentials = service_account.Credentials.from_service_account_info(st.secrets['username'], st.secrets["gcp_service_account"])40ee.Initialize()41# Intialize earth engine42#ee.Initialize()#st.secrets['EARTHENGINE_TOKEN'])43# Exclusion zones44exclusions_dict = {"Wind Speed": ee.Image('projects/data-sunlight-311713/assets/wind_cutoff').lt(1),45"Slope": ee.Terrain.slope(ee.Image("USGS/SRTMGL1_003")).lt(15),46"Slope > 10": ee.Terrain.slope(ee.Image("USGS/SRTMGL1_003")).lt(10),47"Transmission Lines":ee.FeatureCollection('projects/data-sunlight-311713/assets/transmission').reduceToImage(properties= ['FEATCODE'], reducer= ee.Reducer.first()).unmask().lt(1),48"Roads": ee.FeatureCollection('projects/data-sunlight-311713/assets/UK_Roads_Buffer_200m').reduceToImage(properties= ['FEATCODE'], reducer= ee.Reducer.first()).unmask().lt(1),49"Peatland": ee.FeatureCollection('projects/data-sunlight-311713/assets/merged_peatlands').reduceToImage(properties = ['Shape__Are'], reducer= ee.Reducer.first()).unmask().lt(1),50"Woodlands": ee.FeatureCollection('projects/data-sunlight-311713/assets/woodlands').reduceToImage(properties= ['FEATCODE'], reducer = ee.Reducer.first()).unmask().lt(1),51"Cycle Paths": ee.FeatureCollection('projects/data-sunlight-311713/assets/cyclenet').reduceToImage(properties= ['FID'], reducer= ee.Reducer.first()).unmask().lt(1),52"Railway": ee.FeatureCollection('projects/data-sunlight-311713/assets/traintracks').reduceToImage(properties = ['FEATCODE'], reducer = ee.Reducer.first()).unmask().lt(1),53"Areas of Natural Beauty": ee.FeatureCollection("projects/data-sunlight-311713/assets/Areas_of_Outstanding_Natural_Beauty_England").reduceToImage(properties= ['stat_area'], reducer= ee.Reducer.first()).unmask().lt(1),54"Protected Areas": ee.FeatureCollection("projects/data-sunlight-311713/assets/gb_protected_areas_nobuffer").reduceToImage(properties= ['Shape_Area'], reducer= ee.Reducer.first()).unmask().gt(0).eq(0),55"Surface Water":ee.FeatureCollection('projects/data-sunlight-311713/assets/UK_SurfaceWater_Area_Buffer_50m').reduceToImage(properties= ['FEATCODE'], reducer= ee.Reducer.first()).unmask().lt(1),56"Cultural Sites": ee.FeatureCollection('projects/data-sunlight-311713/assets/england_culturalsites').reduceToImage(properties = ['ListEntry'], reducer = ee.Reducer.first()).unmask().lt(1),57"Parks and Green Space": ee.FeatureCollection("projects/data-sunlight-311713/assets/GreenspaceEngArea").reduceToImage(properties= ['areaHa'], reducer= ee.Reducer.first()).unmask().lt(1),58"Functional Sites": ee.FeatureCollection('projects/data-sunlight-311713/assets/Functional_sites').reduceToImage(properties= ['FEATCODE'], reducer= ee.Reducer.first()).unmask().lt(1),59"Built Up Areas": get_build_up_area_buffer(100).unmask().lt(1),60"Existing Solar PV": ee.FeatureCollection('projects/data-sunlight-311713/assets/solar_pv').reduceToImage(properties= ['FID'], reducer = ee.Reducer.first()).unmask().lt(1),61"Existing Other Renewable":ee.FeatureCollection('projects/data-sunlight-311713/assets/other_renewables').reduceToImage(properties= ['FID'], reducer= ee.Reducer.first()).unmask().lt(1),62"Existing Onshore Wind": ee.FeatureCollection('projects/data-sunlight-311713/assets/onshore_wind').reduceToImage(properties= ['FID'], reducer= ee.Reducer.first()).unmask().lt(1),63"Flood Risk Zone 2": ee.FeatureCollection('users/Josh_Redmond/EA_FloodMapForPlanningRiversAndSeaFloodZone2_SHP_Full').reduceToImage(properties= ['st_area_sh'], reducer= ee.Reducer.first()).unmask().lt(1),64"Flood Risk Zone 3": ee.FeatureCollection('users/Josh_Redmond/EA_FloodMapForPlanningRiversAndSeaFloodZone3_SHP_Full').reduceToImage(properties= ['st_area_sh'], reducer= ee.Reducer.first()).unmask().lt(1)65}66test_exclusions = list(exclusions_dict.keys())67wind_exclusions = ["Wind Speed",68"Transmission Lines",69"Aircraft Flightpath",70"Noise",71"Built Up Areas",72"Slope",73"Existing Onshore Wind",74"Existing Other Renewable"]75common_exclusions = ["Roads",76"Railway",77#"Public Rights of Way",78#"Heritage Sites",79"Peatland",80"Protected Areas",81"Areas of Natural Beauty",82"Woodlands",83"Cycle Paths",84"Surface Water",85"Cultural Sites",86"Parks and Green Space",87"Functional Sites",88]89solar_exclusions = ["Slope > 10",90"Existing Solar PV"]91# Streamlit formatting92#st.title("UK Renewables Map", anchor=None)93geometry_mode = st.selectbox("Local Area Type", ['Constituencies', 'Local Authorities'])94mode = st.radio("Power Option", ["🌞 Solar", "💨 Wind"])95with st.form("Parameters"):96 st.header("Map Options")97 with st.container():98 # col1, col2 = st.columns(2)99 #with col1:100 # with col2:101 if geometry_mode == "Constituencies":102 103 area = st.selectbox("Area", polys_list) #on_change =area_change_callback, args={"Cheshire", uk_adm2, m})104 105 else:106 area =st.selectbox("Area", lad_list)107 st.session_state['geometry'] = area108 st.header("Toggle Exclusion Criteria")109 radio_button = st.radio("Scenarios", ["Maximum Exclusions", "Allow on Peatland", "Custom"])110 # if radio_button == "Custom":111 with st.expander("Options"):112 exclusion_buttons = {}113 if mode == "💨 Wind":114 key_list = common_exclusions+wind_exclusions115 #test_exclusions = list({exclusions_dict[k] for k in key_list}.keys())116 test_exclusions = key_list117 exclusion_options = test_exclusions118 else:119 key_list = common_exclusions+solar_exclusions120 test_exclusions = key_list121 # test_exclusions = list({exclusions_dict[k] for k in key_list}.keys())122 exclusion_options = test_exclusions123 for ex in exclusion_options:124 #st.write(ex)125 x = st.checkbox(ex)126 exclusion_buttons[ex] = x127 128 if radio_button == "Maximum Exclusions":129 exclusion_buttons = {key:True for key in list(exclusions_dict.keys())}130 if radio_button == "Allow on Peatland":131 exclusion_buttons = {key:True for key in list(exclusions_dict.keys())}132 exclusion_buttons['Peatland'] = False133 134 #st.multiselect("Toggleable Criteria", wind_exclusions+common_exclusions)135 go_button = st.form_submit_button("Draw Map")136# Save exclusions buttons output in session state to display between pages137#exclusion_buttons_side = pd.DataFrame.from_dict(exclusion_buttons, orient = "index")138#if 'exclusion_buttons_side' not in st.session_state:139# st.session_state['exclusion_buttons_side'] = exclusion_buttons_side140#if go_button:141# st.session_state['exclusion_buttons_side'] = exclusion_buttons_side142# Make the true/false dict emojis143#torf = {True : "❌", False : "✅"}144#display_df = st.session_state['exclusion_buttons_side']145#display_df[0] = display_df[0].map(torf)146#display_df = display_df.style.hide_columns()147#st.sidebar.write(display_df.to_html(), unsafe_allow_html=True)148#st.sidebar.dataframe(display_df)149if go_button:150 m = geemap.Map(center=[55.3, 0], zoom=6)151 if geometry_mode == "Constituencies":152 uk_adm2_all = ee.FeatureCollection("projects/data-sunlight-311713/assets/Westminster_Parliamentary_Constituencies_December_2019_Boundaries_UK_BUC")#.filter(f"pcon19nm == '{area}'")153 uk_adm2 = uk_adm2_all.filter(f"pcon19nm == '{area}'")154 else:155 uk_adm2_all = ee.FeatureCollection("projects/data-sunlight-311713/assets/local_authorities_UK")#.filter(f"pcon19nm == '{area}'")156 uk_adm2 = uk_adm2_all.filter(f"LAD21NM == '{area}'")157 m.centerObject(uk_adm2)158 image_exclusion = []159 for x in exclusion_buttons.keys():160 # st.write(x)161 # st.write(exclusion_buttons[x])162 if exclusion_buttons[x]:163 image_exclusion.append(exclusions_dict[x])164 # st.write(exclusions_dict[x])165 if mode == "🌞 Solar":166 power = ee.Image('projects/data-sunlight-311713/assets/PV_Average')167 minvis = 500168 maxvis = 1500169 else:170 power = ee.Image('projects/data-sunlight-311713/assets/wind_power')171 minvis = 1172 maxvis = 1000173 power = compute_exclusions(image_exclusion, power)174 power = power.updateMask(power.gt(0))175 st.session_state['power'] = power176 power = power.clip(uk_adm2)177 st.session_state['bounds'] = uk_adm2#_all178 empty = ee.Image().byte()179 outline = empty.paint(180 featureCollection= uk_adm2,181 color= 1,182 width= 3183 )184 m.addLayer(outline, {}, f"{area}", True, 0.5)185 m.addLayer(power, {"min":minvis, "max":maxvis, "palette":['#140b34', '#84206b', '#e55c30', '#f6d746']})186 m.add_colorbar(colors=['#140b34', '#84206b', '#e55c30', '#f6d746'], vmin=minvis, vmax=maxvis, layer_name="Potential Power")187 m.addLayerControl() 188 if mode == '🌞 Solar':189 st.write("Map Power Units in kWh/kWp")190 else:191 st.write("Map Power Units in W/M2")192 folium_static(m, width=800, height=700)193 try:194 os.remove("test_csv.csv")195 except:196 pass197 #power = st.session_state['power']198 geom_mode = st.session_state['geometry']199 geemap.zonal_statistics(power.gt(0).multiply(ee.Image.constant(30)), st.session_state['bounds'] , "test_csv.csv", statistics_type='SUM', scale=30)200 # try:201 # Page title202 #st.title("UK Renewables Table")203 # Read in county names204 constituencies = pd.read_csv("test_csv.csv")205 #st.write(print(constituencies))206 constituencies['Wind Energy Estimate (GW)'] = constituencies['sum']/1000 * 19.8 / 1000207 constituencies['Solar Energy Estimate (GW)'] = constituencies['sum']/1000 * 200 / 1000208 constituencies['Total Area Available for Devleopment (Km/2)'] = constituencies['sum']/1000 209 try:210 constituencies = constituencies.rename(columns = {"pcon19nm" : "Constituency"})211 #constituencies.set_index(constituencies['Constituency'])212 constituencies = constituencies[['Constituency', 'Wind Energy Estimate (GW)', 'Solar Energy Estimate (GW)', 'Total Area Available for Devleopment (Km/2)']]213 except:214 constituencies = constituencies.rename(columns = {"LAD21NM" : "Local Authority"})215 #constituencies.set_index(constituencies['Local Authority'])216 constituencies = constituencies[['Local Authority', 'Wind Energy Estimate (GW)', 'Solar Energy Estimate (GW)', 'Total Area Available for Devleopment (Km/2)']]217 # constituencies = constituencies["sum"]218 st.dataframe(constituencies)219 @st.cache220 def convert_df(df):221 return df.to_csv().encode('utf-8')222 csvDownload = convert_df(constituencies)223 st.download_button(224 "Download .csv",225 csvDownload,226 "Renewable Energy Potential.csv",227 "text/csv",...

Full Screen

Full Screen

test_tournament_manager_factory.py

Source:test_tournament_manager_factory.py Github

copy

Full Screen

1import unittest2import axelrod3class TestTournamentManagerFactory(unittest.TestCase):4 @classmethod5 def setUpClass(cls):6 cls.tmf = axelrod.TournamentManagerFactory7 cls.test_output_directory = './assets/'8 cls.test_with_ecological = True9 cls.test_rebuild_cache = False10 cls.test_cache_file = './cache.txt'11 cls.test_exclusions = ['basic_strategies', 'cheating_strategies']12 cls.test_kwargs = {13 'processes': 2,14 'turns': 10,15 'repetitions': 200,16 'noise': 017 }18 cls.expected_basic_strategies = axelrod.basic_strategies19 cls.expected_strategies = (20 axelrod.ordinary_strategies)21 cls.expected_cheating_strategies = axelrod.cheating_strategies22 cls.expected_all_strategies = (23 axelrod.ordinary_strategies +24 axelrod.cheating_strategies)25 def test_tournaments_dict(self):26 # Tests to ensure that the tournaments dictionary contains the correct27 # keys and values28 actual_basic_strategies = (29 self.tmf._tournaments_dict()['basic_strategies'])30 actual_strategies = self.tmf._tournaments_dict()['strategies']31 actual_cheating_strategies = (32 self.tmf._tournaments_dict()['cheating_strategies'])33 actual_all_strategies = self.tmf._tournaments_dict()['all_strategies']34 self.assertEqual(35 actual_basic_strategies, self.expected_basic_strategies)36 self.assertEqual(actual_strategies, self.expected_strategies)37 self.assertEqual(38 actual_cheating_strategies, self.expected_cheating_strategies)39 self.assertEqual(actual_all_strategies, self.expected_all_strategies)40 # Tests to ensure that the exclusions list works as intended41 with_exclusions = self.tmf._tournaments_dict(self.test_exclusions)42 self.assertFalse('basic_strategies' in with_exclusions)43 self.assertFalse('cheating_strategies' in with_exclusions)44 self.assertEqual(45 with_exclusions['strategies'], self.expected_strategies)46 def test_add_tournaments(self):47 mgr = axelrod.TournamentManager(48 self.test_output_directory,49 self.test_with_ecological)50 self.tmf._add_tournaments(mgr, self.test_exclusions, self.test_kwargs)51 self.assertEqual(len(mgr._tournaments), 2)52 self.assertIsInstance(mgr._tournaments[0], axelrod.Tournament)53 self.assertEqual(mgr._tournaments[0].name, 'strategies')54 def test_create_tournament_manager(self):55 mgr = self.tmf.create_tournament_manager(56 output_directory=self.test_output_directory,57 no_ecological=False,58 rebuild_cache=self.test_rebuild_cache,59 cache_file=self.test_cache_file,60 exclusions=self.test_exclusions,61 **self.test_kwargs)62 self.assertIsInstance(mgr, axelrod.TournamentManager)63 self.assertEqual(mgr._output_directory, self.test_output_directory)64 self.assertEqual(len(mgr._tournaments), 2)65 self.assertTrue(mgr._with_ecological)...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run autotest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful