Re: merge 2 time series with same time units, but different start and end times

From: Will Hobbs <Will.Hobbs_at_nyahnyahspammersnyahnyah>
Date: Mon Dec 23 2013 - 16:49:26 MST

Sam

How about this (all in NCL, no netcdf operators required):

> f1 = addfile(<1st buoy filepath>, "r")
> t1 = f1->time

> f2 = addfile(<2nd buoy filepath>, "r")
> t2 = f2->time

>st = max((/t1(0),t2(0)/)) ; this is the 'latest' start time of the two data files

> en = min((/ max(t1),max(t2) /)) ; this is the earliest finish time of the two files. st, and en now give the overlapping range

>dat1 = f1->monthly_anom({st:en},:,:)
>dat2 = f2->monthly_anom({st:en},:,:)

It's not particularly interesting, but it's not that tedious eitherů.

Will

From: "Sam McClatchie (NOAA Federal)" <sam.mcclatchie@noaa.gov<mailto:sam.mcclatchie@noaa.gov>>
Reply-To: "sam.mcclatchie@noaa.gov<mailto:sam.mcclatchie@noaa.gov>" <sam.mcclatchie@noaa.gov<mailto:sam.mcclatchie@noaa.gov>>
Date: Tuesday, 24 December 2013 10:41 AM
To: NCL maillist <ncl-talk@ucar.edu<mailto:ncl-talk@ucar.edu>>
Subject: merge 2 time series with same time units, but different start and end times

Hello

I have two buoy temperature time series (as netcdf files) with differing start and end times that I want to align in time. The time units are the same (this is not a re-basing problem). I see that I could do this by subsetting with the netcdf operators by dumping the time variables and then choosing a matching subset from each time series:

;*********************************************
;;dump the time values using NCO
;*********************************************
smc@caiman:~/Dropbox/dynamic_data/projects2013/spawning_further_north/data/buoys_erddap$ ncdump -v time buoy_46218_temperature_anomalies.nc

netcdf buoy_46218_temperature_anomalies {
dimensions:
    time = 108 ;
    ncl1 = 2 ;
    ncl2 = 1 ;
    longitude = 1 ;
variables:
    double temp_monthly_ss(time, ncl1) ;
        temp_monthly_ss:operation_tag = "calculate_monthly_values: avg" ;
        temp_monthly_ss:units = "degree_C" ;
        temp_monthly_ss:long_name = "SST" ;
        temp_monthly_ss:_FillValue = -9999999. ;
    double time(time) ;
        time:units = "seconds since 1970-01-01T00:00:00Z" ;
        time:operation_tag = "calculate_monthly_values: avg" ;
        time:long_name = "SST" ;
        time:_FillValue = -9999999. ;
    double monthly_anom(time, ncl2, longitude) ;
        monthly_anom:long_name = "SST" ;
        monthly_anom:units = "degree_C" ;
        monthly_anom:operation_tag = "calculate_monthly_values: avg" ;
        monthly_anom:_FillValue = -9999999. ;
        monthly_anom:anomaly_op_ncl = "Anomalies from Annual Cycle: calcMonAnomTLL: contributed.ncl" ;
    float longitude(longitude) ;
data:

 time = 1104451200, 1104537600, 1107216000, 1109635200, 1112313600,
    1114905600, 1117584000, 1120176000, 1122854400, 1125532800, 1128124800,
    1130803200, 1133395200, 1136073600, 1138752000, 1141171200, 1143849600,
    1146441600, 1149120000, 1151712000, 1154390400, 1157068800, 1159660800,
    1162339200, 1164931200, 1167609600, 1170288000, 1172707200, 1175385600,
    1177977600, 1180656000, 1183248000, 1185926400, 1188604800, 1191196800,
    1193875200, 1196467200, 1199145600, 1201824000, 1204329600, 1207008000,
    1209600000, 1212278400, 1214870400, 1217548800, 1220227200, 1222819200,
    1225497600, 1228089600, 1230768000, 1233446400, 1235865600, 1238544000,
    1241136000, 1243814400, 1246406400, 1249084800, 1251763200, 1254355200,
    1257033600, 1259625600, 1262304000, 1264982400, 1267401600, 1270080000,
    1272672000, 1275350400, 1277942400, 1280620800, 1283299200, 1285891200,
    1288569600, 1291161600, 1293840000, 1296518400, 1298937600, 1301616000,
    1304208000, 1306886400, 1309478400, 1312156800, 1314835200, 1317427200,
    1320105600, 1322697600, 1325376000, 1328054400, 1330560000, 1333238400,
    1335830400, 1338508800, 1341100800, 1343779200, 1346457600, 1349049600,
    1351728000, 1354320000, 1356998400, 1359676800, 1362096000, 1364774400,
    1367366400, 1370044800, 1372636800, 1375315200, 1377993600, 1380585600,
    1383264000 ;
}

