Python Forum
Reading a .dat file in Python
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Reading a .dat file in Python
#1
Good Morning,

I am trying to study the correlations between different field quantities in turbulent flows. I have written a code which computes everything that I need and it writes the 2D cross-correlations to a data file in 'ascii' format. The structure of the file goes like this:

# write correlation coefficient in ascii file
dz = z - (z[-1]-z[0])/2.0
rdth= (th- (th[-1]-th[0])/2.0) * r[k]
fnam = 'piCorr2dBoxF'+'{:08d}'.format(iFirst)+'to'+'{:08d}'.format(iLast)+'nt'+'{:04d}'.format(nt)+'.dat'
print('-------------------------------------------------------------------------')
print('Writing cross-correlation to file', fnam)
f = open(fnam, 'w')
f.write('# Two-dimensional two-point cross-correlations\n')
f.write('# For all three velocity components (u_r, u_th, u_z) with eFlux\n')
f.write("# At wall-normal location r = %f -> y+ = %f\n" % (r[k], (1-r[k])*180.4))
f.write('# Python post-processing on data set nsPipe/pipe0002 generated in a DNS using nsPipe\n')
f.write('# Temporal (ensemble) averaging over %d samples\n' % (nt))
f.write("# First snapshot: %08d\n" % (iFirst))
f.write("# Last snapshot:  %08d\n" % (iLast))
f.write("# 01st column: axial separation dz in units of pipe radii (R)\n")
f.write("# 02nd column: azimuthal separation rdth in units of pipe radii (R)\n")
f.write("# 03rd column: u_rPi  correlation in units of RMS\n")
f.write("# 04th column: u_thPi correlation in units of RMS\n")
f.write("# 05th column: u_zPi  correlation in units of RMS\n")
for i in range(nth-1):
 for j in range(nz-1):
  f.write("%23.16e %23.16e %23.16e %23.16e %23.16e\n" % (rdth[i], dz[j], acr[i,j], acth[i,j], acz[i,j]) )
f.close()
I want to generate some 2D plots and for that, I'm writing a new script. The problem is that I don't know how to read this file.
Any kind of help will be appreciated.

Thank you so much.
Have a nice day.
Reply


Messages In This Thread
Reading a .dat file in Python - by mohd_umair - Apr-24-2019, 10:06 AM
RE: Reading a .dat file in Python - by Gribouillis - Apr-24-2019, 10:46 AM
RE: Reading a .dat file in Python - by mohd_umair - Apr-24-2019, 11:45 AM
RE: Reading a .dat file in Python - by Gribouillis - Apr-24-2019, 12:02 PM
RE: Reading a .dat file in Python - by mohd_umair - Apr-24-2019, 12:07 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Reading large crapy text file in anaconda to profile data syamatunuguntla 0 838 Nov-18-2022, 06:15 PM
Last Post: syamatunuguntla
  How to form a dataframe reading separate dictionaries from .txt file? Doug 1 4,263 Nov-09-2020, 09:24 AM
Last Post: PsyPy
  reading tab file Mandiph 1 2,203 Sep-05-2019, 01:03 PM
Last Post: ThomasL
  Reading time steps from nc file ankurk017 1 2,603 Jul-16-2018, 07:06 PM
Last Post: woooee
  reading, modifying and writing json file metalray 2 10,952 Jun-06-2018, 03:09 PM
Last Post: metalray
  Reading json file as pandas data frame? Alberto 1 8,381 Feb-05-2018, 12:43 AM
Last Post: snippsat
  matplotlib help with reading values from CSV file cps13 6 7,341 Aug-22-2017, 10:21 AM
Last Post: andre
  Need help reading in a binary file shaynehansen 2 3,955 Jun-22-2017, 10:04 AM
Last Post: zivoni

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020