Skip to content

Instantly share code, notes, and snippets.

@kinverarity1
Created August 25, 2017 12:21
Show Gist options
  • Save kinverarity1/775cb09758416780c90f5a45f4edb416 to your computer and use it in GitHub Desktop.
Save kinverarity1/775cb09758416780c90f5a45f4edb416 to your computer and use it in GitHub Desktop.
'''drillerslog2wellcad.py - convert GD logs to WellCAD formats
This script converts drillers logs (also in the future lithological,
hydrostratigraphic, and stratigraphic) from the Groundwater Data (GD) section of
the WaterConnect website into formats suitable for direct import into
WellCAD software.
Usage is pretty straightforward. The easiest way is to download the CSV file
from GD, which produces a file by default called ``WellDownload.csv``. Then run
this script in that folder, and it will produce a file titled
``drillers_UNITNO.wac``
This is in the format suitable for importing directly into WellCAD as a comment
log (a .wac file). UNITNO is replaced by the unit number of the well in question,
which comes from the WellDownload.csv.
In the future I'll make it so it also creates WellCAD lith logs (.wal files)
and perhaps strat logs too.
'''
import argparse
import sys
import pandas
INPUT_CHOICES = ["drillers", "lith", "hydrostrat", "strat"]
OUTPUT_CHOICES = ["comment", "lith", "all"]
def main():
p = argparse.ArgumentParser()
p.add_argument("-o", "--output", choices=OUTPUT_CHOICES, default="all")
p.add_argument("-i", "--input", choices=INPUT_CHOICES, default="drillers")
p.add_argument("-I", "--input-filename", default="WellDownload.csv")
args = p.parse_args(sys.argv[1:])
with open(args.input_filename, mode="r") as inputf:
dl = pandas.read_csv(inputf)
out_fn_base = "%s_%s" % (args.input, str(dl.Unit_No[0]))
if args.output == "all":
output_types = list(OUTPUT_CHOICES[:-1])
else:
output_types = [args.output]
for output_type in output_types:
if output_type == "comment":
ext = "wac"
out_fn = out_fn_base + "." + ext
d = pandas.DataFrame()
d["TopDepth"] = dl["depth_from"]
d["BottomDepth"] = dl["depth_to"]
d["comment"] = dl["description"]
with open(out_fn, mode="w") as outputf:
d.to_csv(outputf, index=False)
elif output_type == "lith":
raise Exception("Not supported yet")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment