Skip to content
Snippets Groups Projects
Select Git revision
  • 02704bc5309b1db2f00887e5d4353a89c48d0d6e
  • master default protected
  • beyond-mesh-pair-removal
  • optimise-space-split-tpool
  • split-space-split
  • better-space-split-tpool
  • melion/BalsaraKim
  • darwin/gear_preSN_fbk_merge
  • reyz/gear_preSN_feedback
  • mark_bug
  • FS_VP_m2_allGrad
  • nickishch/MHD_canvas/OWAR_fully_symmetric_ShearAndRotation
  • fstasys/VEP_Fm2
  • darwin/gear_chemistry_fluxes
  • MHD_canvas protected
  • sidm_merge protected
  • fewer_gpart_comms
  • zoom_merge protected
  • MAGMA2_matthieu
  • darwin/sink_mpi_physics
  • darwin/gear_mechanical_feedback
  • v2025.10 protected
  • v2025.04 protected
  • v2025.01 protected
  • v1.0.0 protected
  • v0.9.0 protected
  • v0.8.5 protected
  • v0.8.4 protected
  • v0.8.3 protected
  • v0.8.2 protected
  • v0.8.1 protected
  • v0.8.0 protected
  • v0.7.0 protected
  • v0.6.0 protected
  • v0.5.0 protected
  • v0.4.0 protected
  • v0.3.0 protected
  • v0.2.0 protected
  • v0.1.0-pre protected
  • v0.1 protected
  • v0.0 protected
41 results

reader_example.py

Blame
  • Loic Hausammann's avatar
    Loic Hausammann authored and Matthieu Schaller committed
    6c149cd8
    History
    reader_example.py 1.40 KiB
    #!/usr/bin/env python3
    """
    Read a logger file by using an index file.
    Example: ./reader_example.py ../../examples/SedovBlast_3D/index 0.1
    """
    import sys
    import numpy as np
    import matplotlib.pyplot as plt
    sys.path.append("../.libs/")
    
    import liblogger as logger
    
    
    def plot3D(pos):
        from mpl_toolkits.mplot3d import Axes3D
        fig = plt.figure()
        ax = fig.add_subplot(111, projection="3d")
        ax.plot(pos[:, 0], pos[:, 1], pos[:, 2], ".", markersize=0.2)
    
    
    def plot2D():
        center = np.array([0.5]*3)
        r2 = np.sum((pos - center)**2, axis=1)
    
        # plot entropy vs distance
        plt.plot(np.sqrt(r2), data["entropies"], '.',
                 markersize=0.2)
    
        plt.xlim(0., 0.5)
        plt.ylim(-1, 50)
        plt.xlabel("Radius")
        plt.ylabel("Entropy")
    
    
    basename = "../../examples/HydroTests/SedovBlast_3D/index"
    time = 0.05
    if len(sys.argv) >= 2:
        basename = sys.argv[1]
    else:
        print("No basename supplied (first argument), using default.")
    if len(sys.argv) >= 3:
        time = float(sys.argv[2])
    else:
        print("No time supplied (second argument), using default.")
    if len(sys.argv) > 3:
        print("Ignoring excess arguments '%s'." % sys.argv[3:])
    print("basename: %s" % basename)
    print("time: %g" % time)
    
    # read dump
    
    t = logger.getTimeLimits(basename)
    data = logger.loadSnapshotAtTime(basename, time)
    print("The data contains the following elements:")
    print(data.dtype.names)
    
    pos = data["positions"]
    
    plot3D(pos)
    plt.show()