[ncl-talk] converting 360 day calendar to 365 day (standard) calendar
Gus Correa
gus at ldeo.columbia.edu
Mon Feb 25 15:49:53 MST 2019
Hi Kwesi
One thing that came to mind.
First, simplify, note that
34*365=12410 is the number of ouput time records you want,
and 34*360=12240 is the number of input time records.
Right?
I would guess what you want is that your output time
starts at time_360(0) (the first input time record)
ends at time_360(12240 - 1) (the last input time record)
and has 12410 data points.
Hence, maybe you need to create time_365 like this:
time_365=fspan(time_360(0), time_360(12240 - 1), 12410).
Right?
This way your output "day" may be shorter than one input day, but that is
unavoidable if you're going from 360 to 365 days.
Also, then you need to use the same units as in the original time.
Now you're using "days since 1980-01-01 12:00:00" , but you haven't shown
if these are the original units or not.
I hope this helps,
Gus Correa
On Mon, Feb 25, 2019 at 5:13 PM Kwesi A. Quagraine <starskykwesi at gmail.com>
wrote:
> Thanks Gus.
>
> Replacing the line with;
>
> zg_new = (/ linint1_n( time_360, rm_single_dims(var), False, time_365,
> 0, 0) /)
>
> The script runs OK, however, the variable "zg_new" is empty although the
> time axis looks standard calendar.
>
> I’d be grateful for some help on this. Attached is my script.
>
> Thanks
> Kwesi
>
> On 25 February 2019 at 23:38:13, Gus Correa (gus at ldeo.columbia.edu) wrote:
>
> Hi Kwesi
>
> Sorry, I may have misinterpreted the use of linint1_n.
> Have you tried simply:
>
> zg_new = (/ linint1_n( time_360, rm_single_dims(var), False, time_365,
> 0, 0) /)
>
> This seems to be similar to "example 3" in the linint1_n documentation:
> https://www.ncl.ucar.edu/Document/Functions/Built-in/linint1_n.shtml
> and more similar to your original code.
>
> Gus
>
> On Mon, Feb 25, 2019 at 3:27 PM Kwesi A. Quagraine <starskykwesi at gmail.com>
> wrote:
>
>> Hello Gus, NCLers,
>>
>> Thanks for the earlier help. However, I still get this error;
>>
>> fatal:_NclBuildArray: each element of a literal array must have the same
>> dimension sizes, at least one item doesn't
>> fatal:["Execute.c":8640]:Execute: Error occurred at or near line 22 in
>> file change_360day-365day.ncl
>>
>> after replacing with this;
>> —> this is line 22
>> zg_new = (/ linint1_n( (/ time_360, lat, lon /), rm_single_dims(var),
>> False, (/ time_365, lat, lon/), 0, 0) /)
>>
>>
>> A snap of the code as it is now;
>> zg_new = new( (/ time_steps, dimsizes(lat), dimsizes(lon) /),
>> "float", 1.0e+20 )
>> zg_new = (/ linint1_n( (/ time_360, lat, lon /),
>> rm_single_dims(var), False, (/ time_365, lat, lon/), 0, 0) /)
>> ;zg_new = linint1_n(time_360,var,False,time_365,0,0)
>> zg_new!0 = "time"
>> zg_new&time = time_365
>> zg_new!1 = "lat"
>> zg_new&lat = lat
>> zg_new!2 = "lon"
>> zg_new&lon = lon
>>
>> zg_new at _FillValue = 1.0e+20
>> zg_new at missing_value = 1.0e+20
>> zg_new at standard_name = "geopotential_height"
>> zg_new at long_name = "Geopotential Height"
>> zg_new at units = "m"
>> zg_new at coordinates = "lon lat time"
>> zg_new at cell_methods = "time: mean"
>> printVarSummary(zg_new)
>> I’d be grateful for more help on this.
>>
>> Thanks
>> Kwesi
>>
>> On 25 February 2019 at 01:44:57, Gus Correa (gus at ldeo.columbia.edu)
>> wrote:
>>
>> Have you tried to define zg_new dimensions and metadata before you use it
>> on the r.h.s. of linint1_n?
>> Something like this:
>> zg_new=new( (/ time_steps, dimsizes(lat), dimsizes(lon) /), "float",
>> 1.0e+20 )
>>
>> Then the part of the code where you define zg_new metadata:
>> zg_new!0 = "time"
>> zg_new&time = time_365
>> zg_new!1 = "lat"
>> zg_new&lat = lat
>> zg_new!2 = "lon"
>> zg_new&lon = lon
>> zg_new at _FillValue = 1.0e+20
>> zg_new at missing_value = 1.0e+20
>> zg_new at standard_name = "geopotential_height"
>> zg_new at long_name = "Geopotential Height"
>> zg_new at units = "m"
>> zg_new at coordinates = "lon lat plev" < Why time is not
>> included? Why plev is included?
>> zg_new at cell_methods = "time: maximum" <- Why maximum if your
>> original data says mean?
>>
>> And only then the interpolation.
>> The extra (/ ... /) parenthesis on the l.h.s. prevent inheriting the
>> metadata from "var".
>> The rm_single_dims is to remove the degenerate (dimension=1) "plev" of
>> "var", making it 3D (not 4D anymore).
>> Also, var is multidimensional, so I think the arguments of linint1_n need
>> to honor that:
>>
>> zg_new = (/ linint1_n( (/ time_360, lat, lon /),
>> rm_single_dims(var), False, (/ time_365, lat, lon/), 0, 0) /)
>>
>> I haven't tested it, so it goes with no guarantees.
>> I hope this helps.
>>
>>
>> On Sun, Feb 24, 2019 at 5:31 PM Kwesi A. Quagraine <
>> starskykwesi at gmail.com> wrote:
>>
>>> Hello NCLers
>>>
>>> I am trying to convert a netcdf file with 360 day calendar to standard,
>>> 365 day calendar with the script below; I am having errors when I try. I
>>> will be grateful for any help.
>>>
>>> For printVarSummary;
>>>
>>> Variable: var
>>> Type: float
>>> Total Size: 37013760 bytes
>>> 9253440 values
>>> Number of Dimensions: 4
>>> Dimensions and sizes: [time | 12240] x [plev | 1] x [lat | 36] x [lon |
>>> 21]
>>> Coordinates:
>>> time: [43590.5..55829.5]
>>> plev: [70000..70000]
>>> lat: [-44.375..-0.625]
>>> lon: [6.5625..44.0625]
>>> Number Of Attributes: 9
>>> standard_name : geopotential_height
>>> long_name : Geopotential Height
>>> units : m
>>> _FillValue : 1e+20
>>> missing_value : 1e+20
>>> original_name : mo: m01s30i207/m01s30i301
>>> cell_methods : time: mean
>>> history : 2012-06-26T08:31:01Z altered by CMOR: replaced missing value
>>> flag (-1.07374e+09) with standard missing value (1e+20).
>>> associated_files : baseURL:
>>> http://cmip-pcmdi.llnl.gov/CMIP5/dataLocation gridspecFile:
>>> gridspec_atmos_fx_HadGEM2-ES_historical_r0i0p0.nc
>>>
>>> fatal:Coordinate variables must be the same dimension as their dimension
>>> fatal:No coordinate variable exists for dimension (lat) in variable
>>> (zg_new)
>>> fatal:["Execute.c":8640]:Execute: Error occurred at or near line 25 in
>>> file
>>>
>>>
>>> For Script:
>>> f =
>>> addfile("zg700_day_HadGEM2-ES_rcp85_r1i1p1_19800101-20131231.nc","r")
>>> var = f->zg
>>> time_360 = var&time
>>> lat = f->lat
>>> lon = f->lon
>>> plev = f->plev
>>> printVarSummary(var)
>>>
>>> time_steps = 34*365 ;1980 to 2013
>>> time_365 = fspan(1,time_steps,time_steps)
>>> time_365!0 = "time"
>>> time_365&time = time_365
>>> time_365 at standard_name = "time"
>>> time_365 at units = "days since 1980-01-01 12:00:00"
>>> time_365 at calendar = "365_day"
>>> time_365 at long_name = "time"
>>> time_365 at axis = "T"
>>>
>>> zg_new = linint1_n(time_360,var,False,time_365,0,0)
>>> zg_new!0 = "time"
>>> zg_new&time = time_365
>>> zg_new!1 = "lat"
>>> zg_new&lat = lat
>>> zg_new!2 = "lon"
>>> zg_new&lon = lon
>>>
>>> zg_new at _FillValue = 1.0e+20
>>> zg_new at missing_value = 1.0e+20
>>> zg_new at standard_name = "geopotential_height"
>>> zg_new at long_name = "Geopotential Height"
>>> zg_new at units = "m"
>>> zg_new at coordinates = "lon lat plev"
>>> zg_new at cell_methods = "time: maximum"
>>> printVarSummary(zg_new)
>>>
>>> ;system("rm -rf
>>> zg700_day_HadGEM2-ES_rcp85_r1i1p1_19800101-20131231_cal.nc")
>>> outf =
>>> addfile("zg700_day_HadGEM2-ES_rcp85_r1i1p1_19800101-20131231_cal.nc","c")
>>> outf->lat = lat
>>> outf->lon = lon
>>> outf->plev = plev
>>> outf->zg = zg_new
>>>
>>> I will be grateful for any help on this.
>>>
>>> Thanks
>>> Kwesi
>>> ------------
>>> Try not to become a man of success but rather a man of value- Albert
>>> Einstein
>>>
>>> Kwesi A. Quagraine
>>> Department of Physics
>>> School of Physical Sciences
>>> College of Agriculture and Natural Sciences
>>> University of Cape Coast
>>> Cape Coast, Ghana
>>>
>>> Alt. Email: kwesi at csag.uct.ac.za
>>> Web: http://www.recycleupghana.org/
>>> Office: +27 21 650 3164
>>> Skype: quagraine_cwasi
>>> _______________________________________________
>>> ncl-talk mailing list
>>> ncl-talk at ucar.edu
>>> List instructions, subscriber options, unsubscribe:
>>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>>>
>> _______________________________________________
>> ncl-talk mailing list
>> ncl-talk at ucar.edu
>> List instructions, subscriber options, unsubscribe:
>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>>
>> ------------
>> Try not to become a man of success but rather a man of value- Albert
>> Einstein
>>
>> Kwesi A. Quagraine
>> Department of Physics
>> School of Physical Sciences
>> College of Agriculture and Natural Sciences
>> University of Cape Coast
>> Cape Coast, Ghana
>>
>> Alt. Email: kwesi at csag.uct.ac.za
>> Web: http://www.recycleupghana.org/
>> Office: +27 21 650 3164
>> Skype: quagraine_cwasi
>>
> _______________________________________________
> ncl-talk mailing list
> ncl-talk at ucar.edu
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>
> ------------
> Try not to become a man of success but rather a man of value- Albert
> Einstein
>
> Kwesi A. Quagraine
> Department of Physics
> School of Physical Sciences
> College of Agriculture and Natural Sciences
> University of Cape Coast
> Cape Coast, Ghana
>
> Alt. Email: kwesi at csag.uct.ac.za
> Web: http://www.recycleupghana.org/
> Office: +27 21 650 3164
> Skype: quagraine_cwasi
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20190225/ef8bd88f/attachment.html>
More information about the ncl-talk
mailing list