def write_data(file, data, buttons, start_date, elevation): status.insert(END, "Writing output file...\n") index = status.window.index("end linestart") lno = int(float(index))-1 for i in range(len(data)): status.replace(lno, "Processing data record %d..." % i) # output data according to the checkbuttons file.write(" ") if buttons.rel_date.query() == 1: file.write(" %7.3f" % (data[i].time,)) if buttons.abs_date.query() == 1: file.write(" %13.3f" % (data[i].time + start_date,)) if buttons.time_str.query() == 1: (year, month, day, h, m, s) = grav_util.un_jday(data[i].time + start_date) file.write("%02d/%02d/%04d %02d:%02d:%02d"%(month,day,year, h,m,s)) if buttons.station_id.query() == 1: file.write(" %25s" % (data[i].station_id,)) if buttons.gravity.query() == 1: file.write(" %8.3f" % (data[i].gravity,)) if buttons.sigma.query() == 1: file.write(" %6.3f" % (data[i].sigma,)) if buttons.tilt_x.query() == 1: file.write(" %3d" % (data[i].tilt_x,)) if buttons.tilt_y.query() == 1: file.write(" %3d" % (data[i].tilt_y,)) if buttons.temp.query() == 1: file.write(" %6.3f" % (data[i].temp,)) if buttons.etc.query() == 1: file.write(" %6.3f" % (data[i].etc,)) if buttons.tetc.query() == 1: if buttons.flip_lat.query() == 1: lat = -1*data[i].meterInfo.Lat else: lat = data[i].meterInfo.Lat if buttons.flip_lon.query() == 1: lon = -1*data[i].meterInfo.Lon else: lon = data[i].meterInfo.Lon (year, month, day, hour, minute, second)=grav_util.un_jday(data[i].jul_day) data[i].elevation = elevation gmt_off = data[i].GMT_Diff if buttons.flip_GMT.query() == 1: gmt_off = -1*gmt_off C = tamura.tide(year, month, day, hour, minute, second, data[i].meterInfo.Lon, data[i].meterInfo.Lat, data[i].elevation, 0.0, gmt_off) if C == 3e38: # Error in input values! tide_error(i, data[i].jul_day, year, month, day, hour, minute, second, lat, lon, data[i].elevation, gmt_off) C = 0.0 file.write(" %6.3f" % (C/1000.0,)) if buttons.duration.query() == 1: file.write(" %4d" % (data[i].duration,)) if buttons.rejects.query() == 1: file.write(" %4d" % (data[i].rejects,)) if buttons.lat.query() == 1: file.write(" %7.3f" % (data[i].Lat,)) if buttons.lon.query() == 1: file.write(" %8.3f" % (data[i].Lon,)) file.write("\n")
def correction(date, lat, lon, ele, gmt): # compute Tamura ETC (year, month, day, hour, minute, second) = grav_util.un_jday(date) C = etc.tide(year, month, day, hour, minute, second, lon, lat, ele, 0.0, gmt) # Tamura's routine yields results in microgal! return C / 1000.0
def correction(date, lat, lon, ele, gmt): # compute Tamura ETC (year, month, day, hour, minute, second)=grav_util.un_jday(date) C = etc.tide(year, month, day, hour, minute, second, lon, lat, ele, 0.0, gmt) # Tamura's routine yields results in microgal! return C/1000.0
def cmd_write_data(file, data, fields, start_date, elevation): for i in range(len(data)): # output data according to fields file.write(" ") if fields.rel_date == 1: file.write(" %10.6f" % (data[i].time, )) if fields.abs_date == 1: file.write(" %20.6f" % (data[i].time + start_date, )) if fields.time_str == 1: (year, month, day, h, m, s) = grav_util.un_jday(data[i].jul_day) file.write(" %02d/%02d/%04d %02d:%02d:%02d" % (month, day, year, h, m, s)) if fields.station_id == 1: file.write(" %25s" % (data[i].station_id, )) if fields.gravity == 1: file.write(" %8.3f" % (data[i].gravity, )) if fields.tilt_x == 1: file.write(" %6d" % (data[i].tilt_x, )) if fields.tilt_y == 1: file.write(" %6d" % (data[i].tilt_y, )) if fields.temp == 1: file.write(" %6.2f" % (data[i].temp, )) if fields.tetc == 1: (year, month, day, hour, minute, second) = grav_util.un_jday(data[i].jul_day) data[i].elevation = elevation C = earth_tide(year, month, day, hour, minute, second, data[i].Lon, data[i].Lat, data[i].elevation, 0.0, data[i].GMT_Diff) if C == 3e38: # Error in input values! cmd_tide_error(i, data[i].jul_day, year, month, day, hour, minute, second, data[i].Lat, data[i].Lon, data[i].elevation, data[i].GMT_Diff) C = 0.0 file.write(" %6.3g" % (C / 1000.0, )) if fields.lat == 1: file.write(" %7.3f" % (data[i].Lat, )) if fields.lon == 1: file.write(" %8.3f" % (data[i].Lon, )) if fields.GMT == 1: file.write(" %8.3f" % (data[i].GMT_Diff, )) file.write("\n")
def cmd_write_data(file, data, fields, start_date, elevation): for i in range(len(data)): # output data according to fields file.write(" ") if fields.rel_date == 1: file.write(" %10.6f" % (data[i].time,)) if fields.abs_date == 1: file.write(" %20.6f" % (data[i].time + start_date,)) if fields.time_str == 1: (year, month, day, h, m, s) = grav_util.un_jday(data[i].jul_day) file.write(" %02d/%02d/%04d %02d:%02d:%02d"%(month,day,year, h,m,s)) if fields.station_id == 1: file.write(" %25s" % (data[i].station_id,)) if fields.gravity == 1: file.write(" %8.3f" % (data[i].gravity,)) if fields.tilt_x == 1: file.write(" %6d" % (data[i].tilt_x,)) if fields.tilt_y == 1: file.write(" %6d" % (data[i].tilt_y,)) if fields.temp == 1: file.write(" %6.2f" % (data[i].temp,)) if fields.tetc == 1: (year, month, day, hour, minute, second)=grav_util.un_jday(data[i].jul_day) data[i].elevation = elevation C = earth_tide(year, month, day, hour, minute, second, data[i].Lon, data[i].Lat, data[i].elevation, 0.0, data[i].GMT_Diff) if C == 3e38: # Error in input values! cmd_tide_error(i, data[i].jul_day, year, month, day, hour, minute, second, data[i].Lat, data[i].Lon, data[i].elevation, data[i].GMT_Diff) C = 0.0 file.write(" %6.3g" % (C/1000.0,)) if fields.lat == 1: file.write(" %7.3f" % (data[i].Lat,)) if fields.lon == 1: file.write(" %8.3f" % (data[i].Lon,)) if fields.GMT == 1: file.write(" %8.3f" % (data[i].GMT_Diff,)) file.write("\n")
def correction(data): try: import etc earth_tide = etc.tide except: earth_tide = tamura.tide for i in range(len(data)): # compute Tamura ETC (year, month, day, hour, minute, second) = grav_util.un_jday(data[i].jul_day) C = earth_tide(year, month, day, hour, minute, second, data[i].lon, data[i].lat, data[i].elevation, 0.0, data[i].GMT_Diff) #C = tamura.tide(year, month, day, hour, minute, second, data[i].lon, # data[i].lat, data[i].elevation, 0.0, Offset) # Tamura's routine yields results in microgal! data[i].etc_correction = C / 1000.0
if Flip_Lon: data[i].meterInfo.Lon = -1*data[i].meterInfo.Lon if Flip_Lat: data[i].meterInfo.Lat = -1*data[i].meterInfo.Lat if Flip_GMT: data[i].GMT_Diff = -1*data[i].GMT_Diff if Verbose: print "Done." # # Apply Tamura ETC to readings if Apply_Tamura: if Verbose: print "Applying Tamura ETC..." for i in range(len(data)): (year, month, day, hour, minute, second)=grav_util.un_jday(data[i].jul_day) data[i].elevation = elevation C = tamura.tide(year, month, day, hour, minute, second, data[i].meterInfo.Lon, data[i].meterInfo.Lat, data[i].elevation, 0.0, data[i].GMT_Diff) if C == 3e38: print "Error computing Tamura ETC for record #%d. No correction applied"%i C = 0.0 data[i].gravity = data[i].gravity + (C/1000.0) # # Apply temp correction if desired if tempThresh != 0.0: if Verbose: print "Correcting Temp. corrections outside +-%f mK"%abs(tempThresh) temp_correct.fix(data, tempThresh)
def cmd_write_data(file, data, fields, Verbose, start_date, elevation): if Verbose: sys.stdout.write("\nProcessing data point ") for i in range(len(data)): if Verbose: sys.stdout.write("%08d\b\b\b\b\b\b\b\b" % i) sys.stdout.flush() # output data according to fields file.write(" ") if fields.rel_date == 1: file.write(" %10.6f" % (data[i].time, )) if fields.abs_date == 1: file.write(" %20.6f" % (data[i].time + start_date, )) if fields.time_str == 1: (year, month, day, h, m, s) = grav_util.un_jday(data[i].jul_day) file.write(" %02d/%02d/%04d %02d:%02d:%02d" % (month, day, year, h, m, s)) if fields.station_id == 1: file.write(" %25s" % (data[i].station_id, )) if fields.gravity == 1: file.write(" %8.3f" % (data[i].gravity, )) if fields.sigma == 1: file.write(" %6.3f" % (data[i].sigma, )) if fields.tilt_x == 1: file.write(" %3d" % (data[i].tilt_x, )) if fields.tilt_y == 1: file.write(" %3d" % (data[i].tilt_y, )) if fields.temp == 1: file.write(" %6.3f" % (data[i].temp, )) if fields.outside_temp == 1: file.write(" %6.3f" % (data[i].outsideTemp, )) if fields.tempCorr == 1: if hasattr(data[i], "uncorrected_temp"): temp = data[i].uncorrected_temp[1] grav = data[i].uncorrected_temp[0] else: temp = data[i].temp grav = data[i].gravity file.write(" %6.3f %6.3f" % (temp, grav)) if fields.etc == 1: file.write(" %6.3f" % (data[i].etc, )) if fields.tetc == 1: (year, month, day, hour, minute, second) = grav_util.un_jday(data[i].jul_day) data[i].elevation = elevation C = tamura.tide(year, month, day, hour, minute, second, data[i].meterInfo.Lon, data[i].meterInfo.Lat, data[i].elevation, 0.0, data[i].GMT_Diff) if C == 3e38: # Error in input values! cmd_tide_error(i, data[i].jul_day, year, month, day, hour, minute, second, data[i].meterInfo.Lat, data[i].meterInfo.Lon, data[i].elevation, data[i].GMT_Diff) C = 0.0 file.write(" %6.3g" % (C / 1000.0, )) if fields.duration == 1: file.write(" %4d" % (data[i].duration, )) if fields.rejects == 1: file.write(" %4d" % (data[i].rejects, )) if fields.lat == 1: file.write(" %7.3f" % (data[i].meterInfo.Lat, )) if fields.lon == 1: file.write(" %8.3f" % (data[i].meterInfo.Lon, )) if fields.GMT == 1: file.write(" %8.3f" % (data[i].GMT_Diff, )) file.write("\n")
data[i].meterInfo.Lon = -1 * data[i].meterInfo.Lon if Flip_Lat: data[i].meterInfo.Lat = -1 * data[i].meterInfo.Lat if Flip_GMT: data[i].GMT_Diff = -1 * data[i].GMT_Diff if Verbose: print "Done." # # Apply Tamura ETC to readings if Apply_Tamura: if Verbose: print "Applying Tamura ETC..." for i in range(len(data)): (year, month, day, hour, minute, second) = grav_util.un_jday(data[i].jul_day) data[i].elevation = elevation C = tamura.tide(year, month, day, hour, minute, second, data[i].meterInfo.Lon, data[i].meterInfo.Lat, data[i].elevation, 0.0, data[i].GMT_Diff) if C == 3e38: print "Error computing Tamura ETC for record #%d. No correction applied" % i C = 0.0 data[i].gravity = data[i].gravity + (C / 1000.0) # # Apply temp correction if desired if tempThresh != 0.0: if Verbose: print "Correcting Temp. corrections outside +-%f mK" % abs(tempThresh) temp_correct.fix(data, tempThresh)
def write_data(file, data, buttons, start_date, elevation): status.insert(END, "Writing output file...\n") index = status.window.index("end linestart") lno = int(float(index)) - 1 for i in range(len(data)): status.replace(lno, "Processing data record %d..." % i) # output data according to the checkbuttons file.write(" ") if buttons.rel_date.query() == 1: file.write(" %7.3f" % (data[i].time, )) if buttons.abs_date.query() == 1: file.write(" %13.3f" % (data[i].time + start_date, )) if buttons.time_str.query() == 1: (year, month, day, h, m, s) = grav_util.un_jday(data[i].time + start_date) file.write("%02d/%02d/%04d %02d:%02d:%02d" % (month, day, year, h, m, s)) if buttons.station_id.query() == 1: file.write(" %25s" % (data[i].station_id, )) if buttons.gravity.query() == 1: file.write(" %8.3f" % (data[i].gravity, )) if buttons.sigma.query() == 1: file.write(" %6.3f" % (data[i].sigma, )) if buttons.tilt_x.query() == 1: file.write(" %3d" % (data[i].tilt_x, )) if buttons.tilt_y.query() == 1: file.write(" %3d" % (data[i].tilt_y, )) if buttons.temp.query() == 1: file.write(" %6.3f" % (data[i].temp, )) if buttons.etc.query() == 1: file.write(" %6.3f" % (data[i].etc, )) if buttons.tetc.query() == 1: if buttons.flip_lat.query() == 1: lat = -1 * data[i].meterInfo.Lat else: lat = data[i].meterInfo.Lat if buttons.flip_lon.query() == 1: lon = -1 * data[i].meterInfo.Lon else: lon = data[i].meterInfo.Lon (year, month, day, hour, minute, second) = grav_util.un_jday(data[i].jul_day) data[i].elevation = elevation gmt_off = data[i].GMT_Diff if buttons.flip_GMT.query() == 1: gmt_off = -1 * gmt_off C = tamura.tide(year, month, day, hour, minute, second, data[i].meterInfo.Lon, data[i].meterInfo.Lat, data[i].elevation, 0.0, gmt_off) if C == 3e38: # Error in input values! tide_error(i, data[i].jul_day, year, month, day, hour, minute, second, lat, lon, data[i].elevation, gmt_off) C = 0.0 file.write(" %6.3f" % (C / 1000.0, )) if buttons.duration.query() == 1: file.write(" %4d" % (data[i].duration, )) if buttons.rejects.query() == 1: file.write(" %4d" % (data[i].rejects, )) if buttons.lat.query() == 1: file.write(" %7.3f" % (data[i].Lat, )) if buttons.lon.query() == 1: file.write(" %8.3f" % (data[i].Lon, )) file.write("\n")
def cmd_write_data(file, data, fields, Verbose, start_date, elevation): if Verbose: sys.stdout.write("\nProcessing data point ") for i in range(len(data)): if Verbose: sys.stdout.write("%08d\b\b\b\b\b\b\b\b" % i) sys.stdout.flush() # output data according to fields file.write(" ") if fields.rel_date == 1: file.write(" %10.6f" % (data[i].time,)) if fields.abs_date == 1: file.write(" %20.6f" % (data[i].time + start_date,)) if fields.time_str == 1: (year, month, day, h, m, s) = grav_util.un_jday(data[i].jul_day) file.write(" %02d/%02d/%04d %02d:%02d:%02d"%(month,day,year, h,m,s)) if fields.station_id == 1: file.write(" %25s" % (data[i].station_id,)) if fields.gravity == 1: file.write(" %8.3f" % (data[i].gravity,)) if fields.sigma == 1: file.write(" %6.3f" % (data[i].sigma,)) if fields.tilt_x == 1: file.write(" %3d" % (data[i].tilt_x,)) if fields.tilt_y == 1: file.write(" %3d" % (data[i].tilt_y,)) if fields.temp == 1: file.write(" %6.3f" % (data[i].temp,)) if fields.tempCorr == 1: if hasattr(data[i], "uncorrected_temp"): temp = data[i].uncorrected_temp[1] grav = data[i].uncorrected_temp[0] else: temp = data[i].temp grav = data[i].gravity file.write(" %6.3f %6.3f"%(temp, grav)) if fields.etc == 1: file.write(" %6.3f" % (data[i].etc,)) if fields.tetc == 1: (year, month, day, hour, minute, second)=grav_util.un_jday(data[i].jul_day) data[i].elevation = elevation C = tamura.tide(year, month, day, hour, minute, second, data[i].meterInfo.Lon, data[i].meterInfo.Lat, data[i].elevation, 0.0, data[i].GMT_Diff) if C == 3e38: # Error in input values! cmd_tide_error(i, data[i].jul_day, year, month, day, hour, minute, second, data[i].meterInfo.Lat, data[i].meterInfo.Lon, data[i].elevation, data[i].GMT_Diff) C = 0.0 file.write(" %6.3g" % (C/1000.0,)) if fields.duration == 1: file.write(" %4d" % (data[i].duration,)) if fields.rejects == 1: file.write(" %4d" % (data[i].rejects,)) if fields.lat == 1: file.write(" %7.3f" % (data[i].meterInfo.Lat,)) if fields.lon == 1: file.write(" %8.3f" % (data[i].meterInfo.Lon,)) if fields.GMT == 1: file.write(" %8.3f" % (data[i].GMT_Diff,)) file.write("\n")
#! /usr/bin/python # convert Absolute Julian Day to date string import grav_util import sys, string if len(sys.argv) < 4: print "usage: %s <infile> <outfile> column"%sys.argv[0] sys.exit(0) date_col = int(sys.argv[3]) - 1 infile = open(sys.argv[1], "rt") outfile = open(sys.argv[2], "wt") while 1: line = infile.readline() if not line: break cols = string.split(line) (year, month, day, hour, minute, second) = grav_util.un_jday(float(cols[date_col])) for i in range(date_col): outfile.write("%s "%cols[i]) outfile.write("%02d/%02d/%04d %02d:%02d:%02d "%(month,day,year, hour,minute, second)) for i in range(date_col+1, len(cols)): outfile.write("%s "%cols[i]) outfile.write("\n") infile.close() outfile.close()