Crocetti2023

Will return the ZWD prediction for a requested latitude, longitude, height, and time/timespan.
The model will only return ZWD predictions at full hours. If the query time or timespan does not cover full hours, the surrounding time is provided.
For example: if the query time is 00:03:00, it will return a ZWD prediction for 00:00:00 and one for 01:00:00.
Interpolation to 00:03:00 must be performed by the user. 

Important: ZWD predictions using the Crocetti2023 approach are limited to the year 2019! For predictions outside 2019, use the Crocetti2024 approach.

Parameter Value Example
"lat" Query latitude in degrees -15.322
"lon" Query longitude in degrees 302.231
"height" Query height in meters (WGS84) 132.13
"time"1 String, query time. Format: "yyyy-mm-dd HH:MM:SS" "2019-01-31 12:34:56"
"time_range"1 String, query timespan. Format: "yyyy-mm-dd HH:MM:SS/yyyy-mm-dd HH:MM:SS" "2019-01-31 12:34:56/2019-01-31 14:02:10"
¹ only one parameter type per query

Return: Dictinary with following key/value pairs:

Key Value Example
"zwd" Dictionary with time as key and predicted ZWD in millimeter as value "zwd":{"2019-01-01 00:00:00":80.79846954345703,"2019-01-01 01:00:00":76.88582611083984}
"source" Dictionary with time as key and data source of meteorological features ("ERA5(T)" or "yyyy-mm-dd.HH" indicating forecast file) as value "source":{"2019-01-01 00:00:00":"ERA5(T)","2019-01-01 01:00:00":"ERA5(T)"}
"_duration_load_q" Duration to load meteorological parameters "_duration_load_q":"0.1 [s]"
"_duration_predict" Duration to make ZWD predictions "_duration_predict":"0.0 [s]"
"_model" Machine learning model version "_model":"v000"
"_unit" ZWD unit "_unit":"[mm]"

Crocetti2024

Currently under development

Examples

curl

Can be executed from most terminals:
Request for time:
curl -L -H"Content-Type: application/json" -d '{"lat":12.1311,"lon":13.1313,"height":331.131,"time":"2019-01-01 00:00:00"}' https://test-zwd.space01.phys.ethz.ch/Crocetti2023
Request for timespan:
curl -L -H"Content-Type: application/json" -d '{"lat":12.1311,"lon":13.1313,"height":331.131,"time_range":"2019-01-01 00:00:00/2019-03-01 23:00:00"}' https://test-zwd.space01.phys.ethz.ch/Crocetti2023

Python

import requests
import json

url = "https://test.space01.phys.ethz.ch/return_sum"

headers = {
    "Content-Type": "application/json"
}

data = {
    "lat": 12.1311,
    "lon": 13.1313,
    "height": 331.131,
#    "time": "2019-01-01 00:00:00"                            # request for time
    "time_range": "2019-01-01 00:00:00/2019-01-01 23:00:00"   # request for timespan
}

response = requests.post(url, headers=headers, data=json.dumps(data))

if response.status_code == 200:
    print("Request was successful")
    print(response.text)
else:
    print(f"Request failed with status code {response.status_code}")
if you want to get your ZWD as a Pandas DataFrame, you can simply convert it:
import pandas as pd

...
if response.status_code == 200:
    data = response.json()
    df = pd.DataFrame.from_dict(data["zwd"], orient="index", columns=["ZWD"])
    df.index = pd.to_datetime(df.index)

Matlab

url = 'https://test-zwd.space01.phys.ethz.ch/Crocetti2023/';

data = struct(...
    'lat', 12.1311, ...
    'lon', 13.1313, ...
    'height', 331.131, ...
    ... % 'time', '2019-01-01 00:00:00' ...                       % request for time   
    'time_range', '2019-01-01 00:00:00/2019-01-01 23:00:00' ...   % request for timespan
);

options = weboptions('RequestMethod', 'post');
options.HeaderFields = {'Content-Type', 'application/json'};

request = matlab.net.http.RequestMessage;
uri = matlab.net.URI(url);
[response,completedrequest,history] = send(request,uri);
finaluri = history(end).URI;

response = webwrite(url, data, options);

disp(response);
disp(response.zwd)

C++

CMakeLists.txt
cmake_minimum_required(VERSION 3.17)
project(project_name)

# Find the libcurl package
find_package(CURL REQUIRED)

set(CMAKE_CXX_STANDARD 20)

add_executable(project_name main.cpp)

# Link against the libcurl library
target_link_libraries(project_name CURL::libcurl)
main.cpp
#include <iostream>
#include <string>
#include <curl/curl.h>

// Callback function to capture response data
size_t WriteCallback(void* contents, size_t size, size_t nmemb, std::string* output) {
    size_t totalSize = size * nmemb;
    output->append(static_cast<char*>(contents), totalSize);
    return totalSize;
}


int main() {
    // Initialize libcurl
    CURL* curl = curl_easy_init();
    if (curl) {
        // Set the URL
        const char* url = "https://test-zwd.space01.phys.ethz.ch/Crocetti2023";
        curl_easy_setopt(curl, CURLOPT_URL, url);

        // Set the request headers
        struct curl_slist* headers = nullptr;
        headers = curl_slist_append(headers, "Content-Type: application/json");
        curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);

        // Set the request data
        const char* data = "{\"lat\":12.1311,\"lon\":13.1313,\"height\":331.131,\"time\":\"2019-01-01 00:00:00\"}";
        curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data);

        // Follow redirects
        curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);

        // Response data
        std::string response_data;

        // Set the callback to capture the response data
        curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback);
        curl_easy_setopt(curl, CURLOPT_WRITEDATA, &response_data);

        // Perform the request
        CURLcode res = curl_easy_perform(curl);

        // Check for errors
        if (res != CURLE_OK) {
            std::cerr << "curl_easy_perform() failed: " << curl_easy_strerror(res) << std::endl;
        } else {
            // Response data is now in 'response_data'
            std::cout << "Response Data: " << response_data << std::endl;

            // Parse the JSON response to access the "zwd" variable
            // You'll need a JSON parsing library for this task
            // For example, you can use a library like nlohmann/json, or cJSON.

            // Example parsing using nlohmann/json:
            // #include <nlohmann/json.hpp>
            // nlohmann::json json_response = nlohmann::json::parse(response_data);
            // double zwd = json_response["zwd"];
            // std::cout << "zwd: " << zwd << std::endl;
        }

        // Cleanup
        curl_slist_free_all(headers);
        curl_easy_cleanup(curl);
    }

    return 0;
}