<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
{font-family:Wingdings;
panose-1:5 0 0 0 0 0 0 0 0 0;}
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
{font-family:-webkit-standard;
panose-1:2 11 6 4 2 2 2 2 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0cm;
margin-bottom:.0001pt;
font-size:11.0pt;
font-family:"Calibri",sans-serif;}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:blue;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{mso-style-priority:99;
color:purple;
text-decoration:underline;}
p.MsoListParagraph, li.MsoListParagraph, div.MsoListParagraph
{mso-style-priority:34;
margin-top:0cm;
margin-right:0cm;
margin-bottom:0cm;
margin-left:36.0pt;
margin-bottom:.0001pt;
font-size:11.0pt;
font-family:"Calibri",sans-serif;}
p.msonormal0, li.msonormal0, div.msonormal0
{mso-style-name:msonormal;
mso-margin-top-alt:auto;
margin-right:0cm;
mso-margin-bottom-alt:auto;
margin-left:0cm;
font-size:11.0pt;
font-family:"Calibri",sans-serif;}
span.EmailStyle18
{mso-style-type:personal-reply;
font-family:"Calibri",sans-serif;
color:windowtext;}
span.apple-converted-space
{mso-style-name:apple-converted-space;}
.MsoChpDefault
{mso-style-type:export-only;
font-size:10.0pt;}
@page WordSection1
{size:612.0pt 792.0pt;
margin:72.0pt 72.0pt 72.0pt 72.0pt;}
div.WordSection1
{page:WordSection1;}
/* List Definitions */
@list l0
{mso-list-id:1441294059;
mso-list-type:hybrid;
mso-list-template-ids:1768444116 -2044195742 67698691 67698693 67698689 67698691 67698693 67698689 67698691 67698693;}
@list l0:level1
{mso-level-start-at:7;
mso-level-number-format:bullet;
mso-level-text:;
mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-18.0pt;
font-family:Wingdings;
mso-fareast-font-family:Calibri;
mso-bidi-font-family:"Times New Roman";}
@list l0:level2
{mso-level-number-format:bullet;
mso-level-text:o;
mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-18.0pt;
font-family:"Courier New";}
@list l0:level3
{mso-level-number-format:bullet;
mso-level-text:;
mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-18.0pt;
font-family:Wingdings;}
@list l0:level4
{mso-level-number-format:bullet;
mso-level-text:;
mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-18.0pt;
font-family:Symbol;}
@list l0:level5
{mso-level-number-format:bullet;
mso-level-text:o;
mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-18.0pt;
font-family:"Courier New";}
@list l0:level6
{mso-level-number-format:bullet;
mso-level-text:;
mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-18.0pt;
font-family:Wingdings;}
@list l0:level7
{mso-level-number-format:bullet;
mso-level-text:;
mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-18.0pt;
font-family:Symbol;}
@list l0:level8
{mso-level-number-format:bullet;
mso-level-text:o;
mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-18.0pt;
font-family:"Courier New";}
@list l0:level9
{mso-level-number-format:bullet;
mso-level-text:;
mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-18.0pt;
font-family:Wingdings;}
ol
{margin-bottom:0cm;}
ul
{margin-bottom:0cm;}
--></style>
</head>
<body lang="EN-AU" link="blue" vlink="purple">
<div class="WordSection1">
<p class="MsoNormal">Adriana<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">There’s a number of ways of doing this that are probably more efficient. You can preselect the files that you’re opening, and then use cd_calendar() to select the days for each year’s seasonal average. (Note that this approach would need
some alteration for ‘DJF’ or ‘NDJ’, where the 3 months are across different years<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">year1 = 2005<o:p></o:p></p>
<p class="MsoNormal">year2 = 2007<o:p></o:p></p>
<p class="MsoNormal">mois = (/6,7,8/) ;You only want JJA right – you could edit this to deal with different seasons<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><span style="font-size:13.5pt;font-family:"-webkit-standard",serif;color:black">file1 := systemfunc(" ls /PROJETS/MOUSSON-NEW/MAM7_CMIP6_CAMS/MAM7_test10_MERRA2.cam.h0.????-{"+str_join(mois,”,”)+"}-*.nc") ;only selects files for the appropriate
months<o:p></o:p></span></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">fi = addfile(file1,”r”) ;default ListSetType is “cat” ; don’t need to alter this<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">time = cd_calendar(fi[:]->time, 0) ; creates array split into (year, month, day,…etc)<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">data = fi[:]->$dataName$ ; I don’t know what varaibles you’re reading., you didn’t explain in your email. I’m assuming it’s dimensioned (time, lev, lat ,lon) though<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">year = ispan(year1,year2,1)<o:p></o:p></p>
<p class="MsoNormal">nyr = dimsizes(year)<o:p></o:p></p>
<p class="MsoNormal">dataSeas = data(:nyr-1,:,:,:) ; new array for seasonal means<o:p></o:p></p>
<p class="MsoNormal">dataSeas&time := year<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">do yy = year1, year2<o:p></o:p></p>
<p class="MsoNormal"> <o:p></o:p></p>
<p class="MsoNormal"> ii = ind(time(:,0).eq.yy.and.any(time(:.1).eq.mois)) ;selects time indices of desired month/year<o:p></o:p></p>
<p class="MsoNormal"> dataSeas({yy},:,:,:) = dim_avg_n(data(ii,:,:,:), 0) ;average of those time indices<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">end do<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<div style="border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0cm 0cm 0cm">
<p class="MsoNormal"><b><span style="font-size:12.0pt;color:black">From: </span></b><span style="font-size:12.0pt;color:black">ncl-talk <ncl-talk-bounces@ucar.edu> on behalf of Adriana via ncl-talk <ncl-talk@ucar.edu><br>
<b>Reply-To: </b>"adriana.bossolasco@cnrs-orleans.fr" <adriana.bossolasco@cnrs-orleans.fr><br>
<b>Date: </b>Friday, 13 September 2019 at 7:47 AM<br>
<b>To: </b>"ncl-talk@ucar.edu" <ncl-talk@ucar.edu><br>
<b>Subject: </b>[ncl-talk] how to Calculate Seasonal average for a variable for different years<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<p class="MsoNormal">Hi everyone<br>
<br>
I have different .nc daily files and I want to calculate the seasonal <br>
(JJA) for several year and save in one variable that contain all the <br>
years for this three months. I did one code ncl that works for one year <br>
but after I don't realize how to continue. I think the problem is <br>
because I add time dimension after using dim_avg_n and the index doesn't <br>
change. I will put part of my code to be clear<br>
<br>
<br>
year1=2005<br>
year2=2007<br>
nyear=year2-year1<br>
<br>
month1=6<br>
month2=8<br>
nmonths=month2-month1+1<br>
<br>
do i = 1,nyear<br>
y= i+year1-1<br>
do j = 1,nmonths<br>
print(nmonths)<br>
if (month1+j-1 .ge. 10) then<br>
mois=10<br>
else<br>
mois="0"+(j-1+month1) ; ver aqui<br>
end if<br>
printVarSummary(mois)<br>
<br>
<br>
file1 := systemfunc(" ls <br>
/PROJETS/MOUSSON-NEW/MAM7_CMIP6_CAMS/MAM7_test10_MERRA2.cam.h0."+y+"-"+mois+"-*.nc")<br>
<br>
print(file1)<br>
setfileoption("nc","SuppressClose", False)<br>
f = addfiles(file1,"r")<br>
<br>
ListSetType (f, "cat")<br>
<br>
<br>
After I read different variables and for calculate the seasonal average <br>
I do the next:<br>
<br>
;------------------<br>
if (j .eq. 1) then ;for JUN<br>
CO_press_JUN = new ((/60*nyear,nlev,nlat,nlon/),"float",CO_2@_FillValue)<br>
CO_press_JUN(60*(i-1):60*(i)-1,:,:,:) = CO_2<br>
CO_JUN_avg = CO_press_JUN(0:0,:,:,:)<br>
CO_JUN_avg(0,:,:,:) = (/ dim_avg_n(CO_press_JUN,0)/)<br>
printMinMax(CO_JUN_avg, True)<br>
printVarSummary(CO_JUN_avg)<br>
<br>
<br>
if (j .eq. 2) then ; for JUL<br>
CO_press_JUL = new ((/62*nyear,nlev,nlat,nlon/),"float",CO_2@_FillValue)<br>
CO_press_JUL(62*(i-1):62*(i)-1,:,:,:) = CO_2<br>
CO_JUL_avg = CO_press_JUL(0:0,:,:,:)<br>
CO_JUL_avg(0,:,:,:) = (/dim_avg_n(CO_press_JUL,0)/)<br>
printMinMax(CO_JUL_avg, True)<br>
printVarSummary(CO_JUL_avg)<br>
<br>
if (j .eq. 3) then ; For AUG<br>
CO_press_AUG = new ((/62*nyear,nlev,nlat,nlon/),"float",CO_2@_FillValue)<br>
CO_press_AUG(62*(i-1):62*(i)-1,:,:,:) = CO_2<br>
CO_AUG_avg = CO_press_AUG(0:0,:,:,:)<br>
CO_AUG_avg(0,:,:,:) = (/dim_avg_n(CO_press_AUG,0)/)<br>
printMinMax(CO_AUG_avg, True)<br>
printVarSummary(CO_AUG_avg)<br>
<br>
end do ; boucle mois<br>
;---------<br>
<br>
Now I want to create a variable<br>
CO_JJA = new((/nyear,nlev,nlat,nlon/),"float")<br>
which contain the number of year and the values CO_JUN_avg, CO_JUL_avg, <br>
CO_AUG_avg of each year<br>
However I didn't arrive to this because I think that the problem is due <br>
to this CO_AUG_avg = CO_press_AUG(0:0,:,:,:) and the index is always 0.<br>
<br>
I'm stuck with this! Can anyone give me any advice or help?<br>
<br>
I really appreciate<br>
<br>
Thank you in advance<br>
<br>
Adriana<br>
-- <br>
Adriana Bossolasco<br>
LPC2E UMR 7328 (CNRS, Université d'Orléans)<br>
3A avenue de la Recherche Scientifique<br>
45071 Orléans Cedex 2 - FRANCE<br>
Tel +33 (0)2 38 25 52 85<br>
e-mail: adriana.bossolasco@cnrs-orleans.fr<br>
_______________________________________________<br>
ncl-talk mailing list<br>
ncl-talk@ucar.edu<br>
List instructions, subscriber options, unsubscribe:<br>
<a href="http://mailman.ucar.edu/mailman/listinfo/ncl-talk">http://mailman.ucar.edu/mailman/listinfo/ncl-talk</a>
<o:p></o:p></p>
</div>
<p style="font-size:10pt; line-height:10pt; font-family: Calibri,sans-serif;"><br>
<br>
University of Tasmania Electronic Communications Policy (December, 2014). <br>
This email is confidential, and is for the intended recipient only. Access, disclosure, copying, distribution, or reliance on any of it by anyone outside the intended recipient organisation is prohibited and may be a criminal offence. Please delete if obtained
in error and email confirmation to the sender. The views expressed in this email are not necessarily the views of the University of Tasmania, unless clearly intended otherwise.
</p>
</body>
</html>