def main(): parser = argparse.ArgumentParser(description='Update analysis departures') parser.add_argument('-d','--db', dest="sqlitefile", default=None, type=str,help='Name of database to write',required=True) parser.add_argument('-a','--an', dest="anfile", default=None, type=str,help='Name of analysis file',required=True) parser.add_argument('-v', '--var', dest="var", default=None, type=str, help='Name of variable',required=True) if len(sys.argv) == 1: parser.print_help() sys.exit(1) args = parser.parse_args() conn = sqlite3.connect(args.sqlitefile) c = conn.cursor() c.execute("SELECT lon, lat,name, value, fgdep, elevation, status FROM obs WHERE name == '"+args.var+"'") data = c.fetchall() observations=list() for row in data: lon = row[0] lat = row[1] name= row[2] value= row[3] fgdep= row[4] elevation=row[5] obsQ=obsQuality(15) observations+=[observation(name,lon,lat,value,obsQ,elevation=elevation,fgdep=fgdep)] conn.close() db=sqlite(args.sqlitefile) calculateDeparture(args.anfile,args.var,observations,"an") db.update(observations)
def __init__(self, master_only, slave_only, slave_timeout, no_cache): self.master_only = master_only self.slave_only = slave_only self.slave_timeout = slave_timeout self._q = queue.Queue() self.no_cache = no_cache self.cache = IthoWPUCache() self.nodeid = self.get("getnodeid") self.datatype = self.get("getdatatype") self.heatpump_db = db.sqlite("heatpump.sqlite")
def convert(par_file, sqlite_db): par_file = par_file.replace("$", "\\$") par_conn = pyodbc.connect(f"DRIVER={{MDBTools}};DBQ={par_file};") par_conn.setencoding("UTF-8") par_conn.setdecoding(pyodbc.SQL_CHAR, encoding="UTF-8") par_cur = par_conn.cursor() sqlite_db = db.sqlite(sqlite_db) tables = [] for table_info in par_cur.tables(tableType="TABLE"): if re.match("^(VersieBeheer|Data[Ll]abel|Parameterlijst)", table_info.table_name): tables.append(table_info.table_name) for t in sorted(tables): sqlite_db.create_table(t.lower()) data = [] if re.match("^Data[Ll]abel", t): par_cur.execute( f"select Index, Naam, Tekst_NL, Tooltip_NL, Eenheid_NL from {t}" ) rows = par_cur.fetchall() for r in sorted(rows): data.append( (r.Index, r.Naam, r.Tekst_NL, r.Tooltip_NL, r.Eenheid_NL)) if re.match("^Parameterlijst", t): par_cur.execute( "select Index, Naam, Naam_fabriek, Min, Max, Default, " f"Tekst_NL, Omschrijving_NL, Eenheid_NL from {t}") rows = par_cur.fetchall() for r in sorted(rows): data.append(( r.Index, r.Naam, r.Naam_fabriek, r.Min, r.Max, r.Default, r.Tekst_NL, r.Omschrijving_NL, r.Eenheid_NL, )) if re.match("^VersieBeheer", t): par_cur.execute( f"select VersieNummer, DataLabel, ParameterLijst from {t}") rows = par_cur.fetchall() for r in sorted(rows): data.append((r.VersieNummer, r.DataLabel, r.ParameterLijst)) sqlite_db.insert(t.lower(), data)
def main(): parser = argparse.ArgumentParser( description='Convert TITAN output to SQLite') parser.add_argument('-i', dest="input", help='Input file', required=True) parser.add_argument('-o', dest="output", help='Output SQLite file', required=True) parser.add_argument('--debug', dest="debug", help='Show debug information', action="store_true") parser.add_argument('--delim', dest="delim", type=str, help='Delimiter', default=";") parser.add_argument('-f', '--fg', dest="fgfile", default=None, type=str, help='Name of first guess file') parser.add_argument('-v', '--var', dest="var", default=None, type=str, help='Name of variable') if len(sys.argv) == 1: parser.print_help() sys.exit(1) args = parser.parse_args() db = sqlite(args.output) observations = readInput(args.var, args.input, args.delim) # First guess check if args.fgfile is not None: calculateDeparture(args.fgfile, args.var, observations, "fg") db.update(observations)
def main(): parser = argparse.ArgumentParser( description= 'Create parameter file for calibration methods (currently OI and override) in gridpp.i The program reads TITAN output and puts observed and CI values into the parameter file. If CI (rep column) is missing in the input, then a default value is used.' ) parser.add_argument('files', help='Input file', nargs="*") parser.add_argument('-o', help='Output file', dest="ofilename", required=True) parser.add_argument( '-k', metavar="FLAGS", help= 'Only keep rows with these DQC flags. Comma-separated list accepted.', dest="keep") parser.add_argument('-m', default="oi", help='Write parameters for this method (default oi).', dest="method", choices=["oi", "override"]) parser.add_argument( '-p', metavar="PROVIDERS", help= 'Only keep rows with these providers. Comma-separated list accepted.', dest="providers") parser.add_argument( '-latrange', help='Only keep stations within these latitudes (min,max)', dest="latrange") parser.add_argument( '-lonrange', help='Only keep stations within these longitudes (min,max)', dest="lonrange") parser.add_argument( '--add', type=float, default=0, help='Add this value to the values (e.g. to change units)', dest="add") parser.add_argument('--delim', default=';', help='Delimiter separating columns', dest="delim") parser.add_argument( '--multiply', type=float, default=1, help='Multiply this value to the values (e.g. to change units)', dest="multiply") parser.add_argument('--override_ci', type=float, help='Override CI values with this value (if -m oi)', dest="override_ci") parser.add_argument( '--default_ci', default=1, type=float, help='Use this value if CI is missing (if -m oi; default 1)', dest="default_ci") parser.add_argument('--debug', help='Show debug information', action="store_true") parser.add_argument('-d', '--db', dest="sqlitefile", default=None, type=str, help='Name of database to write') parser.add_argument('-f', '--fg', dest="fgfile", default=None, type=str, help='Name of first guess file') parser.add_argument('-v', '--var', dest="var", default=None, type=str, help='Name of variable') if len(sys.argv) == 1: parser.print_help() sys.exit(1) args = parser.parse_args() # Setup database db = None if args.sqlitefile is not None: db = sqlite(args.sqlitefile) print args.files delim = [",", ";"] keep = [None, "0"] files = args.files add = [0, 273.15] multiply = [1, 1] fgcheck = [True, False] if any(fgcheck) and args.fgfile is None: print "You must specify a first guess file" sys.exit(1) observations = list() for file in range(0, len(files)): print files[file] # Read observations observations_read = readInput(args.var, files[file], args.lonrange, args.latrange, keep[file], args.providers, delim[file], args.default_ci, args.override_ci, add[file], multiply[file]) # First guess check if args.fgfile is not None: calculateDeparture(args.fgfile, args.var, observations_read, "fg") if fgcheck[file]: print "Performing First Guess Check" FGCheck(observations_read, db) observations = observations + observations_read if args.sqlitefile is not None: db.update(observations) # Write parameter file writeParamFile(args.ofilename, observations, method=args.method)