Previous changeset 0:0077885b6f1d (2024-10-14) |
Commit message:
planemo upload for repository https://github.com/AquaINFRA/tools-ecology/tree/master commit 3989415663771a85b3a0be6c02308994ac4adc85 |
modified:
aquainfra_ogc_api_processes.R aquainfra_ogc_api_processes.xml test-data/points_att_polygon_test_input_3.txt |
b |
diff -r 0077885b6f1d -r 1ff618d89af4 aquainfra_ogc_api_processes.R --- a/aquainfra_ogc_api_processes.R Mon Oct 14 12:23:01 2024 +0000 +++ b/aquainfra_ogc_api_processes.R Wed Oct 23 22:35:20 2024 +0000 |
[ |
@@ -5,9 +5,7 @@ cat("start generic wrapper service \n") remove_null_values <- function(x) { - # Check if the input is a list if (is.list(x)) { - # Remove NULL values and apply the function recursively to sublists x <- lapply(x, remove_null_values) x <- x[!sapply(x, is.null)] } @@ -18,11 +16,10 @@ con <- file("inputs.json", "r") lines <- readLines(con) close(con) - + json_string <- paste(lines, collapse = "\n") json_data <- fromJSON(json_string) - - # Remove NULL values from json_data + cleaned_json_data <- remove_null_values(json_data) return(cleaned_json_data$conditional_process) } @@ -38,9 +35,10 @@ getOutputs <- function(inputs, output, server) { url <- - paste(paste(server, "/processes/", sep = ""), + paste(paste(server, "processes/", sep = ""), inputs$select_process, sep = "") + print(url) request <- request(url) response <- req_perform(request) responseBody <- parseResponseBody(response$body) @@ -81,10 +79,6 @@ cat("\n Process executed") cat("\n status: ", response$status_code) - #if ( process == "barplot-trend-results") { - # process = "batplot-trend-results" - #} - #href <- parseResponseBody(response$body)$outputs[[gsub("-", "_", process)]]$href jobId <- parseResponseBody(response$body)$jobID return(jobId) @@ -115,20 +109,14 @@ return(response) } -# Recursive function to search for href in a nested list findHref <- function(obj) { - hrefs <- c() # Initialize an empty vector to store hrefs - + hrefs <- c() if (is.list(obj)) { - # If the object is a list, loop through its elements for (name in names(obj)) { element <- obj[[name]] - if (is.list(element)) { - # Recursively search if the element is another list hrefs <- c(hrefs, findHref(element)) } else if (name == "href") { - # If the element has a name "href", capture its value hrefs <- c(hrefs, element) } } @@ -154,16 +142,11 @@ if (result$status_code == 200) { resultBody <- parseResponseBody(result$body) print(resultBody) - - # Call the recursive function to find all hrefs hrefs <- findHref(resultBody) if (length(hrefs) > 0) { - # Collapse the URLs with a newline urls_with_newline <- paste(hrefs, collapse = "\n") print(urls_with_newline) - - # Write the URLs to a file con <- file(outputData, "w") writeLines(urls_with_newline, con = con) close(con) @@ -190,8 +173,6 @@ } } - - saveResult <- function(href, outputData) { con <- file(outputData, "w") writeLines(href, con = con) @@ -206,7 +187,6 @@ print("--> Retrieve parameters") inputParameters <- getParameters() -#print(inputParameters) print("--> Parameters retrieved") args <- commandArgs(trailingOnly = TRUE) @@ -217,54 +197,24 @@ print("--> Outputs retrieved") print("--> Parse inputs") + convertedKeys <- c() + for (key in names(inputParameters)) { if (is.character(inputParameters[[key]]) && (endsWith(inputParameters[[key]], ".dat") || endsWith(inputParameters[[key]], ".txt"))) { con <- file(inputParameters[[key]], "r") url_list <- list() - #while (length(line <- readLines(con, n = 1)) > 0) { - # if (is_url(line)) { - # url_list <- c(url_list, list(list(href = trimws(line)))) - # } - #} + con <- file(inputParameters[[key]], "r") lines <- readLines(con) - print("--------------------------------------------------------------------1") print(length(lines)) close(con) - if (!length(lines) > 1 && endsWith(lines, ".jp2") && startsWith(lines, "https")) { - print("--------------------------------------------------------------------2") - tmp <- list() - tmp$href <- lines - tmp$type <- "image/jp2" - inputParameters[[key]] <- tmp - } - else if (!length(lines) > 1 && endsWith(lines, ".zip") && startsWith(lines, "https")) { - print("--------------------------------------------------------------------3") - json_string <- paste(lines, collapse = "\n") - inputParameters[[key]] <- json_string - } else if (!length(lines) > 1 && (endsWith(lines, ".xlsx") || endsWith(lines, ".csv") || grepl("f=csv", lines)) && startsWith(lines, "https")) { - print("--------------------------------------------------------------------4") - json_string <- paste(lines, collapse = "\n") - inputParameters[[key]] <- json_string - } else if (inputParameters$select_process == "plot-image" || - inputParameters$select_process == "reproject-image") { - print("--------------------------------------------------------------------5") - tmp <- list() - tmp$href <- lines - tmp$type <- "image/tiff; application=geotiff" - if (inputParameters$select_process == "reproject-image") { - tmp$type <- "image/tiff; subtype=geotiff" - } - inputParameters[[key]] <- tmp - } else { - print("-----------------------------------6") - json_string <- paste(lines, collapse = "\n") - json_data <- fromJSON(json_string) - inputParameters[[key]] <- json_data - } + + json_string <- paste(lines, collapse = "\n") + inputParameters[[key]] <- json_string + convertedKeys <- append(convertedKeys, key) } else if (grepl("_Array_", key)) { @@ -296,24 +246,15 @@ } inputParameters[[key]] <- convertedValues - print("-------------------------") - print(convertedValues) - print("-------------------------") convertedKeys <- append(convertedKeys, convertedKey) } else { - print("-------------------------") - print(key) - print(inputParameters[[key]]) if (!is.null(inputParameters[[key]])) { convertedKeys <- append(convertedKeys, key) } - print("-------------------------") - } } print(inputParameters) names(inputParameters) <- convertedKeys -#print(inputParameters) print("--> Inputs parsed") print("--> Prepare process execution") |
b |
diff -r 0077885b6f1d -r 1ff618d89af4 aquainfra_ogc_api_processes.xml --- a/aquainfra_ogc_api_processes.xml Mon Oct 14 12:23:01 2024 +0000 +++ b/aquainfra_ogc_api_processes.xml Wed Oct 23 22:35:20 2024 +0000 |
[ |
b'@@ -1,11 +1,11 @@\n-<tool id="aquainfra_ogc_api_processes" name="AquaINFRA OGC API Processes" version="0.1.0" profile="22.05">\n+<tool id="aquainfra_ogc_api_processes" name="AquaINFRA OGC API Processes" version="0.2.0" profile="22.05">\n <description/>\n <macros>\n <import>macros.xml</import>\n </macros>\n-\t<creator>\n+ <creator>\n \t <organization name="EOSC AquaINFRA" url="https://aquainfra.eu/"/>\n-\t</creator>\n+ </creator>\n <expand macro="requirements"/>\n <command detect_errors="exit_code"><![CDATA[\n Rscript \'$__tool_directory__/aquainfra_ogc_api_processes.R\'\n@@ -25,20 +25,21 @@\n <option value="barplot-trend-results">barplot-trend-results: Visualisation of statistical analysis results</option>\n <option value="map-trends-static">map-trends-static: Spatial visualisation of regions and data points</option>\n <option value="map-shapefile-points">map-shapefile-points: Spatial visualisation of regions and data points</option>\n+ <option value="owt-classification">OWT-classification: Optical Water Type classification for ocean, coastal and inland waters</option>\n </param>\n <when value="points-att-polygon">\n <param name="regions" label="Study region or study subregions" optional="false" help="URL (stored in a .txt file) to the study region, or several regions, to classify your input data into groups of interest. Currently it has to be provided as a shapefile. It can be in any coordinate system and will be transformed to WGS84 during this process." type="data" format="txt"/>\n <param name="input_data" label="Table to be merged with study region" optional="false" help="URL (stored in a .txt file) to the input table containing the in-situ data points with coordinates. Can be provided as Excel file or CSV file (comma-separated text file). The coordinates have to be in WGS84 coordinate system." type="data" format="txt"/>\n- <param name="colname_long" label="Column name for longitude" optional="false" help="Name of the column that contains longitude values (in WGS84)." type="text"/>\n- <param name="colname_lat" label="Column name for latitude" optional="false" help="Name of the column that contains latitude values (in WGS84)." type="text"/>\n+ <param name="colname_long" label="Column name for longitude" help="Name of the column that contains longitude values (in WGS84)." type="text"/>\n+ <param name="colname_lat" label="Column name for latitude" help="Name of the column that contains latitude values (in WGS84)." type="text"/>\n </when>\n <when value="peri-conv">\n <param name="input_data" label="Table to be grouped by date, with date colum" help="URL (stored in a .txt file) to the table with a column containing a date. It can have other columns which will not be changed during this process." type="data" format="txt"/>\n <param name="colname_date" label="Date column name" optional="false" help="Column name of the date column in the format defined above. Example: \'visit date\'." type="text"/>\n <param name="date_format" label="Date format" optional="true" help="The date format used to parse the date, i.e. to extract day, month and year from the date column, e.g. or \'y-m-d\' for dates like \'1998-08-22\' (this is the default) or \'y/m/d\' for dates like \'1998/08/22\'." type="select">\n-\t\t\t\t <option value="y-m-d">y-m-d</option>\n+ <option value="y-m-d">y-m-d</option>\n <option value="y/m/d">y/m/d</option>\n-\t\t\t\t</param>\n+ </param>\n <param name="group_to_periods" label="Periods to group the data into" optional="true" help="Define the periods that you want the data to be grouped into. Please follow the example: \'Dec-01:Mar-01,Mar-02:May-30,Jun-01:Aug-30,Sep-01:Nov-30\' (first three letters of each month, then a minus/'..b' optional="false" help="The name of the column containing longitude values for the data points." type="text"/>\n+ <param name="colname_lat" label="Column name for latitude" optional="false" help="The name of the column containing latitude values for the data points." type="text"/>\n+ <param name="colname_value_name" label="Column name of data point identifier" optional="false" help="The name of the column containing identifier (e.g., site name) or values (e.g., depth) to color the points according to their corresponding values." type="text"/>\n+ <param name="colname_region_id" label="Column name of region identifier" optional="false" help="The name of the column containing identifiers (e.g., basin name) to distinguish the polygons on the map if multiple regions are present." type="text"/>\n+ </when>\n+ <when value="owt-classification">\n+ <param name="input_data_url" label="Input data" optional="false" help="URL (stored in a .txt file) to your input file. Find example data on https://github.com/bishun945/pyOWT/tree/main/projects/AquaINFRA." type="data" format="txt"/>\n+ <param name="input_option" label="Type of input" optional="false" help="csv: for text data input (first line wavelength, following lines remote-sensing reflectance). sat: for satellite product input containing reflectance (e.g., Sentinel-3 OLCI Level-2)." type="select">\n+ <option value="csv">csv</option>\n+ <option value="sat">sat</option>\n+ </param>\n+ <param name="sensor" label="Sensor name" optional="false" help="Spectral band configuration of satellite mission (includes adaptation to sensor spectral response functions)." type="select">\n+ <option value="HYPER">HYPER</option>\n+ <option value="AERONET_OC_1">AERONET_OC_1</option>\n+ <option value="AERONET_OC_2">AERONET_OC_2</option>\n+ <option value="CMEMS_BAL_HROC">CMEMS_BAL_HROC</option>\n+ <option value="CMEMS_BAL_NRT">CMEMS_BAL_NRT</option>\n+ <option value="CMEMS_MED_MYINT">CMEMS_MED_MYINT</option>\n+ <option value="CZCS">CZCS</option>\n+ <option value="GOCI">GOCI</option>\n+ <option value="HawkEye">HawkEye</option>\n+ <option value="MERIS">MERIS</option>\n+ <option value="ODIS_Aqua">ODIS_Aqua</option>\n+ <option value="MODIS_Terra">MODIS_Terra</option>\n+ <option value="MSI_S2A">MSI_S2A</option>\n+ <option value="MSI_S2B">MSI_S2B</option>\n+ <option value="OCTS">OCTS</option>\n+ <option value="OLCI_S3A">OLCI_S3A</option>\n+ <option value="OLCI_S3B">OLCI_S3B</option>\n+ <option value="OLI">OLI</option>\n+ <option value="SeaWiFS">SeaWiFS</option>\n+ <option value="VIIRS_JPSS1">VIIRS_JPSS1</option>\n+ <option value="VIIRS_JPSS2">VIIRS_JPSS2</option> \n+ <option value="VIIRS_SNPP">VIIRS_SNPP</option>\n+ </param>\n+ <param name="output_option" label="Output option" help="1: for standard output with five variables. 2: for extensive output including memberships of all water types" optional="false" type="select">\n+ <option value="1">1</option>\n+ <option value="2">2</option>\n+ </param>\n+ </when>\n </conditional>\n </inputs>\n-\t<outputs>\n-\t\t<data name="output_data" format="txt" label="$select_process"/>\n-\t</outputs>\n+ <outputs>\n+ <data name="output_data" format="txt" label="$select_process"/>\n+ </outputs>\n <expand macro="tests"/>\n-\t<expand macro="help" />\n-\t<expand macro="citations"/>\n+ <expand macro="help" />\n+ <expand macro="citations"/>\n </tool>\n' |
b |
diff -r 0077885b6f1d -r 1ff618d89af4 test-data/points_att_polygon_test_input_3.txt --- a/test-data/points_att_polygon_test_input_3.txt Mon Oct 14 12:23:01 2024 +0000 +++ b/test-data/points_att_polygon_test_input_3.txt Wed Oct 23 22:35:20 2024 +0000 |
b |
@@ -1,1 +1,1 @@ -https://aqua.igb-berlin.de/download/data_merged_with_regions-06550086-857a-11ef-8e41-e14810fdd7f8.csv \ No newline at end of file +https://aqua.igb-berlin.de/download/data_merged_with_regions-668a3c72-9039-11ef-aad4-8935a9f30073.csv \ No newline at end of file |