# Code for Fix-Hewitt et al 2025: Properties and Characteristics of Atmospheric Deserts over Europe
#
# F. Fix-Hewitt, 10.2025
#
# this file explains the steps taken to prepare the data, results and plots in the mentioned paper in order. 
# with adjustments for revision
#
#

functions.py
	contains all python functions needed in this work
	REQUIREMENT, SPECIFY gridcellarea_file, which contains area of each grid cell of ERA5 data


00_BLH_interp_job.slurm
    * SPECIFY input and output files and directories as well as years it should be run for
    needs to be run, it calls the BLH_interp.py script
    
    00_BLH_interp.py  
        * no specifications needed within
        finds the daily BLH maxima in the given data, and calculculates the interpolated BLH from that, ssaving it to the specified outfile


01_prepare_data_run.sh
    * SPECIFY years and months that data should be prepared for, as well as outputdir, and indir of ERA5 data and modified ERA5 indir
    loops through years and months and calls prepare_data.slurm for all days in those months then

    01_prepare_data.slurm
        * specify only if filenames differ
        selects times, merges with vertical coords, inverts lat, calls prep_data.py, selects variables, 
        saves P_ and S_ files as needed by LARGRANTO
       01_ prep_data.py
            * SPECIFY levels_coeff.nc file (contains info about model level altitudes)
            processes ERA5 input data so that it has shape and naming convections as LAGRANTO needs it
       REQUIREMENTS 
            level_coeffs.nc file

02_Lagranto_run.sh
    * SPECIFY script and input data dir, start of period, length of trajectories and length of perdiod in hours
    calls Lagranto_job.slurm

    02_Lagranto_job.slurm
	* SPECIFY LAGRANTO setup in respective commands, if desired differently
	calculates timestamps as needed and then runs LAGRANTO startf, select, caltra, and trace 

    REQUIREMENTS: 
	tracevars_startf
	tracevars_short
	curtain_points

03_corrTHE.slurm
    * nothing to specify
    calls 03_corrTHE.py

    03_corrTHE.py
	* SPECIFY indata dir, where Lagranto folders are
	because of numerical inacuracies, q is sometimes negative, which leads to missing values in THE, even though TH exists. 
	this script puts the value of TH into THE where this happens and prints how often it did happen


04_AddTrajnumber.sh
    * nothing to specify
    calls 04_AddTrajnumbers.py

    04_addTrajnumbers.py
	* SPECIFY indir
	goes through all trajectories in the indir and adds identification numbers to them, used later in clusterin


05_seldate.sh
    * SPECIFY time period over which it should select dates, and trajectory length, indir and outdir

    05_seldate.slurm
	* nothing to specify
	calls 05_seldate.py

	05_seldate.py
	    * nothing to specify in here
	    selects data from all traj files for specific date

06_grid.sh
    * SPECIFY period for which to grid AD data, length of trajectories and threshold for lid detection
    loops through period and submits 06_grid.slurm

    06_grid.slurm
	runs 06_grid.py

	06_grid.py
	    * SPECIFY grid it should be gridded to (defailt dx=0.25degrees, dz=500m)
	    * SPECIFY files for BLH and geopotential ERA5input data
	    groups trajectory data to grid and calculates counts, means, lid etc
	    saves gridded AD data to {outdir}AD_gridded_{YEAR:04}{MONTH:02}{DAY:02}T{TIME:02}00_length{LENGTH}tmp.nc


07_mergegrid.sh
    * SPECIFY year and months for which this should be done and data location
    merges outfiles from 03_grid.sh into monthly files


08_changesHist.slurm
    * nothing to specify here 
    calls 08_changesHist.py 
    
    08_changesHist.py
	* SPECIFY input and output directories as well as experiment setup
        calculates histogram of average changes since intialisation

09_local_maxima.ipynb
    finds local maxima and clusters geopotential height for specified dates, details see notebook
09_local_maxima_rev.ipynb
    finds local maxima and clusters geopotential height for specified dates, details see notebook
    adjustements according to revision


10_TrajectoryClustering_Kennnumbers.sh
    * SPECIFY experiment setup, infile, outfile and file with dates to cluster for
    calls 10_TrajectoryClustering_Kennnumbers.slurm

    10_TRajectoryClustering_Kennnumbers.slurm
	starts 10_trajectoryClustering_Kennnumbers.py

	10_TrajectoryCLustering_Kennnumbers.py
	    calculates all variables that could be clustered by and saves them to file

11_TrajectoryClustering.sh
    * SPECIFY experiment setup, infile, outfile and file with dates to cluster for
    calls 11_TrajectoryClustering.slurm

    11_TrajectoryClustering.slurm
	calls 11_TrajectoryClustering.py

	11_TrajectoryClustering.py
	    * SPECIFY variables to cluster by
	    clusters trajectories according to specified variables, saves cluster averages


12_TrajectoryClustering.py
    * SPECIFY input and output directories
    plots cluster plots for all startingdays for which Clusterdata is in input dir


13_PaperPlotting.ipynb
   * SPECIFY experiment setup etc in Input-cell
   does some remaining post-processing and plots all figures for the paper, and those that are not shown but mentioned
13_PaperPlotting_rev.ipynb
   * SPECIFY experiment setup etc in Input-cell
   does some remaining post-processing and plots all figures for the paper, and those that are not shown but mentioned
   adjustments according to revision
   
14_Supplement_TrajClusteringPlots.ipynb
    plots the trajectory clusters for each AD event for the Supplement

	 
