Skip to content
Open

Suna #1006

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
242 commits
Select commit Hold shift + click to select a range
478c060
suna log file checker for pachyderm.
Apr 9, 2025
139ec50
Additional work on suna log file checker
Apr 9, 2025
4b9bb3c
suna pipeline structure
ncatolico Apr 9, 2025
ec0eb5c
trino data
ncatolico Apr 9, 2025
14fb044
Additional updated to SUNA log checker
Apr 10, 2025
96c9286
Merge branch 'suna' of https://github.com/NEONScience/NEON-IS-data-pr…
Apr 10, 2025
1738b81
add LECO
ncatolico Apr 10, 2025
a05d72d
Updates to suna logged data checker.
Apr 15, 2025
3606247
Updates to SUNA log file checker.
Apr 15, 2025
26a1faf
Update to SUNA log file formatter that pulls asset information from f…
Apr 18, 2025
3253a73
fast forward
ncatolico May 14, 2025
6dcb3d1
fast forward
ncatolico May 29, 2025
2fcaea8
update to sunav2
ncatolico May 29, 2025
b6e16ab
debug
ncatolico May 29, 2025
d659133
update dates
ncatolico May 29, 2025
5be5712
latest
ncatolico May 30, 2025
18dd3ca
suna trino loader
ncatolico May 30, 2025
c126367
fast forward
ncatolico Jun 2, 2025
3ea505c
fast forward
ncatolico Jun 27, 2025
b39dacc
fast forward
ncatolico Jun 27, 2025
8a124f7
Updates to SUNA modules.
Jun 27, 2025
66b0dc6
latest
ncatolico Jun 27, 2025
efa81a1
latest
ncatolico Jun 27, 2025
13c8203
latest
ncatolico Jun 27, 2025
b2df2d3
latest
ncatolico Jun 27, 2025
a9859eb
fast forward
ncatolico Jun 27, 2025
75cbee2
latest
ncatolico Jun 27, 2025
431b28e
latest
ncatolico Jun 27, 2025
4982871
latest
ncatolico Jun 27, 2025
8f87d5c
latest
ncatolico Jun 30, 2025
1a9c472
Added code to generate SUNA log QF output file.
Jun 30, 2025
dd94e8c
combined suna log fill module
ncatolico Jun 30, 2025
d48d008
combined module git action
ncatolico Jun 30, 2025
91a3f4d
combined module
ncatolico Jun 30, 2025
d92ba06
latest
ncatolico Jun 30, 2025
c5f1411
latest
ncatolico Jun 30, 2025
2476643
minor
ncatolico Jun 30, 2025
6f50b98
latest
ncatolico Jun 30, 2025
bd6f222
fast forward
ncatolico Jul 2, 2025
63873b3
fix
ncatolico Jul 2, 2025
4946c27
testing
ncatolico Jul 2, 2025
e5a94b8
update environs
ncatolico Jul 2, 2025
cfa9a11
more logs
ncatolico Jul 3, 2025
a243d3e
logs
ncatolico Jul 3, 2025
6025c51
latest
ncatolico Jul 3, 2025
e100ec6
Update sunav2_data_parser.yaml
covesturtevant Jul 11, 2025
afb2bfa
Update sunav2_data_parser.yaml
covesturtevant Jul 11, 2025
e1ea41f
fast forward
ncatolico Jul 11, 2025
696cae7
latest
ncatolico Jul 11, 2025
81f23b2
fast forward
ncatolico Jul 15, 2025
5646b28
Deleted parsing of L0 data within sunav2.log.fill, since we realized …
Jul 15, 2025
0730496
Merge branch 'master' into suna
covesturtevant Jul 15, 2025
c77753b
Merge branch 'suna' of github.com:NEONScience/NEON-IS-data-processing…
covesturtevant Jul 16, 2025
06f552b
load and parse suna data
covesturtevant Jul 17, 2025
ff8d2f7
change source type in suna calibration loader to "sunav2" instead of …
covesturtevant Jul 17, 2025
638456a
bug fix
covesturtevant Jul 17, 2025
9666aec
fix source type
covesturtevant Jul 17, 2025
155c3d8
update image
ncatolico Jul 17, 2025
704b149
ignor kafka data for now
ncatolico Jul 17, 2025
b28f2da
latest
ncatolico Jul 17, 2025
898036c
latest
ncatolico Jul 17, 2025
0144981
Merge branch 'master' into suna
covesturtevant Jul 17, 2025
976f388
update kafka image
covesturtevant Jul 17, 2025
7e0e002
Merge branch 'suna' of github.com:NEONScience/NEON-IS-data-processing…
ncatolico Jul 17, 2025
3919b2e
update resource request
covesturtevant Jul 30, 2025
8f8994d
update resource requests
covesturtevant Jul 31, 2025
a1ff444
fast forward
ncatolico Aug 18, 2025
4324225
latest suna pipeline
ncatolico Aug 18, 2025
1bced34
fast forward
ncatolico Aug 20, 2025
390f2d5
Started work on SUNA flagging module.
Aug 20, 2025
e1d6a9a
nitrate latest
ncatolico Aug 21, 2025
8c8ab74
Merge branch 'suna' of github.com:NEONScience/NEON-IS-data-processing…
ncatolico Aug 21, 2025
d2c004e
update column name
ncatolico Aug 22, 2025
df76ba6
SUNA sensor-specific QAQC
Aug 22, 2025
11b4466
Merge branch 'suna' of github.com:NEONScience/NEON-IS-data-processing…
Aug 22, 2025
df8c415
latest
ncatolico Aug 22, 2025
1a1ca7a
Merge branch 'suna' of github.com:NEONScience/NEON-IS-data-processing…
ncatolico Aug 22, 2025
bae8aad
latest
ncatolico Aug 22, 2025
a91bb09
latest
ncatolico Aug 22, 2025
b3411bc
latest
ncatolico Aug 22, 2025
9220a18
latest
ncatolico Aug 22, 2025
f2bb5ee
Merge branch 'suna' of github.com:NEONScience/NEON-IS-data-processing…
ncatolico Aug 22, 2025
46ec1c4
Updates to SUNA-specific quality flag module.
Aug 25, 2025
aa6b7f7
Fixed param names in header.
Aug 25, 2025
e375937
latest
ncatolico Aug 26, 2025
41ca917
fast forward
ncatolico Aug 26, 2025
9951b01
Work on .flow and docker files for suna quality flags.
Aug 26, 2025
8c2db63
Merge branch 'suna' of github.com:NEONScience/NEON-IS-data-processing…
Aug 26, 2025
dccb601
Updates to suna quality flag .flow and docker.
Aug 26, 2025
31cb3b2
latest
ncatolico Aug 26, 2025
381a3ca
fast forward
ncatolico Aug 26, 2025
4d0c318
rename dockerfile
ncatolico Aug 26, 2025
fe28578
renv file
ncatolico Aug 26, 2025
b982e99
test continuous data
ncatolico Aug 28, 2025
a8733f5
fast forward
ncatolico Aug 28, 2025
1056388
latest
ncatolico Aug 28, 2025
5a8c180
Merge branch 'master' into suna
covesturtevant Sep 2, 2025
bf5a842
update node selector
covesturtevant Sep 2, 2025
598a6f6
point to correct site list
covesturtevant Sep 2, 2025
2cca82d
Merge branch 'master' into suna
covesturtevant Sep 10, 2025
d568fcf
stop triggering daily cron
covesturtevant Sep 10, 2025
0f097aa
fast forward
ncatolico Sep 15, 2025
47da90c
udpated for dev testing
ncatolico Sep 15, 2025
e69bd7a
latest
ncatolico Sep 15, 2025
f361dd5
minor
ncatolico Sep 15, 2025
b1a2efe
update docker file
ncatolico Sep 15, 2025
ecbf4e7
update docker file
ncatolico Sep 15, 2025
612f69c
Merge branch 'suna' of github.com:NEONScience/NEON-IS-data-processing…
ncatolico Sep 15, 2025
d6f7873
flags specific pipeline
ncatolico Sep 15, 2025
954fbca
update output path
ncatolico Sep 15, 2025
39d7171
minor
ncatolico Sep 15, 2025
5deb085
latest
ncatolico Sep 15, 2025
071eb46
fast forward
ncatolico Sep 16, 2025
67fd9bc
Updates to SUNA sensor specific flagging module. Determines measurmen…
Sep 16, 2025
1e1e4ba
Merge branch 'suna' of github.com:NEONScience/NEON-IS-data-processing…
Sep 16, 2025
5a22ea5
Updates to SUNA sensor specific flag module.
Sep 16, 2025
ce92249
latest
ncatolico Sep 16, 2025
4b4f1ce
ignore problematic spec_channels for now
ncatolico Sep 16, 2025
086338d
change field names back
ncatolico Sep 16, 2025
326b3b4
schema update
ncatolico Sep 16, 2025
8b0b9a2
latest
ncatolico Sep 16, 2025
d75b5b3
spec channels update
ncatolico Sep 17, 2025
67564eb
update images
ncatolico Sep 17, 2025
5bf1c42
minor
ncatolico Sep 17, 2025
a9c9ab0
latest
ncatolico Sep 17, 2025
f284f86
image
ncatolico Sep 17, 2025
bc57507
fast forward
ncatolico Sep 17, 2025
1c32a70
Updated suna quality flag module to remove measuremnts where lamp has…
Sep 19, 2025
054e370
latest
ncatolico Sep 22, 2025
b90a00b
image update
ncatolico Sep 22, 2025
17df9ef
latest
ncatolico Sep 22, 2025
b4d82d2
update image
ncatolico Sep 22, 2025
ca8ce76
Added check that output data and flags have same number of measuremnts.
Sep 22, 2025
03d73eb
updated image
ncatolico Sep 22, 2025
8c3129c
test image
covesturtevant Oct 17, 2025
a6927e6
merge master, resolve conflicts
covesturtevant Oct 17, 2025
8fba6ef
update with semver tag
covesturtevant Oct 17, 2025
b95b90a
fast forward
ncatolico Oct 20, 2025
eb55407
update expired image
ncatolico Oct 20, 2025
9886b88
Merge branch 'master' into suna
covesturtevant Oct 27, 2025
02522a0
Merge branch 'suna' of github.com:NEONScience/NEON-IS-data-processing…
covesturtevant Oct 27, 2025
26aeb64
update image version
covesturtevant Oct 27, 2025
06aa4ba
image update
ncatolico Oct 28, 2025
3780a7a
minor fix
ncatolico Oct 29, 2025
3d22ecf
latest
ncatolico Oct 29, 2025
2b2d433
latest
ncatolico Oct 29, 2025
d582b02
latest
ncatolico Oct 29, 2025
033e5f8
fast forward
ncatolico Oct 29, 2025
1485cc0
Updated to revert plausibility flags at end of each burst.
Oct 30, 2025
72c2253
Merge branch 'suna' of github.com:NEONScience/NEON-IS-data-processing…
Oct 30, 2025
b713685
Updated change log.
Oct 30, 2025
4dc1f50
update image
ncatolico Oct 30, 2025
e28141b
Created insufficient data quality flagging module.
Oct 31, 2025
d571c85
Updates to flow script.
Oct 31, 2025
1f2d34b
Updates
Oct 31, 2025
3b8cb41
Created expanded uncertainty module for SUNA.
Nov 3, 2025
2f8ea6d
Updates to SUNA expanded uncertainty module.
Nov 3, 2025
5dbc533
Merge branch 'suna' of github.com:NEONScience/NEON-IS-data-processing…
ncatolico Nov 4, 2025
1187b1c
combined module for uncertainty
ncatolico Nov 4, 2025
58e6da6
fast forward
ncatolico Nov 4, 2025
ee522b5
build flow image
ncatolico Nov 4, 2025
5a578f5
git actions
ncatolico Nov 4, 2025
036fd47
latest
ncatolico Nov 4, 2025
3d1fee3
add in cal package
ncatolico Nov 4, 2025
d590e7a
latest
ncatolico Nov 4, 2025
4a9eb21
latest
ncatolico Nov 4, 2025
1bdfe3e
create docker image
ncatolico Nov 4, 2025
db7a283
latest
ncatolico Nov 5, 2025
238d31d
combine modules
ncatolico Nov 5, 2025
fee1f15
fast forward
ncatolico Nov 5, 2025
71a3f84
latest
ncatolico Nov 5, 2025
3e2d1f9
fast forward
ncatolico Nov 11, 2025
bbf9fb7
fast forward
ncatolico Nov 20, 2025
43af1e4
update cron
ncatolico Nov 20, 2025
f974ce4
fast forward
ncatolico Dec 2, 2025
4fa99b1
full site list
ncatolico Dec 2, 2025
e99ca00
Merge branch 'master' into suna
covesturtevant Dec 3, 2025
70b0372
update cal module image
covesturtevant Dec 3, 2025
470c3b9
merge master, resolve conflict
covesturtevant Dec 3, 2025
34dac9f
remove json version
covesturtevant Dec 3, 2025
d7a4a0d
update image
covesturtevant Dec 3, 2025
6dd24fc
latest
ncatolico Dec 3, 2025
6897331
fill date incorporated
ncatolico Dec 3, 2025
06ff071
Merge branch 'suna' of github.com:NEONScience/NEON-IS-data-processing…
ncatolico Dec 3, 2025
be62238
new function for gap filling non-regularized data
ncatolico Dec 4, 2025
a7ff455
combined module
ncatolico Dec 4, 2025
5203a85
latest
ncatolico Dec 4, 2025
b102443
fix name
ncatolico Dec 4, 2025
e6a716a
add in file schema parameters
ncatolico Dec 8, 2025
98108c3
no schema case
ncatolico Dec 8, 2025
7a91b1d
added indicator for gap filling
ncatolico Dec 10, 2025
d5e56d6
reverting added row
ncatolico Dec 10, 2025
0c61706
Updated SUNA sensor specific flagging module to pass added null fille…
Dec 10, 2025
6fa7b75
Merge branch 'suna' of github.com:NEONScience/NEON-IS-data-processing…
Dec 10, 2025
62da0a9
updates for case of blank ucrt coef file
ncatolico Dec 10, 2025
4ec5d70
latest
ncatolico Dec 11, 2025
38f5444
update image
ncatolico Dec 11, 2025
e0a9482
turn daily kafka loading back on for sunav2 so ENG can test issues
covesturtevant Dec 12, 2025
8611098
fix nan
ncatolico Dec 12, 2025
d8bedbe
latest
ncatolico Dec 15, 2025
0de87d0
Merge branch 'suna' of github.com:NEONScience/NEON-IS-data-processing…
ncatolico Dec 15, 2025
23401b4
fast forward
ncatolico Dec 15, 2025
32315a4
latest
ncatolico Dec 15, 2025
0c988f0
publication pipelines
ncatolico Dec 15, 2025
7162cce
latest
ncatolico Dec 16, 2025
736e55e
change minPoints to numeric
ncatolico Dec 16, 2025
1610ebb
Updated SUNA specific flag script so dark measuremts caused by lamp t…
Dec 16, 2025
7eaa562
Merge branch 'suna' of github.com:NEONScience/NEON-IS-data-processing…
Dec 16, 2025
ae78d24
update images
ncatolico Dec 16, 2025
f5e027b
Update to to SUNA flagging script to set error codes that didn't othe…
Dec 16, 2025
6370f37
Merge branch 'suna' of github.com:NEONScience/NEON-IS-data-processing…
Dec 16, 2025
c5d41aa
Changed where in script low transmittence values are quality flagged.
Dec 17, 2025
538bf66
Updated change log.
Dec 17, 2025
e42f297
dates and images updated
ncatolico Dec 18, 2025
658d7fb
Update to insifficient data quality flag script that makes it the onl…
Dec 18, 2025
2025667
Merge branch 'suna' of github.com:NEONScience/NEON-IS-data-processing…
Dec 18, 2025
0d132ba
Updated suna specific flag script to set lamp warmup measuremnts to N…
Dec 18, 2025
016ceb3
update image
ncatolico Dec 22, 2025
94855c7
Merge branch 'suna' of github.com:NEONScience/NEON-IS-data-processing…
ncatolico Dec 22, 2025
95e1912
Updated light dark ratio test for dark measurements.
Dec 22, 2025
beec397
fast forward
ncatolico Dec 22, 2025
6aa3811
latest
ncatolico Dec 22, 2025
7bc4ad2
Merge branch 'master' into suna
covesturtevant Dec 22, 2025
dc90260
update image tags
covesturtevant Dec 22, 2025
ac2d5e5
fast forward
ncatolico Jan 1, 2026
6f1efb7
fast forward
ncatolico Jan 21, 2026
b1c4632
change dev to prod for log file bucket
ncatolico Jan 21, 2026
b9de053
Uncomment print statements for debugging
covesturtevant Jan 23, 2026
6437098
Update base image version to v1.7.0
covesturtevant Jan 23, 2026
2e6eaa7
Update base image version in Dockerfile
covesturtevant Jan 23, 2026
186f0f2
Update base image version in Dockerfile
covesturtevant Jan 23, 2026
140f1da
Update Docker base image version to v1.7.0
covesturtevant Jan 23, 2026
84aa10d
Update Dockerfile
covesturtevant Jan 23, 2026
29c70cc
Update base image version in Dockerfile
covesturtevant Jan 23, 2026
89bd7ec
Update base image version in Dockerfile
covesturtevant Jan 23, 2026
0c0d4db
Add HQTW
covesturtevant Jan 23, 2026
cd20787
Update Docker image version in YAML configuration
covesturtevant Jan 23, 2026
97f1049
fix L1 bucket structure
covesturtevant Jan 24, 2026
fc59d42
Update image version for sunav2_location_asset
covesturtevant Jan 26, 2026
92495d6
Merge branch 'suna' of github.com:NEONScience/NEON-IS-data-processing…
covesturtevant Jan 26, 2026
4931319
bring images to current
covesturtevant Jan 26, 2026
f6ecf1a
bring image to current
covesturtevant Jan 26, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions flow/flow.gap.fill.nonrglr/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Dockerfile for NEON IS Data Processing - flow.gap.fill.nonrglr

