def test_points_gridding(tmpdir, reek_map, generate_plot):
    """Make points of surface; then grid back to surface."""
    xs = reek_map
    assert xs.ncol == 554

    xyz = Points(xs)

    xyz.dataframe["Z_TVDSS"] = xyz.dataframe["Z_TVDSS"] + 300

    logger.info("Avg of points: %s", xyz.dataframe["Z_TVDSS"].mean())

    xscopy = xs.copy()

    logger.info(xs.values.flags)
    logger.info(xscopy.values.flags)

    # now regrid
    xscopy.gridding(xyz, coarsen=1)  # coarsen will speed up test a lot

    if generate_plot:
        logger.info("Output plots to file (may be time consuming)")
        xs.quickplot(filename=join(tmpdir, "s1.png"))
        xscopy.quickplot(filename=join(tmpdir, "s2.png"))

    tsetup.assert_almostequal(xscopy.values.mean(), xs.values.mean() + 300, 2)

    xscopy.to_file(join(tmpdir, "reek_points_to_map.gri"),
                   fformat="irap_binary")
def test_get_zone_thickness_one_well(testpath):
    """Import a well and get the zone thicknesses"""

    wlist = [Well((testpath / WFILES1), zonelogname="Zonelog")]

    mypoints = Points()
    mypoints.from_wells(wlist, tops=False, zonelist=[12, 13, 14])
Exemple #3
0
def test_export_points():
    """Export XYZ points to file, various formats"""

    mypoints = Points(POINTSET4)  # should guess based on extesion

    print(mypoints.dataframe)
    mypoints.to_file(join(TMPD, "poi_export1.rmsattr"), fformat="rms_attr")
Exemple #4
0
def test_points_gridding(reek_map):
    """Make points of surface; then grid back to surface."""

    xs = reek_map
    assert xs.ncol == 554

    xyz = Points(xs)

    xyz.dataframe['Z_TVDSS'] = xyz.dataframe['Z_TVDSS'] + 300

    logger.info('Avg of points: {}'.format(xyz.dataframe['Z_TVDSS'].mean()))

    xscopy = xs.copy()

    logger.info(xs.values.flags)
    logger.info(xscopy.values.flags)

    # now regrid
    xscopy.gridding(xyz, coarsen=1)  # coarsen will speed up test a lot

    if XTGSHOW:
        logger.info('Output plots to file (may be time consuming)')
        xs.quickplot(filename=os.path.join(TMPD, 's1.png'))
        xscopy.quickplot(filename=os.path.join(TMPD, '/tmp/s2.png'))

    tsetup.assert_almostequal(xscopy.values.mean(), xs.values.mean() + 300, 2)

    xscopy.to_file(os.path.join(TMPD, 'reek_points_to_map.gri'),
                   fformat='irap_binary')
Exemple #5
0
def test_check_multi_point_single_polygon_zdir():
    pol = Polygons(SMALL_POLY_INNER)
    poi = Points([(4.0, 4.0, 0.0), (4.0, 4.0, 4.0), (4.0, 4.0, 8.0)])
    assert len(poi.dataframe) == 3

    # Note z-direction has no effect. All points are deleted.
    poi.operation_polygons(pol, value=1, opname="eli", inside=True)
    assert len(poi.dataframe) == 0
Exemple #6
0
def test_polygons_overlap():
    pol = Polygons(SMALL_POLY_INNER + SMALL_POLY_OVERLAP_INNER)
    # The Four points are placed: within first poly, within the overlap, within the
    # second poly, outside both poly
    poi = Points([(3.5, 3.5, 0.0), (4.5, 4.5, 0.0), (5.5, 5.5, 0.0),
                  (6.5, 6.5, 0.0)])
    poi.operation_polygons(pol, value=1, opname="eli", inside=True)
    assert len(poi.dataframe) == 1
Exemple #7
0
def test_oper_points_inside_overlapping_polygon(oper, expected):
    pol = Polygons(SMALL_POLY_INNER + SMALL_POLY_OVERLAP_INNER)
    # The Four points are placed: within first poly, within the overlap, within the
    # second poly, outside both poly
    poi = Points([(3.5, 3.5, 10.0), (4.5, 4.5, 10.0), (5.5, 5.5, 10.0),
                  (6.5, 6.5, 10.0)])
    # Operations are performed n times, where n reflects the number of polygons a
    # point is outside
    poi.operation_polygons(pol, value=2, opname=oper, inside=False)
    assert list(poi.dataframe[poi.zname].values) == expected
