Part 2

advertisement
Matlab Documentation Part IIData Analysis
The following sections provide a generic outline for performing many kinds of data
analyses useful for this project using model information.
All of the m-files described in this documentation are currently written in a way that is
compatible with the GFDL CM2.1 model. Any features of these functions, including input
arguments, variable dimensions, calculation procedures, labels on maps, color scales, etc.,
can be altered by opening the m-file and saving changes.
Table of Contents
Section 1:
Global Temperature Change Maps…………………………………………
Section 2:
Global Soil Moisture Change Maps………………………………………..
Section 3:
Global “Precipitation Percentile Value” Maps……………………………..
Section 4:
Global “Percent Change in Precip. per Degree K” Maps…………..............
Section 5:
Global “r2” Maps Associated with Section 4 Maps………………………...
Section 6:
Finding the Median of a Global 2-Dimensional Variable………………….
Section 7:
“QQ” Plots for Individual Locations……………………………………….
Section 8:
Histograms for Individual Locations………………………………………..
Section 9:
Global Mean Precipitation Change Maps……………………………………
Section 10:
Global “Percentile Bin Frequency Change” Maps…………………………..
Section 11:
Variables for Multi-Day Periods and Seasons……………………………….
2-3
4-5
6-8
9-12
13-16
17-18
19-20
21-23
24-26
27-30
31-34
1
Section 1
Making Global Maps of Average Temperature Change between Climates with
Different CO2 Forcing:
These maps plot the absolute change in daily average temperature between the
control and elevated CO2 climate, with units of °K. Positive values indicate an
increase in the warmer climate, while negative values a decrease.
Step 1: You must have a variable of two dimensions, where each piece of data is a temperature
change between climates for each grid box of the globe of the model in use. For the CM2.1
model, the dimensions of this variable are (90 x 144). I have already saved this variable in the
MAT-file ‘globetdiff.mat’.
If you need to make a new variable for a different model, you can obtain temperature
information to make this variable from appropriate netCDF files and by using ‘nc_varget.m’.
One way to do this is by subtracting two annual average temperature variables within Matlab,
where each variable corresponds to a different climate experiment (control or elevated CO2).
Note: To make a variable of this size there is no need to break up the globe into pieces, because
the data should only have one value in the time dimension, and be small enough for Matlab to
handle.
Step 2: Load a variable that is of the same dimensions of the global variable you are mapping,
which has a land fraction for each grid box. For the CM2.1 model, I have already saved this
variable in ‘globeland.mat’. This will be used to mask out land or water in the final map.
A variable like this can come directly from a netCDF file and can be brought into Matlab using
‘nc_varget.m’.
Step 3: Use the function ‘tdiffmap.m’ to make the map.
General usage of ‘tdiffmap.m’:
>>tdiffmap(globetdiff,globeland,l)
The first argument is the temperature difference variable to be mapped, from step 1.
The second argument is the land fractions variable loaded in step 2.
The third argument is the number 1, 2, or 0, corresponding to the type of map you wish to make:
1 refers to a map that plots land data only (land fraction >= 0.50).
2 refers to water data only (land fraction < 0.50).
2
0 refers to all data (where no points are masked out, that is, set to NaN)
The way the function is written, if you type any other number in this argument, a map
with all data will be made.
The end result is that the desired map will pop up.
Note: The functions ‘landmask.m’ and ‘watermask.m’ are nested in this function and can be
altered, particularly with respect to the definition of a land vs. water point.
Example for using ‘tdiffmap’:
How do I make a temperature difference map showing only land with the variable ‘tempdiff’.
Type:
>>tdiffmap(tempdiff,globeland,1)
where globeland is the land fractions variable
3
Section 2
Making a Global Map of Soil Moisture Change between Climates with
Different Forcing:
These maps display the absolute change in daily average soil moisture between the
control and elevated CO2 climates in units of kg/m2. Positive values indicate an
increase in the warmer climate, while negative values a decrease.
Step 1: Obtain a variable that is two dimensional and has information about soil moisture change
for each grid box of the globe for the model you are using. For the CM2.1 model, the
dimensions of this variable are (90 x 144) and is saved in the Matlab MAT-file
‘globesoildiff.mat’.
When using a new model, you can obtain soil moisture information to make this variable from
appropriate netCDF files and by using ‘nc_varget.m’. One way to do this is by subtracting two
annual average soil moisture variables within Matlab, where each variable corresponds to a
different climate experiment (control or elevated CO2).
Note: To make a variable of this size there is no need to break up the globe into pieces, because
the data should only have one value in the time dimension, and be small enough for Matlab to
handle.
Step 2: Load a land fractions variable of the same dimensions as your soil moisture change
variable. For the CM2.1 model, I have already saved this variable in ‘globeland.mat’. This will
be used to mask out land or water in the final map.
A variable like this can come directly from a netCDF file and can be brought into Matlab using
‘nc_varget.m’.
Step 3: Use the function ‘soildiffmap.m’.
General usage of ‘soildiffmap.m’:
>>soildiffmap(soildiff,globeland)
The first argument is the soil difference variable from step 1.
The second argument is the land fractions variable from step 2.
The end result is that the desired map will pop up.
Example for using ‘soildiffmap.m’:
4
How do I make a soil difference map using the variable ‘globalsoilchange’?
Type:
>>soildiffmap(globalsoilchange,globeland)
5
Section 3
Making Global Maps Plotting Precipitation Percentile Values
This section makes maps of the nth percentile precipitation values in mm/day for
either the control or elevated CO2 precipitation data. The map function is currently
written for daily data including all seasons.
Step 1: Load the appropriate precipitation model data into Matlab (or from a saved MAT file).
You will need only one variable which corresponds to a particular climate forcing (the control
variable or elevated CO2 variable).
It is important to note that this analysis cannot be performed on the entire globe at once, so the
precipitation variable must be a fraction of the globe that is small enough for Matlab to handle.
For the CM2.1 model, an even fraction size that works is 1/6th. For daily all-season data a
variable of this size has the dimensions (36500 x 45 x 48). You can only work with one region
at a time.
Step 2: Load a land fractions variable that is the same size and resolution as the full globe
associated with the model you are using. For the CM2.1 model, I have already saved this
variable in ‘globeland.mat’. This will be used to mask out land or water in the final map.
For other models, a variable like this can come directly from a netCDF file and can be brought
into Matlab using ‘nc_varget.m’.
Step 3: Create the variables that will be mapped, recognizing that you will end up with a variable
corresponding to each region of the globe.
Use the function ‘percvar.m’
General usage of ‘percvar.m’:
>>newvar=percvar(precipvar);
newvar is the name of “percentile values” variable that will be created.
The input argument is the precipitation variable from which percentiles will be found.
As written, this function will return a variable of dimensions (5 x lat x lon), where the first
dimension corresponds to the 50th, 80th, 97th, 99th, and 99.7th percentile precipitation values in
that order of the data you entered (I have it written like this because it corresponds to the
percentiles in the “percent change in precipitation per degree K” analysis, see section 4). The
units are in mm/day.
6
Note: This m-file contains the nested function ‘createsedgesprec.m’ which determines the
percentiles that are found. By changing the contents of this function, you can find different
percentiles and the dimensions of the output variable of ‘percvar.m’ can be different.
Example for using ‘percvar’:
How do I create a “percentile values” variable from the control precipitation variable for my
region 1, ‘controlprecipreg1’?
Type:
>>region1perc=percvar(controlprecipreg1);
Step 4: You must append the “percentile values” variables obtained in step 3 into a global
“regression percentiles” variable.
Use the function ‘appendreg3D.m’
General usage of ‘appendred3D.m’:
>>globevar=appendreg3D(varreg1,varreg2,varreg3,varreg4,varreg5,varreg6,...varregk)
globevar is the name of the global “percentile values” variable you wish to create.
The input arguments varreg1 through varregk, are the individual regional “percentile values”
variables you wish to append. They must be in order of region 1 through region k.
The output variable will essentially be the input variables connected into the globe.
Note: This function is written specifically for the way in which I divided the CM2.1 model, and
the way I defined region numbers. It will vary if a different climate model resolution, splitting
procedure, or region definition scheme is used.
Example for using ‘appendreg3D.m’
How do I append my 6 regional “percentile values” variables, ‘percreg1’ through ‘percreg6’ into
one variable, ‘globeperc’:
Type:
>>globeperc=appendreg3D(percreg1,percreg2,percreg3,percreg4,percreg5,percreg6);
Step 5: Make a global map of the precipitation percentile value you wish.
Use the function ‘percmap.m’
7
General usage of ‘percmap.m’
>>percmap(globepercvar,globeland,p,l)
The first argument is the global “percentile values” variable you created from step 4.
The second argument is the global land fractions variable of the same spatial dimensions as the
above variable, loaded in step 2.
The third argument is the percentile you wish to plot (50, 80, 97, 99, 99.7- as the function is
written).
The fourth argument is the number 0, 1, or 2 specifying the map type- land, water, or both.
1 refers to a map that plots land data only (land fraction >= 0.50).
2 refers to water data only (land fraction < 0.50).
0 refers to all data (where no points are masked out, that is, set to NaN)
The way the function is written, if you type any other number in this argument, a map
with all data will be made.
The end result is the desired map which will pop up.
Note 1: This function is written specifically for the percentiles 50, 80, 97, 99, and 99.7. The title
is also written for “control percentiles,” which can be changed.
Note 2: The functions ‘landmask.m’ and ‘watermask.m’ are nested in this function and can be
altered, particularly with respect to the definition of a land vs. water point.
Example for using ‘percmap.m’
How do I make a “control 97th percentile” map of only water data from the variable ‘globereg’?
Type:
>>percmap(globereg,globeland,97,2)
Globeland is the land fractions variable from step 2.
8
Section 4
Making Global Maps of “Percent Change in Precipitation per Degree K”
The end result of this section is to display maps that give the “percent change of
precipitation per degree K” for a particular percentile range of control and elevated
CO2 precipitation data. It is based on a linear regression of a scatter plot of the
sorted daily precipitation values of each data set that is forced through the origin
(0, 0). It also depends on the specific daily average temperature change for each
grid box between the control and elevated CO2 climate. The map function is
currently written for daily data including all seasons.
Step 1: You must load precipitation variables (from a netCDF file or Matlab MAT file).
You should have two precipitation variables of the exact same dimensions. One corresponds to a
climate with a control forcing (the control variable). The other corresponds to a climate with a
different forcing (such as quadrupled CO2 in the CM2.1)
It is important to note that this analysis cannot be performed on the entire globe at once, so the
precipitation variables must be a fraction of the globe that is small enough for Matlab to handle
two of at once. For the CM2.1 model, the largest even fraction size that works is 1/6th. For daily
all-season data each variable of this size has the dimensions (36500 x 45 x 48).
Step 2: Load a land fractions variable that is the same size and resolution as the full globe
associated with the model you are using. For the CM2.1 model, I have already saved this
variable in ‘globeland.mat’. This will be used to mask out land or water in the final map.
A variable like this can come directly from a netCDF file and can be brought into Matlab using
‘nc_varget.m’.
Step 3: Load a global temperature difference variable (see section 1) that is the same size and
resolution as the globe associated with your model.
Step 4: Create the variables that will be mapped, recognizing that you will end up with a set of
variables (one for each percentile range) corresponding to each region of the globe.
Use the function ‘regresvar.m’
General usage of ‘regresvar.m’
>>newvar=regresvar(controlvar,fourxvar,globetdiff,p1,p2,region);
newvar is the name of the output variable associated with this region and percentile range
9
The first two input arguments are the control precipitation and elevated CO2 precipitation
variables loaded from step 1.
The third input argument is the global temperature difference variable loaded from step 3.
The fourth and fifth input arguments are the beginning and ending percentiles that are being put
under the analysis, in that order.
The sixth input argument is the region number associated with input data (first two arguments).
This function returns a variable of the dimensions (lat x lon) corresponding to region size that
contains the “percent change in precipitation per degree K” corresponding to the chosen
percentile bin for each grid box. It is called ‘regresvar’ because it uses a linear regression to
compute the percent change.
Note: This function is specifically written for the CM2.1 model and the way in which I defined
regions, and can be altered according to a new model and region definition method.
Example for using ‘regresvar.m’
How do I create a variable for my region 3, corresponding to the 99th to 100th percentiles of my
precipitation data? My 3 dimensional precipitation variables are ‘controlprec’ and ‘fourxprec’. I
also loaded a global temperature difference variable ‘globetdiff’. I wish to call the new variable
‘reg1regres99to100’.
Type:
>>reg1regres99to100=regresvar(controlprec,fourxprec,globetdiff,99,100,3);
Step 5: You must append the regional regression variables associated with each percentile bin
into global variables for that percentile bin.
Use the function ‘appendreg.m’
General usage of ‘appendreg.m’
>>globeregvar=appendreg(regvar1,regvar2,regvar3,….regvark);
globeregvar is the output global variable.
The input arguments in the function are the regression variables for the individual regions in
order from region 1 to region k.
The result is a global regression variable that is the region variables connected.
10
Note that all variables inputted and outputted from this function correspond to the same
percentile range.
Note also that this function is written specifically for the way in which I divided the CM2.1
model, and the way I defined region numbers. It will vary if a different climate model
resolution, splitting procedure, or region definition scheme is used.
Example for using ‘appendreg.m’
How do I append my 6 regional “regression” variables corresponding to the 80th to 97th
percentiles? The variables are ‘regres1_80to97’ through ‘regres6_80to97’. I wish to save the
global variable as ‘globereg_80to97’.
Type:
>>globereg_80to97=appendreg(regres1_80to97,regres2_80to97,regres3_80to97,regres4_80to97,
regres5_80to97,regres6_80to97);
Note: this should all be on one line with no spacing in between.
Step 6: Create the maps.
Use the function ‘regresmap.m’
General usage of ‘regresmap.m’
>>regresmap(globevar,globeland,p1,p2,l);
The first argument is the global regression variable corresponding to a specific percentile range,
which was created in step 5.
The second argument is the global land fractions variable loaded in step 2.
The third and fourth arguments are the beginning and ending percentiles of the percentile range
which you are plotting, in order from lower to higher. This is for title purposes.
The fifth argument is a 0, 1, or 2, corresponding to the map type:
1 refers to a map that plots land data only (land fraction >= 0.50).
2 refers to water data only (land fraction < 0.50).
0 refers to all data (where no points are masked out, that is, set to NaN)
11
The way the function is written, if you type any other number in this argument, a map
with all data will be made.
The end result is a map which will pop up.
Note: The functions ‘landmask.m’ and ‘watermask.m’ are nested in this function and can be
altered, particularly with respect to the definition of a land vs. water point.
Example for using ‘regresmap.m’
How do I make a global map of “percent change in precipitation per degree K” from the global
variable ‘globereg97_100’ for the 97th to 100th percentiles for the land only?
Type:
>>regresmap(globereg97_100,globeland,97,100,1)
12
Section 5
Making r2 Maps that Correspond to the Linear Regression from the “Percent
Change in Precipitation per Degree K” Maps
The end result of this section is to produce maps plotting “r2” values for the linear
regression of a scatter-plot of sorted control and elevated CO2 precipitation- for a
specified “percentile range” of each data set. These maps correspond to those
made in Section 4. The map function is currently written for daily data including
all seasons.
Step 1: You must load precipitation variables (from a netCDF file or Matlab MAT file).
You should have two precipitation variables of the exact same dimensions. One corresponds to a
climate with a control forcing (the control variable). The other corresponds to a climate with a
different forcing (such as quadrupled CO2 in the CM2.1)
It is important to note that this analysis cannot be performed on the entire globe at once, so the
precipitation variables must be a fraction of the globe that is small enough for Matlab to handle
two of at once. For the CM2.1 model, the largest even fraction size that works is 1/6th. For daily
all-season data, each variable of this size has the dimensions (36500 x 45 x 48).
Step 2: Load a land fractions variable that is the same size and resolution as the full globe
associated with the model you are using. For the CM2.1 model, I have already saved this
variable in ‘globeland.mat’. This will be used to mask out land or water in the final map.
A variable like this can come directly from a netCDF file and can be brought into Matlab using
‘nc_varget.m’.
Step 3: Create the variables that will be mapped, recognizing that you will end up with a set of
variables (one for each percentile range) corresponding to each region of the globe.
Use the function ‘r2var.m’
General usage of ‘r2var.m’
>>newvar=r2var(controlvar,fourxvar,p1,p2);
newvar is the name of the output variable associated with this region and percentile range
The first two input arguments are the control precipitation and elevated CO2 precipitation
variables loaded from step 1.
13
The third and fourth input arguments are the beginning and ending percentiles that are being put
under the analysis, in that order.
This function returns a variable of the dimensions (lat x lon) corresponding to the selected region
that contains the “r2” value corresponding to the linear regression analysis from section 4, where
these is one value for each grid box.
Note: This function is specifically written for the CM2.1 model and the way in which I defined
regions, and can be altered according to a new model and region definition method.
Example for using ‘r2var.m’
How do I create an r2 variable for my region 4 for the 50th to 80th percentile bin, where my 3
dimensional control and elevated CO2 precipitation variables are ‘controlprecreg4’ and
‘fourxprecreg4’? I wish to call the variable ‘r2reg4_50to80’.
Type:
>>r2reg4_50to80=r2var(controlprecreg4,fourxprecreg4,50,80);
Step 5: You must append the regional r2 variables associated with each percentile bin into global
variables for that percentile bin.
Use the function ‘appendreg.m’
General usage of ‘appendreg.m’
>>globeregvar=appendreg(regvar1,regvar2,regvar3,….regvark);
globeregvar is the output global variable.
The input arguments in the function are the r2 variables for the individual regions in order from
region 1 to region k.
The result is a global r2 variable that is the region variables connected.
Note that all variables inputted and outputted from this function correspond to the same
percentile range.
Note also that this function is written specifically for the way in which I divided the CM2.1
model, and the way I defined region numbers. It will vary if a different climate model
resolution, splitting procedure, or region definition scheme is used.
Example for using ‘appendreg.m’
14
How do I append my 6 regional “r2” variables corresponding to the 50th to 80th percentiles? The
variables are ‘r2reg1_50to80’ through ‘r2reg6_50to80’. I wish to save the global variable as
‘glober2_50to50’.
Type:
>>glober2_50to80=appendreg(r2reg1_50to80,r2reg2_50to80,r2reg3_50to80,r2reg4_50to80,r2re
g5_50to80,r2reg6_50to80);
Note: this should all be on one line with no spacing in between.
Step 6: Create the maps.
Use the function ‘r2map.m’
General usage of ‘r2map.m’
>>r2map(globevar,globeland,p1,p2,l);
The first argument is the global r2 variable corresponding to a specific percentile range, which
was created in step 5.
The second argument is the global land fractions variable loaded in step 2.
The third and fourth arguments are the beginning and ending percentiles of the percentile range
which you are plotting, in order from lower to higher. These inputs are for title purposes.
The fifth argument is a 0, 1, or 2, corresponding to the map type:
1 refers to a map that plots land data only (land fraction >= 0.50).
2 refers to water data only (land fraction < 0.50).
0 refers to all data (where no points are masked out, that is, set to NaN)
The way the function is written, if you type any other number in this argument, a map
with all data will be made.
The end result is a map which will pop up.
Note: The functions ‘landmask.m’ and ‘watermask.m’ are nested in this function and can be
altered, particularly with respect to the definition of a land vs. water point.
Example for using ‘regresmap.m’
15
How do I make a global map of r2 values corresponding to the linear regression in the “percent
change per degree K” analysis from the global variable ‘globr2_997to100’ for the 99.7th to 100th
percentiles showing both land and water points?
Type:
>>r2map(glober2_997to100,globeland,99.7,100,0)
Note: The last argument can be 0, or any other number besides 1 or 2.
16
Section 6
Finding the Median of a Global 2-Dimensional Variable
As you can imagine, this section discusses a function which simply displays the
median of any two-dimensional variable (such as the “percent change in
precipitation per degree K” for the globe).
Step 1: Load a variable that is 2-dimensional and the size of the entire globe for the particular
model you are using.
Variables like this include the global temperature difference variable (Section 1), the “percent
change in precipitation per degree K” variables, or the “r2” variables. You can also find the
median of the “percentile values” (from Section 3) by making a 2-dimensional variable from the
3-dimensional variable that contains the percentile information.
Step 2: Load a land fractions variable that is the same size and resolution as the full globe
associated with the model you are using. For the CM2.1 model, I have already saved this
variable in ‘globeland.mat’. This will be used to mask out land or water in the final map.
A variable like this can come directly from a netCDF file and can be brought into Matlab using
‘nc_varget.m’.
Step 3: Find the median.
Use the function ‘convmed.m’
General usage of ‘convmed.m’:
>>convmed(variable,globeland,l)
The first argument is the 2-dimensional variable you wish to find the median of, obtained in step
1.
The second argument is the land fractions variable loaded in step 2.
The fifth argument is a 0, 1, or 2, corresponding to the type of data from which the median will
be found:
1 refers to the median from land data only (land fraction >= 0.50).
2 refers to water data only (land fraction < 0.50).
0 refers to all data (where no points are masked out, that is, set to NaN)
17
The way the function is written, if you type any other number in this argument, the
function will yell at you and tell you to type either 0, 1, or 2.
This function will display the median of the input variable on the Matlab command window.
Note: This function is only compatible with the size and resolution of the GFDL CM2.1 model
as written, and can be altered according to other variable sizes and dimensions.
Example for using ‘convmed.m’:
How do I display the median of the variable ‘globetdiff’ where I only wish to find the median
associated with the land points?
Type:
>>convmed(globetdiff,globeland,1)
18
Section 7
Making “QQ” Plots Showing Precipitation Change Characteristics
What is a QQ plot?
Essentially, a QQ plot is a scatter plot of two one-dimensional variables having the
same number of data points. Here, we make QQ plots of the control and elevated
CO2 data, where the control is on the x-axis and elevated CO2 is on the y-axis.
These plots are for one individual location.
These particular QQ plots also display a linear regression of the scatter plot, as
well as a 1:1 line. The QQ plot function is currently written for daily data
including all seasons.
Step 1: You must load two precipitation variables that are of 1 dimension, both corresponding to
the same grid box from your full 3-dimensional global precipitation data. One of these variables
corresponds to the control data, while the other corresponds to the “elevated CO2” data. If you
don’t have these “location variables” saved, this can be done by starting with the full 3dimensional global precipitation variables and setting new Matlab variables of one dimension
corresponding to a particular grid box.
Example:
The two variables ‘globecontrolprec’ and ‘globefourxprec’ are my (36500 x 90 x 144)
daily all-season global precipitation variables. I wish to create two one dimensional
variables for the location with the following indices: 111, 45: where 111 is the longitude
and 45 is the latitude. I want to save the variables as ‘loccontrol’ and ‘locfourx’.
>>loccontrol=globecontrolprec(:,45,111);
>>locfourx=globefourxprec(:,45,111);
Clearly, you must know where on the globe the indices correspond to. There is a Microsoft
Word document on the Matlab Documentation webpage which lists the indices of the CM2.1
model and the corresponding latitude and longitude locations.
Once you know which locations you would like to make a QQ for, you should create them all at
once using the above procedure, then save them together in a MAT file so you can access them
later. A slew of locations within the United States (and Canada) for the CM2.1 model are
already saved under the MAT-file ‘preclocann1.mat’. For more information on which locations
these variable names correspond to, see the “USA locations within preclocann1.mat” Word
document on the Matlab Documentation webpage.
Step 2: Make the QQ plot.
19
Use the function ‘qqplotr.m’.
General usage of ‘qqplotr.m’:
>>qqplotr(controlvar,fourxvar,lon,lat,p1,p2);
The first two arguments are the one dimensional control and elevated CO2 precipitation variables
for a particular location, in that order.
The third and fourth arguments are the longitude and latitude of the location of the location you
are plotting. Note that negative values of longitude and latitude correspond to the western and
southern hemispheres respectively. Positive values of longitude and latitude correspond to the
eastern and northern hemispheres respectively. These inputs are for titling purposes.
The fifth and sixth arguments are the beginning and ending percentiles of the percentile range
you wish to plot in the QQ plot, where the lower one is typed first. Note that to plot all data, the
percentiles are 0 and 100.
The end result is a QQ plot which will pop up. In addition to merely plotting the raw input data,
this function also computes the linear regression of the data (where the regression line is forced
through the origin), and this line is plotted on the graph as well, hence the “r” after “qqplot” in
the function name. This linear regression is the same as performed in the “percent change in
precipitation per degree K” analysis and their corresponding “r2” maps (Sections 4 and 5).
Additionally, a 1:1 line is plotted (y= x) for reference.
After the graph pops up, you will need to click somewhere on the graph to place a “gtext”
displaying the percentile range for the data used. You can also move the legend if it is blocking
part of the plot.
Example for using ‘qqplotr.m’:
How do I make a qq plot for the location with latitude and longitude 86W, 50N, for the 80th to
97th percentiles of the precipitation data? My two one-dimensional variables for this location are
‘loccontrol’ and ‘locfourx’.
Type:
>>qqplotr(loccontrol,locfourx,-86,50,80,97)
Don’t forget to place the “gtext” and move the legend if necessary.
20
Section 8
Making Histograms Showing Precipitation Change Characterstics for
Individual Locations
What is a histogram?
A plot that shows the frequency of a variable (such as precipitation) falling in
specific ranges of that variable (such as 20 to 30mm/day, or the 95th to 98th
percentile of control daily precipitation, for example). Here, these plots
correspond to one individual location. The map function is currently written for
daily data including all seasons.
For details on what these histograms display, see step 2.
Step 1: You must load two precipitation variables that are of 1 dimension, both corresponding to
the same grid box from your full 3-dimensional global precipitation data. One of these variables
corresponds to the control data, while the other corresponds to the “elevated CO2” data. If you
don’t have these “location variables” saved, this can be done by starting with the full 3dimensional global precipitation variables and setting new Matlab variables of one dimension
corresponding to a particular grid box.
Example:
The two variables ‘globecontrolprec’ and ‘globefourxprec’ are my (36500 x 90 x 144)
daily all-season global precipitation variables. I wish to create two one dimensional
variables for the location with the following indices: 111, 45: where 111 is the longitude
and 45 is the latitude. I want to save the variables as ‘loccontrol’ and ‘locfourx’.
>>loccontrol=globecontrolprec(:,45,111);
>>locfourx=globefourxprec(:,45,111);
Clearly, you must know where on the globe the indices correspond to. There is a Microsoft
Word document on the Matlab Documentation webpage which lists the indices of the CM2.1
model and the corresponding latitude and longitude locations.
Once you know which locations you would like to make a histogram for, you should create them
all at once using the above procedure, then save them together in a MAT file so you can access
them later. A slew of locations within the United States (and Canada) for the CM2.1 model are
already saved under the MAT-file ‘preclocann1.mat’. For more information on which locations
these variable names correspond to, see the “USA locations within preclocann1.mat” Word
document on the Matlab Documentation webpage.
Step 2: Decide which type of histogram you would like to make, then make it.
21
There are three main types of histograms that are useful in expressing precipitation change
characteristics between two climates with different CO2 forcings:
‘histogramcont.m’ makes a histogram using the control precipitation data for a particular
location, where the bin edges (the boundaries of the bins) correspond to the following percentiles
of the control data: minimum, 1st, 2nd, 5th, 10th, 15th 20th, 25th, 30th, 35th, 40th, 45th, 50th, 55th, 60th,
65th, 70th, 75th, 80th, 85th, 90th, 95th, 98th, 99th, maximum. This histogram will always have the
same shape for each location (due to the fact that there will always be the same frequency of data
values within bins that correspond to fixed fractions of the data). The main purpose of this
function thus is to display the actual precipitation values of a subset of the above percentiles for
the control precipitation data, which will print above the bars and below the title.
‘histogram4x.m’ plots the elevated CO2 data in the histogram, using the percentile bins from the
control data for that location, which can be displayed in the ‘histogramcont.m’ function. In other
words, the bin edges (the boundaries of the bins) correspond to the following percentiles of the
CONTROL data: minimum, 1st, 2nd, 5th, 10th, 15th 20th, 25th, 30th, 35th, 40th, 45th, 50th, 55th, 60th,
65th, 70th, 75th, 80th, 85th, 90th, 95th, 98th, 99th, maximum. The frequencies of elevated CO2
precipitation events that fall within those bins are then plotted. The purpose of this histogram is
to show how the frequency of events within the control bins changes in the warmer climate. This
histogram also displays the actual precipitation values for a subset of the above percentiles for
the elevated CO2 data, which print above the bars and below the title.
‘histogramdiff.m’ plots the difference in frequency of events that fall in the control percentile
bins between the two climates with different forcings for a particular location. Positive values
indicate an increase in the warmer climate, while negative values a decrease. The bin edges (the
boundaries of the bins) correspond to the following percentiles of the control data: minimum, 1st,
2nd, 5th, 10th, 15th 20th, 25th, 30th, 35th, 40th, 45th, 50th, 55th, 60th, 65th, 70th, 75th, 80th, 85th, 90th,
95th, 98th, 99th, maximum. This histogram essentially summarizes a comparison of the
‘histogramcont.m’ and ‘histogram4x.m’ plots by clearly showing how precipitation frequency in
the warmer climate differs from that in the control climate in one plot.
All three histogram functions are used the same way, so I will only provide the usage format and
an example for ‘histogramdiff.m’. Even through ‘histogramcont.m’ doesn’t need the elevated
CO2 data to make the histogram, it still takes it as an input argument for the sake of consistency
among the histogram functions.
General usage of ‘histogramdiff.m’:
>>histogramdiff(loccontvar,locfourxvar,lon,lat)
Arguments one and two are the one-dimensional control and elevated CO2 precipitation variables
for the same location respectively.
The third and fourth arguments are the longitude and latitude of the location you are plotting
respectively. Note that negative values of longitude and latitude correspond to the western and
22
southern hemispheres respectively. Positive values of longitude and latitude correspond to the
eastern and northern hemispheres respectively. These inputs are for titling purposes.
The end result is a map which will pop up. A more detailed description of what this function
plots and displays is above.
Example for using ‘histogramdiff.m’
I wish to plot a “difference histogram” for the location 120E, 45S. The variables ‘loccontprec’
and ‘locfourxprec’ are the control and elevated CO2 precipitation variables for this location.
How do I do it?
Type:
>>histogramdiff(loccontprec,locfourxprec,120,-45)
23
Section 9
Maps Showing the Change in Mean Precipitation
Not surprisingly, these maps show the change in mean precipitation in mm/day
between two climates with different CO2 forcings. Positive numbers indicate an
increase in the warmer climate, while negative numbers indicate a decrease. The
map function is currently written for daily data including all seasons.
Step 1: You must load precipitation variables (from a netCDF file or Matlab MAT-file).
You should have two precipitation variables of the exact same dimensions. One corresponds to a
climate with a control forcing (the control variable). The other corresponds to a climate with a
different forcing (such as quadrupled CO2 in the CM2.1)
It is important to note that this analysis cannot be performed on the entire globe at once, so the
precipitation variables must be a fraction of the globe that is small enough for Matlab to handle
two of at once. For the CM2.1 model, the largest even fraction size that works is 1/6th. For daily
all-season data, each variable of this size has the dimensions (36500 x 45 x 48).
Step 2: Load a land fractions variable that is the same size and resolution as the full globe
associated with the model you are using. For the CM2.1 model, I have already saved this
variable in ‘globeland.mat’. This will be used to mask out land or water in the final map.
A variable like this can come directly from a netCDF file and can be brought into Matlab using
‘nc_varget.m’.
Step 3: Create the variables that will be mapped, recognizing that you will end up with a variable
(one for each percentile range) corresponding to each region of the globe.
Use the function ‘meanvar.m’
General usage of ‘meanvar.m’
>>newvar=meanvar(controlvar,fourxvar);
newvar is the name of the output variable associated with this region and percentile range.
The two input arguments are the regional 3-dimensional control precipitation and elevated CO2
precipitation variables loaded from step 1.
This function returns a variable of the dimensions (lat x lon) corresponding to the selected region
that contains the absolute change in the daily mean precipitation in mm/day.
24
Note: This function is specifically written for the CM2.1 model and the way in which I defined
regions, and can be altered according to a new model and region definition method.
Example for using ‘meanvar.m’
How do I create a “mean change” variable for my region 2 of the global data set, where my 3
dimensional control and elevated CO2 precipitation variables are ‘controlprecreg2’ and
‘fourxprecreg2’ for this region? I wish to call the variable ‘meanreg2’.
Type:
>>meanreg2=meanvar(controlprecreg2,fourxprecreg2);
Step 5: You must append the regional “mean change” variables into one global “mean change”
variable.
Use the function ‘appendreg.m’
General usage of ‘appendreg.m’
>>globeregvar=appendreg(regvar1,regvar2,regvar3,….regvark);
globeregvar is the output global variable.
The input arguments in the function are the “mean change” variables for the individual regions in
order from region 1 to region k.
The result is a global “mean change” variable that is the region “mean change” variables
connected.
Note: This function is written specifically for the way in which I divided the CM2.1 model, and
the way I defined region numbers. It will vary if a different climate model resolution, splitting
procedure, or region definition scheme is used.
Example for using ‘appendreg.m’
How do I append my 6 regional “mean change” variables? The variables are ‘meanreg1’
through ‘meanreg6’. I wish to save the global variable as ‘globemean’.
Type:
>>globemean=appendreg(meanreg1,meanreg2,meanreg3,meanreg4,meanreg5,meanreg6);
Step 6: Create the maps.
Use the function ‘meanmap.m’
25
General usage of ‘meanmap.m’
>>meanmap(globevar,globeland,l);
The first argument is the global “mean change” variable which was created in step 5.
The second argument is the global land fractions variable loaded in step 2.
The third argument is a 0, 1, or 2, corresponding to the map type:
1 refers to a map that plots land data only (land fraction >= 0.50).
2 refers to water data only (land fraction < 0.50).
0 refers to all data (where no points are masked out, that is, set to NaN)
The way the function is written, if you type any other number in this argument, a map
with all data will be made.
The end result is a map which will pop up.
Note: The functions ‘landmask.m’ and ‘watermask.m’ are nested in this function and can be
altered, particularly with respect to the definition of a land vs. water point.
Example for using ‘meanmap.m’
How do I make a global map of annual daily precipitation mean change values from the global
“mean change” variable ‘globemean’ showing only water points?
Type:
>>meanmap(globemean,globeland,2)
Recall that ‘globeland’ is the land fractions variable loaded in step 2.
26
Section 10
Global Percentile Bin Frequency Change Maps
What exactly do these maps show?
These maps are the equivalent to the “difference” histograms for all grid boxes of
the model (see Section 8). They plot the percent change in the frequency of >95th,
>98th, and >99th percentile precipitation events (between the control and elevated
CO2 climates), where the control precipitation data is used to define the 95th, 98th,
and 99th percentiles. The way these functions are written, they also compute the
percent change in frequency of <5th, <2nd, and <1st percentile precipitation and
these values can also be mapped. The map function is currently written for daily
data including all seasons.
Step 1: You must load precipitation variables (from a netCDF file or Matlab MAT file).
You should have two precipitation variables of the exact same dimensions. One corresponds to a
climate with a control forcing (the control variable). The other corresponds to a climate with a
different forcing (such as quadrupled CO2 in the CM2.1)
It is important to note that this analysis cannot be performed on the entire globe at once, so the
precipitation variables must be a fraction of the globe that is small enough for Matlab to handle
two of at once. For the CM2.1 model, the largest even fraction size that works is 1/6th. For daily
all-season data, each variable of this size has the dimensions (36500 x 45 x 48).
Step 2: Load a land fractions variable that is the same size and resolution as the full globe
associated with the model you are using. For the CM2.1 model, I have already saved this
variable in ‘globeland.mat’. This will be used to mask out land or water in the final map.
A variable like this can come directly from a netCDF file and can be brought into Matlab using
‘nc_varget.m’.
Step 3: Create the variables that will be mapped, recognizing that you will end up with a variable
corresponding to each region of the globe.
Use the function ‘freqvar.m’
General usage of ‘freqvar.m’:
>>newvar=freqvar(contprecipvar,fourxprecipvar);
newvar is the name of “frequency change” variable that will be created.
27
The two input arguments are the control and elevated CO2 3-dimensional precipitation variables
respectively for the selected region.
As written, this function will return a variable of dimensions (6 x lat x lon), where the first
dimension corresponds to the percent change in frequency of the <1st, <2nd, <5th, >95th, >98th,
and >99th percentiles (where the percentiles are taken from control data) in that order.
Note: This m-file contains the nested function ‘createsedgesfreq.m’ which determines the
percentiles that are initially found corresponding to the percentile bins discussed above. By
changing the contents of this function, you may also need to change the contents of ‘freqvar.m’,
which takes these percentiles to compute the frequency changes.
Example for using ‘freqvar.m’:
How do I create a “frequency change” variable for the >95th percentile from my two region 5
precipitation variables, ‘reg5contprec’ and ‘reg5fourxprec’?
Type:
>>region1freq=freqvar(reg5contprec,reg5fourxprec);
Step 4: You must append the “frequency change” variables obtained in step 3 into a global
“frequency change” variable.
Use the function ‘appendreg3D.m’
General usage of ‘appendred3D.m’:
>>globevar=appendreg3D(varreg1,varreg2,varreg3,varreg4,varreg5,varreg6,...varregk)
globevar is the name of the global “frequency change” variable you wish to create.
The input arguments varreg1 through varregk, are the individual regional “frequency change”
variables you wish to append. They must be in order of region 1 through region k.
The output variable will essentially be the input variables connected into the globe.
Note: This function is written specifically for the way in which I divided the CM2.1 model, and
the way I defined region numbers. It will vary if a different climate model resolution, splitting
procedure, or region definition scheme is used.
Example for using ‘appendreg3D.m’
How do I append my 6 regional “frequency change” variables, ‘freqreg1’ through ‘freqreg6’ into
one variable, ‘globefreq’:
28
Type:
>>globefreq=appendreg3D(freqreg1,freqreg2,freqreg3,freqreg4,freqreg5,freqreg6);
Step 5: Make a global map of the frequency change for the percentile bin you wish.
Use the function ‘freqmap.m’:
General usage of ‘freqmap.m’
>>freqmap(globefreqvar,globeland,p,l)
The first argument is the global “frequency change” variable you created from step 4.
The second argument is the global land fractions variable of the same spatial dimensions as the
above variable, loaded in step 2.
The third argument is the percentile of the percentile bin you wish to plot (1, 2, 5, 95, 98, 99- as
the function is written).
The fourth argument is the number 0, 1, or 2 specifying the map type- land, water, or both.
1 refers to a map that plots land data only (land fraction >= 0.50).
2 refers to water data only (land fraction < 0.50).
0 refers to all data (where no points are masked out, that is, set to NaN)
The way the function is written, if you type any other number in this argument, a map
with all data will be made.
The end result is the desired map which will pop up.
Note 1: This function is written specifically for the percentile bins <1st, <2nd, <5th, >95th, >98th,
and >99th, which can be changed.
Note 2: The functions ‘landmask.m’ and ‘watermask.m’ are nested in this function and can be
altered, particularly with respect to the definition of a land vs. water point.
Example for using ‘freqmap.m’
How do I make a “>99th percentile frequency change” map of only land data from the variable
‘globefreq’?
Type:
29
>>freqmap(globefreq,globeland,99,1)
globeland is the land fractions variable from step 2.
30
Section 11
Creating Precipitation Variables for Multi-Day Periods or Seasons
Up to this point, we have gone over the procedures for analyzing precipitation
using daily data that includes all seasons. However, it is also possible to use these
same procedures with data for multi-day periods or seasons. This simply entails
initially loading the appropriate multi-day or seasonal data in step 1 of all of the
above procedures.
This section goes over the process of converting daily all-season data into multiday and/or seasonal data. The functions in this section can be performed on 3dimensional regional data or on one-dimensional grid box data. The following two
subsections provide the general procedure for regional data. The procedure for
one-dimensional data is very similar and is discussed in bold in the general usage
boxes.
The map functions that produce the final products in the mapping procedures from
Sections 1 through 10 can be re-written with new input arguments (such as d for
“days” and s for “season”), which will automatically re-title the plots based on the
values put in for these arguments.
What do you mean by multi-day periods?
Here, we define multi-day periods as the rolling average of a specified number of
days from the original daily-all season data.
Seasons?
Seasons are essentially the daily (or multi-day) data where precipitation values
corresponding to specific months of the year are extracted out. We define summer
as the months May through September. Winter is defined as November through
March.
The “seasons” functions are written specifically for the time dimension associated
with the CM2.1. If a model with different time indices for different months/days is
used, these functions will need to be changed dramatically.
31
Subsection A- Multi-Day Data for a Region
Step 1: Load the appropriate DAILY- ALL SEASON precipitation model data into Matlab
(from a netCDF file or a saved MAT-file). You will need only one variable which corresponds
to a particular climate forcing (the control variable or elevated CO2 variable). But, you can open
two if you wish.
It is important to note that this analysis cannot be performed on the entire globe at once, so the
precipitation variable must be a fraction of the globe that is small enough for Matlab to handle.
For the CM2.1 model, an even fraction size that works is 1/6th. Each variable of this size has the
dimensions (36500 x 45 x 48). You can only work with one region at a time.
It is also important to realize why the data put into this analysis must be for all-seasons. You
cannot perform the rolling averages associated with this procedure if there is a break in the time
dimension (such as going from March one year, right to the following November and skipping
over the months in between- like in the winter seasonal data).
Step 2: Use the function ‘averages3D.m’.
General usage of ‘averages3D.m’:
>>avgvar=averages3D(origprec,d);
avgvar is the output variable giving the new “rolling-averaged” precipitation data for the
specified number of days.
The first input argument is the original daily all-season precipitation variable corresponding to a
certain region.
The second input argument is the number of days you wish to average in a rolling average style.
The output variable from this function will have the dimensions (time, lat, lon). Lat and lon will
be the same no matter what the number of days is. Time will be shorter for longer multi-day
periods.
Note: Be aware that this function is slow and will take a long time to run. It may need to be run
overnight.
One-dimensional data: This function contains the nested function ‘averages.m’.
‘averages.m’ essentially performs the rolling averages procedure for each individual grid
box of the full input data set. If you are only interested in obtaining multi-day data for one
location, just use this function- it has the same input and output arguments as
‘averages3D.m’ shown above. The only difference is that you will be inputting and
returning a one-dimensional variable.
32
Example for using ‘averages3D.m’:
How do I create a variable of multi-day precipitation data with day length 7 from my original
daily all-season control precipitation variable for region 2, ‘contprecreg2’? I wish to call the new
variable ‘contprecreg2_7’.
Type:
>>contprecreg2_7=averages3D(contprecreg2,7);
Subsection B- Seasonal Data for a Region
Step 1: Load the appropriate ALL-SEASON precipitation model data into Matlab (from a
netCDF file or a saved MAT-file). You will need only one variable which corresponds to a
particular climate forcing (the control variable or elevated CO2 variable). But, you can open two
if you wish.
It is important to note that this analysis cannot be performed on the entire globe at once, so the
precipitation variable must be a fraction of the globe that is small enough for Matlab to handle.
For the CM2.1 model, an even fraction size that works is 1/6th. For daily all-season data, each
variable of this size has the dimensions (36500 x 45 x 48). You can only work with one region
at a time.
In this procedure, the data you load can be for daily or multi-day data of any length. If you wish
to obtain a variable that is both multi-day and seasonal, the “averaging” functions from
Subsection A must be used first. This is because after data has been converted into seasonal, you
cannot perform the rolling averages procedure if there is a break in the time dimension (such as
going from March one year, right to the following November and skipping over the months in
between- like in the winter seasonal data).
Step 2: Use the function ‘seasons3D.m’.
General usage of ‘seasons3D.m’:
>>seasonvar=seasons3D(origprec,d,s);
seasonvar is the output variable giving the new precipitation data with the specific months for the
desired season extracted out of the old data.
The first input argument is the original daily (or multi-day) all-season precipitation variable
corresponding to a certain region.
The second input argument specifies the length of the multi-day period associated with the
precipitation data that is inputted. If it is daily data, this value is simply 1. The possible values
for this argument are 1, 3, 7, 30, 60, and 90 as written. The function will yell at you if you type
anything else.
33
The third input argument is the number 1 or 2 corresponding to the season desired:
1 refers to the northern hemisphere summer (the months May through September)
2 refers to the northern hemisphere winter (the months November through March)
The function will yell at you if any other number is entered.
The output variable from this function will have the dimensions (time, lat, lon). Lat and lon will
be the same no matter what the number of days is. Time will be shorter for longer multi-day
periods for the input data. Also, the time dimension will be considerable shorter in the output
variable than the input variable, because 7months of the year are being removed.
Note1: Be aware that this function is slow and will take a long time to run. It may need to be run
overnight.
Note 2: This function is specifically written for input data with multi-day period lengths of 1, 2,
3, 7, 30, 60, or 90 days. If you wish to use this function for input multi-day data with any other
length, you must edit the m-file.
One-dimensional data: This function contains the nested function ‘seasons.m’. ‘seasons.m’
essentially performs the season extraction procedure for each individual grid box of the full
input data set. If you are only interested in obtaining seasonal data for one location, just
use this function- it has the same input and output arguments as ‘seasons3D.m’ shown
above. The only difference is that you will be inputting and returning a one-dimensional
variable.
Example for using ‘seasons3D.m’:
How do I create a “winter” variable from my multi-day control precipitation data with day length
7 that I made in Subsection A, ‘contprecreg2_7’ for my region 2? I wish to call the new variable
‘contprecreg2_7wint’.
Type:
>>contprecreg2_7wint=seasons3D(contprecreg2_7,7,2);
34
Download