[SWAT hydrological model] SWAT hydrological model establishment and application Phase 4: Preparation of meteorological data (traditional weather station) (including MATLAB data sorting code)

This blog mainly introduces the preparation of meteorological data, which is divided into two parts: data download and data processing.

1 Introduction

The meteorological data required by the SWAT model mainly include daily precipitation, maximum/minimum air temperature, solar radiation, wind speed, and relative humidity in the watershed. These data can be statistical data, generated by the SWAT model's weather simulation program (Weather Generator), or a combination of statistical and simulated production data.
Ideally, the SWAT model needs at least 20 years of weather data, and if the necessary data is lacking, it can be supplemented by a weather generator.
On the time scale, the simulation time step of the model can be years, months, or days.

1.1 Data sources

Meteorological data such as precipitation, daily maximum/minimum temperature, wind speed, relative humidity, and solar radiation are provided by the China Meteorological Data Sharing Service Network .

The case study area is the Taohe River Basin (Gansu Province) , and the distribution of meteorological stations around it is as follows:
insert image description here
The length of the data series is the entire research period (including the rate period and inspection period) : 1970-2020. The site information is as follows:
insert image description here

2 Preparation of Meteorological Data (Traditional Weather Station)

The importance of meteorological data to hydrological processes is self-evident. In the process of building the SWAT model, there are three data that are necessary for the model, namely weather generator, precipitation data, temperature data, relative humidity, wind speed and sunshine (optional) . The former is a SWAT model because it can make up for the lack of meteorological data. Built-in, the database information must be established in advance before modeling, and the latter two can obtain data from weather stations.

key step:

  • Calculation of Parameters of Weather Generator
  • Precipitation and temperature input data preparation

2.1 Calculation of the parameters of the weather generator

The weather generator can simulate and produce daily meteorological data based on monthly meteorological data for many years, but the database requires many input parameters. The main input data include monthly average maximum temperature, monthly average minimum temperature, maximum temperature standard deviation, and monthly average rainfall. , standard deviation of rainfall, number of dry days in a month, dew point temperature, monthly average solar radiation, etc. The calculation formula
of the weather generator parameters is as follows: For the detailed introduction of the weather generator, please refer to another blog - [SWAT hydrological model] SwatWeather software tutorial .
insert image description here

Open the SWAT2012.mdb database, the WGEN_user table, as follows:
insert image description here
export it as an excel table, and organize the site data in the research area.
insert image description here
Then, import the organized table WGEN_user into the WGEN_user table in the SWAT2012.mdb database. When importing the table, select [I choose the primary key myself], as shown in the figure below:
insert image description here

2.2 Preparation of precipitation and air temperature input data

In the meteorological input file of the model, precipitation and temperature data are required files. The long-term measured data required for precipitation is as long as possible. Its format is divided into two columns as shown in the figure below. The time series must be continuous. If there is no measured value, replace it with -99 and store it in .DBF format. Because precipitation directly has an important impact on runoff, although the weather generator can simulate daily precipitation data, it is strongly recommended that model users directly input measured daily-scale precipitation data.
If the site of precipitation and temperature is the same as that of the weather generator, SwatWeather.exe can directly generate the input file in the required format. If there are more sites, it needs to be converted into an input file of the corresponding format. It is recommended that precipitation and temperature Data taken from as many sites as possible.

2.2.1 Precipitation data preparation

The input format of SWAT model meteorological data can be viewed in the case that comes with the software after installation.
Taking precipitation as an example, the precipitation data of each station should form a separate text file, the file is named as the name of the station, the index file of precipitation and the station data must be under the same folder, and only the index needs to be entered in the SWAT input file, it will automatically look for site data under the same folder.
insert image description here
Specific format: Each type of data needs to have an index file of a station , such as precipitation, an index file of a precipitation station is required, and the index file needs to contain the name of the station (for the specific header, please refer to the case that comes with it) , the specific appearance of the index file is as follows: it must be entered strictly according to the format, and the last three are latitude, longitude and elevation.
Points to note for each site's data:

  • There must be one data every day from the first day to the last day of the simulation. Even if the data is missing, it must be replaced by -99. Make sure that the data is not missing, and the data length of each station is the same;
  • Each site name must correspond to the site name (NAME) field in the site index file;
  • Pay attention to the processing of outliers. The data downloaded from the Internet usually have outliers, such as 9999, which must be replaced with -99

The MATLAB implementation code of the PCPfork file is as follows:

clc
close all
clear
%% 基本设置
pathFiles= '.\DataFiles\' ;

%% 导入数据

load('StationYT.mat');
nStation = length( StationYT );

%% 导出数据 ID NAME LATITUDE LONGITUDE ELEVATION
nVariable = 5;
Title = 'PCPfork';
fid = fopen([pathFiles,'PCPfork.txt'],'wt');
fprintf(fid,'%s\n','ID,NAME,LAT,LONG,ELEVATION');
for iStation=1:nStation
    for iVariable=1:nVariable
        switch iVariable
            case 1
                fprintf(fid,'%s',num2str( StationYT(iStation,1) ) );
                fprintf(fid,'%c',',');
            case 2
                fprintf(fid,'%s','PCP');
                fprintf(fid,'%s',num2str( StationYT(iStation,1) ) );
                fprintf(fid,'%c',',');
            case 3
                fprintf(fid,'%0.4f',StationYT(iStation,2));
                fprintf(fid,'%c',',');
            case 4
                fprintf(fid,'%0.4f',StationYT(iStation,3));
                fprintf(fid,'%c',',');
            case 5
                fprintf(fid,'%0.2f\n',StationYT(iStation,4));
        end
    end
