Skip to content

Instantly share code, notes, and snippets.

View kwilcox's full-sized avatar
🎯
ABC

Kyle Wilcox kwilcox

🎯
ABC
View GitHub Profile
@kwilcox
kwilcox / intake.py
Created March 1, 2023 20:28
xpublish-intake
import yaml
import logging
from typing import Sequence
from starlette.routing import NoMatchFound
from fastapi import APIRouter, Depends, Response, Request
from xpublish.utils.api import DATASET_ID_ATTR_KEY
from xpublish.plugins import Dependencies, Plugin, hookimpl
@kwilcox
kwilcox / best_in_forecast.py
Last active November 7, 2017 14:52
Calculating the "best in forecast" for a model.
def forecast_member(dt, timestep_period, forecast_period, runtimes, base_date=None):
# Go back as far as we could go to still be in a forecast
# The datetime won't be in any future forecasts
# Only supporting hourly runtimes so set minutes to 0 so we can match on the "hourly" runtimes
starting = dt - forecast_period
starting = starting.replace(minute=0, second=0, microsecond=0)
compare_dt = copy(dt)
if timestep_period >= timedelta(days=1):
compare_dt = compare_dt.replace(hour=0)
@kwilcox
kwilcox / changes.py
Last active September 11, 2017 19:38
Compare (2) ERDDAP datasest.xml files and output a new one with the active flag set correctly.
#! /usr/bin/env python
import os
import argparse
from lxml import etree
def main(oldxml, newxml, outfile):
oldtree = None
@kwilcox
kwilcox / convert.py
Created August 1, 2017 18:20
Takes Cambell Scientific High Resolution 18-Bit Binary Format and converts it to a CSV row
def decode_campbell_18_bit_binary_message(bites):
"""
Takes Cambell Scientific High Resolution 18-Bit Binary Format and converts
it to a CSV row.
"""
row = []
while True:
# Number are three bytes long
byte_s = bites.read(3)
if not byte_s:
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@kwilcox
kwilcox / ascii.txt
Last active April 26, 2017 20:20
Decode results
-88881,2017,116,18,49,3161,0,105,141,0,3000,-88885,116,1700,50181,2017,116,75104,21342,23429,130,3,8,280,253,245,914,117879,-32873,9,0,0,0,-9999,-9999,-9999,-9999,-9999,-9999,-9999,-9999,-9999,-9999,-9999,-9999,-9999,-9999,-9999,-9999,-9999,-9999,-9999,-9999,-9999,-9999,-9999,-9999,-9999,-9999,-9999,-9999,-9999,-9999,-9999,-9999,-9999,-9999,-9999,-9999,-9999,-9999,-9999,-9999,-9999,-9999,-9999,-9999,-9999,-9999,-9999,-9999,-9999,-9999,-9999,-9999,-9999,-9999,-9999,-9999,-9999,-9999,-9999,-9999,-9999,-9999,-9999,-9999,-9999,-9999,-9999,-9999,-9999,-9999,-9999,-9999,-9999,-9999,-9999,-9999,-9999,-9999,-9999,-9999,-9999,-9999,-9999,-9999,-9999,-9999,-9999,-9999,-9999,-9999,-9999,-9999,-9999,-9999,-9999,-9999,-9999,-9999,-9999,-9999,-9999,-9999,-9999,-9999,-9999,-9999,-9999,-9999,-9999,-9999,-9999,-9999,-9999,-9999,-9999,-9999,-9999,-9999,-9999,-9999,-9999,-9999,-9999,-9999,-9999,-9999,-9999,-9999,-9999,-9999,-9999,-9999,-9999,-9999,-9999,-9999,-9999,-9999,-9999,-9999,-9999,-9999,-9999,-9999,-9999,-9999,-9999,-99
@kwilcox
kwilcox / difference.py
Created January 6, 2017 21:41
Write out an ERDDAP `datasets.xml` after comparing and old and new file for dataset removals.
#! /usr/bin/env python
import os
import argparse
from lxml import etree
def main(oldxml, newxml, outfile):
oldtree = None
@kwilcox
kwilcox / packages.txt
Created December 2, 2016 21:48
CC conda issue
/data/Development/compliance-checker   stringerror ✔ 
$ conda list
# packages in environment at /home/kwilcox/miniconda3/envs/cc35:
#
Using Anaconda API: https://api.anaconda.org
arrow 0.8.0 py35_0 conda-forge
ca-certificates 2016.9.26 0 conda-forge
certifi 2016.9.26 py35_0 conda-forge
cf_units 1.1.3 py35_0 conda-forge
curl 7.49.1 1 conda-forge
@kwilcox
kwilcox / convert.ipynb
Last active October 14, 2016 14:22
NetCDF to JSON
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@kwilcox
kwilcox / crawl.py
Created October 3, 2016 16:26
OOI Thredds Catalog Crawl
In [1]: from thredds_crawler.crawl import Crawl
In [2]: url = 'http://opendap.oceanobservatories.org:8090/thredds/catalog/ooi-preliminary-datasets/Coastal_Endurance/CE05MOAS/05-CTDGVM000/recovered_host/catalog.html'
In [3]: c = Crawl(url, debug=True)
2016-10-03 12:25:45,151 - [INFO] Crawling: http://opendap.oceanobservatories.org:8090/thredds/catalog/ooi-preliminary-datasets/Coastal_Endurance/CE05MOAS/05-CTDGVM000/recovered_host/catalog.html
2016-10-03 12:25:45,294 - [DEBUG] Processing ooi-preliminary-datasets/Coastal_Endurance/CE05MOAS/05-CTDGVM000/recovered_host/CE05MOAS-GL319-05-CTDGVM000-ctdgv_m_glider_instrument_recovered-recovered_host/CE05MOAS-GL319-05-CTDGVM000-ctdgv_m_glider_instrument_recovered-recovered_host.ncml
2016-10-03 12:25:45,294 - [DEBUG] Processing ooi-preliminary-datasets/Coastal_Endurance/CE05MOAS/05-CTDGVM000/recovered_host/CE05MOAS-GL319-05-CTDGVM000-ctdgv_m_glider_instrument_recovered-recovered_host/CE05MOAS-GL319-05-CTDGVM000-recovered_host-ctdgv_m_glider_instrument_recovered-20140