# Start with the neon-is-base-r image.
FROM us-central1-docker.pkg.dev/neon-shared-service/neonscience/neon-is-pack-base-r:v1.7.0

ARG FLOW_DIR="./flow"
ARG APP_DIR="flow.gap.fill.nonrglr"

# maintainer handle
MAINTAINER "Nora Catolico" ncatolico@battelleecology.org

# Copy the lockfile and restore known working versions of R dependency packages
COPY ${FLOW_DIR}/${APP_DIR}/renv.lock /renv.lock
RUN R -e 'renv::restore(lockfile="/renv.lock")'

# Create app user
RUN groupadd app && \
useradd app -g app
WORKDIR /home/app

# Copy in application code
COPY ${FLOW_DIR}/${APP_DIR}/flow.gap.fill.nonrglr.R .
COPY ${FLOW_DIR}/${APP_DIR}/wrap.gap.fill.nonrglr.R .

# Run as app user
RUN chown app:app -R /home/app
USER app
249 changes: 249 additions & 0 deletions flow/flow.gap.fill.nonrglr/flow.gap.fill.nonrglr.R
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, but please update the header to reflect that regularization is not performed. There is some conflicting language in a few places, likely from using flow.rglr as a template.

Original file line number Diff line number Diff line change
@@ -0,0 +1,249 @@
##############################################################################################
#' @title Gap filling module for non-regularized data in NEON IS data processing.

