[ncl-talk] data match days before plot
Dave Allured - NOAA Affiliate
dave.allured at noaa.gov
Fri Sep 4 13:29:56 MDT 2026
Debasish, attached is a demo program to align station data with model
data. Also see attached output. There is more than one way to do this. I
decided to create integer dates in YYYYDDD format, to be able to
cross-reference the dates. This seemed like the simplest way, given the
format of your input data.
This demo adds an extra "column" for station data values, next to the model
data values. Then a search loop plus NCL's "ind" function is used, to find
each position where the station date matches the model date. You will need
to find a way to add the year number to both model and station data that
you showed.
On Fri, Sep 4, 2026 at 9:27 AM Debasish Hazra <debasish.hazra5 at gmail.com>
wrote:
> Thanks Dave. Able to bring both data in julian day format and common
> starting time. But having issues with two unequal records, one from the
> model and one from the station observations (several days in obs are
> missing). Attached are two examples of output. And the missing days are
> random among different stations. Not able to use regline_stats etc because
> of unequal length. How to match these two to create the same length
> considering the random nature of missing days in Station obs. Any
> help would be appreciated.
>
> Thanks
> Debasish
>
> On Sun, Aug 30, 2026 at 11:56 AM Dave Allured - NOAA Affiliate <
> dave.allured at noaa.gov> wrote:
>
>> Oops, I forgot that you are making a scatter plot. This means that you
>> need an X axis that is linear in time. Therefore, you must use a numeric
>> time line, not a decimal coded time line. So use the method that I
>> mentioned first, to convert both inputs to a common time line such as "days
>> since".
>>
>>
>> On Sat, Aug 29, 2026 at 10:53 AM Dave Allured - NOAA Affiliate <
>> dave.allured at noaa.gov> wrote:
>>
>>> Put both the obs and model data on a common time line. For the obs
>>> (station) data, it looks like you need to combine the year number into the
>>> calculation. You did not show any time information for the model data, but
>>> I am sure it is something simple like "days since" or "hours since". I
>>> suggest convert both to "days since", since the obs data is already based
>>> on day numbers.
>>>
>>> Also when calculating the new time lines, you must pick a common
>>> starting point. I suggest YYYY January 1, where YYYY is the starting year
>>> of either data set.
>>>
>>> Alternatively, you could use a decimal coded time line such as YYYYDDD
>>> or YYYYMMDD, rather than a pure numeric time line. With this type, dates
>>> are absolute in one sense, so there is no need to pick a common starting
>>> date.
>>>
>>> For the scatter plot, you compare both time lines and pick out the dates
>>> in common. This is possible with any kind of time line, as long as both
>>> are computed accurately, and roundoff error is resolved. My final advice
>>> is, pick whichever method seems easiest to create the time lines.
>>>
>>> NCL has date functions to assist with creating and converting time lines.
>>> https://www.ncl.ucar.edu/Document/Functions/date.shtml
>>>
>>>
>>> On Thu, Aug 27, 2026 at 2:20 PM Debasish Hazra via ncl-talk <
>>> ncl-talk at mailman.ucar.edu> wrote:
>>>
>>>> Hi,
>>>> I am trying to plot a scatter plot using Ncl and plotting daily
>>>> averaged station data vs model output using more than 2 years data.
>>>> However, I am seeing more than one data gaps in station data, like below
>>>> (first value is in Julian days, second is precip value for a station of
>>>> that day), but model data has values in all days.
>>>>
>>>> 350,0.418833
>>>> 351,0.494576
>>>> 355,0.389460
>>>> 356,0.406334
>>>> ...SNIP...
>>>> 362,0.113083
>>>> 363,0.124250
>>>> 364,0.081895
>>>> 365,0.159218
>>>> 2,0.125749
>>>> 3,0.217326
>>>> 4,0.276310
>>>>
>>>> How to match those two data set in terms of exact days before the
>>>> scatter plot ? Any help ?
>>>> Thanks
>>>> Debasish
>>>>
>>>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.ucar.edu/pipermail/ncl-talk/attachments/20260904/f4403f51/attachment.htm>
-------------- next part --------------
; Align station data to model data, by year and day number.
; NCL mailing list, 2026 Sept 4
begin
model_source = (/ \
2021, 363, 0.094491, \
2021, 364, 0.094271, \
2021, 365, 0.077117, \
2022, 1 , 0.079632, \
2022, 2 , 0.092311, \
2022, 3 , 0.102403 /)
model_year = toint (model_source(0::3))
model_day = toint (model_source(1::3))
model_values = model_source(2::3)
print ("Raw model data:")
print (model_year + sprintf ("%5.f", model_day) + " " + model_values)
print ("")
print ("Create fake station data by selecting subset of model data:")
station_values = model_values(1:4) + 77 ; add 77 to make traceable fake data
station_year = model_year(1:4)
station_day = model_day(1:4)
station_day(2) = 555 ; create intentional mistake in dates
print (station_year + sprinti ("%5i", station_day) + " " + station_values)
model_date = model_year + sprinti ("%3.3i", model_day)
station_date = station_year + sprinti ("%3.3i", station_day)
print ("")
print ("Model dates as YYYYDDD:")
print (model_date+"")
print ("")
print ("Station dates as YYYYDDD:")
print (station_date+"")
print ("")
print ("Create new column for station values next to model values.")
nmodel = dimsizes (model_day)
missing_value = -999.0
station_values_aligned = new (nmodel, float, missing_value)
print ("")
print ("Locate each station date within model dates.")
ndates_station = dimsizes (station_day)
do i = 0, ndates_station-1
inds := ind (station_date(i) .eq. model_date)
xind = inds(0)
if (ismissing (xind)) then
print (" Station date not found within model dates: " + station_date(i))
continue
end if
station_values_aligned(xind) = station_values(i)
end do
print ("")
print (model_year + sprinti ("%5i", model_day) \
+ sprintf ("%12.4f", model_values) \
+ sprintf ("%12.4f", station_values_aligned))
end
-------------- next part --------------
(0) Raw model data:
(0) 2021 363 0.094491
(1) 2021 364 0.094271
(2) 2021 365 0.077117
(3) 2022 1 0.079632
(4) 2022 2 0.092311
(5) 2022 3 0.102403
(0)
(0) Create fake station data by selecting subset of model data:
(0) 2021 364 77.0943
(1) 2021 365 77.0771
(2) 2022 555 77.0796
(3) 2022 2 77.0923
(0)
(0) Model dates as YYYYDDD:
(0) 2021363
(1) 2021364
(2) 2021365
(3) 2022001
(4) 2022002
(5) 2022003
(0)
(0) Station dates as YYYYDDD:
(0) 2021364
(1) 2021365
(2) 2022555
(3) 2022002
(0)
(0) Create new column for station data next to model data.
(0)
(0) Locate each station date within model dates.
(0) Station date not found within model data: 2022555
(0)
(0) 2021 363 0.0945 -999.0000
(1) 2021 364 0.0943 77.0943
(2) 2021 365 0.0771 77.0771
(3) 2022 1 0.0796 -999.0000
(4) 2022 2 0.0923 77.0923
(5) 2022 3 0.1024 -999.0000
More information about the ncl-talk
mailing list