<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Make Textfile Demo
Demonstrates how to read in the topography or an event and write it out to a text file, as might be needed to read it into ArcGIS, for example.
Step1:  Read in topography data
Step2:  Write out to text file
The file will have 3 columns containing x, y, B at each of the $250^2 = 62500$ grid points.
Step3:  Another way to do the same thing
Step4:  Read in zeta for a single event
Step5:  Write out to text file
Either of the approaches above could be used, e.g.
<ASSISTANT_TASK:>
Python Code:
%pylab inline
from __future__ import print_function
import sys, os
from ptha_paths import data_dir, events_dir
Explanation: Make Textfile Demo
Demonstrates how to read in the topography or an event and write it out to a text file, as might be needed to read it into ArcGIS, for example.
End of explanation
fixed_grid_file = os.path.join(data_dir, 'MapsTopo', 'fixedgrid_xyB_small.npy')
d=load(fixed_grid_file)
x=d[:,0]
y=d[:,1]
B=d[:,2]
print("x,y,B are 1-dimensional arrays of length %s" % len(x))
# to reshape them as 2-dimensional arrays:
topo = reshape(B, (250,250), order='F')
X = reshape(x, (250,250), order='F')
Y = reshape(y, (250,250), order='F')
print("X,Y,topo are 2-dimensional arrays with shape ", X.shape)
Explanation: Read in topography data
End of explanation
fname = 'xyB.txt'
f = open(fname,'w')
for npts in range(len(B)):
    f.write('%24.10f %24.10f %24.10f\n' % (x[npts],y[npts],B[npts]))
f.close()
print("Created file ", os.path.abspath(fname))
Explanation: Write out to text file
The file will have 3 columns containing x, y, B at each of the $250^2 = 62500$ grid points.
End of explanation
fname = 'xyB.txt'
data_array = vstack((x, y, B)).T
savetxt(fname, data_array, fmt='%24.10f')
print("Created file ", os.path.abspath(fname))
Explanation: Another way to do the same thing:
End of explanation
event = 'AASZb'
event_dir = os.path.join(events_dir, event)
zeta_file = os.path.join(event_dir, 'h_eta_small.npy')
zeta = load(zeta_file)
Explanation: Read in zeta for a single event:
End of explanation
fname = '%s.txt' % event
data_array = vstack((x, y, zeta)).T
savetxt(fname, data_array, fmt='%24.10f')
print("Created file ", os.path.abspath(fname))
Explanation: Write out to text file
Either of the approaches above could be used, e.g.
End of explanation
<END_TASK>