#' @author
#' Nora Catolico \email{ncatolico@battelleecology.org} \cr

#' @description Workflow. Bin data to generate a regular time sequence of observations.
#' General code workflow:
#' Parse input parameters
#' Read in output schemas if indicated in parameters
#' Determine datums to process (set of files/folders to process as a single unit)
#' For each datum:
#' Create output directories and copy (by symbolic link) unmodified components
#' Read regularization frequency from location file (if not in input parameters)
#' Loop through all data files
#' Regularize data in each file
#' Write out the gap filled data
#'
#' This script is run at the command line with the following arguments. Each argument must be a
#' string in the format "Para=value", where "Para" is the intended parameter name and "value" is
#' the value of the parameter. Note: If the "value" string begins with a $ (e.g. $DIR_IN), the
#' value of the parameter will be assigned from the system environment variable matching the value
#' string.
#'
#' The arguments are:
#'
#' 1. "DirIn=value", where value is the path to the input data directory. NOTE: This path must be a
#' parent of the terminal directory where the data to be gap filled reside. See argument "DirFill"
#' below to indicate the terminal directory.
#'
#' The input path is structured as follows: #/pfs/BASE_REPO/#/yyyy/mm/dd/#, where # indicates any
#' number of parent and child directories of any name, so long as they are not 'pfs', the same name
#' as the terminal directory indicated in argument "DirFill", or recognizable as the 'yyyy/mm/dd'
#' structure which indicates the 4-digit year, 2-digit month, and 2-digit day of the data contained
#' in the folder.
#'
#' For example:
#' Input path = /scratch/pfs/sunav2_fill_date_gaps/sunav2/2019/01/01
#'
#' 2. "DirOut=value", where the value is the output path that will replace the #/pfs/BASE_REPO portion
#' of DirIn.
#'
#' 3. "DirErr=value", where the value is the output path to place the path structure of errored datums that will
#' replace the #/pfs/BASE_REPO portion of DirIn.
#'
#' 4. "DirFill=value", where value is the name of the terminal directory where the data to be
#' gap filled resides. This will be one or more child levels away from "DirIn". All files in the
#' terminal directory will be gap filled. The value may also be a vector of terminal directories,
#' separated by pipes (|). All terminal directories must be present and at the same directory level.
#' For example, "DirFill=data|flags" indicates to regularize the data files within each the data
#' and flags directories.
#'
#' #' 5. "FileSchm=value" (optional), where value is the full path to schema for data output by
#' this workflow. The value may be NA, in which case the output schema will be the same as the input
#' data. The value may be a single file, in which case it will apply to all output, or
#' multiple values in which case the argument is formatted as dir:value|dir:value...
#' where dir is one of the directories specified in DirFill and value is the path to the schema file
#' for the output of that directory. Multiple dir:value pairs are separated by pipes (|).
#' For example, "FileSchm=data:/path/to/schemaData.avsc|flags:NA" indicates that the
#' output from the data directory will be written with the schema /path/to/schemaData.avsc and the
#' output from the flags directory will be the same as the input files found in that
#' directory.
#'
#' 6. "WndwFill=value", where value is the window in minutes in which data are expected. It is formatted as a 3 character sequence,
#' representing the number of minutes over which any number of measurements are expected.
#' For example, "WndwFill=015" refers to a 15-minute interval, while "WndwAgr=030" refers to a
#' 30-minute interval.
#'
#' 7. "DirSubCopy=value" (optional), where value is the names of additional subfolders, separated by
#' pipes, at the same level as the regularization folder in the input path that are to be copied with a
#' symbolic link to the output path.
#'
#' Note: This script implements logging described in \code{\link[NEONprocIS.base]{def.log.init}},
#' which uses system environment variables if available.
#'
#' @return gap filled data and flag output in Parquet format in DirOut, where DirOut directory
#' replaces BASE_REPO but otherwise retains the child directory structure of the input path.

