25
Copyright © 2014 University of Maryland. This material may not be reproduced or redistributed, in whole or in part, without written permission from Ross Salawitch or Tim Canty. 22 Oct 2014 1 Analysis Methods in Atmospheric and Oceanic Science AOSC 652 Introduction to MATLAB continued… Week 8, Day 2 22 Oct 2014

Analysis Methods in Atmospheric and Oceanic Science AOSC ...rjs/class/fall2014/week_08/AOSC652_2014_1022.pdf · From Week 3, find the OMI ozone time series data file you created

  • Upload
    others

  • View
    0

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Analysis Methods in Atmospheric and Oceanic Science AOSC ...rjs/class/fall2014/week_08/AOSC652_2014_1022.pdf · From Week 3, find the OMI ozone time series data file you created

Copyright © 2014 University of Maryland.

This material may not be reproduced or redistributed, in whole or in part, without written permission from Ross Salawitch or Tim Canty. 22 Oct 2014 1

Analysis Methods in Atmospheric and Oceanic Science

AOSC 652

Introduction to MATLAB continued…

Week 8, Day 2

22 Oct 2014

Page 2: Analysis Methods in Atmospheric and Oceanic Science AOSC ...rjs/class/fall2014/week_08/AOSC652_2014_1022.pdf · From Week 3, find the OMI ozone time series data file you created

Copyright © 2014 University of Maryland.

This material may not be reproduced or redistributed, in whole or in part, without written permission from Ross Salawitch or Tim Canty. 22 Oct 2014 2

AOSC 652: Analysis Methods in AOSC

To plot a plain black solid line: plot(x,y,'k-') To plot a blue line dotted line: plot(x,y,'b:') To plot circles to denote data points: plot(x,y,'o') To plot a green dashed line w/diamonds: plot(x,y,'g--d')

Page 3: Analysis Methods in Atmospheric and Oceanic Science AOSC ...rjs/class/fall2014/week_08/AOSC652_2014_1022.pdf · From Week 3, find the OMI ozone time series data file you created

Copyright © 2014 University of Maryland.

This material may not be reproduced or redistributed, in whole or in part, without written permission from Ross Salawitch or Tim Canty. 22 Oct 2014 3

AOSC 652: Analysis Methods in AOSC

From Monday’s lecture: Plotting multiple plots on one page h=figure(1) subplot(2,1,1) t=[0:0.01:1]; ys1=sin(2.*pi*t); plot(t,ys1,'r-o','Linewidth',2) subplot(2,1,2) ys2=cos(2.*pi*t); plot(t,ys2,'b-d','MarkerFaceColor','m') hold off

Page 4: Analysis Methods in Atmospheric and Oceanic Science AOSC ...rjs/class/fall2014/week_08/AOSC652_2014_1022.pdf · From Week 3, find the OMI ozone time series data file you created

Copyright © 2014 University of Maryland.

This material may not be reproduced or redistributed, in whole or in part, without written permission from Ross Salawitch or Tim Canty. 22 Oct 2014 4

AOSC 652: Analysis Methods in AOSC

From Monday’s lecture: Plotting multiple plots on one page h=figure(1) subplot(2,1,1) t=[0:0.01:1]; ys1=sin(2.*pi*t); plot(t,ys1,'r-o','Linewidth',2) subplot(2,1,2) ys2=cos(2.*pi*t); plot(t,ys2,'b-d','MarkerFaceColor','m') hold off How can we save this figure to a file?

Page 5: Analysis Methods in Atmospheric and Oceanic Science AOSC ...rjs/class/fall2014/week_08/AOSC652_2014_1022.pdf · From Week 3, find the OMI ozone time series data file you created

Copyright © 2014 University of Maryland.

This material may not be reproduced or redistributed, in whole or in part, without written permission from Ross Salawitch or Tim Canty. 22 Oct 2014 5

AOSC 652: Analysis Methods in AOSC

Plotting multiple plots on one page h=figure(1) subplot(2,1,1) t=[0:0.01:1]; ys1=sin(2.*pi*t); plot(t,ys1,'r-o','Linewidth',2) subplot(2,1,2) ys2=cos(2.*pi*t); plot(t,ys2,'b-d','MarkerFaceColor','m') hold off saveas(h,’trig2’,’jpg’)

Figure Name Figure Type

Page 6: Analysis Methods in Atmospheric and Oceanic Science AOSC ...rjs/class/fall2014/week_08/AOSC652_2014_1022.pdf · From Week 3, find the OMI ozone time series data file you created

Copyright © 2014 University of Maryland.

This material may not be reproduced or redistributed, in whole or in part, without written permission from Ross Salawitch or Tim Canty. 22 Oct 2014 6

AOSC 652: Analysis Methods in AOSC