;*******************************
;; do a subset of time values 100-107, for example
;*******************************
smc@caiman:~/Dropbox/dynamic_data/projects2013/spawning_further_north/data/buoys_erddap$ ncea -F -d time,100,107 buoy_46218_temperature_anomalies.nc test.nc
ncea: test.nc exists---`e'xit, `o'verwrite (i.e., delete existing file), or `a'ppend (i.e., replace duplicate variables in and add new variables to existing file) (e/o/a)? o
smc@caiman:~/Dropbox/dynamic_data/projects2013/spawning_further_north/data/buoys_erddap$ ncdump -v time test.nc
netcdf test {
dimensions:
    time = 8 ;
    ncl1 = 2 ;
    ncl2 = 1 ;
    longitude = 1 ;
variables:
    double temp_monthly_ss(time, ncl1) ;
        temp_monthly_ss:operation_tag = "calculate_monthly_values: avg" ;
        temp_monthly_ss:units = "degree_C" ;
        temp_monthly_ss:long_name = "SST" ;
        temp_monthly_ss:_FillValue = -9999999. ;
    double time(time) ;
        time:units = "seconds since 1970-01-01T00:00:00Z" ;
        time:operation_tag = "calculate_monthly_values: avg" ;
        time:long_name = "SST" ;
        time:_FillValue = -9999999. ;
    double monthly_anom(time, ncl2, longitude) ;
        monthly_anom:long_name = "SST" ;
        monthly_anom:units = "degree_C" ;
        monthly_anom:operation_tag = "calculate_monthly_values: avg" ;
        monthly_anom:_FillValue = -9999999. ;
        monthly_anom:anomaly_op_ncl = "Anomalies from Annual Cycle: calcMonAnomTLL: contributed.ncl" ;
    float longitude(longitude) ;

// global attributes:
        :history = "Mon Dec 23 15:14:43 2013: ncea -F -d time,100,107 buoy_46218_temperature_anomalies.nc test.nc" ;
        :nco_openmp_thread_number = 1 ;
data:

 time = 1362096000, 1364774400, 1367366400, 1370044800, 1372636800,
    1375315200, 1377993600, 1380585600 ;
}
;*************************************************

This seems a bit tedious. In R, I would just merge the two time series by the time variable.
Is there such a merge function in NCL?

Best fishes

Sam

--
Sam McClatchie,
Supervisory oceanographer,
Fisheries oceanography, Ichthyoplankton, Ship Operations
Southwest Fisheries Science Center, NOAA,
8901 La Jolla Shores Dr.
La Jolla, CA 92037-1509, U.S.A.
email <Sam.McClatchie@noaa.gov><mailto:Sam.McClatchie@noaa.gov>
Office: 858 546 7083, Cellular:  858 752 8495
Research home page <www.fishocean.info<http://www.fishocean.info>>
[cid:part1.09080507.05070100@noaa.gov]


_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk

CALCOFI 63rdLogo150b.png
Received on Mon Dec 23 16:49:49 2013

This archive was generated by hypermail 2.1.8 : Mon Jan 06 2014 - 13:02:22 MST