def export_ts_as_midas_tenu(tsin, outdir, outprefix, coordtype='ENU', export_step=True): """ export to a MIDAS .tneu compatible format outfile will be writed in /outdir/outprefixSTAT.tneu if export_step == True: export a step file as /outdir/outprefixSTAT.step """ if not hasattr(tsin[0], 'X'): print('WARN : export_ts_as_midas_tneu : no XYZ in ts') noXYZ = True else: noXYZ = False tswork = copy.deepcopy(tsin) stat = tswork.stat if coordtype == 'XYZ': mp = tswork.mean_posi() tswork.ENUcalc(mp) outpath = outdir + '/' + outprefix + tswork.stat + '.tenu' outfile = open(outpath, 'w+') E, N, U, T, sE, sN, sU = tswork.to_list('ENU') first_pt = tswork.pts[0] if noXYZ: first_pt.X = 0. first_pt.Y = 0. first_pt.Z = 0. first_pt.L = 0. first_pt.H = 0. first_pt.F = 0. e0, n0, u0, t0 = list(zip(E, N, U, T))[0] for e, n, u, t in zip(E, N, U, T): t = conv.toYearFraction(conv.posix2dt(t)) #outfile.write('{} {:.5f} {:+.6f} {:+.6f} {:+.6f} \n'.format(stat,t,n-n0,e-e0,u-u0)) outfile.write('{} {:.5f} {:+.6f} {:+.6f} {:+.6f} \n'.format( stat, t, e - e0, n - n0, u - u0)) print('INFO : timeserie exported in ' + outpath) if export_step and tswork.bool_discont: outpath_step = outdir + '/' + outprefix + tswork.stat + '.step' outfile_step = open(outpath_step, 'w+') for d in tswork.discont: d = conv.toYearFraction(d) line = tswork.stat + " " + str(d) + "\n" outfile_step.write(line) print('INFO : timeserie discont. (steps) exported in ' + outpath_step) return None
def export_ts_as_neu(tsin, outdir, outprefix, coordtype='ENU'): """ export to a HECTOR .neu compatible format outfile will be writed in /outdir/outprefixSTAT.neu NB: The XYZ mode is quite dirty (191001) """ if not hasattr(tsin[0], 'X'): print('WARN : export_ts_as_neu : no XYZ in ts') noXYZ = True else: noXYZ = False tswork = copy.deepcopy(tsin) #if coordtype == 'XYZ': # mp = tswork.mean_posi() # tswork.ENUcalc(mp) outpath = outdir + '/' + outprefix + tswork.stat + '.neu' outfile = open(outpath, 'w+') E, N, U, T, sE, sN, sU = tswork.to_list(coordtype) first_pt = tswork.pts[0] if noXYZ: first_pt.X = 0. first_pt.Y = 0. first_pt.Z = 0. first_pt.L = 0. first_pt.H = 0. first_pt.F = 0. e0, n0, u0, t0 = list(zip(E, N, U, T))[0] # write the header outfile.write('# Site : {} \n'.format(tswork.stat)) if 'calc_center' in list(tswork.anex.keys()): outfile.write('# Analysis Centre: {} \n'.format( tswork.anex['calc_center'])) else: outfile.write('# Analysis Centre: N/A \n') outfile.write('# Solution code: GINS_PS \n') outfile.write('# Datum: ITRF2008\n') outfile.write('#\n') outfile.write('# Reference epoch: {}\n'.format( conv.toYearFraction(first_pt.Tdt))) outfile.write('# X : {}\n'.format(first_pt.X)) outfile.write('# Y : {}\n'.format(first_pt.Y)) outfile.write('# Z : {}\n'.format(first_pt.Z)) outfile.write('#\n') outfile.write('# Longitude : {}\n'.format(first_pt.L)) outfile.write('# Latitude : {}\n'.format(first_pt.F)) outfile.write('# Height : {}\n'.format(first_pt.H)) outfile.write('#\n') if coordtype == "ENU": outfile.write('# Components : ' + "NEU" + "\n") elif coordtype == "XYZ": outfile.write('# Components : ' + "YXZ" + "\n") outfile.write( '# Cartesian components are undirect to maintain consistency with NEU\n' ) outfile.write('#\n') if tswork.bool_discont: outfile.write( '# type_of_offset : from discontinuties got from a station.info\n') outfile.write('#\n') for disc in sorted(tswork.discont): outfile.write('# offset {} 7\n'.format(conv.toYearFraction(disc))) outfile.write('#\n') # write the data for e, n, u, t, se, sn, su in zip(E, N, U, T, sE, sN, sU): t = conv.toYearFraction(conv.posix2dt(t)) if coordtype == "ENU": outfile.write( '{:.5f} {:+.6f} {:+.6f} {:+.6f} {:+.6f} {:+.6f} {:+.6f}\n' .format(t, n - n0, e - e0, u - u0, se, sn, su)) elif coordtype == "XYZ": outfile.write( '{:.5f} {:+.6f} {:+.6f} {:+.6f} {:+.6f} {:+.6f} {:+.6f}\n' .format(t, n - n0, e - e0, u - u0, se, sn, su)) print('INFO : timeserie exported in ' + outpath) return None