diff --git a/rules/retrieve.smk b/rules/retrieve.smk index 75cf8062..ac89e360 100644 --- a/rules/retrieve.smk +++ b/rules/retrieve.smk @@ -227,6 +227,7 @@ if config["enable"]["retrieve"]: run: move(input[0], output[0]) + if config["enable"]["retrieve"]: # Downloading Copernicus Global Land Cover for land cover and land use: @@ -238,26 +239,29 @@ if config["enable"]["retrieve"]: static=True, ), output: - RESOURCES + "Copernicus_LC100_global_v3.0.1_2019-nrt_Discrete-Classification-map_EPSG-4326.tif", - run: move(input[0], output[0]) + RESOURCES + + "Copernicus_LC100_global_v3.0.1_2019-nrt_Discrete-Classification-map_EPSG-4326.tif", + run: + move(input[0], output[0]) if config["enable"]["retrieve"]: - - current_month = datetime.now().strftime('%b') - current_year = datetime.now().strftime('%Y') + current_month = datetime.now().strftime("%b") + current_year = datetime.now().strftime("%Y") bYYYY = f"{current_month}{current_year}" def check_file_exists(url): response = requests.head(url) return response.status_code == 200 - url = f'https://d1gam3xoknrgr2.cloudfront.net/current/WDPA_{bYYYY}_Public.zip' + url = f"https://d1gam3xoknrgr2.cloudfront.net/current/WDPA_{bYYYY}_Public.zip" if not check_file_exists(url): - prev_month = (datetime.now()-timedelta(30)).strftime('%b') + prev_month = (datetime.now() - timedelta(30)).strftime("%b") bYYYY = f"{prev_month}{current_year}" - assert check_file_exists(f'https://d1gam3xoknrgr2.cloudfront.net/current/WDPA_{bYYYY}_Public.zip'), "The file does not exist." + assert check_file_exists( + f"https://d1gam3xoknrgr2.cloudfront.net/current/WDPA_{bYYYY}_Public.zip" + ), "The file does not exist." # Downloading protected area database from WDPA # extract the main zip and then merge the contained 3 zipped shapefiles @@ -268,7 +272,7 @@ if config["enable"]["retrieve"]: f"d1gam3xoknrgr2.cloudfront.net/current/WDPA_{bYYYY}_Public_shp.zip", static=True, keep_local=True, - ) + ), params: zip=RESOURCES + f"WDPA_{bYYYY}_shp.zip", folder=directory(RESOURCES + f"WDPA_{bYYYY}"), @@ -279,15 +283,16 @@ if config["enable"]["retrieve"]: shell("unzip -o {params.zip} -d {params.folder}") for i in range(3): # vsizip is special driver for directly working with zipped shapefiles in ogr2ogr - layer_path = f"/vsizip/{params.folder}/WDPA_{bYYYY}_Public_shp_{i}.zip" + layer_path = ( + f"/vsizip/{params.folder}/WDPA_{bYYYY}_Public_shp_{i}.zip" + ) print(f"Adding layer {i+1} of 3 to combined output file.") shell("ogr2ogr -f gpkg -update -append {output.gpkg} {layer_path}") - - # Downloading Marine protected area database from WDPA - # extract the main zip and then merge the contained 3 zipped shapefiles - # Website: https://www.protectedplanet.net/en/thematic-areas/marine-protected-areas rule download_wdpa_marine: + # Downloading Marine protected area database from WDPA + # extract the main zip and then merge the contained 3 zipped shapefiles + # Website: https://www.protectedplanet.net/en/thematic-areas/marine-protected-areas input: HTTP.remote( f"d1gam3xoknrgr2.cloudfront.net/current/WDPA_WDOECM_{bYYYY}_Public_marine_shp.zip", @@ -309,6 +314,7 @@ if config["enable"]["retrieve"]: shell("ogr2ogr -f gpkg -update -append {output.gpkg} {layer_path}") + if config["enable"]["retrieve"]: rule retrieve_monthly_co2_prices: