Skip to content

Commit

Permalink
Merge pull request IDEMSInternational#6274 from dannyparsons/netcdf-d…
Browse files Browse the repository at this point in the history
…isplay

Better column names when importing NetCDF files
  • Loading branch information
lloyddewit authored Mar 15, 2021
2 parents 834a6b2 + 5fa9ec9 commit 5af172d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
8 changes: 8 additions & 0 deletions instat/dlgOpenNetCDF.vb
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,9 @@ Public Class dlgOpenNetCDF
End If
Else
MsgBox("File type: '" & strFileExt & "' not recognised as a NetCDF file (.nc).", vbOKOnly)
strShort = ""
strMedium = ""
strLong = ""
End If
End If
End Using
Expand Down Expand Up @@ -239,12 +242,17 @@ Public Class dlgOpenNetCDF
clsNcOpenFunction.ToScript(strTemp)
frmMain.clsRLink.RunScript(strTemp, strComment:="Opening connection to first NetCDF file", bUpdateGrids:=False)
bCloseFile = True
clsRFileDetails.AddParameter("infile", Chr(34) & Replace(strFiles(0), "\", "/") & Chr(34), iPosition:=1)
clsImportNetcdfFunction.AddParameter("path", Chr(34) & Replace(strPath, "\", "/") & Chr(34))
ucrInputDataName.SetName(frmMain.clsRLink.MakeValidText(Path.GetFileName(strPath.TrimEnd(Path.DirectorySeparatorChar))))
FileDetails()
clsImportNetcdfFunction.RemoveParameterByName("boundary")
clsBoundaryListFunction.ClearParameters()
Else
clsNcOpenFunction.RemoveParameterByName("filename")
strShort = ""
strMedium = ""
strLong = ""
End If
End If
End Using
Expand Down
12 changes: 6 additions & 6 deletions instat/static/InstatObject/R/stand_alone_functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -393,9 +393,9 @@ nc_as_data_frame <- function(nc, vars, keep_raw_time = TRUE, include_metadata =
curr_count[2] <- 1
curr_dim_values[[y_var]] <- curr_dim_values[[y_var]][y_ind]
if(show_requested_points) {
curr_dim_values[[paste0("requested_", x_var)]] <- lon_points[i]
curr_dim_values[[paste0("requested_", y_var)]] <- lat_points[i]
if(!is.null(id_points)) curr_dim_values[["requested_id"]] <- id_points[i]
curr_dim_values[[paste0(x_var, "_point")]] <- lon_points[i]
curr_dim_values[[paste0(y_var, "_point")]] <- lat_points[i]
if(!is.null(id_points)) curr_dim_values[["station"]] <- id_points[i]
requested_points_added <- TRUE
}

Expand Down Expand Up @@ -444,14 +444,14 @@ nc_as_data_frame <- function(nc, vars, keep_raw_time = TRUE, include_metadata =
time_ind <- which(raw_time_full %in% raw_time)
units <- ncdf4::ncatt_get(nc, time_var, "units")
if(units$hasatt && units$value == "julian_day") {
time_df[[paste0(time_var, "_date")]] <- as.Date(raw_time, origin = structure(-2440588, class = "Date"))
time_df[["date"]] <- as.Date(raw_time, origin = structure(-2440588, class = "Date"))
}
else {
pcict_time <- ncdf4.helpers::nc.get.time.series(nc, time.dim.name = time_var)
pcict_time <- pcict_time[time_ind]
posixct_time <- PCICt::as.POSIXct.PCICt(pcict_time)
time_df[[paste0(time_var, "_full")]] <- posixct_time
time_df[[paste0(time_var, "_date")]] <- as.Date(posixct_time)
time_df[["date"]] <- as.Date(posixct_time)
time_df[["datetime"]] <- posixct_time
}
})
if(ncol(time_df) > 1) curr_var_data <- dplyr::full_join(curr_var_data, time_df, by = time_var)
Expand Down

0 comments on commit 5af172d

Please sign in to comment.