Exemple #8
0
def test_export_points_rmsattr():
    """Export XYZ points to file, as rmsattr"""

    mypoints = Points(POINTSET4)  # should guess based on extesion
    logger.info(mypoints.dataframe)
    mypoints.to_file(join(TMPD, "poi_export1.rmsattr"), fformat="rms_attr")
    mypoints2 = Points(join(TMPD, "poi_export1.rmsattr"))

    assert mypoints.dataframe["Seg"].equals(mypoints2.dataframe["Seg"])
    assert mypoints.dataframe["MyNum"].equals(mypoints2.dataframe["MyNum"])
Exemple #9
0
def test_map_to_points(reek_map):
    """Get the list of the coordinates"""

    px = Points()

    surf = RegularSurface(ftop1)

    assert isinstance(surf, RegularSurface)

    tsetup.assert_almostequal(surf.values.mean(), 0.5755830099, 0.001)

    px.from_surface(surf)

    # convert to a Points instance
    px = Points(reek_map)
    # or
    # px.from_surface(...)

    outf = os.path.join(td, 'points_from_surf_reek.poi')
    px.to_file(outf)

    assert px.dataframe['X_UTME'].min() == 456719.75
    tsetup.assert_almostequal(px.dataframe['Z_TVDSS'].mean(), 0.57558, 0.001)

    # read the output for comparison
    pxx = Points(outf)

    tsetup.assert_almostequal(px.dataframe['Z_TVDSS'].mean(),
                              pxx.dataframe['Z_TVDSS'].mean(), 0.00001)
Exemple #10
0
def test_export_points_rmsattr(testpath, tmp_path):
    """Export XYZ points to file, as rmsattr."""

    mypoints = Points(testpath / POINTSET4)  # should guess based on extesion
    output_path = tmp_path / "poi_export.rmsattr"

    mypoints.to_file(output_path, fformat="rms_attr")
    mypoints2 = Points(output_path)

    assert mypoints.dataframe["Seg"].equals(mypoints2.dataframe["Seg"])
    assert mypoints.dataframe["MyNum"].equals(mypoints2.dataframe["MyNum"])
Exemple #11
0
def test_check_multi_point_multi_polyon_outside_op():
    pol = Polygons(SMALL_POLY_INNER + LARGE_POLY_SHIFTED)
    # Two points in small cube, one in large cube, one outside
    poi = Points([(4.0, 4.0, 0.0), (4.5, 4.0, 0.0), (7.0, 7.0, 0.0),
                  (20.0, 5.0, 0.0)])
    assert len(poi.dataframe) == 4

    # Note the operation will loop over the polygons, and hence remove the points
    # in the small polygon when considering the large polygon, and vice versa
    poi.operation_polygons(pol, value=1, opname="eli", inside=False)
    assert len(poi.dataframe) == 0
Exemple #12
0
def test_export_load_rmsformatted_points(testpath, tmp_path):
    """Export XYZ points to file, various formats."""

    test_points_path = testpath / POINTSET4
    orig_points = Points(test_points_path)  # should guess based on extesion

    export_path = tmp_path / "attrs.rmsattr"
    orig_points.to_file(export_path, fformat="rms_attr")

    reloaded_points = Points(export_path)

    pd.testing.assert_frame_equal(orig_points.dataframe,
                                  reloaded_points.dataframe)
def test_get_zone_thickness_some_wells(testpath, tmp_path):
    """Import some wells and get the zone thicknesses"""

    wlist = [
        Well(wpath, zonelogname="Zonelog")
        for wpath in glob.glob(str(testpath / WFILES2))
    ]

    mypoints = Points()
    mypoints.from_wells(wlist, tops=False, zonelist=(1, 22))

    mypoints.to_file(
        tmp_path / "zpoints_w_so622.rmsasc",
        fformat="rms_attr",
        attributes=["WellName", "ZoneName"],
        pfilter={"ZoneName": ["SO622"]},
    )

    # filter, for backwards compatibility
    mypoints.to_file(
        tmp_path / "zpoints_w_so622_again.rmsasc",
        fformat="rms_attr",
        attributes=["WellName", "ZoneName"],
        filter={"ZoneName": ["SO622"]},
    )
