예제 #1
0
def test_interpolate_script(tmpdir):
    """Test the built-in interpolate script."""

    # Original input/output age-to-depth test data.
    curve_filename = TEST_DATA_DIR.join('ODP-114-699_age-depth-model.txt')
    input_filename = TEST_DATA_DIR.join('ODP-114-699_strat_boundaries.txt')
    output_base_filename = 'ODP-114-699_strat_boundaries_age_depth.txt'
    output_filename = TEST_DATA_DIR.join(output_base_filename)

    # We'll be writing to temporary directory (provided by pytest 'tmpdir' fixture).
    test_output_filename = tmpdir.join(output_base_filename)

    # The command-line strings to execute:
    #
    #     python -m pybacktrack.util.interpolate
    #         -cx 1 -cy 0
    #         -r
    #         -c test_data/ODP-114-699_age-depth-model.txt
    #         ODP-114-699_strat_boundaries.txt
    #         ODP-114-699_strat_boundaries_age_depth.txt
    #
    interpolate_script_command_line = [
        'python', '-m', 'pybacktrack.util.interpolate', '-cx', '1', '-cy', '0',
        '-r', '-c',
        str(curve_filename),
        str(input_filename),
        str(test_output_filename)
    ]

    # Call the system command.
    call_system_command(interpolate_script_command_line)

    # Compare original output file and temporary output file just written.
    assert test_output_filename.read() == output_filename.read()
예제 #2
0
def test_backtrack_script(tmpdir):
    """Test the built-in backtrack script."""

    # Test data directory is in 'data' sub-directory of directory containing this test module.
    test_data_dir = py.path.local(__file__).dirpath('data')

    # Test data filenames.
    input_well_filename = test_data_dir.join('ODP-114-699-Lithology.txt')
    ammended_well_output_base_filename = 'ODP-114-699_backtrack_amended.txt'
    ammended_well_output_filename = test_data_dir.join(
        ammended_well_output_base_filename)
    decompacted_output_base_filename = 'ODP-114-699_backtrack_decompat.txt'
    decompacted_output_filename = test_data_dir.join(
        decompacted_output_base_filename)

    # We'll be writing to temporary directory (provided by pytest 'tmpdir' fixture).
    test_ammended_well_output_filename = tmpdir.join(
        ammended_well_output_base_filename)
    test_decompacted_output_filename = tmpdir.join(
        decompacted_output_base_filename)

    # The command-line strings to execute:
    #
    #     python -m pybacktrack.backtrack
    #         -w tests/data/ODP-114-699-Lithology.txt
    #         -d age compacted_depth compacted_thickness decompacted_thickness decompacted_density water_depth tectonic_subsidence lithology
    #         -ym M2
    #         -slm Haq87_SealevelCurve_Longterm
    #         -o tests/data/ODP-114-699_backtrack_amended.txt
    #         --
    #         tests/data/ODP-114-699_backtrack_decompat.txt
    #
    backtrack_script_command_line = [
        'python', '-m', 'pybacktrack.backtrack', '-w',
        str(input_well_filename), '-d', 'age', 'compacted_depth',
        'compacted_thickness', 'decompacted_thickness', 'decompacted_density',
        'water_depth', 'tectonic_subsidence', 'lithology', '-ym', 'M2', '-slm',
        'Haq87_SealevelCurve_Longterm', '-o',
        str(test_ammended_well_output_filename), '--',
        str(test_decompacted_output_filename)
    ]

    # Call the system command.
    call_system_command(backtrack_script_command_line)

    # Compare original output files and temporary output files just written.
    assert test_ammended_well_output_filename.read(
    ) == ammended_well_output_filename.read()
    assert test_decompacted_output_filename.read(
    ) == decompacted_output_filename.read()
예제 #3
0
    def _sample_grid(self, grid_age, grid_filename):

        # Get rotation from present day to 'grid_age' using the reconstruction plate ID of the location.
        rotation = self.rotation_model.get_rotation(
            grid_age, self.reconstruction_plate_id)

        # Reconstruct location to 'grid_age'.
        reconstructed_location = rotation * self.location
        reconstructed_latitude, reconstructed_longitude = reconstructed_location.to_lat_lon(
        )

        #
        # Sample mantle frame grid.
        #

        location_data = '{0} {1}\n'.format(reconstructed_longitude,
                                           reconstructed_latitude)

        # The command-line strings to execute GMT 'grdtrack'.
        grdtrack_command_line = [
            "gmt", "grdtrack",
            "-G{0}".format(grid_filename.encode(sys.getfilesystemencoding()))
        ]

        # Call the system command.
        stdout_data = call_system_command(grdtrack_command_line,
                                          stdin=location_data,
                                          return_stdout=True)

        # GMT grdtrack returns a single line containing "longitude latitude sampled_value".
        # Note that if GMT returns "NaN" then we'll return float('nan').
        return float(stdout_data.split()[2])