Plotting multiple plots on one page h=figure(1) subplot(2,1,1) t=[0:0.01:1]; ys1=sin(2.*pi*t); plot(t,ys1,'r-o','Linewidth',2) subplot(2,1,2) ys2=cos(2.*pi*t); plot(t,ys2,'b-d','MarkerFaceColor','m') hold off saveas(h,’trig2’,’jpg’) print –depsc trig2.eps print –dpsc trig2.ps

Page 7: Analysis Methods in Atmospheric and Oceanic Science AOSC ...rjs/class/fall2014/week_08/AOSC652_2014_1022.pdf · From Week 3, find the OMI ozone time series data file you created

Copyright © 2014 University of Maryland.

This material may not be reproduced or redistributed, in whole or in part, without written permission from Ross Salawitch or Tim Canty. 22 Oct 2014 7

AOSC 652: Analysis Methods in AOSC

Copy and run the file ~tcanty/AOSC652/2014/week_08/plot_trig2.m What's missing?

Page 8: Analysis Methods in Atmospheric and Oceanic Science AOSC ...rjs/class/fall2014/week_08/AOSC652_2014_1022.pdf · From Week 3, find the OMI ozone time series data file you created

Copyright © 2014 University of Maryland.

This material may not be reproduced or redistributed, in whole or in part, without written permission from Ross Salawitch or Tim Canty. 22 Oct 2014 8

AOSC 652: Analysis Methods in AOSC