Exemple #14
0
def test_export_and_load_points(tmp_path):
    """Export XYZ points to file."""
    plist = [(1.0, 1.0, 1.0), (2.0, 3.0, 4.0), (5.0, 6.0, 7.0)]
    test_points = Points(plist)

    export_path = tmp_path / "test_points.xyz"
    test_points.to_file(export_path)

    exported_points = Points(export_path)

    pd.testing.assert_frame_equal(test_points.dataframe,
                                  exported_points.dataframe)
    assert list(itertools.chain.from_iterable(plist)) == list(
        test_points.dataframe.values.flatten())
def test_get_zone_thickness_one_well():
    """Import a well and get the zone thicknesses"""

    wlist = []
    for w in glob.glob(str(WFILES1)):
        wlist.append(Well(w, zonelogname="Zonelog"))
        logger.info("Imported well {}".format(w))

    mypoints = Points()
    nwell = mypoints.from_wells(wlist, tops=False, zonelist=[12, 13, 14])

    print(mypoints.dataframe)

    logger.info("Number of well made to tops: {}".format(nwell))
Exemple #16
0
def test_import_rmsattr_format(testpath, tmp_path):
    """Import points with attributes from RMS attr format."""

    orig_points = Points()

    test_points_path = testpath / POINTSET3
    orig_points.from_file(test_points_path, fformat="rms_attr")

    export_path = tmp_path / "attrs.rmsattr"
    orig_points.to_file(export_path, fformat="rms_attr")

    reloaded_points = Points()
    reloaded_points.from_file(export_path, fformat="rms_attr")
    pd.testing.assert_frame_equal(orig_points.dataframe,
                                  reloaded_points.dataframe)
Exemple #17
0
def test_import():
    """Import XYZ points from file."""

    mypoints = Points(PFILE)  # should guess based on extesion

    x0 = mypoints.dataframe["X_UTME"].values[0]
    tsetup.assert_almostequal(x0, 460842.434326, 0.001)
Exemple #18
0
def test_points_in_polygon():
    """Import XYZ points and do operations if inside or outside"""

    poi = Points(POINTSET2)
    pol = Polygons(POLSET2)
    assert poi.nrow == 30

    # remove points in polygon
    poi.operation_polygons(pol, 0, opname="eli", where=True)

    assert poi.nrow == 19
    poi.to_file(join(TMPD, "poi_test.poi"))

    poi = Points(POINTSET2)
    # remove points outside polygon
    poi.operation_polygons(pol, 0, opname="eli", inside=False, where=True)
    assert poi.nrow == 1
def test_get_zone_thickness_some_wells():
    """Import some wells and get the zone thicknesses"""

    wlist = []
    for w in glob.glob(wfiles2):
        wlist.append(Well(w, zonelogname='Zonelog'))
        logger.info('Imported well {}'.format(w))

    mypoints = Points()
    nwell = mypoints.from_wells(wlist, tops=False, zonelist=(1, 22))

    print(nwell, '\n', mypoints.dataframe)

    mypoints.to_file('TMP/zpoints_w_so622.rmsasc',
                     fformat='rms_attr',
                     attributes=['WellName', 'ZoneName'],
                     pfilter={'ZoneName': ['SO622']})

    # filter, for backwards compatibility
    mypoints.to_file('TMP/zpoints_w_so622_again.rmsasc',
                     fformat='rms_attr',
                     attributes=['WellName', 'ZoneName'],
                     filter={'ZoneName': ['SO622']})

    logger.info('Number of well made to tops: {}'.format(nwell))