#' @references
#' License: (example) GNU AFFERO GENERAL PUBLIC LICENSE Version 3, 19 November 2007

#' @keywords Currently none

#' @examples
#' Stepping through the code in R studio
# log <- NEONprocIS.base::def.log.init(Lvl = "debug")
# arg<-c( "DirIn=~/pfs/sunav2_fill_date_gaps/sunav2/2025/06/23/CFGLOC110819",
# "DirOut=~/pfs/out ",
# "DirErr=~/pfs/out/errored_datums ",
# "DirFill=data|flags",
# "WndwFill=015",
# "FileSchm=data:/home/NEON/ncatolico/pfs/sunav2_avro_schemas/sunav2/sunav2_logfilled.avsc|flags:/home/NEON/ncatolico/pfs/sunav2_avro_schemas/sunav2/sunav2_calibration_flags.avsc|flags:/home/NEON/ncatolico/pfs/sunav2_avro_schemas/sunav2/sunav2_log_flags.avsc",
# "DirSubCopy=location|uncertainty_coef")
#' @seealso \code{\link[eddy4R.base]{def.rglr}}

# changelog and author contributions / copyrights
# Nora Catolico (12/4/2025)
# original creation
##############################################################################################
library(foreach)
library(doParallel)
library(dplyr)

# Source the wrapper function. Assume it is in the working directory
source("./wrap.gap.fill.nonrglr.R")

