Exemple #1
0
def plotCov(cov, refl, point, map, grid_spacing, file_name, roi=50, normalize=(-1, 1)):
    pylab.figure(figsize=(10, 8))

    pt_z, pt_lat, pt_lon = point
    pt_x, pt_y = map(pt_lon, pt_lat)

    dx, dy = grid_spacing
    nx, ny = cov.shape

    xs, ys = np.meshgrid(dx * np.arange(nx), dy * np.arange(ny))

    lbound, ubound = normalize
    dbound = (ubound - lbound) / 20.
    levels = np.arange(lbound, ubound + dbound, dbound)

    map.contourf(xs, ys, cov, levels=levels)
    pylab.colorbar()
    pylab.contour(xs, ys, refl, levels=[20., 40.], colors='k')

    pylab.plot(pt_x, pt_y, 'ko')
    roi_circle = CirclePolygon((pt_x, pt_y), roi * 1000., resolution=40, ec='k', fc='none')
    axes_box = Rectangle((0, 0), 1, 1, ec='w', fc='w', alpha=0.5, clip_path=roi_circle, transform=(pylab.gca().transAxes + pylab.gca().transData.inverted()))

    path_codes = [ Path.MOVETO ] + (axes_box.get_verts().shape[0] - 1) * [ Path.LINETO ] + [ Path.MOVETO ] + (roi_circle.get_verts().shape[0] - 1) * [ Path.LINETO ]
    path_verts = np.concatenate((axes_box.get_verts(), roi_circle.get_verts()[::-1]))

    mask_path = Path(path_verts, path_codes)
    mask_patch = PathPatch(mask_path, fc='w', ec='w', alpha=0.7)
    pylab.gca().add_patch(mask_patch)

    map.drawcoastlines(linewidth=1.5)
    map.drawcountries(linewidth=1.5)
    map.drawstates(linewidth=1.0)
    if not hasattr(map, 'counties'):
        map.readshapefile('countyp020', 'counties', linewidth=0.5)
    else:
        for county, data in izip(map.counties_info, map.counties):
            if county['STATE'] in ['NE', 'WY', 'CO']:
                pylab.gca().add_patch(Polygon(data, ec='k', fc='none', linewidth=0.5))

    pylab.savefig(file_name)
    pylab.close()
    return
def test_rotate_rect():
    loc = np.asarray([1.0, 2.0])
    width = 2
    height = 3
    angle = 30.0

    # A rotated rectangle
    rect1 = Rectangle(loc, width, height, angle=angle)

    # A non-rotated rectangle
    rect2 = Rectangle(loc, width, height)

    # Set up an explicit rotation matrix (in radians)
    angle_rad = np.pi * angle / 180.0
    rotation_matrix = np.array([[np.cos(angle_rad), -np.sin(angle_rad)], [np.sin(angle_rad), np.cos(angle_rad)]])

    # Translate to origin, rotate each vertex, and then translate back
    new_verts = np.inner(rotation_matrix, rect2.get_verts() - loc).T + loc

    # They should be the same
    assert_almost_equal(rect1.get_verts(), new_verts)
Exemple #3
0
def test_rotate_rect():
    loc = np.asarray([1.0, 2.0])
    width = 2
    height = 3
    angle = 30.0

    # A rotated rectangle
    rect1 = Rectangle(loc, width, height, angle=angle)

    # A non-rotated rectangle
    rect2 = Rectangle(loc, width, height)

    # Set up an explicit rotation matrix (in radians)
    angle_rad = np.pi * angle / 180.0
    rotation_matrix = np.array([[np.cos(angle_rad), -np.sin(angle_rad)],
                                [np.sin(angle_rad),  np.cos(angle_rad)]])

    # Translate to origin, rotate each vertex, and then translate back
    new_verts = np.inner(rotation_matrix, rect2.get_verts() - loc).T + loc

    # They should be the same
    assert_almost_equal(rect1.get_verts(), new_verts)
Exemple #4
0
def plotCov(cov,
            refl,
            point,
            map,
            grid_spacing,
            file_name,
            roi=50,
            normalize=(-1, 1)):
    pylab.figure(figsize=(10, 8))

    pt_z, pt_lat, pt_lon = point
    pt_x, pt_y = map(pt_lon, pt_lat)

    dx, dy = grid_spacing
    nx, ny = cov.shape

    xs, ys = np.meshgrid(dx * np.arange(nx), dy * np.arange(ny))

    lbound, ubound = normalize
    dbound = (ubound - lbound) / 20.
    levels = np.arange(lbound, ubound + dbound, dbound)

    map.contourf(xs, ys, cov, levels=levels)
    pylab.colorbar()
    pylab.contour(xs, ys, refl, levels=[20., 40.], colors='k')

    pylab.plot(pt_x, pt_y, 'ko')
    roi_circle = CirclePolygon((pt_x, pt_y),
                               roi * 1000.,
                               resolution=40,
                               ec='k',
                               fc='none')
    axes_box = Rectangle(
        (0, 0),
        1,
        1,
        ec='w',
        fc='w',
        alpha=0.5,
        clip_path=roi_circle,
        transform=(pylab.gca().transAxes + pylab.gca().transData.inverted()))

    path_codes = [Path.MOVETO
                  ] + (axes_box.get_verts().shape[0] - 1) * [Path.LINETO] + [
                      Path.MOVETO
                  ] + (roi_circle.get_verts().shape[0] - 1) * [Path.LINETO]
    path_verts = np.concatenate(
        (axes_box.get_verts(), roi_circle.get_verts()[::-1]))

    mask_path = Path(path_verts, path_codes)
    mask_patch = PathPatch(mask_path, fc='w', ec='w', alpha=0.7)
    pylab.gca().add_patch(mask_patch)

    map.drawcoastlines(linewidth=1.5)
    map.drawcountries(linewidth=1.5)
    map.drawstates(linewidth=1.0)
    if not hasattr(map, 'counties'):
        map.readshapefile('countyp020', 'counties', linewidth=0.5)
    else:
        for county, data in izip(map.counties_info, map.counties):
            if county['STATE'] in ['NE', 'WY', 'CO']:
                pylab.gca().add_patch(
                    Polygon(data, ec='k', fc='none', linewidth=0.5))

    pylab.savefig(file_name)
    pylab.close()
    return
Exemple #5
0
    sample = fk.Sample(f)
    sample.apply_transform(xform)

    new_name = os.path.basename(f).replace('fcs', 'csv')

    sample.export_csv(source='xform', filename=new_name, directory=xform_dir)

# Extract Batch Control:
from matplotlib.patches import Rectangle
from matplotlib.path import Path
import pandas as pd
import numpy as np

fs = glob('./csv_xform/*')

for f in fs:
    df = pd.read_csv(f)
    x = df['Pr141Di']
    y = df['Y89Di']
    r1 = Rectangle((0.1, 0.5),
                   0.4,
                   0.3,
                   linewidth=2,
                   edgecolor='red',
                   facecolor='none')
    p1 = Path(r1.get_verts())
    bc = df[p1.contains_points(np.c_[x, y])]
    fn = f.split('/')[-1]

    bc.to_csv(os.path.join('csv_xform', fn.replace('.csv', '_bc.csv')))