pythonflopy

Extract subsidence data from MODFLOW-2000 binary output using FloPy


I am using MODFLOW-2000 to run a land subsidence model. However, the output of the subsidence file is in binary data. Is there any way to use the python script to convert it into text since I am doing hundreds of scenarios for the model.


Solution

  • Binary output from the SUB package has the same format as MODFLOW binary head files. You need to know the name of the output text string written to the binary file. See Table 1 in the MODFLOW-2005 online documentation for the SUB package to determine the text string for a given SUB package binary file.

    The following shows how to convert Z DISPLACEMENT data in a binary subsidence file to an ascii file using flopy and numpy:

    import numpy as np
    import flopy
    
    # open the binary file
    sobj = flopy.utils.HeadFile('model.zdisplacement.bin', 
                                text='Z DISPLACEMENT')
    
    # get all of the available times in the file
    times = sobj.get_times()
    
    # extract the data for the last time in the file
    zd = sobj.get_data(totim=times[-1])
    
    # save the z-displacement for the first layer (layer 0) to an ascii file
    # zd is a 3D numpy array with a shape of (nlay, nrow, ncol)
    np.savetxt('layer0.zdisplacement.txt', zd[0])
    

    If you have more than one layer you will need to save the data for each layer.

    You could output all of the data in the file using:

    for t in sobj.get_times():
        zd = sobj.get_data(totim=t)
        for k in range(nlay):
            fpth = 'layer{}_{}.zdisplacement.txt'.format(k, t)
            np.savetxt(fpth, zd[k])