This repository contains scripts for processing climate data from the MPI-ESM1-2-HR model. These scripts handle data interpolation, selection, and conversion to a common grid format suitable for further analysis.
The Bash script processes the Sea Surface Temperature (SST) data from the MPI-ESM1-2-HR historical dataset by selecting specific time steps and interpolating the data to a target grid.
File: process_var_tos.sh
-
Input Files:
input_files=( "tos_3hr_MPI-ESM1-2-HR_historical_r1i1p1f1_gn_198001010300-198501010000.nc" "tos_3hr_MPI-ESM1-2-HR_historical_r1i1p1f1_gn_198501010300-199001010000.nc" "tos_3hr_MPI-ESM1-2-HR_historical_r1i1p1f1_gn_199001010300-199501010000.nc" "tos_3hr_MPI-ESM1-2-HR_historical_r1i1p1f1_gn_199501010300-200001010000.nc" "tos_3hr_MPI-ESM1-2-HR_historical_r1i1p1f1_gn_200001010300-200501010000.nc" "tos_3hr_MPI-ESM1-2-HR_historical_r1i1p1f1_gn_200501010300-201001010000.nc" "tos_3hr_MPI-ESM1-2-HR_historical_r1i1p1f1_gn_201001010300-201501010000.nc" )
-
Target Grid Description: The target grid is defined in
target_grid.txt
:gridtype = lonlat gridsize = 73728 xsize = 384 ysize = 192 xfirst = -179.53125 xinc = 0.9375 yfirst = -89.4625 yinc = 0.9375
-
Processing Loop: The script loops through each input file, adjusts the start time, selects specific time steps, performs bilinear interpolation, and saves the output file.
The Python script processes climate data from the MPI-ESM1-2-HR model by reading multiple variables, performing boundary checks, and ensuring data integrity by handling missing values. The script then interpolates the data to a common grid and saves the results for further analysis.
File: process_mpi2wrf.py
-
Constants and Directories:
- Start and End Dates:
START_DATE = DT.datetime(1980, 1, 1, 6, 0, 0) END_DATE = DT.datetime(1985, 1, 1, 0, 0, 0)
- Directories:
INPUT_DIR = '/path/to/input/' OUTPUT_DIR = '/path/to/output/'
- Start and End Dates:
-
Variable File Patterns: The script handles multiple variables such as
tas
,huss
,ps
, etc. -
Utility Functions:
format_time()
: Formats datetime objects.read_and_process_variable()
: Reads and processes 2D variables from NetCDF files.read_and_process_3d_variable()
: Reads and processes 3D variables from NetCDF files.map_to_pywinter_name()
: Maps variable names to PyWinter naming conventions.
-
Processing Functions:
process_chunks()
: Processes data in chunks.process_variables()
: Main function to process variables from NetCDF files.
-
Main Execution Flow: The script defines the main execution flow and processes data in chunks:
if __name__ == "__main__": main()
Ensure the following dependencies are installed before running the scripts:
- Bash
- CDO (for the Bash script)
- Python 3.x
- numpy
- pywinter
- netCDF4
- scipy
-
Set Execute Permission:
chmod +x process_var_tos.sh
-
Run the Script:
./process_var_tos.sh
-
Set Directories: Ensure the
INPUT_DIR
andOUTPUT_DIR
paths are correctly set in the script. -
Run the Script:
python process_mpi2wrf.py
Husile Bai
Email: [email protected]
The author extends gratitude to Prof. Alfonso Fernandez ([email protected]) for recommending the 'pywinter' package and providing codes for data processing.