Copy and run the file ~tcanty/AOSC652/2014/week_08/plot_trig2.m Labels!!!! h1=legend('sin',3) ylabel('SIN’)

For more information on adding legends, under the helpdesk search for “legend”

Page 9: Analysis Methods in Atmospheric and Oceanic Science AOSC ...rjs/class/fall2014/week_08/AOSC652_2014_1022.pdf · From Week 3, find the OMI ozone time series data file you created

Copyright © 2014 University of Maryland.

This material may not be reproduced or redistributed, in whole or in part, without written permission from Ross Salawitch or Tim Canty. 22 Oct 2014 9

AOSC 652: Analysis Methods in AOSC

Copy and run the file ~tcanty/AOSC652/2014/week_08/plot_trig2.m Labels!!!! h1=legend('sin',’Location’,’Southwest’) ylabel('SIN')

Page 10: Analysis Methods in Atmospheric and Oceanic Science AOSC ...rjs/class/fall2014/week_08/AOSC652_2014_1022.pdf · From Week 3, find the OMI ozone time series data file you created

Copyright © 2014 University of Maryland.

This material may not be reproduced or redistributed, in whole or in part, without written permission from Ross Salawitch or Tim Canty. 22 Oct 2014 10

AOSC 652: Analysis Methods in AOSC

From Week 3, find the OMI ozone time series data file you created. My file is called 'omi_ozone_interpolate.dat' Please copy to your working directory, the file ~tcanty/AOSC652/2014/week_08/plot_omi.m

Page 11: Analysis Methods in Atmospheric and Oceanic Science AOSC ...rjs/class/fall2014/week_08/AOSC652_2014_1022.pdf · From Week 3, find the OMI ozone time series data file you created

Copyright © 2014 University of Maryland.

This material may not be reproduced or redistributed, in whole or in part, without written permission from Ross Salawitch or Tim Canty. 22 Oct 2014 11

AOSC 652: Analysis Methods in AOSC

From Week 3, find the OMI ozone time series data file you created. My file is called 'omi_ozone_interpolate.dat' Please copy to your working directory, the file ~tcanty/AOSC652/2014/week_08/plot_omi.m Change the path name (d_nm) and filename (f_nm) to point to your OMI file. Run the code…

Page 12: Analysis Methods in Atmospheric and Oceanic Science AOSC ...rjs/class/fall2014/week_08/AOSC652_2014_1022.pdf · From Week 3, find the OMI ozone time series data file you created

Copyright © 2014 University of Maryland.

This material may not be reproduced or redistributed, in whole or in part, without written permission from Ross Salawitch or Tim Canty. 22 Oct 2014 12

AOSC 652: Analysis Methods in AOSC

From Week 3, find the OMI ozone time series data file you created. My file is called 'omi_ozone_interpolate.dat' Please copy to your working directory, the file ~tcanty/AOSC652/2014/week_08/plot_omi.m Change the path name (d_nm) and filename (f_nm) to point to your OMI file. Run the code… Note: you can specify the range of your axes with the axis command. What if you have missing data?

Page 13: Analysis Methods in Atmospheric and Oceanic Science AOSC ...rjs/class/fall2014/week_08/AOSC652_2014_1022.pdf · From Week 3, find the OMI ozone time series data file you created

Copyright © 2014 University of Maryland.

This material may not be reproduced or redistributed, in whole or in part, without written permission from Ross Salawitch or Tim Canty. 22 Oct 2014 13

AOSC 652: Analysis Methods in AOSC

From Week 3, find the OMI ozone time series data file you created. What if you have missing data? The “find” command determines the indices of an array that fulfill a logical argument. For example: good=find(ozone ~= -999.00);

Page 14: Analysis Methods in Atmospheric and Oceanic Science AOSC ...rjs/class/fall2014/week_08/AOSC652_2014_1022.pdf · From Week 3, find the OMI ozone time series data file you created

Copyright © 2014 University of Maryland.

This material may not be reproduced or redistributed, in whole or in part, without written permission from Ross Salawitch or Tim Canty. 22 Oct 2014 14

AOSC 652: Analysis Methods in AOSC

From Week 3, find the OMI ozone time series data file you created. What if you have missing data? The “find” command determines the indices of an array that fulfill a logical argument. For example: good=find(ozone ~= -999.00);

Page 15: Analysis Methods in Atmospheric and Oceanic Science AOSC ...rjs/class/fall2014/week_08/AOSC652_2014_1022.pdf · From Week 3, find the OMI ozone time series data file you created

Copyright © 2014 University of Maryland.

This material may not be reproduced or redistributed, in whole or in part, without written permission from Ross Salawitch or Tim Canty. 22 Oct 2014 15

AOSC 652: Analysis Methods in AOSC

Modify plot_omi.m good=find(ozone ~= -999.00); h1=figure(1); plot(day(good),ozone(good),'b-') axis([1 31 280 530]) xlabel('DAY');ylabel('OZONE (DU)') title('OMI OZONE LAT=51.75, LON=0.25') hold off saveas(h1,'omi_wo_error','jpg')

Page 16: Analysis Methods in Atmospheric and Oceanic Science AOSC ...rjs/class/fall2014/week_08/AOSC652_2014_1022.pdf · From Week 3, find the OMI ozone time series data file you created

Copyright © 2014 University of Maryland.

This material may not be reproduced or redistributed, in whole or in part, without written permission from Ross Salawitch or Tim Canty. 22 Oct 2014 16

AOSC 652: Analysis Methods in AOSC

In your MATLAB code after the first plot is created, add the following to create a new plot. h=figure(2); plot(day,ozone,'r-') axis([1 31 280 530]) hold on ozst=ones(1,length(good)); ozst(good)=std(ozone(good)); errorbar(day(good),ozone(good),ozst(good),'rd') xlabel('DAY');ylabel('OZONE (DU)') title('OMI OZONE LAT=51.75, LON=0.25') hold off saveas(h,'omi_w_error','jpg')

Page 17: Analysis Methods in Atmospheric and Oceanic Science AOSC ...rjs/class/fall2014/week_08/AOSC652_2014_1022.pdf · From Week 3, find the OMI ozone time series data file you created

Copyright © 2014 University of Maryland.

This material may not be reproduced or redistributed, in whole or in part, without written permission from Ross Salawitch or Tim Canty. 22 Oct 2014 17

AOSC 652: Analysis Methods in AOSC

In your MATLAB code after the first plot is created, add the following to create a new plot. h=figure(2); plot(day,ozone,'r-') axis([1 31 280 530]) hold on ozst=ones(1,length(good)); ozst(good)=std(ozone(good)); errorbar(day(good),ozone(good),ozst(good),'rd') xlabel('DAY');ylabel('OZONE (DU)') title('OMI OZONE LAT=51.75, LON=0.25') hold off saveas(h,'omi_w_error','jpg')

These lines of code: 1) Creates an array “ozst” 2) Fills “ozst” with the calculated Standard Deviation of ozone 3) Plots the standard deviation as an error bar

Page 18: Analysis Methods in Atmospheric and Oceanic Science AOSC ...rjs/class/fall2014/week_08/AOSC652_2014_1022.pdf · From Week 3, find the OMI ozone time series data file you created

Copyright © 2014 University of Maryland.

This material may not be reproduced or redistributed, in whole or in part, without written permission from Ross Salawitch or Tim Canty. 22 Oct 2014 18

AOSC 652: Analysis Methods in AOSC

Least squares fitting: MATLAB has a large library of subroutines that can greatly simplify our work. Please copy the file: ~tcanty/AOSC652/2014/week_08/test_fit.dat Also copy and run the code ~tcanty/AOSC652/2014/week_08/plot_fit.m

Page 19: Analysis Methods in Atmospheric and Oceanic Science AOSC ...rjs/class/fall2014/week_08/AOSC652_2014_1022.pdf · From Week 3, find the OMI ozone time series data file you created

Copyright © 2014 University of Maryland.

This material may not be reproduced or redistributed, in whole or in part, without written permission from Ross Salawitch or Tim Canty. 22 Oct 2014 19

AOSC 652: Analysis Methods in AOSC

