cate = c("aircraft-pfp",
"aircraft-insitu",
"aircraft-flask",
"surface-insitu",
"surface-flask",
"surface-pfp",
"tower-insitu",
"aircore",
"shipboard-insitu",
"shipboard-flask")
obs <- "Z:/torf/obspack_ch4_1_GLOBALVIEWplus_v5.1_2023-03-08/data/nc/"
index <- obs_summary(obs = obs,
categories = cate)
#> Number of files of index: 479
#> sector N
#> <char> <int>
#> 1: aircraft-pfp 42
#> 2: aircraft-insitu 17
#> 3: surface-flask 106
#> 4: surface-insitu 121
#> 5: aircraft-flask 4
#> 6: aircore 1
#> 7: surface-pfp 33
#> 8: tower-insitu 150
#> 9: shipboard-flask 4
#> 10: shipboard-insitu 1
#> 11: Total sectors 479
#> Detected 203 files with agl
#> Detected 276 files without agl
Now we read the aircraft-pfp
using the function
obs_read_nc
. To this date, solar_time
is not
included for aircraft, so we FALSE
that argument.
datasetid <- "aircraft-pfp"
df <- obs_read_nc(index = index,
categories = datasetid,
solar_time = FALSE,
verbose = T)
#> Searching aircraft-pfp...
#> 1: ch4_aao_aircraft-pfp_1_allvalid.nc
#> 2: ch4_acg_aircraft-pfp_1_allvalid.nc
#> 3: ch4_act_aircraft-pfp_1_allvalid-b200.nc
#> 4: ch4_act_aircraft-pfp_1_allvalid-c130.nc
#> 5: ch4_alf_aircraft-pfp_433_representative.nc
#> 6: ch4_bgi_aircraft-pfp_1_allvalid.nc
#> 7: ch4_bne_aircraft-pfp_1_allvalid.nc
#> 8: ch4_car_aircraft-pfp_1_allvalid.nc
#> 9: ch4_cma_aircraft-pfp_1_allvalid.nc
#> 10: ch4_crv_aircraft-pfp_1_allvalid.nc
#> 11: ch4_dnd_aircraft-pfp_1_allvalid.nc
#> 12: ch4_esp_aircraft-pfp_1_allvalid.nc
#> 13: ch4_etl_aircraft-pfp_1_allvalid.nc
#> 14: ch4_ftl_aircraft-pfp_1_allvalid.nc
#> 15: ch4_fwi_aircraft-pfp_1_allvalid.nc
#> 16: ch4_haa_aircraft-pfp_1_allvalid.nc
#> 17: ch4_hfm_aircraft-pfp_1_allvalid.nc
#> 18: ch4_hil_aircraft-pfp_1_allvalid.nc
#> 19: ch4_hip_aircraft-pfp_1_allvalid.nc
#> 20: ch4_inx_aircraft-pfp_1_allvalid.nc
#> 21: ch4_lef_aircraft-pfp_1_allvalid.nc
#> 22: ch4_man_aircraft-pfp_433_representative.nc
#> 23: ch4_mci_aircraft-pfp_1_allvalid.nc
#> 24: ch4_mrc_aircraft-pfp_1_allvalid.nc
#> 25: ch4_nha_aircraft-pfp_1_allvalid.nc
#> 26: ch4_oil_aircraft-pfp_1_allvalid.nc
#> 27: ch4_pfa_aircraft-pfp_1_allvalid.nc
#> 28: ch4_rba-b_aircraft-pfp_433_representative.nc
#> 29: ch4_rta_aircraft-pfp_1_allvalid.nc
#> 30: ch4_sah_aircraft-pfp_433_representative.nc
#> 31: ch4_sam_aircraft-pfp_1_allvalid.nc
#> 32: ch4_san_aircraft-pfp_1_allvalid.nc
#> 33: ch4_san_aircraft-pfp_433_representative.nc
#> 34: ch4_sca_aircraft-pfp_1_allvalid.nc
#> 35: ch4_sgp_aircraft-pfp_1_allvalid.nc
#> 36: ch4_tab_aircraft-pfp_433_representative.nc
#> 37: ch4_tef_aircraft-pfp_433_representative.nc
#> 38: ch4_tgc_aircraft-pfp_1_allvalid.nc
#> 39: ch4_thd_aircraft-pfp_1_allvalid.nc
#> 40: ch4_tom_aircraft-pfp_1_allvalid.nc
#> 41: ch4_ulb_aircraft-pfp_1_allvalid.nc
#> 42: ch4_wbi_aircraft-pfp_1_allvalid.nc
Now we check the data
df
#> year month day hour minute second time start_time
#> <int> <int> <int> <int> <int> <int> <int> <int>
#> 1: 2006 6 7 22 11 47 1149718307 1149718307
#> 2: 2006 6 7 22 28 22 1149719302 1149719302
#> 3: 2006 6 7 22 41 24 1149720084 1149720084
#> 4: 2006 6 7 22 55 31 1149720931 1149720931
#> 5: 2006 6 7 23 22 23 1149722543 1149722543
#> ---
#> 86429: 2021 12 27 18 31 21 1640629881 1640629881
#> 86430: 2021 12 27 18 33 36 1640630016 1640630016
#> 86431: 2021 12 27 18 35 47 1640630147 1640630147
#> 86432: 2021 12 27 18 37 54 1640630274 1640630274
#> 86433: 2021 12 27 18 39 56 1640630396 1640630396
#> midpoint_time datetime time_decimal time_interval
#> <int> <char> <num> <int>
#> 1: 1149718307 2006-06-07T22:11:47Z 2006.433 3600
#> 2: 1149719302 2006-06-07T22:28:22Z 2006.433 3600
#> 3: 1149720084 2006-06-07T22:41:24Z 2006.433 3600
#> 4: 1149720931 2006-06-07T22:55:31Z 2006.433 3600
#> 5: 1149722543 2006-06-07T23:22:23Z 2006.433 3600
#> ---
#> 86429: 1640629881 2021-12-27T18:31:21Z 2021.988 3600
#> 86430: 1640630016 2021-12-27T18:33:36Z 2021.988 3600
#> 86431: 1640630147 2021-12-27T18:35:47Z 2021.988 3600
#> 86432: 1640630274 2021-12-27T18:37:54Z 2021.988 3600
#> 86433: 1640630396 2021-12-27T18:39:56Z 2021.988 3600
#> value value_unc nvalue value_std_dev latitude longitude altitude
#> <num> <num> <int> <num> <num> <num> <num>
#> 1: 1.81998e-06 1.70e-09 1 NA 40.1000 -88.5500 4758.10
#> 2: 1.81748e-06 1.70e-09 1 NA 40.1000 -88.5500 3801.47
#> 3: 1.83108e-06 1.70e-09 1 NA 40.1000 -88.5500 3170.38
#> 4: 1.83283e-06 1.70e-09 1 NA 40.1000 -88.5500 2539.71
#> 5: 1.84134e-06 1.70e-09 1 NA 40.1000 -88.5500 1905.77
#> ---
#> 86429: 1.97486e-06 5.75e-10 1 NA 41.7268 -91.2929 3698.75
#> 86430: 1.97552e-06 5.75e-10 1 NA 41.7193 -91.3886 3068.42
#> 86431: 1.97551e-06 5.75e-10 1 NA 41.7149 -91.4808 2417.67
#> 86432: 1.97882e-06 5.75e-10 1 NA 41.7103 -91.5746 1793.14
#> 86433: 1.99104e-06 5.75e-10 1 NA 41.6643 -91.5096 1173.48
#> elevation intake_height qcflag instrument analysis_datetime method
#> <num> <num> <char> <char> <char> <char>
#> 1: 210 4548.10 ... H4 2006-06-16T17:06:00 A
#> 2: 210 3591.47 ... H4 2006-06-16T17:21:00 A
#> 3: 210 2960.38 ... H4 2006-06-16T17:36:00 A
#> 4: 210 2329.71 ... H4 2006-06-16T17:51:00 A
#> 5: 210 1695.77 ... H4 2006-06-16T18:20:00 A
#> ---
#> 86429: 241 3457.75 ... PC2 2022-01-07T09:58:36 R
#> 86430: 237 2831.42 ... PC2 2022-01-07T10:13:53 R
#> 86431: 234 2183.67 ... PC2 2022-01-07T10:29:10 R
#> 86432: 213 1580.14 ... PC2 2022-01-07T10:44:27 R
#> 86433: 223 950.48 ... PC2 2022-01-07T10:59:43 R
#> event_number air_sample_container_id obs_flag obspack_num
#> <char> <char> <int> <int>
#> 1: 218410 3141-01 1 959079
#> 2: 218411 3141-02 1 959080
#> 3: 218412 3141-03 1 959081
#> 4: 218413 3141-04 1 959082
#> 5: 218415 3141-06 1 959083
#> ---
#> 86429: 498170 3096-07 1 1033163
#> 86430: 498171 3096-08 1 1033164
#> 86431: 498172 3096-09 1 1033165
#> 86432: 498173 3096-10 1 1033166
#> 86433: 498174 3096-11 1 1033167
#> obspack_id
#> <char>
#> 1: obspack_ch4_1_GLOBALVIEWplus_v5.1_2023-03-08~ch4_aao_aircraft-pfp_1_allvalid~959079
#> 2: obspack_ch4_1_GLOBALVIEWplus_v5.1_2023-03-08~ch4_aao_aircraft-pfp_1_allvalid~959080
#> 3: obspack_ch4_1_GLOBALVIEWplus_v5.1_2023-03-08~ch4_aao_aircraft-pfp_1_allvalid~959081
#> 4: obspack_ch4_1_GLOBALVIEWplus_v5.1_2023-03-08~ch4_aao_aircraft-pfp_1_allvalid~959082
#> 5: obspack_ch4_1_GLOBALVIEWplus_v5.1_2023-03-08~ch4_aao_aircraft-pfp_1_allvalid~959083
#> ---
#> 86429: obspack_ch4_1_GLOBALVIEWplus_v5.1_2023-03-08~ch4_wbi_aircraft-pfp_1_allvalid~1033163
#> 86430: obspack_ch4_1_GLOBALVIEWplus_v5.1_2023-03-08~ch4_wbi_aircraft-pfp_1_allvalid~1033164
#> 86431: obspack_ch4_1_GLOBALVIEWplus_v5.1_2023-03-08~ch4_wbi_aircraft-pfp_1_allvalid~1033165
#> 86432: obspack_ch4_1_GLOBALVIEWplus_v5.1_2023-03-08~ch4_wbi_aircraft-pfp_1_allvalid~1033166
#> 86433: obspack_ch4_1_GLOBALVIEWplus_v5.1_2023-03-08~ch4_wbi_aircraft-pfp_1_allvalid~1033167
#> unique_sample_location_num scale site_elevation_unit
#> <int> <char> <char>
#> 1: 2718218 WMO CH4 X2004A masl
#> 2: 2718192 WMO CH4 X2004A masl
#> 3: 2718174 WMO CH4 X2004A masl
#> 4: 2718138 WMO CH4 X2004A masl
#> 5: 2718094 WMO CH4 X2004A masl
#> ---
#> 86429: 49849587 WMO CH4 X2004A masl
#> 86430: 49849579 WMO CH4 X2004A masl
#> 86431: 49849573 WMO CH4 X2004A masl
#> 86432: 49849564 WMO CH4 X2004A masl
#> 86433: 49849546 WMO CH4 X2004A masl
#> dataset_project dataset_selection_tag
#> <char> <char>
#> 1: aircraft-pfp allvalid
#> 2: aircraft-pfp allvalid
#> 3: aircraft-pfp allvalid
#> 4: aircraft-pfp allvalid
#> 5: aircraft-pfp allvalid
#> ---
#> 86429: aircraft-pfp allvalid
#> 86430: aircraft-pfp allvalid
#> 86431: aircraft-pfp allvalid
#> 86432: aircraft-pfp allvalid
#> 86433: aircraft-pfp allvalid
#> site_name site_elevation
#> <char> <num>
#> 1: Airborne Aerosol Observatory, Bondville, Illinois 230.0
#> 2: Airborne Aerosol Observatory, Bondville, Illinois 230.0
#> 3: Airborne Aerosol Observatory, Bondville, Illinois 230.0
#> 4: Airborne Aerosol Observatory, Bondville, Illinois 230.0
#> 5: Airborne Aerosol Observatory, Bondville, Illinois 230.0
#> ---
#> 86429: West Branch, Iowa 241.7
#> 86430: West Branch, Iowa 241.7
#> 86431: West Branch, Iowa 241.7
#> 86432: West Branch, Iowa 241.7
#> 86433: West Branch, Iowa 241.7
#> site_latitude site_longitude site_country site_code site_utc2lst
#> <num> <num> <char> <char> <num>
#> 1: 40.0500 -88.3700 United States AAO -6
#> 2: 40.0500 -88.3700 United States AAO -6
#> 3: 40.0500 -88.3700 United States AAO -6
#> 4: 40.0500 -88.3700 United States AAO -6
#> 5: 40.0500 -88.3700 United States AAO -6
#> ---
#> 86429: 41.7248 -91.3529 United States WBI -6
#> 86430: 41.7248 -91.3529 United States WBI -6
#> 86431: 41.7248 -91.3529 United States WBI -6
#> 86432: 41.7248 -91.3529 United States WBI -6
#> 86433: 41.7248 -91.3529 United States WBI -6
#> lab_1_abbr dataset_calibration_scale altitude_final type_altitude
#> <char> <char> <num> <num>
#> 1: NOAA WMO CH4 X2004A 4758.10 1
#> 2: NOAA WMO CH4 X2004A 3801.47 1
#> 3: NOAA WMO CH4 X2004A 3170.38 1
#> 4: NOAA WMO CH4 X2004A 2539.71 1
#> 5: NOAA WMO CH4 X2004A 1905.77 1
#> ---
#> 86429: NOAA WMO CH4 X2004A 3698.75 1
#> 86430: NOAA WMO CH4 X2004A 3068.42 1
#> 86431: NOAA WMO CH4 X2004A 2417.67 1
#> 86432: NOAA WMO CH4 X2004A 1793.14 1
#> 86433: NOAA WMO CH4 X2004A 1173.48 1
#> air_flag bl_bt_flag flight_flag flight_id gps_altitude h2o
#> <int> <int> <int> <char> <num> <num>
#> 1: NA NA NA <NA> NA NA
#> 2: NA NA NA <NA> NA NA
#> 3: NA NA NA <NA> NA NA
#> 4: NA NA NA <NA> NA NA
#> 5: NA NA NA <NA> NA NA
#> ---
#> 86429: NA NA NA <NA> NA NA
#> 86430: NA NA NA <NA> NA NA
#> 86431: NA NA NA <NA> NA NA
#> 86432: NA NA NA <NA> NA NA
#> 86433: NA NA NA <NA> NA NA
#> maneuver_flag maneuver_flagqc pressure pressure_altitude profile_id
#> <int> <int> <num> <num> <char>
#> 1: NA NA NA NA <NA>
#> 2: NA NA NA NA <NA>
#> 3: NA NA NA NA <NA>
#> 4: NA NA NA NA <NA>
#> 5: NA NA NA NA <NA>
#> ---
#> 86429: NA NA NA NA <NA>
#> 86430: NA NA NA NA <NA>
#> 86431: NA NA NA NA <NA>
#> 86432: NA NA NA NA <NA>
#> 86433: NA NA NA NA <NA>
#> source_id temperature u v
#> <char> <num> <num> <num>
#> 1: <NA> NA NA NA
#> 2: <NA> NA NA NA
#> 3: <NA> NA NA NA
#> 4: <NA> NA NA NA
#> 5: <NA> NA NA NA
#> ---
#> 86429: <NA> NA NA NA
#> 86430: <NA> NA NA NA
#> 86431: <NA> NA NA NA
#> 86432: <NA> NA NA NA
#> 86433: <NA> NA NA NA
Now we can process the data. We first filter for observations within our spatial domain:
Checks and definitions
north <- 80
south <- 10
west <- -170
east <- -50
max_altitude <- 8000
yy <- 2020
We check altitude, intake_height, altitude_final and elevation. altitude_final is a column from intake_height, added to match column from obs_read text files.
df[, c("altitude", "altitude_final", "intake_height", "elevation")]
#> altitude altitude_final intake_height elevation
#> <num> <num> <num> <num>
#> 1: 4758.10 4758.10 4548.10 210
#> 2: 3801.47 3801.47 3591.47 210
#> 3: 3170.38 3170.38 2960.38 210
#> 4: 2539.71 2539.71 2329.71 210
#> 5: 1905.77 1905.77 1695.77 210
#> ---
#> 86429: 3698.75 3698.75 3457.75 241
#> 86430: 3068.42 3068.42 2831.42 237
#> 86431: 2417.67 2417.67 2183.67 234
#> 86432: 1793.14 1793.14 1580.14 213
#> 86433: 1173.48 1173.48 950.48 223
The temporal range of data is
range(df$year)
#> [1] 1992 2021
We also check for dimensions of data
dim(df)
#> [1] 2872 62
Filters
df <- df[year == yy]
df <- df[altitude_final < max_altitude &
latitude < north &
latitude > south &
longitude < east &
longitude > west]
dim(df)
#> [1] 2872 62
Adding time as POSIXct class
df <- obs_addtime(df)
df[, "timeUTC"]
#> timeUTC
#> <POSc>
#> 1: 2020-01-02 19:50:20
#> 2: 2020-01-02 19:59:18
#> 3: 2020-01-02 20:08:11
#> 4: 2020-01-02 20:16:34
#> 5: 2020-01-02 20:23:47
#> ---
#> 2868: 2020-12-28 20:21:43
#> 2869: 2020-12-28 20:23:59
#> 2870: 2020-12-28 20:26:07
#> 2871: 2020-12-28 20:28:09
#> 2872: 2020-12-28 20:30:23
Cut time
now we can cut time every 20 seconds. We can chosse other frequency as well.
#> second sec2
#> <int> <num>
#> 1: 20 0
#> 2: 18 0
#> 3: 11 0
#> 4: 34 20
#> 5: 47 40
#> ---
#> 2868: 43 40
#> 2869: 59 40
#> 2870: 7 0
#> 2871: 9 0
#> 2872: 23 20
Aggregate data
now we need to add the column key_time, that it will be used to aggregate other variables
df$key_time <- ISOdatetime(year = df$year,
month = df$month,
day = df$day,
hour = df$hour,
min = df$minute,
sec = df$sec2,
tz = "UTC")
df[, c("timeUTC", "key_time")]
#> timeUTC key_time
#> <POSc> <POSc>
#> 1: 2020-01-02 19:50:20 2020-01-02 19:50:00
#> 2: 2020-01-02 19:59:18 2020-01-02 19:59:00
#> 3: 2020-01-02 20:08:11 2020-01-02 20:08:00
#> 4: 2020-01-02 20:16:34 2020-01-02 20:16:20
#> 5: 2020-01-02 20:23:47 2020-01-02 20:23:40
#> ---
#> 2868: 2020-12-28 20:21:43 2020-12-28 20:21:40
#> 2869: 2020-12-28 20:23:59 2020-12-28 20:23:40
#> 2870: 2020-12-28 20:26:07 2020-12-28 20:26:00
#> 2871: 2020-12-28 20:28:09 2020-12-28 20:28:00
#> 2872: 2020-12-28 20:30:23 2020-12-28 20:30:20
Add local time
Now we add local time
df3 <- obs_addltime(df2)
setorderv(df3, cols = c("site_code", "timeUTC"),
order = c(-1, 1))
df3
#> timeUTC site_code lab_1_abbr dataset_calibration_scale year
#> <POSc> <char> <char> <char> <int>
#> 1: 2020-01-14 18:28:20 WBI NOAA WMO CH4 X2004A 2020
#> 2: 2020-01-14 18:33:00 WBI NOAA WMO CH4 X2004A 2020
#> 3: 2020-01-14 18:37:40 WBI NOAA WMO CH4 X2004A 2020
#> 4: 2020-01-14 18:40:40 WBI NOAA WMO CH4 X2004A 2020
#> 5: 2020-01-14 18:43:20 WBI NOAA WMO CH4 X2004A 2020
#> ---
#> 2868: 2020-12-25 21:09:20 CAR NOAA WMO CH4 X2004A 2020
#> 2869: 2020-12-25 21:20:20 CAR NOAA WMO CH4 X2004A 2020
#> 2870: 2020-12-25 21:27:20 CAR NOAA WMO CH4 X2004A 2020
#> 2871: 2020-12-25 21:33:00 CAR NOAA WMO CH4 X2004A 2020
#> 2872: 2020-12-25 21:35:40 CAR NOAA WMO CH4 X2004A 2020
#> month day hour minute second time time_decimal value
#> <int> <char> <int> <int> <int> <num> <num> <num>
#> 1: 1 14 18 28 20 1579026500 2020.038 1.91295e-06
#> 2: 1 14 18 33 0 1579026780 2020.038 1.92525e-06
#> 3: 1 14 18 37 40 1579027060 2020.038 1.92408e-06
#> 4: 1 14 18 40 40 1579027240 2020.038 1.91808e-06
#> 5: 1 14 18 43 20 1579027400 2020.038 1.92311e-06
#> ---
#> 2868: 12 25 21 9 20 1608930560 2020.983 1.93444e-06
#> 2869: 12 25 21 20 20 1608931220 2020.983 1.93578e-06
#> 2870: 12 25 21 27 20 1608931640 2020.983 1.93419e-06
#> 2871: 12 25 21 33 0 1608931980 2020.983 1.93514e-06
#> 2872: 12 25 21 35 40 1608932140 2020.983 2.00509e-06
#> latitude longitude altitude_final elevation intake_height gps_altitude
#> <num> <num> <num> <num> <num> <num>
#> 1: 41.7505 -91.0213 7618.48 242 7376.48 NaN
#> 2: 41.7427 -91.1791 6958.89 234 6724.89 NaN
#> 3: 41.7232 -91.3675 5685.43 236 5449.43 NaN
#> 4: 41.7275 -91.4877 4987.14 244 4743.14 NaN
#> 5: 41.7177 -91.5966 4333.95 235 4098.95 NaN
#> ---
#> 2868: 40.7275 -104.6853 2926.69 1559 1367.69 NaN
#> 2869: 40.7813 -104.6506 2453.94 1590 863.94 NaN
#> 2870: 40.7955 -104.6787 2138.78 1599 539.78 NaN
#> 2871: 40.6879 -104.6850 1832.76 1543 289.76 NaN
#> 2872: 40.7908 -104.6855 1668.78 1614 54.78 NaN
#> pressure pressure_altitude u v temperature type_altitude
#> <num> <num> <num> <num> <num> <num>
#> 1: NaN NaN NaN NaN NaN 1
#> 2: NaN NaN NaN NaN NaN 1
#> 3: NaN NaN NaN NaN NaN 1
#> 4: NaN NaN NaN NaN NaN 1
#> 5: NaN NaN NaN NaN NaN 1
#> ---
#> 2868: NaN NaN NaN NaN NaN 1
#> 2869: NaN NaN NaN NaN NaN 1
#> 2870: NaN NaN NaN NaN NaN 1
#> 2871: NaN NaN NaN NaN NaN 1
#> 2872: NaN NaN NaN NaN NaN 1
#> local_time lh
#> <POSc> <int>
#> 1: 2020-01-14 12:24:14 12
#> 2: 2020-01-14 12:28:17 12
#> 3: 2020-01-14 12:32:11 12
#> 4: 2020-01-14 12:34:42 12
#> 5: 2020-01-14 12:36:56 12
#> ---
#> 2868: 2020-12-25 14:10:35 14
#> 2869: 2020-12-25 14:21:43 14
#> 2870: 2020-12-25 14:28:37 14
#> 2871: 2020-12-25 14:34:15 14
#> 2872: 2020-12-25 14:36:55 14
Master
Before generating the receptors list, we have the databe with all the required information
master <- df3
We may replace missing values with a nine nines. Here is commented
#master[is.na(master)] <- 999999999
We transform the time variables to character and round coordinates with 4 digits
master$timeUTC <- as.character(master$timeUTC)
master$local_time <- as.character(master$local_time)
master$latitude <- round(master$latitude, 4)
master$longitude <- round(master$longitude, 4)
Save master
Finally we save the master file
out <- tempfile()
txt
message(paste0(out,"_", datasetid, ".txt\n"))
fwrite(master,
paste0(out,"_", datasetid, ".txt"),
sep = " ")
#> C:\Users\sibarrae\AppData\Local\Temp\Rtmp8sNX0E\filea6ec44f76552_aircraft-pfp.txt
csv
message(paste0(out,"_", datasetid, ".csv\n"))
fwrite(master,
paste0(out,"_", datasetid, ".csv"),
sep = ",")
#> C:\Users\sibarrae\AppData\Local\Temp\Rtmp8sNX0E\filea6ec44f76552_aircraft-pfp.csv
csvy
CSVY are csv files with a YAML header to include metadata in tabulated text files
cat("\nAdding notes in csvy:\n")
notes <- c(paste0("sector: ", datasetid),
paste0("timespan: ", yy),
paste0("spatial_limits: north = ", north, ", south = ", south, ", east = ", east, ", west = ", west),
"data: Data averaged every 20 seconds",
paste0("altitude: < ", max_altitude),
"hours: All",
"local_time: if var `site_utc2lst` is not available, calculated as",
"longitude/15*60*60 (John Miller)")
cat(notes, sep = "\n")
message(paste0(out,"_", datasetid, ".csvy\n"))
obs_write_csvy(dt = master,
notes = notes,
out = paste0(out,"_", datasetid, ".csvy"))
#>
#> sector: aircraft-pfp
#> timespan: 2020
#> spatial_limits: north = 80, south = 10, east = -50, west = -170
#> data: Data averaged every 20 seconds
#> altitude: < 8000
#> hours: All
#> local_time: if var `site_utc2lst` is not available, calculated as
#> longitude/15*60*60 (John Miller)
#> C:\Users\sibarrae\AppData\Local\Temp\Rtmp8sNX0E\filea6ec44f76552_aircraft-pfp.csvy
obs_read_csvy(paste0(out,"_", datasetid, ".csvy"))
#> [1] "---"
#> [2] "name: Metadata "
#> [3] "sector: aircraft-pfp"
#> [4] "timespan: 2020"
#> [5] "spatial_limits: north = 80, south = 10, east = -50, west = -170"
#> [6] "data: Data averaged every 20 seconds"
#> [7] "altitude: < 8000"
#> [8] "hours: All"
#> [9] "local_time: if var `site_utc2lst` is not available, calculated as"
#> [10] "longitude/15*60*60 (John Miller)"
#> [11] "structure: "
#> [12] "Classes 'data.table' and 'data.frame':\t2872 obs. of 27 variables:"
#> [13] " $ timeUTC : chr \"2020-01-14 18:28:20\" \".."
#> [14] " $ site_code : chr \"WBI\" \"WBI\" ..."
#> [15] " $ lab_1_abbr : chr \"NOAA\" \"NOAA\" ..."
#> [16] " $ dataset_calibration_scale: chr \"WMO CH4 X2004A\" \"WMO \".."
#> [17] " $ year : int 2020 2020 2020 2020 202.."
#> [18] " $ month : int 1 1 1 1 1 ..."
#> [19] " $ day : chr \"14\" \"14\" ..."
#> [20] " $ hour : int 18 18 18 18 18 ..."
#> [21] " $ minute : int 28 33 37 40 43 ..."
#> [22] " $ second : int 20 0 40 40 20 ..."
#> [23] " $ time : num 1.58e+09 1.58e+09 ..."
#> [24] " $ time_decimal : num 2020 2020 ..."
#> [25] " $ value : num 1.91e-06 1.93e-06 ..."
#> [26] " $ latitude : num 41.8 41.7 ..."
#> [27] " $ longitude : num -91 -91.2 ..."
#> [28] " $ altitude_final : num 7618 6959 ..."
#> [29] " $ elevation : num 242 234 236 244 235 ..."
#> [30] " $ intake_height : num 7376 6725 ..."
#> [31] " $ gps_altitude : num NaN NaN NaN NaN NaN ..."
#> [32] " $ pressure : num NaN NaN NaN NaN NaN ..."
#> [33] " $ pressure_altitude : num NaN NaN NaN NaN NaN ..."
#> [34] " $ u : num NaN NaN NaN NaN NaN ..."
#> [35] " $ v : num NaN NaN NaN NaN NaN ..."
#> [36] " $ temperature : num NaN NaN NaN NaN NaN ..."
#> [37] " $ type_altitude : num 1 1 1 1 1 ..."
#> [38] " $ local_time : chr \"2020-01-14 12:24:14.8\".."
#> [39] " $ lh : int 12 12 12 12 12 ..."
#> [40] " - attr(*, \".internal.selfref\")=<externalptr> "
#> [41] "NULL"
#> [42] "---"
#> timeUTC site_code lab_1_abbr dataset_calibration_scale year
#> <POSc> <char> <char> <char> <int>
#> 1: 2020-01-14 18:28:20 WBI NOAA WMO CH4 X2004A 2020
#> 2: 2020-01-14 18:33:00 WBI NOAA WMO CH4 X2004A 2020
#> 3: 2020-01-14 18:37:40 WBI NOAA WMO CH4 X2004A 2020
#> 4: 2020-01-14 18:40:40 WBI NOAA WMO CH4 X2004A 2020
#> 5: 2020-01-14 18:43:20 WBI NOAA WMO CH4 X2004A 2020
#> ---
#> 2868: 2020-12-25 21:09:20 CAR NOAA WMO CH4 X2004A 2020
#> 2869: 2020-12-25 21:20:20 CAR NOAA WMO CH4 X2004A 2020
#> 2870: 2020-12-25 21:27:20 CAR NOAA WMO CH4 X2004A 2020
#> 2871: 2020-12-25 21:33:00 CAR NOAA WMO CH4 X2004A 2020
#> 2872: 2020-12-25 21:35:40 CAR NOAA WMO CH4 X2004A 2020
#> month day hour minute second time time_decimal value
#> <int> <int> <int> <int> <int> <int> <num> <num>
#> 1: 1 14 18 28 20 1579026500 2020.038 1.91295e-06
#> 2: 1 14 18 33 0 1579026780 2020.038 1.92525e-06
#> 3: 1 14 18 37 40 1579027060 2020.038 1.92408e-06
#> 4: 1 14 18 40 40 1579027240 2020.038 1.91808e-06
#> 5: 1 14 18 43 20 1579027400 2020.038 1.92311e-06
#> ---
#> 2868: 12 25 21 9 20 1608930560 2020.983 1.93444e-06
#> 2869: 12 25 21 20 20 1608931220 2020.983 1.93578e-06
#> 2870: 12 25 21 27 20 1608931640 2020.983 1.93419e-06
#> 2871: 12 25 21 33 0 1608931980 2020.983 1.93514e-06
#> 2872: 12 25 21 35 40 1608932140 2020.983 2.00509e-06
#> latitude longitude altitude_final elevation intake_height gps_altitude
#> <num> <num> <num> <int> <num> <lgcl>
#> 1: 41.7505 -91.0213 7618.48 242 7376.48 NA
#> 2: 41.7427 -91.1791 6958.89 234 6724.89 NA
#> 3: 41.7232 -91.3675 5685.43 236 5449.43 NA
#> 4: 41.7275 -91.4877 4987.14 244 4743.14 NA
#> 5: 41.7177 -91.5966 4333.95 235 4098.95 NA
#> ---
#> 2868: 40.7275 -104.6853 2926.69 1559 1367.69 NA
#> 2869: 40.7813 -104.6506 2453.94 1590 863.94 NA
#> 2870: 40.7955 -104.6787 2138.78 1599 539.78 NA
#> 2871: 40.6879 -104.6850 1832.76 1543 289.76 NA
#> 2872: 40.7908 -104.6855 1668.78 1614 54.78 NA
#> pressure pressure_altitude u v temperature type_altitude
#> <lgcl> <lgcl> <lgcl> <lgcl> <lgcl> <int>
#> 1: NA NA NA NA NA 1
#> 2: NA NA NA NA NA 1
#> 3: NA NA NA NA NA 1
#> 4: NA NA NA NA NA 1
#> 5: NA NA NA NA NA 1
#> ---
#> 2868: NA NA NA NA NA 1
#> 2869: NA NA NA NA NA 1
#> 2870: NA NA NA NA NA 1
#> 2871: NA NA NA NA NA 1
#> 2872: NA NA NA NA NA 1
#> local_time lh
#> <POSc> <int>
#> 1: 2020-01-14 12:24:14 12
#> 2: 2020-01-14 12:28:17 12
#> 3: 2020-01-14 12:32:11 12
#> 4: 2020-01-14 12:34:42 12
#> 5: 2020-01-14 12:36:56 12
#> ---
#> 2868: 2020-12-25 14:10:35 14
#> 2869: 2020-12-25 14:21:43 14
#> 2870: 2020-12-25 14:28:37 14
#> 2871: 2020-12-25 14:34:15 14
#> 2872: 2020-12-25 14:36:55 14
Receptors
Now we can do the last step which is generating the receptor list files. Now we filter selected columns
receptor <- master[, c("site_code",
"year",
"month",
"day",
"hour",
"minute",
"second",
"latitude",
"longitude",
"altitude_final",
"type_altitude")]
We can round altitude also
receptor$altitude_final <- round(receptor$altitude_final)
Now we can format time variables with two digits
receptor <- obs_format(receptor,
spf = c("month", "day",
"hour", "minute", "second"))
We have a column that indicate AGL or ASL
receptor_agl <- receptor[type_altitude == 0]
receptor_asl <- receptor[type_altitude == 1]
Finally, we save the receptors
if(nrow(receptor_agl) > 0) {
message(paste0(out, "_", datasetid, "_receptor_AGL.txt"), "\n")
fwrite(x = receptor_agl,
file = paste0(out, "_", datasetid, "_receptor_AGL.txt"),
sep = " ")
}
if(nrow(receptor_asl) > 0) {
message(paste0(out, "_", datasetid, "_receptor_ASL.txt"), "\n")
fwrite(x = receptor_asl,
file = paste0(out, "_", datasetid, "receptor_ASL.txt"),
sep = " ")
}
#> C:\Users\sibarrae\AppData\Local\Temp\Rtmp8sNX0E\filea6ec44f76552_aircraft-pfp_receptor_ASL.txt
Plot
Finally, we just plot some data, run it locally
obs_plot(df3, time = "timeUTC", yfactor = 1e9)
library(sf)
x <- st_as_sf(df3, coords = c("longitude", "latitude"), crs = 4326)
plot(x["value"], axes = T, reset = F)
maps::map(add = T)
x <- df3
x$ch4 <- x$value*1e+9
obs_plot(x,
time = "ch4",
y = "altitude_final",
colu = "site_code", #n = c(1L, 3L, 6L, 8L, 9L, 11L, 12L),
type = "b",
xlab = expression(CH[4]~ppb),
ylab = "altitude (m)")