Beispiel #1
0
def createncd(x, data1, data2, data3, z, height, ncfilename):
    NT = len(x)
    NZ = len(z)
    print "**********************"
    print "Creating file: {}".format(ncfilename)
    #Dimensions
    ncfile = Dataset(ncfilename, 'w', format="NETCDF3_CLASSIC")
    ncfile.createDimension("time", None)
    ncfile.createDimension("alt", NZ)

    #Coordinate variables
    time = ncfile.createVariable("time", "f4", ("time", ))
    altitude = ncfile.createVariable("alt", "f4", ("alt", ))

    #Coordinate variable attributes
    altitude.units = "km"
    altitude.description = "altitude"
    altitude[:] = z

    day_0 = datetime(x[0].year, x[0].month, x[0].day)
    time.units = day_0.strftime("minutes since %Y-%m-%d 00:00:00")
    time.description = "time after 0000UTC"
    time[:] = [item.total_seconds() / 60.0 for item in x - day_0]

    #Variables
    ch1 = ncfile.createVariable("ch1", "f4", (
        "time",
        "alt",
    ))
    ch1.units = "mV"
    ch1.description = "532-nm channel - component: o"
    ch1[:, :] = data1

    ch2 = ncfile.createVariable("ch2", "f4", (
        "time",
        "alt",
    ))
    ch2.units = "mV"
    ch2.description = "532-nm channel - component: p"
    ch2[:, :] = data2

    ch3 = ncfile.createVariable("ch3", "f4", (
        "time",
        "alt",
    ))
    ch3.units = "mV"
    ch3.description = "1064-nm channel"
    ch3[:, :] = data3

    #Global Attributes
    ncfile.TITLE = "LIDAR data from Licel"
    ncfile.YEAR = day_0.year
    ncfile.MONTH = day_0.month
    ncfile.DAY = day_0.day
    ncfile.HEIGHT = height

    ncfile.close()
    print "Done!"
    print "**********************"
Beispiel #2
0
def save_ncd(filename, station, x, lz, absc532, absc1064, ldep, dust, sphere,
             zb, zt, invtop, NZ1, NZ2):
    if Debug:
        print "**********************"
        print "Creating output file: {}".format(filename)
    ### Dimensions
    ncfile = Dataset(filename, 'w', format="NETCDF3_CLASSIC")
    ncfile.createDimension("time", None)
    ncfile.createDimension("alt1", NZ1)
    ncfile.createDimension("alt2", NZ2)

    ### Coordinate variables
    time = ncfile.createVariable("time", "f4", ("time", ))
    alt1 = ncfile.createVariable("alt1", "f4", ("alt1", ))
    alt2 = ncfile.createVariable("alt2", "f4", ("alt2", ))

    ### Coordinate variable attributes
    alt1.units = "km"
    alt1.description = "altitude"
    alt1[:] = lz[:NZ1]

    alt2.units = "km"
    alt2.description = "altitude"
    alt2[:] = lz[:NZ2]

    day_0 = x[0]
    time.units = day_0.strftime("minutes since %Y-%m-%d 00:00:00")
    time.description = "time after 0000UTC"
    time[:] = date2num(x, units=time.units)

    ### Variables
    bsc1 = ncfile.createVariable("bsc532", "f4", (
        "time",
        "alt1",
    ))
    bsc1.units = "/sr /km"
    bsc1.description = "Attenuated Backscatter coefficient (532 nm)"
    bsc1[:, :] = 1000.0 * (absc532[:NZ1, :]).T

    bsc2 = ncfile.createVariable("bsc1064", "f4", (
        "time",
        "alt1",
    ))
    bsc2.units = "/sr /km"
    bsc2.description = "Attenuated Backscatter coefficient (1064 nm)"
    bsc2[:, :] = 1000.0 * (absc1064[:NZ1, :]).T

    dep1 = ncfile.createVariable("dep", "f4", (
        "time",
        "alt1",
    ))
    dep1.units = ""
    dep1.description = "Volume Depolarization ratio"
    dep1[:, :] = (ldep[:NZ1, :]).T

    ext1 = ncfile.createVariable("ext_d", "f4", (
        "time",
        "alt2",
    ))
    ext1.units = "/km"
    ext1.description = "Extinction coefficient - Non spherical particles"
    ext1[:, :] = 1000.0 * (dust[:NZ2, :]).T

    ext2 = ncfile.createVariable("ext_s", "f4", (
        "time",
        "alt2",
    ))
    ext2.units = "/km"
    ext2.description = "Extinction coefficient - Spherical particles"
    ext2[:, :] = 1000.0 * (sphere[:NZ2, :]).T

    zb1 = ncfile.createVariable("zb", "f4", ("time", ))
    zb1.units = "km"
    zb1.description = "Cloud Bottom"
    zb1[:] = zb

    zt1 = ncfile.createVariable("zt", "f4", ("time", ))
    zt1.units = "km"
    zt1.description = "Cloud Top"
    zt1[:] = zt

    zinv1 = ncfile.createVariable("zinv", "f4", ("time", ))
    zinv1.units = "km"
    zinv1.description = "Inversion height"
    zinv1[:] = invtop

    ### Global Attributes
    ncfile.TITLE = "LIDAR products"
    ncfile.YEAR = day_0.year
    ncfile.MONTH = day_0.month
    ncfile.DAY = day_0.day
    ncfile.STATION = station

    ncfile.close()
    if Debug: print "Done!"