# Pull in command line arguments (parameters)
arg <- base::commandArgs(trailingOnly = TRUE)

# Start logging
log <- NEONprocIS.base::def.log.init()

# Use environment variable to specify how many cores to run on
numCoreUse <- base::as.numeric(Sys.getenv('PARALLELIZATION_INTERNAL'))
numCoreAvail <- parallel::detectCores()
if (base::is.na(numCoreUse)){
numCoreUse <- 1
}
if(numCoreUse > numCoreAvail){
numCoreUse <- numCoreAvail
}
log$debug(paste0(numCoreUse, ' of ',numCoreAvail, ' available cores will be used for internal parallelization.'))

# Parse the input arguments into parameters
Para <-
NEONprocIS.base::def.arg.pars(
arg = arg,
NameParaReqd = c(
"DirIn",
"DirOut",
"DirErr",
"DirFill",
"WndwFill"
),
NameParaOptn = c(
"DirSubCopy",
"FileSchm"
),
log = log
)

# Retrieve output schema(s)
log$debug(base::paste0(
'Output schema(s) for regularized data: ',
base::paste0(Para$FileSchm, collapse = ',')
))
if(length(Para$FileSchm)>0){
SchmFill <-
NEONprocIS.base::def.vect.pars.pair(
vect = Para$FileSchm,
KeyExp = Para$DirFill,
ValuDflt = 'NA',
NameCol = c('DirFill', 'FileSchmFill'),
log = log
)
# Read in the schema(s)
SchmFill$SchmFill <- NA
for (idxSchmFill in 1:base::length(SchmFill$FileSchmFill)) {
if (SchmFill$FileSchmFill[idxSchmFill] != 'NA') {
SchmFill$SchmFill[idxSchmFill] <-
base::paste0(base::readLines(SchmFill$FileSchmFill[idxSchmFill]),
collapse = '')
}
}
}else{
SchmFill <- NA
}


