[ncl-talk] month_to_season
Dennis Shea
shea at ucar.edu
Mon May 30 16:10:37 MDT 2022
*month_to_season *
<https://www.ncl.ucar.edu/Document/Functions/Contributed/month_to_season.shtml>
Computes each year's seasonal mean. Multiple years are expected. Not one
year.
minLat = -35
maxLat = 35
minLon = -30
maxLon = 60
f = addfiles(fili, "r")
o3x_surf = f[:]->O3(:,55,:,:) ; input only surface
o3x_surf = o3x_surf*1.e+09 ; units change
;;o3x_surf at units = "..."
printVarSummary(o3x_surf) ; (time,lat,lon) ; lon: 0->360;
time=12
print("==========================================")
; reorder longitudes
o3x_surf := lonFlip(o3x_surf)
print("++++++++++++++++++++++++++++++++++++++++++")
print(" AFTER LONGITUDE REORDER ")
print("++++++++++++++++++++++++++++++++++++++++++")
printVarSummary(o3x_surf) ; (time,lat,lon) ; lon: -180->180;
time=12
; Simple/Crude climatological seasonal mean from a 12-month climatology
xSea_surf = o3x_surf(0:11:3,:,:) ; trick; create array with meta data
printVarSummary(xSea_surf) ; (4,lat,lon)
print("==========")
xSea_surf(0,:,:) = (x(0,:,:) + x(1,:,:) + x(11,:,:) )/3.0 ; Jan, Feb, Dec
xSea_surf(1,:,:) = (x(2,:,:) + x(3,:,:) + x( 4,:,:) )/3.0 ; Mar, Apr, May
xSea_surf(2,:,:) = (x(5,:,:) + x(6,:,:) + x( 7,:,:) )/3.0 ; Jun, Jul, Aug
xSea_surf(3,:,:) = (x(8,:,:) + x(9,:,:) + x(10,:,:) )/3.0 ; Sep. Oct Nov
printMinMax(xSea_surf(0,:,:), True) ; DJF
printMinMax(xSea_surf(1,:,:), True) ; MAM
printMinMax(xSea_surf(2,:,:), True) ; JJA
printMinMax(xSea_surf(3,:,:), True) ; SON
print("==========")
; PLOT
On Mon, May 30, 2022 at 4:52 PM Najib Yusuf <najibgal at yahoo.com> wrote:
> I tried it but as you said there is something unusual, I got this error in
> subscript #1 "nyear", I looked at the summary of the variable and tried
> with "1" but yet got this error;
>
>
> plot1 = gsn_csm_contour_map_ce(wks,xSea(0,nyear,0,0),res)
> fatal:Subscript out of range, error in subscript #1
> fatal:An error occurred reading xSea
> fatal:["Execute.c":8635]:Execute: Error occurred at or near line 103
>
> ncl 104> plot1 = gsn_csm_contour_map_ce(wks,xSea(0,nyear,:,:),res)
> fatal:Subscript out of range, error in subscript #1
> fatal:An error occurred reading xSea
>
> Could you please look at my data in this directory: /glade/scratch/najiby/
>
>
> ncl 0> spec_units = ("ppb")
> ncl 1> factor = (/1.e+09/)
> ncl 2> wkdir = "/glade/scratch/najiby/"
> ncl 3> diri = "/glade/scratch/najiby/"
> ncl 4> fili = systemfunc("ls
> "+diri+"f.e20.FSCD_FullEmissNig.cam.h0.2013*.nc")
> ncl 5> print(fili)
> ncl 6> minLat = -35
> ncl 7> maxLat = 35
> ncl 8> minLon = -30
> ncl 9> maxLon = 60
> ncl 10>
> ncl 11> f = addfiles(fili, "r")
> ncl 12> o3x_surf = f[:]->O3(:,55,:,:) ; input only surface
> ncl 13> o3x_surf = o3x_surf*1.e+09 ; units change
> ncl 14> ;;o3x_surf at units = "..."
> ncl 15> printVarSummary(o3x_surf)
>
> Variable: o3x_surf
> Type: float
> Total Size: 2654208 bytes
> 663552 values
> Number of Dimensions: 3
> Dimensions and sizes: [time | 12] x [lat | 192] x [lon | 288]
> Coordinates:
> time: [2953..3287]
> lat: [ -90.. 90]
> lon: [ 0..358.75]
> Number Of Attributes: 5
> lev : 992.5000106104562
> mdims : 1
> units : mol/mol
> long_name : O3 concentration
> cell_methods : time: mean
> ncl 16> o3x_surf := lonFlip(o3x_surf)
> ncl 17> printVarSummary(o3x_surf)
>
> Variable: o3x_surf
> Type: float
> Total Size: 2654208 bytes
> 663552 values
> Number of Dimensions: 3
> Dimensions and sizes: [time | 12] x [lat | 192] x [lon | 288]
> Coordinates:
> time: [2953..3287]
> lat: [ -90.. 90]
> lon: [-180..178.75]
> Number Of Attributes: 6
> lev : 992.5000106104562
> mdims : 1
> units : mol/mol
> long_name : O3 concentration
> cell_methods : time: mean
> lonFlip : longitude coordinate variable has been reordered via
> lonFlip
> ncl 18> date = f[:]->date
> ncl 19> printVarSummary(date)
>
> Variable: date
> Type: integer
> Total Size: 48 bytes
> 12 values
> Number of Dimensions: 1
> Dimensions and sizes: [time | 12]
> Coordinates:
> time: [2953..3287]
> Number Of Attributes: 1
> long_name : current date (YYYYMMDD)
> ncl 20> print(date)
> ncl 21> nyear = dimsizes(date)/12 ; number of years
> ncl 22> xSea = month_to_seasonN(o3x_surf,(/"DJF","MAM","JJA","SON"/))
> ncl 23> printVarSummary(xSea)
>
> Variable: xSea
> Type: float
> Total Size: 884736 bytes
> 221184 values
> Number of Dimensions: 4
> Dimensions and sizes: [season | 4] x [time | 1] x [lat | 192] x [lon |
> 288]
> Coordinates:
> season: [DJF..SON]
> time: [2953..2953]
> lat: [ -90.. 90]
> lon: [-180..178.75]
> Number Of Attributes: 7
> lonFlip : longitude coordinate variable has been reordered via
> lonFlip
> cell_methods : time: mean
> long_name : Seasonal Means: O3 concentration
> units : mol/mol
> mdims : 1
> lev : 992.5000106104562
> _FillValue : 9.96921e+36
>
>
> Thank you for always helping.
>
>
> *------------------------------------*
>
> *Najib Yusuf Galadanci Ph.D.*
>
> *Assistant Director (R & D)*
>
> Lower Atmospheric Dynamics
>
> (Aerosol radiative forcing, air quality observations and modeling)
>
> Centre for Atmospheric Research
>
> National Space Research and Development Agency. Kogi State
>
> University Campus, Anyigba. Kogi State. Nigeria
>
> +234 80 3871 4158
> ------------------------------------
> Know that Victory comes with Patience,
> Relief with Affliction, and Ease with Hardship.
>
> Prophet Muhammad Rasulullah
>
>
>
>
>
> On Monday, May 30, 2022, 02:14:23 PM GMT+1, Dennis Shea <shea at ucar.edu>
> wrote:
>
>
> As I noted in my 1st response, "there may be errors" because I did it very
> quickly.
>
> Still, something is unusual. I didn't have your data file(s). try the
> following
>
>
> *month_to_season *
> <https://www.ncl.ucar.edu/Document/Functions/Contributed/month_to_season.shtml>computes
> the seasonal mean for *each year*.
> This is *not* a climatological seasonal mean.
>
> **********************************************************************************
> begin
>
> ; read model data
>
> spec_units = ("ppb")
> factor = (/1.e+09/)
> wkdir = "/glade/scratch/najiby/"
> diri = "/glade/scratch/najiby/"
> fili = systemfunc("ls "+diri+"f.e20.FSCD_FullEmissNig.cam.h0.2013*.nc")
> print(fili)
> print("==========================================")
>
> minLat = -35
> maxLat = 35
> minLon = -30
> maxLon = 60
>
> f = addfiles(fili, "r")
> o3x_surf = f[:]->O3(:,55,:,:) ; input only surface
> o3x_surf = o3x_surf*1.e+09 ; units change
> ;;o3x_surf at units = "..."
> printVarSummary(o3x_surf) ; (time,lat,lon) ; lon: 0->360
> print("==========================================")
>
> ; reorder longitudes
> o3x_surf := *lonFlip*(o3x_surf)
> print("++++++++++++++++++++++++++++++++++++++++++")
> print(" AFTER LONGITUDE REORDER ")
> print("++++++++++++++++++++++++++++++++++++++++++")
> printVarSummary(o3x_surf) ; (time,lat,lon) ; lon: -180->180
>
> date = f[:]->date
> print("==========================================")
> ;;printVarSummary(date)
> print(date) ; (time)
>
> print("==========================================")
>
> nyear = dimsizes(date)/12 ; number of years
> print("nyear="+nyear)
> print("==========================================")
>
> ;-------------------------------------------------------
> ; season average for ** EACH YEAR ** This is NOT a climatological
> average
> xSea = month_to_seasonN(o3x_surf,(/"DJF","MAM","JJA","SON"/))
> printVarSummary(xSea) ; (4,nyr,lat,lon)
> ; DJF -> (0,nyear,lat,lon) for EACH year
> [time-> nyr]
> ; MAM -> (1,nyear,lat,lon) for EACH year
> ; JJA -> (2,nyear,lat,lon) for EACH year
> ; SON -> (3,neayr,lat,lon) for EACH year
>
>
>
> On Sun, May 29, 2022 at 12:51 PM Najib Yusuf <najibgal at yahoo.com> wrote:
>
> Dear Dennis,
>
> Thank you. I did as you said and I know have (time,lat,lon) atributes and
> xSea_surf [season | 4] x (time | 1] x [lat | 192] x [lon | 288), the
> subscripting is a bit confusing. However, I used these to plot:
>
> res at gsnLeftString = "DJF_dry cold"
> plot1 = gsn_csm_contour_map_ce(wks,xSea_surf(0,{-35:35},{-30:60}),res)
>
> res at gsnLeftString = "MAM_dry warm"
> plot2 = gsn_csm_contour_map_ce(wks,xSea_surf2(1,:,:),res)
>
> but got error of subscripting then I tried this to have 4 subscripts
> (seas,time,lat,lon) I still got error
>
> res at gsnLeftString = "DJF_dry cold"
> plot1 = gsn_csm_contour_map_ce(wks,xSea_surf(0,:,{-35:35},{-30:60}),res)
>
> res at gsnLeftString = "MAM_dry warm"
> plot2 = gsn_csm_contour_map_ce(wks,xSea_surf2(1,1,:,:),res)
>
> Variable: xSea_surf
> Type: float
> Total Size: 884736 bytes
> 221184 values
> Number of Dimensions: 4
> Dimensions and sizes: [season | 4] x [time | 1] x [lat | 192] x [lon |
> 288]
> Coordinates:
> season: [DJF..SON]
> time: [2953..2953]
> lat: [ -90.. 90]
> lon: [-180..178.75]
> Number Of Attributes: 7
> lonFlip : longitude coordinate variable has been reordered via
> lonFlip
> mdims : 1
> units : mol/mol
> long_name : Seasonal Means: O3 concentration
> cell_methods : time: mean
> lev : 992.5000106104562
> _FillValue : 9.96921e+36
> fatal:Number of subscripts do not match number of dimensions of
> variable,(3) Subscripts used, (4) Subscripts expected
> fatal:["Execute.c":8637]:Execute: Error occurred at or near line 143 in
> file month_to_seasO3.ncl
>
> Kindly, help me out.
>
> Thank you so much.
>
> *------------------------------------*
>
> *Najib Yusuf Galadanci Ph.D.*
>
> *Assistant Director (R & D)*
>
> Lower Atmospheric Dynamics
>
> (Aerosol radiative forcing, air quality observations and modeling)
>
> Centre for Atmospheric Research
>
> National Space Research and Development Agency. Kogi State
>
> University Campus, Anyigba. Kogi State. Nigeria
>
> +234 80 3871 4158
> ------------------------------------
> Know that Victory comes with Patience,
> Relief with Affliction, and Ease with Hardship.
>
> Prophet Muhammad Rasulullah
>
>
>
>
>
> On Friday, May 27, 2022, 01:46:31 PM GMT+1, Dennis Shea <shea at ucar.edu>
> wrote:
>
>
> [2]
> o3x_surf = o3x(0,55,:,:)
> printVarSummary(o3x_surf) ; TWO dimension (lat,lon); NO 'time'
> dimension
>
> I think you want
> o3x_surf = o3x(*:,*55,:,:) ; (time,lat,lon)
> ----------------
>
> You have
> Variable: o3x_surf
> Number of Dimensions: 2
> Dimensions and sizes: [lat | 192] x [lon | 288] <=== NO TIME DIMENSION
>
> You must do as I suggested:
>
> o3x_surf = o3x(:,55,:,:) ; (time,lat,lon)
> printVarSummary(o3x_surf)
>
> You must have a time dimension
>
> On Fri, May 27, 2022 at 7:03 AM Najib Yusuf <najibgal at yahoo.com> wrote:
>
> Dear Dennis,
>
> I have done as you advise, 1 to 5 all work out, thank you, but I had to do
> this first:
>
> o3x_surf_flip := lonFlip(o3x_surf)
> printVarSummary(o3x_surf_flip) ,,,,,,,and it works, prior to the
> seasons average but the xSea_surf (below)
>
> xSea_surf = month_to_seasonN(o3x_surf_flip,(/"DJF","MAM","JJA","SON"/))
> printVarSummary(xSea_surf)
>
> is giving this error:
>
> (0) contributed: month_to_seasonN: rank=2
> (0) ----- rank currently not handled -----
> (0) contributed: month_to_season12: rank=2
> (0) ----- rank currently not handled -----
> fatal:Illegal right-hand side type for assignment
>
> I haven't seen this rank error before. Please help out.
>
> Thank you
>
>
>
>
>
> Summary of variables
> Variable: o3x
> Type: float
> Total Size: 148635648 bytes
> 37158912 values
> Number of Dimensions: 4
> Dimensions and sizes: [time | 12] x [lev | 56] x [lat | 192] x [lon |
> 288]
> Coordinates:
> time: [2953..3287]
> lev: [1.867879997007549..992.5000106104562]
> lat: [ -90.. 90]
> lon: [ 0..358.75]
> Number Of Attributes: 4
> mdims : 1
> units : mol/mol
> long_name : O3 concentration
> cell_methods : time: mean
>
> Variable: o3x_surf
> Type: float
> Total Size: 221184 bytes
> 55296 values
> Number of Dimensions: 2
> Dimensions and sizes: [lat | 192] x [lon | 288]
> Coordinates:
> lat: [ -90.. 90]
> lon: [ 0..358.75]
> Number Of Attributes: 6
> lev : 992.5000106104562
> time : 2953
> cell_methods : time: mean
> long_name : O3 concentration
> units : mol/mol
> mdims : 1
> (0) O3 concentration (mol/mol) : min=3.61245 max=77.7517
>
> Variable: o3x_surf_flip
> Type: float
> Total Size: 221184 bytes
> 55296 values
> Number of Dimensions: 2
> Dimensions and sizes: [lat | 192] x [lon | 288]
> Coordinates:
> lat: [ -90.. 90]
> lon: [-180..178.75]
> Number Of Attributes: 7
> lev : 992.5000106104562
> time : 2953
> cell_methods : time: mean
> long_name : O3 concentration
> units : mol/mol
> mdims : 1
> lonFlip : longitude coordinate variable has been reordered via
> lonFlip
>
> Variable: xMon
> Type: integer
> Total Size: 48 bytes
> 12 values
> Number of Dimensions: 1
> Dimensions and sizes: [time | 12]
> Coordinates:
> time: [2953..3287]
> Number Of Attributes: 1
> long_name : current date (YYYYMMDD)
>
>
> Variable: xMon
> Type: integer
> Total Size: 48 bytes
> 12 values
> Number of Dimensions: 1
> Dimensions and sizes: [time | 12]
> Coordinates:
> time: [2953..3287]
> Number Of Attributes: 1
> long_name : current date (YYYYMMDD)
> (0) 20130201
> (1) 20130301
> (2) 20130401
> (3) 20130501
> (4) 20130601
> (5) 20130701
> (6) 20130801
> (7) 20130901
> (8) 20131001
> (9) 20131101
> (10) 20131201
> (11) 20140101
> (0) contributed: month_to_seasonN: rank=2
> (0) ----- rank currently not handled -----
> (0) contributed: month_to_season12: rank=2
> (0) ----- rank currently not handled -----
> fatal:Illegal right-hand side type for assignment
> fatal:["Execute.c":8637]:Execute: Error occurred at or near line 8300 in
> file $NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl
>
> fatal:["Execute.c":8637]:Execute: Error occurred at or near line 55 in
> file month_to_seasO3.ncl
>
>
> *------------------------------------*
>
> *Najib Yusuf Galadanci Ph.D.*
>
> *Assistant Director (R & D)*
>
> Lower Atmospheric Dynamics
>
> (Aerosol radiative forcing, air quality observations and modeling)
>
> Centre for Atmospheric Research
>
> National Space Research and Development Agency. Kogi State
>
> University Campus, Anyigba. Kogi State. Nigeria
>
> +234 80 3871 4158
> ------------------------------------
> Know that Victory comes with Patience,
> Relief with Affliction, and Ease with Hardship.
>
> Prophet Muhammad Rasulullah
>
>
>
>
>
> On Friday, May 27, 2022, 11:58:25 AM GMT+1, Najib Yusuf <
> najibgal at yahoo.com> wrote:
>
>
> Dear Dennis,
>
> I have done as you advise, 1 to 5 all work out, thank you, but I had to do
> this first:
>
> o3x_surf_flip := lonFlip(o3x_surf)
> printVarSummary(o3x_surf_flip) ,,,,,,,and it works, prior to the
> seasons average but the xSea_surf (below)
>
> xSea_surf = month_to_seasonN(o3x_surf_flip,(/"DJF","MAM","JJA","SON"/))
> printVarSummary(xSea_surf)
>
> is giving this error:
>
> (0) contributed: month_to_seasonN: rank=2
> (0) ----- rank currently not handled -----
> (0) contributed: month_to_season12: rank=2
> (0) ----- rank currently not handled -----
> fatal:Illegal right-hand side type for assignment
>
> I haven't seen this rank error before. Please help out.
>
> Thank you
>
> *------------------------------------*
>
> *Najib Yusuf Galadanci Ph.D.*
>
> *Assistant Director (R & D)*
>
> Lower Atmospheric Dynamics
>
> (Aerosol radiative forcing, air quality observations and modeling)
>
> Centre for Atmospheric Research
>
> National Space Research and Development Agency. Kogi State
>
> University Campus, Anyigba. Kogi State. Nigeria
>
> +234 80 3871 4158
> ------------------------------------
> Know that Victory comes with Patience,
> Relief with Affliction, and Ease with Hardship.
>
> Prophet Muhammad Rasulullah
>
>
>
>
>
> On Thursday, May 26, 2022, 03:36:37 PM GMT+1, Dennis Shea <shea at ucar.edu>
> wrote:
>
>
> It is always best to examine the variable's structure via
> printVarSummary(...)
>
> [1]
> o3x = f[:]->O3
> printVarSummary(o3x) ; I speculate 4 dimensions
> (time,level,lat,lon)
>
> [2]
> o3x_surf = o3x(0,55,:,:)
> printVarSummary(o3x_surf) ; TWO dimension (lat,lon); NO 'time'
> dimension
>
> I think you want
> o3x_surf = o3x(:,55,:,:) ; (time,lat,lon)
>
> [3]
> ; seasons average at surface
> xDJF = month_to_seasonN(o3x,(/"DJF","MAM","JJA","SON"/))
> printVarSummary(xDJF) ; I speculate (4,lat,lon)
>
> The name xDJF implies a one season mean for DJF but it is not.
> I think it should contain 4 seasonal means
>
> I think you should name it xSea for 'season'
> xSea_surf = month_to_seasonN(o3x_surf,(/"DJF","MAM","JJA","SON"/))
> printVarSummary(xSea_surf) ; I speculate (4,lat,lon)
>
> [4]
> The following creates a scalar variable of type string
> o3x_surf1 = "DJF"
> print(03x_surf1)
>
> I have no idea why you are doing this.
> ***This has no spatial information.*** It cannot be plotted on a map.
>
>
> [5]
> The rest is too confusing to explain.
>
> To get to the 'answer'
> xSea_surf(4,lat,lon)
>
> has spatial coordinates:
> lat: [ -90.. 90]
> lon: [ 0..358.75]
>
> You must use *lonFlip*
> <https://www.ncl.ucar.edu/Document/Functions/Contributed/lonFlip.shtml>
> to get longitudes to get the -180->180 range
> xSea_surf :=* lonFlip*
> <https://www.ncl.ucar.edu/Document/Functions/Contributed/lonFlip.shtml>
> (xSea_surf)
> printVarSummary(xSea_surf) ; look at 'new' coordinates
>
> --
> res at gsnLeftString = "DJF_dry cold"
> plot1 = gsn_csm_contour_map_ce(wks,xSea_surf(0,{-35:35},{-30:60}),res)
>
> res at gsnLeftString = "MAM_dry warm"
> plot2 = gsn_csm_contour_map_ce(wks,xSea_surf2(1,:,:),res)
>
> etc
> =======
>
> I did this VERY QUICKLY. there may be errors but you shuld have the idea
> of how to proceed.
>
> Good Luck
>
>
> On Thu, May 26, 2022 at 6:59 AM Najib Yusuf via ncl-talk <
> ncl-talk at mailman.ucar.edu> wrote:
>
> Dear NCL experts and colleagues,
>
> I have an error with the subscripting in the attached script while trying
> to plot spatial distribution month_to_season surface Ozone model data. I
> did try to change my subscripting to solve the error but seems beyond my
> little understanding of subscripting in ncl. Kindly assist.
>
> Variable: o3x_surf
> Type: float
> Total Size: 221184 bytes
> 55296 values
> Number of Dimensions: 2
> Dimensions and sizes: [lat | 192] x [lon | 288]
> Coordinates:
> lat: [ -90.. 90]
> lon: [ 0..358.75]
> Number Of Attributes: 6
> lev : 992.5000106104562
> time : 2953
> cell_methods : time: mean
> long_name : O3 concentration
> units : mol/mol
> mdims : 1
> (0) O3 concentration (mol/mol) : min=3.61245 max=77.7517
>
> Variable: xMon
> Type: integer
> Total Size: 48 bytes
> 12 values
> Number of Dimensions: 1
> Dimensions and sizes: [time | 12]
> Coordinates:
> time: [2953..3287]
> Number Of Attributes: 1
> long_name : current date (YYYYMMDD)
>
>
> Variable: xMon
> Type: integer
> Total Size: 48 bytes
> 12 values
> Number of Dimensions: 1
> Dimensions and sizes: [time | 12]
> Coordinates:
> time: [2953..3287]
> Number Of Attributes: 1
> long_name : current date (YYYYMMDD)
> (0) 20130201
> (1) 20130301
> (2) 20130401
> (3) 20130501
> (4) 20130601
> (5) 20130701
> (6) 20130801
> (7) 20130901
> (8) 20131001
> (9) 20131101
> (10) 20131201
> (11) 20140101
> fatal:Number of subscripts do not match number of dimensions of
> variable,(2) Subscripts used, (1) Subscripts expected
> fatal:["Execute.c":8637]:Execute: Error occurred at or near line 137 in
> file month_to_seasO3.ncl
>
>
>
> *------------------------------------*
>
> *Najib Yusuf Galadanci Ph.D.*
>
> *Assistant Director (R & D)*
>
> Lower Atmospheric Dynamics
>
> (Aerosol radiative forcing, air quality observations and modeling)
>
> Centre for Atmospheric Research
>
> National Space Research and Development Agency. Kogi State
>
> University Campus, Anyigba. Kogi State. Nigeria
>
> +234 80 3871 4158
> ------------------------------------
> Know that Victory comes with Patience,
> Relief with Affliction, and Ease with Hardship.
>
> Prophet Muhammad Rasulullah
>
>
>
> _______________________________________________
> ncl-talk mailing list
> ncl-talk at mailman.ucar.edu
> List instructions, subscriber options, unsubscribe:
> https://mailman.ucar.edu/mailman/listinfo/ncl-talk
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.ucar.edu/pipermail/ncl-talk/attachments/20220530/483e5361/attachment.htm>
More information about the ncl-talk
mailing list