Skip to content

Commit 83094a8

Browse files
Add files via upload
1 parent 94df75c commit 83094a8

10 files changed

Lines changed: 6189 additions & 0 deletions
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
***VIC5_Inp_Prep*** --- A Python-based Package for VIC 5.x Climate Input Preparation
2+
writen by Vu Trung Dung (dtvu2205@gmail.com)
3+
4+
________________________________________________________________________________
5+
6+
# Overview
7+
This package provides a suite of Python scripts for preparing climate input data for the Variable Infiltration Capacity (VIC) hydrological model (version 5.x). It processes raw NetCDF-format climate datasets, regrids them to a predefined spatial grid, and exports the outputs in both ASCII format (for the classic VIC driver) and NetCDF format (for the image VIC driver). The package handles a range of essential climate variables, including precipitation, air temperature, shortwave radiation, longwave radiation, atmospheric pressure, vapor pressure, and wind speed. The package requires Python 3.x and depends on libraries such as numpy, pandas, xarray, netCDF4 or h5netcdf, os and math.
8+
9+
________________________________________________________________________________
10+
11+
# How to Use
12+
1. Prepare Input Data
13+
Download raw NetCDF files (e. g., CHIRPS2, ERA5) and organize downloaded data into the directory structure (see below).
14+
15+
2. Define Your Spatial Points
16+
Create a text file named lon_lat.txt with your points of interest. The file is formatted as tab-separated columns of longitude and latitude, one point per line.
17+
18+
3. Run Preprocessing Scripts
19+
***pre_precipitation.py***
20+
***pre_temperature.py***
21+
***pre_radiation.py***
22+
***pre_atmosphere_pressure.py***
23+
***pre_vapor_pressure.py***
24+
***pre_wind_speed.py***
25+
Note: adjust the spatial and temporal domain and spatial resolution in each script as desired.
26+
27+
4. Generate VIC Input Files
28+
Once all climate variables are preprocessed:
29+
For VIC Image Driver (NetCDF input), run vic_inp_netcdf.py. Output are stored in ***/vic_inp_netcdf***
30+
For VIC Classic Driver (ASCII input), run vic_inp_ascii.py, output are stored in ***/vic_inp_ascii***
31+
32+
________________________________________________________________________________
33+
34+
# Directory Structure
35+
```
36+
base_dir/
37+
├─ download/ # Downloaded raw climate data (NetCDF format)
38+
├─ atmosphere_pressure/ # Atmosphere pressure data
39+
├─ precipitation/ # Precipitation data
40+
├─ radiation/ # Radiation data (short-wave and long-wave)
41+
├─ temperature/ # Air and dew point temperature (for vapor pressure) data
42+
├─ wind_speed/ # Wind speed component (u and v) data
43+
├─ preprocess/ # Preprocessed data, used to prepare climate input for VIC
44+
├─ era5_sp_2005-2020.nc # Preprocessed atmospheric pressure data
45+
├─ chirps2_precip_2005-2020.nc # Preprocessed precipitation data
46+
├─ era5_sdswrf_2005-2020.nc # Preprocessed short-wave radiation data
47+
├─ era5_sdlwrf_2005-2020.nc # Preprocessed long-wave radiation data
48+
├─ era5_t2m_2005-2020.nc # Preprocessed air temperature data
49+
├─ era5_vp_2005-2020.nc # Preprocessed vapor pressure datda
50+
├─ era5_w10_2005-2020.nc # Preprocessed wind speed data
51+
├─ vic_inp_netcdf/ # VIC climate input files in NetCDF format
52+
├─ vic_inp_2005-2020.nc
53+
├─ vic_inp_ascii/ # VIC climate input files in ASCII format
54+
├─ gf_lon_lat # Files named by lon and lat (e.g., gf_93.9069_18.9189)
55+
├─ lon_lat.txt # List of lon-lat points to extract VIC climate input flies
56+
├─ pre_atmosphere_pressure.py # Script for processing atmospheric pressure data
57+
├─ pre_precipitation.py # Script for processing precipitation data
58+
├─ pre_radiation.py # Script for processing short-wave and long-wave radiation data
59+
├─ pre_temperature.py # Script for processing air temperature data
60+
├─ pre_vapor_pressure.py # Script for processing vapor pressure data
61+
├─ pre_wind_speed.py # Script for processing wind speed data
62+
├─ vic_inp_netcdf.py # Script for preparing VIC climate input files in NetCDF format
63+
├─ vic_inp_ascii.py # Script for preparing VIC climate input files in ASCII format
64+
```
65+
66+
________________________________________________________________________________
67+
68+
# Data Processing Workflow
69+
1. Download raw climate datasets
70+
Raw data files are stored in the ***/download*** directory.
71+
72+
2. Preprocess each climate variable separately
73+
- Adjust time zones if necessary (e.g., shift by +7 hours for the Mekong region).
74+
- Slice the data temporally (e.g., from 2005-01-01 to 2020-12-31).
75+
- Calculate derived variables where needed (e.g., vapor pressure from dew point temperature, wind speed from u and v components).
76+
- Convert units when required (e.g., temperature from Kelvin to Celsius).
77+
- Re-grid spatially to a uniform resolution (e.g., 0.0625°).
78+
- Save the preprocessed variables as separate NetCDF files in the /preprocess directory.
79+
80+
3. Prepare VIC climate input files in NetCDF format
81+
Merge all preprocessed climate variables into one multi-variable NetCDF file stored in ***/vic_inp_netcdf***.
82+
83+
4. Prepare VIC climate input files in ASCII format
84+
Extract time series for specified longitude-latitude points and save as ASCII files in ***/vic_inp_ascii***.
85+
86+
________________________________________________________________________________
87+
88+
# Script Explanation
89+
1. Preprocessing Scripts
90+
- ***pre_precipitation.py*** --- precipitation preprocessing
91+
Inputs: Raw daily CHIRPS2 precipitation NetCDF files (***/download/precipitation/***)
92+
Operations: Temporal slicing, daily to 6-hr data conversion, re-gridding
93+
Output: ***chirps2_precip_2005-2020.nc*** saved in ***/preprocess***
94+
95+
- ***pre_temperature.py*** --- temperature preprocessing
96+
Inputs: Raw 6-hr ERA5 temperature NetCDF files (***/download/temperature/***)
97+
Operations: Time zone adjustment, temporal slicing, unit conversion (K → °C), re-gridding
98+
Output: ***era5_t2m_2005-2020.nc*** saved in ***/preprocess***
99+
100+
- ***pre_radiation.py*** --- short-wave and long-wave Radiation preprocessing
101+
Inputs: Raw 6-hr ERA5 short-wave and long-wave radiation NetCDF files (***/download/radiation/***)
102+
Operations: Time zone adjustment, temporal slicing, re-gridding
103+
Outputs: ***era5_sdswrf_2005-2020.nc*** (shortwave) and ***era5_sdlwrf_2005-2020.nc*** (longwave) saved in ***/preprocess***
104+
105+
- ***pre_atmosphere_pressure.py*** --- atmospheric pressure preprocessing
106+
Inputs: Raw 6-hr ERA5 surface pressure NetCDF files (***/download/pressure/***)
107+
Operations: Time zone adjustment, temporal slicing, re-gridding
108+
Output: ***era5_sp_2005-2020.nc*** saved in ***/preprocess***
109+
110+
- ***pre_vapor_pressure.py*** --- vapor pressure preprocessing
111+
Inputs: Raw 6-hr ERA5 dew point temperature NetCDF files (***/download/temperature/***)
112+
Operations: Time zone adjustment, temporal slicing, unit conversion, vapor pressure calculation, re-gridding
113+
Output: ***era5_vp_2005-2020.nc*** saved in ***/preprocess***
114+
115+
- ***pre_wind_speed.py*** --- wind speed preprocessing
116+
Inputs: Raw 6-hr ERA5 u10 and v10 wind components NetCDF files (***/download/wind_speed/***)
117+
Operations: Time zone adjustment, temporal slicing, wind speed calculation, re-gridding
118+
Output: ***era5_w10_2005-2020.nc*** saved in ***/preprocess***
119+
120+
2. VIC Input Preparation Scripts
121+
- ***vic_inp_netcdf.py*** --- NetCDF merging script
122+
Inputs: Preprocessed NetCDF climate variable files from ***/preprocess***
123+
Operations: Merge all climate variables into a single NetCDF file
124+
Output: ***vic_inp_2005-2020.nc*** saved in ***/vic_inp_netcdf***
125+
126+
- ***vic_inp_ascii.py*** --- ASCII extraction script
127+
Inputs: Preprocessed NetCDF climate variable files from ***/preprocess*** and list of locations (***lon_lat.txt***)
128+
Operations: Extract nearest grid cell time series for each location, save as tab-separated ASCII files
129+
Output: ASCII VIC input files saved in ***/vic_inp_ascii*** (filename format: ***gf_{lon}_{lat}***)
130+
131+
*--- end of documents ---*

0 commit comments

Comments
 (0)