Ejemplo n.º 1
0
    def amrread(self, fname):
        """Reads the lowest

        Note: Requries the amrfile python module and the libamrfile.so library
        to be compiled.
        """
        amrID = amrio.load(fname)
        thk = extract_field(amrID, 'thickness')
        bas = extract_field(amrID, 'Z_base')
        amrio.free(amrID)
        return thk, bas
Ejemplo n.º 2
0
def collect_field(fnames, field_name, outpath='./', return_ts=False):
    flist = []
    ts = []
    for f in fnames:
        amrID = amrio.load(outpath + f)
        lo, hi = amrio.queryDomainCorners(amrID, 0)
        xh, yh, z = amrio.readBox2D(amrID, 0, lo, hi, field_name, 0)
        ts.append(amrio.queryTime(amrID))

        flist.append(z)
        amrio.free(amrID)
    returnset = np.array(flist),
    if return_ts: returnset += np.array(ts),
    return returnset
Ejemplo n.º 3
0
def extract_ts_and_vols(outpath, skip=1, taf=False):
    fnames = get_fnames(outpath)[::skip]

    vols = []
    ts = []

    for f in fnames:
        amrID = amrio.load(outpath + f)
        lo, hi = amrio.queryDomainCorners(amrID, 0)
        xh, yh, bas1 = amrio.readBox2D(amrID, 0, lo, hi, "Z_base", 0)
        xh, yh, thk1 = amrio.readBox2D(amrID, 0, lo, hi, "thickness", 0)
        ts.append(amrio.queryTime(amrID))
        amrio.freeAll()

        if taf:
            thk1 = thickness_above_floating(thk1, bas1)
        vol = np.trapz(np.trapz(thk1, axis=1, x=xh), x=yh)

        vols.append(vol)

    vols = np.array(vols)

    return ts, vols
Ejemplo n.º 4
0
def get_time_from_plot_file(fname):
    amrID = amrio.load(fname)
    t = amrio.queryTime(amrID)
    amrio.free(amrID)
    return t
Ejemplo n.º 5
0
def intersect_grounding_and_center(fnames,
                                   centerline,
                                   outpath='./',
                                   return_depths=False,
                                   return_thks=False):
    """
    Finds the intersection between the grounding lines in fnames and a
    centerline, using the intersection tool from Sukhbinder Singh.


    """

    xints, yints, depths, thks, ts, slps = [], [], [], [], [], []

    thetas = np.arctan(np.gradient(centerline.xs) / np.gradient(centerline.ys))

    for f in fnames:
        amrID = amrio.load(outpath + f)
        lo, hi = amrio.queryDomainCorners(amrID, 0)
        xh, yh, bas = amrio.readBox2D(amrID, 0, lo, hi, "Z_base", 0)
        xh, yh, bot = amrio.readBox2D(amrID, 0, lo, hi, "Z_bottom", 0)
        xh, yh, thk = amrio.readBox2D(amrID, 0, lo, hi, "thickness", 0)

        p = plt.contour(xh, yh, np.abs(bas - bot), levels=[0.1], colors='r')
        glx, gly = p.allsegs[0][0].T
        xint, yint = intersection.intersection(glx, gly, centerline.xs,
                                               centerline.ys)
        xint = np.mean(xint)
        yint = np.mean(yint)
        xints.append(xint)
        yints.append(yint)
        ts.append(amrio.queryTime(amrID))
        depths.append(interp2d(xh, yh, bas)(xint, yint))
        thks.append(interp2d(xh, yh, thk)(xint, yint))

        xi = np.argmin(np.abs(xh - xint))
        yi = np.argmin(np.abs(yh - yint))
        slpx = bas[yi, xi + 1] - bas[yi, xi - 1] / (2 * (xh[1] - xh[0]))
        slpy = bas[yi + 1, xi] - bas[yi - 1, xi] / (2 * (yh[1] - yh[0]))

        thi = np.argmin((centerline.xs - xint)**2 + (centerline.ys - yint)**2)
        theta = thetas[thi]

        slp = slpx * np.cos(theta) + slpy * np.sin(theta)

        slp = np.sqrt(slpx**2 + slpy**2)
        slps.append(slp)

        amrio.free(amrID)

    xints = np.array(xints)
    yints = np.array(yints)
    depths = np.array(depths)
    ts = np.array(ts)
    plt.close()

    return_set = ts, xints, yints
    if return_depths: return_set += depths,
    if return_thks: return_set += thks,
    return_set += slps,
    return_set = [np.asarray(rs) for rs in return_set]
    return return_set
Ejemplo n.º 6
0
    for Bn in Bns:
        for fn_inBn in os.listdir(datadir + yeardir + Bn):
            fns.append(Bn + '/' + fn_inBn)

#plot.amundsen.2d.hdf5
thkcomp = "thickness"
#thkcomp = "Z_base"
#"xVel", "yVel", "Z_surface", "Z_bottom", "Z_base", "Vel_magnitude"
#"Mesh", "levels", "patches", "Vel"

#read a box of thickness data at the lowest resolution
namr = len(fns)

level = 0
order = 0  # interpolation order, 0 for piecewise constant, 1 for linear
amrID = amrio.load(testdatadir +
                   "plot.extract.ase-lhs-B0000-Cthird-mb.4lev.000000.2d.hdf5")
lo, hi = amrio.queryDomainCorners(amrID, level)
x0, y0, bottom0 = amrio.readBox2D(amrID, level, lo, hi, "Z_bottom", order)
x0, y0, surface0 = amrio.readBox2D(amrID, level, lo, hi, "Z_surface", order)
thk_t0 = surface0 - bottom0
amrio.free(amrID)
print datadir + yeardir + fns[0]

if years == 50.:
    goodruns = np.hstack([range(24), range(25, 140), range(141, namr)])
elif years == 7.:
    goodruns = range(namr)

Vs_full = np.zeros([5, len(goodruns)])  #
Y = np.zeros([57344, len(goodruns)])