Newer
Older
Jeremy Auclair
committed
# -*- coding: UTF-8 -*-
# Python
"""
08-09-2023
@author: jeremy auclair
Main script to run the SAMIR model
"""
if __name__ == '__main__':
import sys, os # system management
currentdir = os.path.dirname(os.path.realpath(__file__))
sys.path.insert(0, os.path.dirname(currentdir))
from modspa_pixel.config.config import config # to import config file
from modspa_pixel.source.code_toolbox import format_duration # to print memory requirements
from modspa_pixel.source.modspa_samir import run_samir # to run SAMIR
from time import time # to time code excecution
# Get start time of script
t0 = time()
# Declare config file path
Jeremy Auclair
committed
config_file = currentdir + os.sep + 'config' + os.sep + 'config_modspa.json'
# Open config file and load parameters
config_params = config(config_file)
# Run parameters
max_ram = config_params.max_ram
max_cpu = config_params.max_cpu
mode = config_params.mode
run_name = config_params.run_name
preferred_provider = config_params.preferred_provider
start_date = config_params.start_date
end_date = config_params.end_date
# Path parameters
param_csv_file = config_params.param_csv_file
download_path = config_params.download_path
era5_path = config_params.era5_path
output_path = config_params.output_path
# Input paths
## NDVI
if preferred_provider == 'copernicus':
ndvi_path = download_path + os.sep + 'SCIHUB' + os.sep + 'NDVI' + os.sep + run_name + os.sep + run_name + '_NDVI_cube_' + start_date + '_' + end_date + '.nc'
Jeremy Auclair
committed
else:
ndvi_path = download_path + os.sep + 'THEIA' + os.sep + 'NDVI' + os.sep + run_name + os.sep + run_name + '_NDVI_cube_' + start_date + '_' + end_date + '.nc'
Jeremy Auclair
committed
## Weather
if mode == 'pixel':
weather_path = era5_path + os.sep + run_name + os.sep + 'ncdailyfiles' + os.sep + start_date + '_' + end_date + '_' + run_name + '_era5-land-daily-meteo.nc'
else:
weather_path = era5_path + os.sep + run_name + os.sep + 'ncdailyfiles' + os.sep + start_date + '_' + end_date + '_' + run_name + '_era5-land-daily-meteo_parcel.nc'
# Soil path
soil_path = config_params.soil_path
# Land Cover path
land_cover_path = config_params.land_cover_path
# Output path
output_save_path = output_path + os.sep + run_name + os.sep + config_params.run_name + '_outputs.nc'
# Run SAMIR
run_samir(param_csv_file, ndvi_path, weather_path, soil_path, land_cover_path, output_save_path, additional_outputs = None, available_ram = max_ram, available_cpu = max_cpu)
Jeremy Auclair
committed
# Print formatted runtime
Jeremy Auclair
committed
print('\nExcecution time: ', end = '')
Jeremy Auclair
committed
format_duration(time() - t0)