Python Presets
Learning objectives
- Read five of the book's models as complete Python programs, and say which constants each takes from the kernel and which from its settings
- Reproduce the book's numbers from code: the Gassmann sand's three velocities and its exact inverse, the soft-sand pack, Thomsen's parameters of a sand-shale stack, the anchor fluids and the carbonate pore-type spread
- Trust a program by the kernel: a printed number is sound when it agrees with the kernel's own value to its last digit
- Name where each program stops: the brine lines of Greenberg and Castagna, the oil that must keep its gas in solution, Gassmann's band, and the pore shape that is an assumption
The Same Physics, in Real Code
The figures of this book run its models in the browser, one setting at a time. This section gives five of them as complete Python programs, numpy for the physics and matplotlib for the closing figure, written to be copied, run and changed. The figure below shows one program at a time: (a) is its source, (b) is what it prints, (c) is the figure it draws, and (d) sets the program's key numbers against the kernel the rest of the book computes with. A button copies the program, downloads it, or opens it in the Python Playground under Tools, which loads numpy and matplotlib.
The programs carry the book's numbers, not private ones. The minerals are those of Figure 1.5; the grain pack is the book's one pack, critical porosity 0.36, 9 contacts a grain and 20 MPa (Section 5.2); the pore fluids are the reservoir anchor, Batzle and Wang (1992) at 50 °C and 25 MPa, with brine GPa, live oil 1.068 GPa and gas 0.061 GPa; and the Backus sand is the cemented sand of Figure 7.4. The anchor fluids and that frame are typed into the code to five decimals, as a reader would carry them. Python cannot run on this page, so the figure runs the same equations in JavaScript and prints what each program prints. The audit that checks this book runs every program under Python and holds each printed line, and each curve the program plots, to the figure's.
Five Programs
The first is GASSMANN FLUID SUBSTITUTION, the workflow of Section 4.2 forward and back (Gassmann, 1951). It takes the quartz sand of Figure 4.2, whose dry frame keeps 30% of the stiffest frame the porosity allows, the Hashin-Shtrikman upper bound of Section 2.4. At 25% porosity that frame is and GPa. Saturated in turn with the anchor brine, oil and gas it prints of 3.286, 3.053 and 2.963 km/s, and the exact inverse takes the brine rock back to GPa. The last table mixes gas and brine the two ways of Sections 3.5 and 3.6. Evenly mixed, Wood's fluid goes into Gassmann and runs 2.935, 2.899, 2.888 and 2.919 km/s at 20, 50, 80 and 90% water, all below the 2.963 km/s of the gas-filled rock; in patches, the Gassmann-Hill average of the P-wave moduli gives 3.013, 3.100, 3.205 and 3.244 km/s.
The second is the SOFT-SAND LINE of Sections 5.2 and 5.3. Hertz-Mindlin gives the dry pack at the critical porosity, and GPa, and the modified Hashin-Shtrikman lower bound carries it up to solid quartz. At 25% porosity with the brine in the pores the program prints GPa, and km/s, and its table of dry moduli runs from GPa at 20% porosity to the pack's 2.051 at 36%.
The third is the BACKUS AVERAGE AND THOMSEN of Section 9.2: Figure 7.4's cemented brine sand ( and GPa) laminated with Figure 0.3's shale ( and GPa) and averaged the exact long-wavelength way. At half sand it prints , and , although both layers are isotropic. The table shows a symmetry worth knowing before you trust a plot: for two layers and are proportional to the product of the layers' shares, so the 10% and 90% rows print the same and , while , which is at 10% and at 90%, is not symmetric.
The fourth is BATZLE-WANG FLUIDS AND VS PREDICTION, Part 3 and Section 7.2 in one program. At 50 °C and 25 MPa it prints the brine GPa, the live oil 1.068 and the gas 0.061 GPa, the gas falling to 0.008 GPa at 5 MPa. It then prints the Greenberg and Castagna (1992) lines at km/s, 1.959 km/s for sandstone, 1.853 for limestone and 1.963 for dolomite, beside the mudrock line of Castagna, Batzle and Eastwood (1985) at 1.845. These are lines for brine-saturated rock, and the program says so: in a hydrocarbon zone the shear velocity is read on the brine leg, after the gas has been taken out with the first program, not on the gas sand's .
The fifth is INCLUSION MODELS, the machinery of Part 6. Berryman's spheroids go into the differential effective medium of Section 6.3, which grows the pores a little at a time; for pores of aspect ratio 0.15 in calcite it prints the dry of 54.00, 38.79, 20.57 and 10.87 GPa at 5, 10, 20 and 30% porosity. Gassmann puts the brine in, and for the three pore shapes of Section 6.6 at 25% porosity it prints of 4.05 km/s for interparticle pores, 5.27 for moldic pores and 2.18 for cracks: one calcite, one brine, and velocities from 2.18 to 5.27 km/s. The last table is Xu-White (Section 6.5), 3.42, 2.80 and 2.38 km/s at 5, 20 and 40% clay.
Trusting a Program's Numbers
A program is trusted when it reproduces a number you already trust. Here that number is the kernel's: panel (d) sets key printed numbers beside the kernel's own values and counts the difference in units of the last printed digit. The two can differ for one reason, the five-decimal constants typed into the code. At the default settings the largest gap in any of the five programs is 0.011 of the last printed digit, and none of the printed numbers is off by a digit. That is what makes a change yours: when a number moves, the arithmetic you changed moved it, not the typing of a constant.
Where the Programs Stop
A program inherits the edges of its model. The Greenberg and Castagna lines are lines for brine-saturated rock (Section 7.2). The live oil of the fourth program holds its 80 L/L of gas in solution only above about 12.5 MPa at 50 °C, by Batzle and Wang's equation 21 (Section 3.3); the pressure control starts at 15 MPa for that reason, and below 12.5 MPa the oil row would describe an oil that is not there. Gassmann's equation has the edges of Section 4.5, the Backus average needs layers far thinner than the wavelength (Section 9.2), and in the inclusion program the aspect ratio is an assumption about the pores, not a measurement of them. For an open-source Python library of rock-physics models, see rockphypy (Yu, Mukerji, & Avseth, 2023).
When the problem grows, a loop over a well's samples or over a thousand draws of an aspect ratio is the same arithmetic run more often, and that is the step a browser slider cannot take. The next section looks up from the code to what the skills you now hold let you do in research.
References
- Batzle, M., & Wang, Z. (1992). Seismic properties of pore fluids. Geophysics, 57(11), 1396-1408.
- Castagna, J. P., Batzle, M. L., & Eastwood, R. L. (1985). Relationships between compressional-wave and shear-wave velocities in clastic silicate rocks. Geophysics, 50(4), 571-581.
- Gassmann, F. (1951). Über die Elastizität poröser Medien. Vierteljahrsschrift der Naturforschenden Gesellschaft in Zürich, 96, 1-23.
- Greenberg, M. L., & Castagna, J. P. (1992). Shear-wave velocity estimation in porous rocks: Theoretical formulation, preliminary verification and applications. Geophysical Prospecting, 40(2), 195-209.
- Yu, J., Mukerji, T., & Avseth, P. (2023). rockphypy: An extensive Python library for rock physics modeling. SoftwareX, 24, 101567.