예제 #4
0
def test_backstrip_script(tmpdir):
    """Test the built-in backstrip script."""
    
    # Test data filenames.
    input_well_filename = TEST_DATA_DIR.join('sunrise_lithology.txt')
    ammended_well_output_base_filename = 'sunrise_backstrip_amended.txt'
    ammended_well_output_filename = TEST_DATA_DIR.join(ammended_well_output_base_filename)
    decompacted_output_base_filename = 'sunrise_backstrip_decompat.txt'
    decompacted_output_filename = TEST_DATA_DIR.join(decompacted_output_base_filename)
    
    # We'll be writing to temporary directory (provided by pytest 'tmpdir' fixture).
    test_ammended_well_output_filename = tmpdir.join(ammended_well_output_base_filename)
    test_decompacted_output_filename = tmpdir.join(decompacted_output_base_filename)
    
    # The command-line strings to execute:
    #
    #     python -m pybacktrack.backstrip
    #         -w test_data/sunrise_lithology.txt
    #         -l primary extended
    #         -d age compacted_depth compacted_thickness decompacted_thickness decompacted_density min_tectonic_subsidence max_tectonic_subsidence average_tectonic_subsidence min_water_depth max_water_depth average_water_depth lithology
    #         -slm Haq87_SealevelCurve_Longterm
    #         -o sunrise_backstrip_amended.txt
    #         --
    #         sunrise_backstrip_decompat.txt
    #
    backstrip_script_command_line = ['python', '-m', 'pybacktrack.backstrip',
                                     '-w', str(input_well_filename),
                                     '-l', 'primary', 'extended',
                                     '-d', 'age', 'compacted_depth', 'compacted_thickness',
                                     'decompacted_thickness', 'decompacted_density',
                                     'min_tectonic_subsidence', 'max_tectonic_subsidence', 'average_tectonic_subsidence',
                                     'min_water_depth', 'max_water_depth', 'average_water_depth',
                                     'lithology',
                                     '-slm', 'Haq87_SealevelCurve_Longterm',
                                     '-o', str(test_ammended_well_output_filename),
                                     '--',
                                     str(test_decompacted_output_filename)]
    
    # Call the system command.
    call_system_command(backstrip_script_command_line)
    
    # Compare original output files and temporary output files just written.
    assert test_ammended_well_output_filename.read() == ammended_well_output_filename.read()
    assert test_decompacted_output_filename.read() == decompacted_output_filename.read()
예제 #5
0
def test_age_to_depth_script(tmpdir):
    """Test the built-in age_to_depth script."""
    
    # Test data directory is in 'data' sub-directory of directory containing this test module.
    test_data_dir = py.path.local(__file__).dirpath('data')
    
    # Original input/output age-to-depth test data.
    input_filename = test_data_dir.join('test_ages.txt')
    output_base_filename = 'test_depths_from_ages.txt'
    output_filename = test_data_dir.join(output_base_filename)
    
    # We'll be writing to temporary directory (provided by pytest 'tmpdir' fixture).
    test_output_filename = tmpdir.join(output_base_filename)
    
    # Convert input ages to output depths and ages (written to temporary output file).
    pybacktrack.convert_age_to_depth_files(
        str(input_filename),
        str(test_output_filename),
        model=pybacktrack.AGE_TO_DEPTH_MODEL_GDH1,
        reverse_output_columns=True)
    
    # The command-line strings to execute:
    #
    #     python -m pybacktrack.age_to_depth
    #        -m GDH1
    #        -r
    #        tests/data/test_ages.txt
    #        tests/data/test_depths_from_ages.txt
    #
    age_to_depth_script_command_line = ['python', '-m', 'pybacktrack.age_to_depth',
                                        '-m', 'GDH1',
                                        '-r',
                                        str(input_filename),
                                        str(test_output_filename)]
    
    # Call the system command.
    call_system_command(age_to_depth_script_command_line)
    
    # Compare original output file and temporary output file just written.
    assert test_output_filename.read() == output_filename.read()
예제 #6
0
def _sample_grid(longitude, latitude, grid_filename):
    """
    Samples the grid file 'grid_filename' at the longitude/latitude location (in degrees).
    
    Returns sampled float value (which can be NaN if location is in a masked region of grid).
    """

    location_data = '{0} {1}\n'.format(longitude, latitude)

    # The command-line strings to execute GMT 'grdtrack'.
    grdtrack_command_line = ["gmt", "grdtrack", "-G{0}".format(grid_filename)]

    # Call the system command.
    stdout_data = call_system_command(grdtrack_command_line,
                                      stdin=location_data,
                                      return_stdout=True)

    # GMT grdtrack returns a single line containing "longitude latitude sampled_value".
    # Note that if GMT returns "NaN" then we'll return float('nan').
    return float(stdout_data.split()[2])