def test_get_faciesfraction_some_wells(testpath, tmp_path):
    """Import some wells and get the facies fractions per zone, for
    wells < 70 degrees inclination.
    """

    wlist = [
        Well(wpath, zonelogname="Zonelog")
        for wpath in glob.glob(str(testpath / WFILES2))
    ]

    mypoints = Points()
    facname = "Facies"
    fcode = [1]

    mypoints.dfrac_from_wells(wlist,
                              facname,
                              fcode,
                              zonelist=None,
                              incl_limit=70)

    # rename column
    mypoints.zname = "FACFRAC"

    myquery = 'WELLNAME == "OP_1" and ZONE == 1'
    usedf = mypoints.dataframe.query(myquery)

    assert abs(usedf[mypoints.zname].values[0] - 0.86957) < 0.001

    mypoints.to_file(
        tmp_path / "ffrac_per_zone.rmsasc",
        fformat="rms_attr",
        attributes=["WELLNAME", "ZONE"],
        pfilter={"ZONE": [1]},
    )
def test_get_zone_thickness_some_wells():
    """Import some wells and get the zone thicknesses"""

    wlist = []
    for w in glob.glob(str(WFILES2)):
        wlist.append(Well(w, zonelogname="Zonelog"))
        logger.info("Imported well {}".format(w))

    mypoints = Points()
    nwell = mypoints.from_wells(wlist, tops=False, zonelist=(1, 22))

    print(nwell, "\n", mypoints.dataframe)

    mypoints.to_file(
        "TMP/zpoints_w_so622.rmsasc",
        fformat="rms_attr",
        attributes=["WellName", "ZoneName"],
        pfilter={"ZoneName": ["SO622"]},
    )

    # filter, for backwards compatibility
    mypoints.to_file(
        "TMP/zpoints_w_so622_again.rmsasc",
        fformat="rms_attr",
        attributes=["WellName", "ZoneName"],
        filter={"ZoneName": ["SO622"]},
    )

    logger.info("Number of well made to tops: {}".format(nwell))
def test_get_zone_tops_some_wells():
    """Import some well and get the zone tops"""

    wlist = []
    for w in glob.glob(str(WFILES2)):
        wlist.append(Well(w, zonelogname="Zonelog"))
        logger.info("Imported well {}".format(w))

    mypoints = Points()
    nwell = mypoints.from_wells(wlist)

    print(mypoints.dataframe)

    logger.info("Number of well made to tops: {}".format(nwell))

    mypoints.to_file(
        "TMP/points_w1_many.rmsasc",
        fformat="rms_attr",
        attributes=["WellName", "TopName"],
    )

    mypoints.to_file(
        "TMP/points_w1_many.rmswpicks",
        fformat="rms_wellpicks",
        wcolumn="WellName",
        hcolumn="TopName",
    )
Exemple #23
0
def test_get_zone_tops_one_well_w_undef():
    """Import a well and get the zone tops, include undef transition"""

    wlist = []
    for w in glob.glob(wfiles1):
        wlist.append(Well(w, zonelogname="Zonelog"))
        logger.info("Imported well {}".format(w))

    mypoints = Points()
    nwell = mypoints.from_wells(wlist, use_undef=True)

    print(mypoints.dataframe)

    logger.info("Number of well made to tops: {}".format(nwell))

    mypoints.to_file(
        "TMP/points_w1_w_undef.rmsasc",
        fformat="rms_attr",
        attributes=["WellName", "TopName"],
    )

    mypoints.to_file(
        "TMP/points_w1_w_undef.rmswpicks",
        fformat="rms_wellpicks",
        wcolumn="WellName",
        hcolumn="TopName",
    )
Exemple #24
0
def test_operation_inclusive_polygon():
    pol = Polygons(SMALL_POLY_INNER)
    # We place a point on the edge of a polygon
    poi = Points([(4.0, 4.0, 0.0)])
    poi.operation_polygons(pol, value=1, opname="eli", inside=True)
    assert len(poi.dataframe) == 0

    # We place a point on a corner of a polygon
    poi = Points([(3.0, 3.0, 0.0)])
    poi.operation_polygons(pol, value=1, opname="eli", inside=True)
    assert len(poi.dataframe) == 0
Exemple #25
0
def test_custom_points():
    """Make points from list of tuples."""

    plist = [(234, 556, 11), (235, 559, 14), (255, 577, 12)]

    mypoints = Points(plist)

    x0 = mypoints.dataframe["X_UTME"].values[0]
    z2 = mypoints.dataframe["Z_TVDSS"].values[2]
    assert x0 == 234
    assert z2 == 12
