Skip to content

cdump2netcdf

get_thickness(xrash)

helper function for mass_loading

Source code in monetio/models/cdump2netcdf.py
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
def get_thickness(xrash):
    """
    helper function for mass_loading
    """
    alts = list(xrash.z.values)
    b = [0]
    alts2 = alts
    if alts[0] != 0:
        b.extend(alts)
        alts = b

    a2 = alts[1:]
    a3 = alts[0:-1]
    delta = np.array(a2) - np.array(a3)
    # if deposition layer then first layer has
    # thickness of 0.
    if alts2[0] == 0:
        b = [0]
        b.extend(delta)
        delta = b
    return np.array(delta)

makeconc(xrash, date1, level, mult=1, tr=True, verbose=False)

INPUTS xrash : xarray data-array date1 : datetime.datetime object level : list of level names RETURNS c1 : data array with concentration from multiple levels combined.

Source code in monetio/models/cdump2netcdf.py
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
def makeconc(xrash, date1, level, mult=1, tr=True, verbose=False):
    """
    INPUTS
    xrash : xarray data-array
    date1 : datetime.datetime object
    level : list of level names
    RETURNS
    c1 : data array with concentration from multiple levels combined.
    """
    if not level:
        c1 = mult * xrash.sel(time=date1)
    else:
        dhash = thickness_hash(xrash)
        tlist = []
        total_thickness = 0
        for lev in level:
            tlist.append(dhash[lev])
            total_thickness += dhash[lev]
        c1 = mult * xrash.sel(time=date1, z=level)
        if verbose:
            print("MAX BEFORE ", np.max(c1))
        print("length", len(level), tlist, dhash)
        c1 = mass_loading(c1, tlist)
        c1 = c1 / total_thickness
    if verbose:
        print("Max AFTER", np.max(c1))
    c1 = c1.expand_dims("time")
    # this line is for netcdf awips output
    if tr:
        c1 = c1.transpose("time", "ensemble", "y", "x")
    if verbose:
        print("C1", c1)
    if verbose:
        print(c1.shape)
    return c1

mass_loading(xrash, delta=None)

input data array with concentration.

return a data-array with mass loading through all the columns

Source code in monetio/models/cdump2netcdf.py
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
def mass_loading(xrash, delta=None):
    """
    # input data array with concentration.
    # return a data-array with mass loading through all the columns
    """
    xrash = remove_dep(xrash)
    if not delta:
        delta = get_thickness(xrash)
    else:
        delta = np.array(delta)
    iii = 1
    if delta[0] == 0:
        iii = 1
        start = 1
    else:
        iii = 0
        start = 0
    for yyy in np.arange(start, len(delta)):
        if iii == start:
            ml = xrash.isel(z=yyy) * delta[yyy]
        else:
            ml2 = xrash.isel(z=yyy) * delta[yyy]
            # import matplotlib.pyplot as plt
            # plt.pcolormesh(ml2)
            # plt.show()
            ml = ml + ml2
        iii += 1
    return ml

remove_dep(xrash)

remove the deposition layer. helper function for mass_loading

Source code in monetio/models/cdump2netcdf.py
49
50
51
52
53
54
55
56
57
58
def remove_dep(xrash):
    """
    remove the deposition layer.
    helper function for mass_loading
    """
    vals = xrash.z.values
    if vals[0] == 0:
        vals = vals[1:]
    x2 = xrash.sel(z=vals)
    return x2