Least squares fitting: MATLAB has a large library of subroutines that can greatly simplify our work. Please copy the file: ~tcanty/AOSC652/2014/week_08/test_fit.dat Also copy and run the code ~tcanty/AOSC652/2014/week_08/plot_fit.m

Page 20: Analysis Methods in Atmospheric and Oceanic Science AOSC ...rjs/class/fall2014/week_08/AOSC652_2014_1022.pdf · From Week 3, find the OMI ozone time series data file you created

Copyright © 2014 University of Maryland.

This material may not be reproduced or redistributed, in whole or in part, without written permission from Ross Salawitch or Tim Canty. 22 Oct 2014 20

AOSC 652: Analysis Methods in AOSC

Least squares fitting: To find the coefficients of a polynomial fit, we use the subroutine “polyfit” coeff=polyfit(x,y,degree)

Page 21: Analysis Methods in Atmospheric and Oceanic Science AOSC ...rjs/class/fall2014/week_08/AOSC652_2014_1022.pdf · From Week 3, find the OMI ozone time series data file you created

Copyright © 2014 University of Maryland.

This material may not be reproduced or redistributed, in whole or in part, without written permission from Ross Salawitch or Tim Canty. 22 Oct 2014 21

AOSC 652: Analysis Methods in AOSC

Least squares fitting: To find the coefficients of a polynomial fit, we use the subroutine “polyfit” coeff=polyfit(x,y,degree) How would we apply this to the quadratic function?

Page 22: Analysis Methods in Atmospheric and Oceanic Science AOSC ...rjs/class/fall2014/week_08/AOSC652_2014_1022.pdf · From Week 3, find the OMI ozone time series data file you created

Copyright © 2014 University of Maryland.

This material may not be reproduced or redistributed, in whole or in part, without written permission from Ross Salawitch or Tim Canty. 22 Oct 2014 22

AOSC 652: Analysis Methods in AOSC

Least squares fitting: To find the coefficients of a polynomial fit, we use the subroutine “polyfit” coeff=polyfit(x,y,degree) How would we apply this to the quadratic function? d_nm=''; f_nm='test_fit.dat'; [hdr,dats]=load_header_data([d_nm,f_nm]); x=dats(:,1); y1=dats(:,2); y2=dats(:,3); coeff=polyfit(x,y1,2)

Page 23: Analysis Methods in Atmospheric and Oceanic Science AOSC ...rjs/class/fall2014/week_08/AOSC652_2014_1022.pdf · From Week 3, find the OMI ozone time series data file you created

Copyright © 2014 University of Maryland.

This material may not be reproduced or redistributed, in whole or in part, without written permission from Ross Salawitch or Tim Canty. 22 Oct 2014 23

AOSC 652: Analysis Methods in AOSC

Extrapolation: Fit coefficients can be used for extrapolation Create a new, independent variable array (i.e., a new “X” array).

xp=[1:0.1:40];

The polyval function evaluates polynomial using coefficients found using polyfit and new “X” array.

yp=polyval(coeff,xp)

Page 24: Analysis Methods in Atmospheric and Oceanic Science AOSC ...rjs/class/fall2014/week_08/AOSC652_2014_1022.pdf · From Week 3, find the OMI ozone time series data file you created

Copyright © 2014 University of Maryland.

This material may not be reproduced or redistributed, in whole or in part, without written permission from Ross Salawitch or Tim Canty. 22 Oct 2014 24

AOSC 652: Analysis Methods in AOSC

Interpolation: Can interpolate functions to a finer resolution grid. Again, create a new “X” array xnew=[0:0.01:30] %This array has a finer resolution Use “xnew” in the “interp1” command: yint=interp1(x,y1,xnew) yint is piecewise linear interpolation of y1 to new x grid. Cubic spline is calculated as follows: yint=interp1(x,y1,xnew,'spline') see helpdesk interp1

Page 25: Analysis Methods in Atmospheric and Oceanic Science AOSC ...rjs/class/fall2014/week_08/AOSC652_2014_1022.pdf · From Week 3, find the OMI ozone time series data file you created

Copyright © 2014 University of Maryland.

This material may not be reproduced or redistributed, in whole or in part, without written permission from Ross Salawitch or Tim Canty. 22 Oct 2014 25

AOSC 652: Analysis Methods in AOSC

Interpolation: Can interpolate functions to a finer resolution grid. Again, create a new “X” array xnew=[0:0.01:30] %This array has a finer resolution Use “xnew” in the “interp1” command: yint=interp1(x,y1,xnew) yint is piecewise linear interpolation of y1 to new x grid. Cubic spline is calculated as follows: yint=interp1(x,y1,xnew,'spline') see helpdesk interp1

There are also interpolation commands (interp2, interp3) for 2-D and 3-D interpolation. Can you think of an example where this might be useful?