Exemple #26
0
def test_map_plot_with_points():
    """Test as simple map plot with underlying points."""

    mysurf = RegularSurface()
    mysurf.from_file(SFILE1)

    mypoints = Points()
    mypoints.from_surface(mysurf)

    df = mypoints.dataframe.copy()
    df = df[::20]
    mypoints.dataframe = df

    # just make the instance, with a lot of defaults behind the scene
    myplot = Map()
    myplot.canvas(title="My o my")
    myplot.colormap = "gist_ncar"
    myplot.plot_surface(mysurf)
    myplot.plot_points(mypoints)

    myplot.savefig("TMP/map_with_points.png")
def test_get_faciesfraction_some_wells():
    """Import some wells and get the facies fractions per zone, for
    wells < 70 degrees inclination.
    """

    wlist = []
    for w in sorted(glob.glob(wfiles2)):
        wlist.append(Well(w, zonelogname='Zonelog'))
        logger.info('Imported well {}'.format(w))

    mypoints = Points()
    facname = 'Facies'
    fcode = [1]

    nwell = mypoints.dfrac_from_wells(wlist,
                                      facname,
                                      fcode,
                                      zonelist=None,
                                      incl_limit=70)

    # rename column
    mypoints.zname = 'FACFRAC'

    logger.info('Number of wells is %s, DATAFRAME:\n, %s', nwell,
                mypoints.dataframe)

    myquery = 'WELLNAME == "OP_1" and ZONE == 1'
    usedf = mypoints.dataframe.query(myquery)

    assert abs(usedf[mypoints.zname].values[0] - 0.86957) < 0.001

    mypoints.to_file('TMP/ffrac_per_zone.rmsasc',
                     fformat='rms_attr',
                     attributes=['WELLNAME', 'ZONE'],
                     pfilter={'ZONE': [1]})
def test_get_faciesfraction_some_wells():
    """Import some wells and get the facies fractions per zone, for
    wells < 70 degrees inclination.
    """

    wlist = []
    for w in sorted(glob.glob(str(WFILES2))):
        wlist.append(Well(w, zonelogname="Zonelog"))
        logger.info("Imported well {}".format(w))

    mypoints = Points()
    facname = "Facies"
    fcode = [1]

    nwell = mypoints.dfrac_from_wells(
        wlist, facname, fcode, zonelist=None, incl_limit=70
    )

    # rename column
    mypoints.zname = "FACFRAC"

    logger.info("Number of wells is %s, DATAFRAME:\n, %s", nwell, mypoints.dataframe)

    myquery = 'WELLNAME == "OP_1" and ZONE == 1'
    usedf = mypoints.dataframe.query(myquery)

    assert abs(usedf[mypoints.zname].values[0] - 0.86957) < 0.001

    mypoints.to_file(
        "TMP/ffrac_per_zone.rmsasc",
        fformat="rms_attr",
        attributes=["WELLNAME", "ZONE"],
        pfilter={"ZONE": [1]},
    )
Exemple #29
0
def test_check_multi_point_multi_polyon_inside_op():
    pol = Polygons(SMALL_POLY_INNER + LARGE_POLY_SHIFTED)
    # Two points in small cube, one in large cube, one outside
    poi = Points([(4.0, 4.0, 0.0), (4.5, 4.0, 0.0), (7.0, 7.0, 0.0),
                  (20.0, 5.0, 0.0)])
    assert len(poi.dataframe) == 4

    poi.operation_polygons(pol, value=1, opname="eli", inside=True)
    assert len(poi.dataframe) == 1

    poi = Points([(4.0, 4.0, 0.0), (4.5, 4.0, 0.0), (7.0, 7.0, 0.0),
                  (20.0, 5.0, 0.0)])
    poi.operation_polygons(pol, value=1, opname="eli", inside=False)
    assert len(poi.dataframe) == 0
Exemple #30
0
def test_create_pointset(points):
    """Create randomly generated points and verify content."""
    pointset = Points(points)
    points = np.array(points)

    assert len(points) == pointset.nrow

    np.testing.assert_array_almost_equal(pointset.dataframe["X_UTME"],
                                         points[:, 0])
    np.testing.assert_array_almost_equal(pointset.dataframe["Y_UTMN"],
                                         points[:, 1])
    np.testing.assert_array_almost_equal(pointset.dataframe["Z_TVDSS"],
                                         points[:, 2])