Skip to content
Snippets Groups Projects
Select Git revision
  • 7ef08b6a4cd072a222002f486991ebf0e9d765a3
  • main default protected
  • assim
  • optim
  • numpy_parallel
5 results

main_run_samir.py

Blame
  • user avatar
    Jeremy Auclair authored
    Further improvements in optimization. Manage to create real empty output dataset and append values along the time dimension, greatly improves total run speed. Reworked the custom_input notebook for a better handling of the land cover class conversion. Added tests on parameters values to make sure they are in correct range, parameter ranges are defined in a csv file (params_samir_min_max.csv). Other small modifications.
    7ef08b6a
    History
    main_run_samir.py 2.71 KiB
    # -*- 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
        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'
        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'
        
        ## 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)
        
        # Print formatted runtime
        print('\nExcecution time: ', end = '')
        format_duration(time() - t0)
        print('')