Skip to content

Commit

Permalink
revert to BASE_DIR usage
Browse files Browse the repository at this point in the history
  • Loading branch information
yerbol-akhmetov committed Oct 24, 2024
1 parent 4058cc6 commit 0f784cb
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 17 deletions.
6 changes: 2 additions & 4 deletions scripts/_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,11 @@
# filename of the regions definition config file
REGIONS_CONFIG = "regions_definition_config.yaml"

# prefix when running pypsa-earth rules in different directories (if running in pypsa-earth directory PREFIX='.')
# prefix when running pypsa-earth rules in different directories (if running in pypsa-earth as subworkflow)
BASE_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir))
RUN_DIR = os.path.abspath(os.getcwd())
PREFIX = os.path.relpath(BASE_DIR, RUN_DIR)

# absolute path to config.default.yaml
CONFIG_DEFAULT_PATH = os.path.join(PREFIX, "config.default.yaml")
CONFIG_DEFAULT_PATH = os.path.join(BASE_DIR, "config.default.yaml")


def check_config_version(config, fp_config=CONFIG_DEFAULT_PATH):
Expand Down
4 changes: 2 additions & 2 deletions scripts/build_demand_profiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
import pypsa
import scipy.sparse as sparse
import xarray as xr
from _helpers import configure_logging, create_logger, read_csv_nafix, read_osm_config, PREFIX
from _helpers import configure_logging, create_logger, read_csv_nafix, read_osm_config, BASE_DIR
from shapely.prepared import prep
from shapely.validation import make_valid

Expand Down Expand Up @@ -121,7 +121,7 @@ def get_load_paths_gegis(ssp_parentfolder, config):
for continent in region_load:
sel_ext = ".nc"
for ext in [".nc", ".csv"]:
load_path = os.path.join(PREFIX, str(load_dir), str(continent) + str(ext))
load_path = os.path.join(BASE_DIR, str(load_dir), str(continent) + str(ext))
if os.path.exists(load_path):
sel_ext = ext
break
Expand Down
4 changes: 2 additions & 2 deletions scripts/build_renewable_profiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@
import pandas as pd
import progressbar as pgb
import xarray as xr
from _helpers import configure_logging, create_logger
from _helpers import configure_logging, create_logger, BASE_DIR
from add_electricity import load_powerplants
from dask.distributed import Client
from pypsa.geo import haversine
Expand Down Expand Up @@ -559,7 +559,7 @@ def create_scaling_factor(
# filter plants for hydro
if snakemake.wildcards.technology.startswith("hydro"):
country_shapes = gpd.read_file(paths.country_shapes)
hydrobasins = gpd.read_file(resource["hydrobasins"])
hydrobasins = gpd.read_file(os.path.join(BASE_DIR, resource["hydrobasins"]))
ppls = load_powerplants(snakemake.input.powerplants)

hydro_ppls = ppls[ppls.carrier == "hydro"]
Expand Down
18 changes: 9 additions & 9 deletions scripts/retrieve_databundle_light.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
create_country_list,
create_logger,
progress_retrieve,
PREFIX
BASE_DIR
)
from google_drive_downloader import GoogleDriveDownloader as gdd
from tqdm import tqdm
Expand Down Expand Up @@ -144,7 +144,7 @@ def download_and_unzip_zenodo(config, rootpath, hot_run=True, disable_progress=F
"""
resource = config["category"]
file_path = os.path.join(rootpath, "tempfile.zip")
destination = os.path.join(PREFIX, config["destination"])
destination = os.path.join(BASE_DIR, config["destination"])
url = config["urls"]["zenodo"]

if hot_run:
Expand Down Expand Up @@ -189,7 +189,7 @@ def download_and_unzip_gdrive(config, rootpath, hot_run=True, disable_progress=F
"""
resource = config["category"]
file_path = os.path.join(rootpath, "tempfile.zip")
destination = os.path.join(PREFIX, config["destination"])
destination = os.path.join(BASE_DIR, config["destination"])
url = config["urls"]["gdrive"]

# retrieve file_id from path
Expand Down Expand Up @@ -267,7 +267,7 @@ def download_and_unzip_protectedplanet(
"""
resource = config["category"]
file_path = os.path.join(rootpath, "tempfile_wpda.zip")
destination = os.path.join(PREFIX, config["destination"])
destination = os.path.join(BASE_DIR, config["destination"])
url = config["urls"]["protectedplanet"]

def get_first_day_of_month(date):
Expand Down Expand Up @@ -439,7 +439,7 @@ def download_and_unzip_direct(config, rootpath, hot_run=True, disable_progress=F
True when download is successful, False otherwise
"""
resource = config["category"]
destination = os.path.join(PREFIX, config["destination"])
destination = os.path.join(BASE_DIR, config["destination"])
url = config["urls"]["direct"]

file_path = os.path.join(destination, os.path.basename(url))
Expand Down Expand Up @@ -493,7 +493,7 @@ def download_and_unzip_hydrobasins(
True when download is successful, False otherwise
"""
resource = config["category"]
destination = os.path.join(PREFIX, config["destination"])
destination = os.path.join(BASE_DIR, config["destination"])
url_templ = config["urls"]["hydrobasins"]["base_url"]
suffix_list = config["urls"]["hydrobasins"]["suffixes"]

Expand Down Expand Up @@ -544,7 +544,7 @@ def download_and_unzip_post(config, rootpath, hot_run=True, disable_progress=Fal
True when download is successful, False otherwise
"""
resource = config["category"]
destination = os.path.join(PREFIX, config["destination"])
destination = os.path.join(BASE_DIR, config["destination"])

# load data for post method
postdata = config["urls"]["post"]
Expand Down Expand Up @@ -793,8 +793,8 @@ def datafiles_retrivedatabundle(config):


def merge_hydrobasins_shape(config_hydrobasin, hydrobasins_level):
basins_path = os.path.join(PREFIX, config_hydrobasin["destination"])
output_fl = os.path.join(PREFIX, config_hydrobasin["output"][0])
basins_path = os.path.join(BASE_DIR, config_hydrobasin["destination"])
output_fl = os.path.join(BASE_DIR, config_hydrobasin["output"][0])

files_to_merge = [
"hybas_{0:s}_lev{1:02d}_v1c.shp".format(suffix, hydrobasins_level)
Expand Down

0 comments on commit 0f784cb

Please sign in to comment.