end

The output file format is as follows:
insert image description here
The daily precipitation data of each station are processed as follows:

clc
close all
clear
%% 基本设置
pathFigure= '.\Figures\' ;
pathFiles= '.\DataFiles\' ;

%% 站点数据资料处理
load('StationID.mat');                                % 840个站点的站点信息                      
load('StationIDSSQ.mat');                          % 研究区内站点信息(区站号 X Y 位置)
nStation = length(StationIDSSQ);

load('Prec.mat');                   % 降水
Datamiss = -99;

% 截取实际采用数据(1970-2020年 共51年数据)18628% ------------------------------------------------------------------
nDay = datenum(2020,12,31)-datenum(1970,1,1)+1;
ii = datenum('01-Jan-1970');
jj = datenum('31-Dec-2020');
% 数据说明:分闰年/平年
if (jj-ii+1)~=nDay
    sprintf("数据有误!")
end

%% 研究区内降水数据处理 日降水资料PRE

% 根据研究区内站点ID得到相应降水数据
% ------------------------------------------------------------------
ID = StationIDSSQ;
PrecSSQ = zeros( length(ID) , length( Prec(1,:)) );
for ilength = 1:length( ID )
    for jlength = 1:length( StationID )
        if ID(ilength)==StationID(jlength)
            PrecSSQ(ilength,:) = Prec(jlength,:);
        end
    end
end

% 降水数据处理
% 32700	表示降水"微量"
% 32XXX	XXX为纯雾露霜
% 31XXX	XXX为雨和雪的总量
% 30XXX	XXX为雪量(仅包括雨夹雪,雪暴)
% ------------------------------------------------------------------
PSSQ = zeros( nStation ,  nDay );
for iStation=1:nStation
    for iday=1:nDay
        if isnan( PrecSSQ( iStation,iday) )
            PSSQ( iStation,iday) = Datamiss;
        elseif PrecSSQ( iStation,iday)==999990
            PSSQ( iStation,iday) = 0;
        elseif PrecSSQ( iStation,iday)==32700
            PSSQ( iStation,iday) = 0;
        elseif PrecSSQ( iStation,iday)>32000
            PSSQ( iStation,iday) = PrecSSQ( iStation,iday)-32000;
        elseif PrecSSQ( iStation,iday)>31000
            PSSQ( iStation,iday) = PrecSSQ( iStation,iday)-31000;
        elseif PrecSSQ( iStation,iday)>30000
            PSSQ( iStation,iday) = PrecSSQ( iStation,iday)-30000;
        else
            PSSQ( iStation,iday) = PrecSSQ( iStation,iday);
        end
    end
end

% txt格式数据导出   起始数据年月日  各日降水量(mm)
% ------------------------------------------------------------------

for iStation=1:nStation
    Title = ['PCP',num2str( StationIDSSQ(iStation,1) )];
    fid = fopen([pathFiles,'PCP\',Title,'.txt'],'wt');
    fprintf(fid,'%s\n','19700101');
    for iday=1:nDay
        fprintf(fid,'%0.2f\n', PSSQ( iStation,iday) );
    end
end

The output folder looks like this:
insert image description here

2.2.2 Air temperature data preparation

The temperature data input format is as follows:

  • The TMPfork.txt file stores the information of each site
  • The MATLAB processing code for storing air temperature data in each subfolder
    insert image description here
    is similar to the precipitation processing code, as follows:
clc
close all
clear
%% 基本设置
pathFiles= '.\DataFiles\' ;

%% 导入数据

load('StationYT.mat');
nStation = length( StationYT );


%% 导出数据 ID NAME LATITUDE LONGITUDE ELEVATION
nVariable = 5;
Title = 'TEMPfork';
fid = fopen([pathFiles,'TEMPfork.txt'],'wt');
fprintf(fid,'%s\n','ID,NAME,LAT,LONG,ELEVATION');
for iStation=1:nStation
    for iVariable=1:nVariable
        switch iVariable
            case 1
                fprintf(fid,'%s',num2str( StationYT(iStation,1) ) );
                fprintf(fid,'%c',',');
            case 2
                fprintf(fid,'%s','TEMP');
                fprintf(fid,'%s',num2str( StationYT(iStation,1) ) );
                fprintf(fid,'%c',',');
            case 3
                fprintf(fid,'%0.4f',StationYT(iStation,2));
                fprintf(fid,'%c',',');
            case 4
                fprintf(fid,'%0.4f',StationYT(iStation,3));
                fprintf(fid,'%c',',');
            case 5
                fprintf(fid,'%0.2f\n',StationYT(iStation,4));
        end
    end
end

According to this MATLAB code, the required input txt file can be obtained.

3 Import of meteorological data in SWAT model

The import of meteorological data in the SWAT model is shown in the following table:
insert image description here

reference

1. CSDN Blog - SWAT Model Tutorial - Land Use, Soil Data, Meteorological Data Processing
2. CSDN Blog - SWAT Model Meteorological Data Processing (1)

おすすめ

転載: blog.csdn.net/qq_44246618/article/details/130391362