# Echo arguments
log$debug(base::paste0('Input directory: ', Para$DirIn))
log$debug(base::paste0('Output directory: ', Para$DirOut))
log$debug(base::paste0('Error directory: ', Para$DirErr))
log$debug(base::paste0(
'Terminal Directories to regularize: ',
base::paste0(Para$DirFill, collapse = ',')
))

# Retrieve intervals for gap filling
WndwFill <- base::as.numeric(Para$WndwFill)
log$debug(base::paste0('Interval for gap filling, in minutes: ',base::paste0(WndwFill,collapse=',')))


# Retrieve output schema(s)
log$debug(base::paste0(
'Output schema(s) for gap filled data: ',
base::paste0(Para$FileSchmFill, collapse = ',')
))

# Retrieve optional subdirectories to copy over
DirSubCopy <-
base::unique(base::setdiff(Para$DirSubCopy, Para$DirFill))
log$debug(base::paste0(
'Additional subdirectories to copy: ',
base::paste0(DirSubCopy, collapse = ',')
))

nameDirSub <- base::as.list(c(Para$DirFill))
log$debug(base::paste0(
'Expected subdirectories of each datum path: ',
base::paste0(nameDirSub, collapse = ',')
))

# Find all the input paths (datums). We will process each one.
DirIn <-
NEONprocIS.base::def.dir.in(DirBgn = Para$DirIn,
nameDirSub = nameDirSub,
log = log)

# Process each datum
doParallel::registerDoParallel(numCoreUse)
foreach::foreach(idxDirIn = DirIn) %dopar% {

log$info(base::paste0('Processing datum path: ', idxDirIn))

# Run the wrapper function for each datum, with error routing
tryCatch(
withCallingHandlers(
wrap.gap.fill.nonrglr(DirIn=idxDirIn,
DirOutBase=Para$DirOut,
WndwFill=WndwFill,
DirFill=Para$DirFill,
SchmFill=SchmFill,
DirSubCopy=DirSubCopy,
log=log
),
error = function(err) {
call.stack <- base::sys.calls() # is like a traceback within "withCallingHandlers"

# Re-route the failed datum
NEONprocIS.base::def.err.datm(
err=err,
call.stack=call.stack,
DirDatm=idxDirIn,
DirErrBase=Para$DirErr,
RmvDatmOut=TRUE,
DirOutBase=Para$DirOut,
log=log
)
}
),
# This simply to avoid returning the error
error=function(err) {}
)


return()

} # End loop around datum paths
Loading