owi2nclight.py 1.18 KB
Newer Older
1 2
#!/usr/bin/env python

ARCHER's avatar
ARCHER committed
3
import sys
4 5 6 7 8
import owi
import argparse
import sys
import netCDF4
import datetime
ARCHER's avatar
ARCHER committed
9 10 11 12 13 14 15 16 17
import logging

logging.basicConfig()
logger = logging.getLogger(__name__)

if sys.gettrace():
    logger.setLevel(logging.DEBUG)
else:
    logger.setLevel(logging.INFO)
18 19 20 21 22 23 24

if __name__ == "__main__":
    description = """Converts owi nc file to lightweight nc format"""
    parser = argparse.ArgumentParser(description = description)
    parser.add_argument('infile')
    parser.add_argument('outfile')
    args = parser.parse_args()
ARCHER's avatar
ARCHER committed
25
    logger.info("read %s" % args.infile)
26 27 28 29 30
    data = owi.readFile(args.infile)
    meta = owi.readMeta(args.infile)
    startdate = datetime.datetime.strptime(owi.getAttribute(args.infile,'firstMeasurementTime'),"%Y-%m-%dT%H:%M:%SZ")
    stopdate = datetime.datetime.strptime(owi.getAttribute(args.infile,'lastMeasurementTime'),"%Y-%m-%dT%H:%M:%SZ")
    owi.writeLight(args.outfile,data,startdate + (stopdate - startdate) / 2,meta=meta)
ARCHER's avatar
ARCHER committed
31
    logger.info("wrote %s" % args.outfile)
32
    
ARCHER's avatar
ARCHER committed
33 34 35

    # gdaldem color-relief  NETCDF:"/tmp/test_gd.nc":wind_speed wind_speed.txt /tmp/testowi1.tif -alpha
    # gdal_translate -of GTiff NETCDF:"/tmp/test_gd.nc":wind_speed /tmp/testowi.tif