Toggle Light / Dark / Auto color theme
Toggle table of contents sidebar
Exchange Checker/Converter
The exchange checker/converter is a fully in browser (no server side processing) file converter for the WHP Exchange format to the newer CF/netCDF format.
It will also output the other legacy formats at CCHDO: WOCE, the COARDS netCDF formats, and a WOCE sum file.
This converter is only available in the html/browser versions of the documentation.
Note
Processing a CTD file can take a long time and I don’t yet know how to show progress in the browser.
Warning
This has been pinned to an older version of cchdo.hydro while numpy 2 support is worked on in pyodide.
cchdo.hydro version:
cchdo.params version:
Add an exchange file (csv or zip)
Options
Check Flags
Process Exchange
from js import document, console, window, Uint8Array, Blob
from pyodide.ffi import create_proxy
import asyncio
import io
import traceback
from cchdo.hydro import read_exchange
from cchdo.hydro import accessors
from cchdo.hydro import __version__ as hydro_version
from cchdo.params import __version__ as params_version
Element("hydro_version").element.innerText = hydro_version
Element("params_version").element.innerText = params_version
import logging
import sys
root = logging.getLogger()
root.setLevel(logging.DEBUG)
handler = logging.StreamHandler(sys.stderr)
handler.setLevel(logging.DEBUG)
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
handler.setFormatter(formatter)
root.addHandler(handler)
async def load_ex_bytes(ex_bytes, checks):
return read_exchange(ex_bytes, checks=checks)
async def to_netcdf(ex):
ex.to_netcdf("out.nc")
with open("out.nc", "rb") as f:
return f.read()
async def to_coards(ex):
return ex.cchdo.to_coards()
async def to_woce(ex):
return ex.cchdo.to_woce()
async def to_xarray_callback(arg):
bytes = bytearray(Uint8Array.new(arg))
ex_bytes = io.BytesIO(bytes)
status = Element("status")
check_flags = Element("checks_flags").element.checked
checks = {
"flags": check_flags
}
try:
ex = await load_ex_bytes(ex_bytes, checks=checks)
except ValueError as er:
traceback.print_exception(er)
status.element.innerText = f"Failure see traceback..."
Element("process_exchange").element.disabled = False
return
status.element.innerText = f"Success, generating files"
await asyncio.sleep(0.1)
try:
nc = await to_netcdf(ex)
nc_blob = Blob.new([Uint8Array.new(nc)], {type : 'application/netcdf'})
nc_url = window.URL.createObjectURL(nc_blob)
nc_download_link = document.createElement("a")
nc_download_link.href = nc_url
nc_fname = ex.cchdo.gen_fname()
nc_download_link.download = nc_fname
nc_download_link.innerText = f"Download CF/netCDF: {nc_fname}"
output = Element("output")
output.element.appendChild(nc_download_link)
output.element.appendChild(document.createElement("br"))
except Exception as er:
status.element.innerText = f"Could not generate CF/netCDF"
await asyncio.sleep(0.1)
#status.element.innerText = f"Generating COARDS netCDF (very slow)"
#await asyncio.sleep(0.1)
#try:
# coards = await to_coards(ex)
# coards_blob = Blob.new([Uint8Array.new(coards)], {type : 'application/octet-stream'})
# coards_url = window.URL.createObjectURL(coards_blob)
# coards_download_link = document.createElement("a")
# coards_download_link.href = coards_url
# coards_download_link.download = "coards_nc.zip"
# coards_download_link.innerText = "Download COARDS netcdf zip"
# output = Element("output")
# output.element.appendChild(coards_download_link)
# output.element.appendChild(document.createElement("br"))
#except Exception as ex:
# print(ex)
# status.element.innerText = f"Could not generate COARDS netCDF"
await asyncio.sleep(0.1)
status.element.innerText = f"Generating WOCE Files"
await asyncio.sleep(0.1)
try:
woce = await to_woce(ex)
woce_blob = Blob.new([Uint8Array.new(woce)], {type : 'application/octet-stream'})
woce_url = window.URL.createObjectURL(woce_blob)
woce_download_link = document.createElement("a")
woce_download_link.href = woce_url
woce_download_link.download = "woce_output.txt"
woce_download_link.innerText = "Download Woce (might be txt or zip)"
output = Element("output")
output.element.appendChild(woce_download_link)
output.element.appendChild(document.createElement("br"))
except:
status.element.innerText = f"Could not generate WOCE"
await asyncio.sleep(0.1)
try:
summary = ex.cchdo.to_sum()
summary_blob = Blob.new([Uint8Array.new(summary)], {type : 'application/octet-stream'})
summary_url = window.URL.createObjectURL(summary_blob)
summary_download_link = document.createElement("a")
summary_download_link.href = summary_url
summary_download_link.download = "woce_sum.txt"
summary_download_link.innerText = "Download Woce Sumfile"
output = Element("output")
output.element.appendChild(summary_download_link)
output.element.appendChild(document.createElement("br"))
except:
status.element.innerText = f"Could not generate WOCE"
Element("process_exchange").element.disabled = False
status.element.innerText = "File Generation Complete"
def _process_exchange():
Element("process_exchange").element.disabled = True
try:
status = Element("status")
status.element.innerText = "Processing..."
file_list = Element("ex_file").element.files
first_item = file_list.item(0)
first_item.arrayBuffer().then(to_xarray_callback)
except:
status.element.innerText = "Error, was a file picked?"
Element("process_exchange").element.disabled = False
Python Log Console
packages = ["xarray", "cchdo.hydro<=1.0.2.8", "netcdf4"]
[[interpreters]]
src = "https://cdn.jsdelivr.net/pyodide/v0.26.2/full/pyodide.js"
name = "pyodide-0.26.2"
lang = "python"