예제 #1
0
def v2light(v, vlon, vlat, rg=[-4, 4]):

    infile = './topo.nc'
    f = h5.File(infile, 'r')
    topo = f['topo'][:]
    topo = topo / 1000
    topo = topo[0::2, 0::2]
    f.close()

    lon = np.linspace(60, 150, topo.shape[1])
    lat = np.linspace(0, 60, topo.shape[0])
    lon2, lat2 = np.meshgrid(lon, lat)
    v2 = griddata.stb(3, vlat, vlon, v, lat, lon)

    rg = [-4, 4]
    v3 = num2rgb(v2, cc0, rg)

    lt = light.point(lon2, lat2, topo * 10, np.array([-1, 1, 1]))
    if True:
        lt[lt < 0] = 0
        lt = lt + 0.3
        lt[lt > 1] = 1

    g = 3
    for i in range(0, 0):
        lt = cv2.filter2D(lt, -1, np.ones((g, g))) /\
            cv2.filter2D(np.ones(lt.shape), -1, np.ones((g, g)))

    v4 = v3 + 0
    v4[:, :, 0] = v3[:, :, 2] * lt
    v4[:, :, 1] = v3[:, :, 1] * lt
    v4[:, :, 2] = v3[:, :, 0] * lt
    return v3, v4
예제 #2
0
def gen_disk_light_topo_tb(infile, rn, outdir, outfile0, cth_file, log_file,
                           json_file):

    # {{{
    outfile = outdir + outfile0
    common.write_log(log_file, 'START disk_light_topo_tb')
    lat_fy4a = gdal.Open(
        './lut4k_1.tif').\
        ReadAsArray(0, 0, 2748, 2748)  # 纬度数据
    lon_fy4a = gdal.Open(
        './lut4k_2.tif').\
        ReadAsArray(0, 0, 2748, 2748)  # 经度数据

    f = h5.File(infile, 'r')
    Channel = 12
    NOMChannel = f['NOMChannel%s' % (Channel)][:]
    CALChannel = f['CALChannel%s' % (Channel)][:]
    tb = Data_Cal(NOMChannel, CALChannel)
    bln = f.attrs[u'Begin Line Number'][0]
    eln = f.attrs[u'End Line Number'][0]
    bpn = f.attrs[u'Begin Pixel Number'][0]
    epn = f.attrs[u'End Pixel Number'][0]
    f.close()

    if False:
        cth_file = re.sub(r'\.HDF', r'.NC', infile)
        cth_file = re.sub(r'FDI', r'CTH', cth_file)
        cth_file = re.sub(r'L1', r'L2', cth_file)
        cth_file = re.sub(r'\/DISK\/', '/DISK/NOM/', cth_file)
    f = h5.File(cth_file, 'r')
    cth = f['CTH'][:]
    f.close()

    tb0 = lon_fy4a * 0 - 100
    tb0[bln:eln + 1, bpn:epn + 1] = tb
    tb = tb0
    cth0 = lon_fy4a * 0
    cth0[bln:eln + 1, bpn:epn + 1] = cth
    cth = cth0

    f = h5.File('topo_fy4a_4km.nc', 'r')
    topo = f['topo'][:]
    topo = np.flip(topo.T, 0)
    f.close()

    # tb[np.where(tb < 50)] = np.nan
    print(tb.dtype)
    # tb[np.where(cth < 0)] = tb[np.where(cth < 0)]+100

    if False:
        tb = cv2.resize(tb.astype(np.double), (2748 * 2, 2748 * 2))
        lon_fy4a = cv2.resize(lon_fy4a.astype(np.double), (2748 * 2, 2748 * 2))
        lat_fy4a = cv2.resize(lat_fy4a.astype(np.double), (2748 * 2, 2748 * 2))
        print(tb.shape)

    if True:
        x4 = np.linspace(0, 10, num=2748)
        y4 = np.linspace(0, 10, num=2748)
        x42, y42 = np.meshgrid(x4, y4)
        xo = np.linspace(0, 10, num=2748 * rn)
        yo = np.linspace(0, 10, num=2748 * rn)
        # id = np.where((tb > 0) & (lon_fy4a > -190) & (lat_fy4a > -100))
        sn = 4
        if rn > 2:
            sn = 8
        tb = griddata.stb(sn, x42, y42, tb, xo, yo).transpose()
        topo = griddata.stb(sn, x42, y42, topo, xo, yo).transpose()
        lon_fy4a = griddata.stb(sn, x42, y42, lon_fy4a, xo, yo)
        lat_fy4a = griddata.stb(sn, x42, y42, lat_fy4a, xo, yo)
        cth = griddata.stb(sn, x42, y42, cth, xo, yo).transpose()

    topo[np.where(cth > 0)] = cth[np.where(cth > 0)]
    topo = topo / 1000
    # cth = 10-tb/20/100*50
    # topo[np.where(tb < -10+273.15)] = cth[np.where(tb < -10+273.15)]

    # imshow total
    # tb[np.where(tb < 50)] = np.nan
    rg = [-110 + 273.15, 50 + 100 + 273.15]
    # rg = [-90+273.15, 60+273.15]
    tb3 = num2rgb(tb, ch8, rg)

    if True:
        tb_nocloud = tb
        tb3_nocloud = num2rgb(tb_nocloud, tcc, [-50 + 273.15, 20 + 273.15])
        r = tb3[:, :, 0]
        g = tb3[:, :, 1]
        b = tb3[:, :, 2]
        rn = tb3_nocloud[:, :, 0]
        gn = tb3_nocloud[:, :, 1]
        bn = tb3_nocloud[:, :, 2]
        rn[np.where(cth > 0)] = r[np.where(cth > 0)]
        gn[np.where(cth > 0)] = g[np.where(cth > 0)]
        bn[np.where(cth > 0)] = b[np.where(cth > 0)]
        # tb3[np.where(tb3_nocloud > 0)] = tb3_nocloud[np.where(tb3_nocloud > 0)]
        tb3[:, :, 0] = rn
        tb3[:, :, 1] = gn
        tb3[:, :, 2] = bn
        # tb3 = tb3_nocloud
        print(tb3.shape)
        print(cth.shape)

    lt = light.point(lon_fy4a, lat_fy4a, topo, np.array([-1, 1, 1]))
    if True:
        lt[lt < 0] = 0
        lt = lt + 0.3
        lt[lt > 1] = 1

    g = 3
    for i in range(0, 2):
        lt = cv2.filter2D(lt, -1, np.ones((g, g))) /\
            cv2.filter2D(np.ones(lt.shape), -1, np.ones((g, g)))

    tb4 = tb3 + 0
    # lt = lt*0+1
    tb4[:, :, 0] = tb3[:, :, 2] * lt
    tb4[:, :, 1] = tb3[:, :, 1] * lt
    tb4[:, :, 2] = tb3[:, :, 0] * lt
    cv2.imwrite(outfile, (tb4 * 255).astype(np.int32))
    common.write_log(log_file, 'FINISH disk_light_topo_tb')
    out_info = common.OutInfo(json_file)
    out_info.update_file_info(outfile0, 'LIGHT', 'R')
    return out_info
예제 #3
0
if False:
    tb = cv2.resize(tb.astype(np.double), (2748 * 2, 2748 * 2))
    lon_fy4a = cv2.resize(lon_fy4a.astype(np.double), (2748 * 2, 2748 * 2))
    lat_fy4a = cv2.resize(lat_fy4a.astype(np.double), (2748 * 2, 2748 * 2))
    print(tb.shape)

if True:
    x4 = np.linspace(0, 10, num=2748)
    y4 = np.linspace(0, 10, num=2748)
    x42, y42 = np.meshgrid(x4, y4)
    xo = np.linspace(0, 10, num=2748 * rn)
    yo = np.linspace(0, 10, num=2748 * rn)
    # id = np.where((tb > 0) & (lon_fy4a > -190) & (lat_fy4a > -100))
    sn = 4
    tb = griddata.stb(sn, x42, y42, tb, xo, yo).transpose()
    topo = griddata.stb(sn, x42, y42, topo, xo, yo).transpose()
    lon_fy4a = griddata.stb(sn, x42, y42, lon_fy4a, xo, yo)
    lat_fy4a = griddata.stb(sn, x42, y42, lat_fy4a, xo, yo)
    cth = griddata.stb(sn, x42, y42, cth, xo, yo).transpose()

topo[np.where(cth > 0)] = cth[np.where(cth > 0)]
topo = topo / 1000
# cth = 10-tb/20/100*50
# topo[np.where(tb < -10+273.15)] = cth[np.where(tb < -10+273.15)]

# imshow total
# {{{
# tb[np.where(tb < 50)] = np.nan
rg = [-110 + 273.15, 50 + 100 + 273.15]
# rg = [-90+273.15, 60+273.15]
예제 #4
0
lonlim = [66, 83]
# latlim = [-28, -2]
# lonlim = [61, 88]
lat_gd = np.linspace(latlim[0], latlim[1],
                     num=2000)  # (latlim[1]-latlim[0])*200)
lon_gd = np.linspace(lonlim[0], lonlim[1],
                     num=2500)  # (lonlim[1]-lonlim[0])*200)
sn = 200

time_start = time.time()
id = np.where((tb > 0) & (lon_fy4a > -190) & (lat_fy4a > -100))
if False:
    tb_gd = griddata.simple(sn, lon_fy4a[id], lat_fy4a[id], tb[id], lon_gd,
                            lat_gd)
else:
    tb_gd = griddata.stb(sn, np.flip(lon_fy4a.T, 1), np.flip(lat_fy4a.T, 1),
                         np.flip(tb.T, 1), lon_gd, lat_gd)
time_end = time.time()
print('time cost', time_end - time_start, 's')
tb_gd2 = tb_gd
tb_gd2[np.where(tb_gd2 < 10)] = np.nan
tb_gd2[np.where(tb_gd2 < 100)] = 100
tb_gd2[np.where(tb_gd2 > 330)] = 330

tb2 = tb_gd2.transpose()

ccc = np.array([[1, 0, 0], [1, 1, 0], [0, 1, 0], [0, 1, 1], [0, 0, 1],
                [1, 0, 1]])
rg = [-110 + 273.15, 50 + 273.15]
rg = [-100 + 273.15, 40 + 273.15]
# rg = [190, 320]
tb3 = num2rgb(tb2, ch8, rg)
예제 #5
0
if False:
    tb = cv2.resize(tb.astype(np.double), (2748*2, 2748*2))
    lon_fy4a = cv2.resize(lon_fy4a.astype(np.double), (2748*2, 2748*2))
    lat_fy4a = cv2.resize(lat_fy4a.astype(np.double), (2748*2, 2748*2))
    print(tb.shape)

if True:
    x4 = np.linspace(0, 10, num=2748)
    y4 = np.linspace(0, 10, num=2748)
    x42, y42 = np.meshgrid(x4, y4)
    xo = np.linspace(0, 10, num=2748*rn)
    yo = np.linspace(0, 10, num=2748*rn)
    # id = np.where((tb > 0) & (lon_fy4a > -190) & (lat_fy4a > -100))
    sn = 4
    tb = griddata.stb(sn, x42, y42, tb, xo, yo).transpose()
    lon_fy4a = griddata.stb(sn, x42, y42, lon_fy4a, xo, yo)
    lat_fy4a = griddata.stb(sn, x42, y42, lat_fy4a, xo, yo)

# imshow total
# {{{
tb[np.where(tb < 50)] = np.nan

rg = [-110+273.15, 50+273.15]
tb3 = num2rgb(tb, ch8, rg)

lt = light.point(lon_fy4a, lat_fy4a, 1-tb/20/100*100, np.array([-1, 1, 1]))
if True:
    lt[lt < 0] = 0
    lt = lt+0.3
    lt[lt > 1] = 1
예제 #6
0
파일: test2.py 프로젝트: toothedsword/light
lonlim = [66, 83]
# latlim = [-28, -2]
# lonlim = [61, 88]
lat_gd = np.linspace(latlim[0], latlim[1],
                     num=2000)  # (latlim[1]-latlim[0])*200)
lon_gd = np.linspace(lonlim[0], lonlim[1],
                     num=2500)  # (lonlim[1]-lonlim[0])*200)
sn = 200

time_start = time.time()
id = np.where((tb > 0) & (lon_fy4a > -190) & (lat_fy4a > -100))
if False:
    tb2 = griddata.simple(sn, lat_fy4a[id], lon_fy4a[id], tb[id], lat_gd,
                          lon_gd)
else:
    tb2 = griddata.stb(sn, np.flip(lat_fy4a, 0), np.flip(lon_fy4a, 0),
                       np.flip(tb, 0), lat_gd, lon_gd)
time_end = time.time()
print('time cost', time_end - time_start, 's')
tb2[np.where(tb2 < 10)] = np.nan
tb2[np.where(tb2 < 100)] = 100
tb2[np.where(tb2 > 330)] = 330

ccc = np.array([[1, 0, 0], [1, 1, 0], [0, 1, 0], [0, 1, 1], [0, 0, 1],
                [1, 0, 1]])
rg = [-110 + 273.15, 50 + 273.15]
rg = [-100 + 273.15, 40 + 273.15]
# rg = [190, 320]
tb3 = num2rgb(tb2, ch8, rg)

fig = plt.figure(figsize=(20, 12), dpi=100)
ax = fig.add_subplot(1, 2, 1)
예제 #7
0
def get_tb3(dtime,
            lonlim,
            latlim,
            addlight=True,
            lon_gd='',
            lat_gd='',
            lat_fy4a='./lut4k_1.tif',
            lon_fy4a='./lut4k_2.tif',
            file_re_path='./AGRI/L1/FDI/*/yyyy/yyyymmdd/' +
            'FY4A-_AGRI--_N_*_1047E_L1-_FDI-_MULT_NOM_' +
            'yyyymmddHHMM??_*_4000M_V0001.HDF',
            filepath=-1,
            lighttype='tb',
            ctype='ch8',
            tbrg=[-300, 400],
            miss=-999):

    # get ccc
    # {{{
    rgb = ((0.2, 0.2, 0), (1, 1, 0), (0.5, 0, 0.5), (1, 0, 1), (1, 0.7,
                                                                1), (1, 1, 1),
           (0, 0, 0), (1, 0, 0), (1, 1, 0), (0, 1, 0), (0, 1, 1), (0, 0, 0))
    ns = [40, 0, 10, 10, 0, 20, 20, 20, 20, 40, 140]
    ch8 = gen_ccc(rgb, ns)
    rg = [-110 + 273.15, 50 + 273.15]
    rgb = ((0, 0, 0), (0, 0, 1), (0.5, 0, 0.5), (1, 0, 1), (1, 0.7, 1), (1, 1,
                                                                         1),
           (0, 0, 0), (1, 0, 0), (1, 1, 0), (0, 1, 0), (0, 1, 1), (0, 0, 0))
    ns = [40, 0, 10, 10, 0, 20, 20, 20, 20, 40, 140]
    # ch8 = gen_ccc(rgb, ns)
    # rg = [-110+273.15, 50+273.15]
    rgb = ((0.2, 0.2, 0), (1, 1, 0), (0.5, 0, 0.5), (1, 0, 1), (1, 0.7, 1),
           (1, 1, 1), (0, 0, 0), (1, 0, 0), (1, 1, 0), (0, 1, 0), (0, 1, 1),
           (0, 0, 0), (1, 0, 0), (0, 1, 1), (0, 1, 0))
    ns = [40, 0, 10, 10, 0, 20, 20, 20, 20, 40, 140, 100, 50, 50]
    # ch8 = gen_ccc(rgb, ns)
    # rg = [-110+273.15, 50+100+273.15]
    if ctype == 'swap':
        rgb = ((1, 1, 1), (0, 0, 0), (1, 0, 0), (1, 1, 0), (0, 1, 0),
               (0, 0, 1), (0, 1, 1), (0.8, 0.8, 0.8), (0.1, 0.1, 0.1))
        ns = [10, 10, 10, 10, 10, 10, 10, 80]
        ch8 = gen_ccc(rgb, ns)
        rg = [-90 + 273.15, 60 + 273.15]
    if ctype == 'gray':
        rgb = ((1, 1, 1), (0, 0, 0))
        ns = [200]
        ch8 = gen_ccc(rgb, ns)
        rg = [-90 + 273.15, 60 + 273.15]

        pass
    # th8 = gen_ccc(rgb, ns)
    # }}}

    # read in data
    print('read')
    # {{{

    if re.search('str', str(type(filepath))):
        pass
    else:
        filepath = htt.time2str(dtime, file_re_path, num=3)
        print(filepath)
        filepath = glob.glob(filepath)
        filepath = filepath[0]

    f = h5.File(filepath, 'r')
    Channel = 12

    NOMChannel = f['NOMChannel%s' % (Channel)][:]
    CALChannel = f['CALChannel%s' % (Channel)][:]
    bln = f.attrs[u'Begin Line Number'][0]
    eln = f.attrs[u'End Line Number'][0]
    bpn = f.attrs[u'Begin Pixel Number'][0]
    epn = f.attrs[u'End Pixel Number'][0]
    print('bln=', bln)
    tb = Data_Cal(NOMChannel, CALChannel)
    f.close()
    tb[np.where(tb < 50)] = np.nan
    # tb[np.where(tb < tbrg[0]+273.15)] = miss
    # tb[np.where(tb > tbrg[1]+273.15)] = miss
    # }}}

    # griddata
    print('griddata')
    # {{{
    if re.search('str', str(type(lat_fy4a))):
        lat_fy4a = gdal.Open(lat_fy4a).\
            ReadAsArray(0, 0, 2748, 2748)  # 纬度数据
        lon_fy4a = gdal.Open(lon_fy4a).\
            ReadAsArray(0, 0, 2748, 2748)  # 经度数据

    if re.search('str', str(type(lat_gd))):
        lat_gd = np.linspace(latlim[0], latlim[1], num=2000)
    if re.search('str', str(type(lon_gd))):
        lon_gd = np.linspace(lonlim[0], lonlim[1], num=2000)
    sn = 200
    tb0 = lon_fy4a * 0 - 100
    tb0[bln:eln + 1, bpn:epn + 1] = tb
    tb = tb0

    id = np.where((tb > 0) & (lon_fy4a > -190) & (lat_fy4a > -100))
    if False:
        tb2 = griddata.simple(sn, lat_fy4a[id], lon_fy4a[id], tb[id], lat_gd,
                              lon_gd)
    else:
        tb2 = griddata.stb(sn, np.flip(lat_fy4a, 0), np.flip(lon_fy4a, 0),
                           np.flip(tb, 0), lat_gd, lon_gd)

    tb2[np.where(tb2 < 10)] = np.nan
    # tb2[np.where(tb2 < tbrg[0]+273.15)] = miss
    # tb2[np.where(tb2 > tbrg[1]+273.15)] = miss

    tb3 = num2rgb(tb2, ch8, rg)
    # }}}

    # light
    print('light')
    # {{{
    lon2, lat2 = np.meshgrid(lon_gd, lat_gd)
    tb4 = -1
    if addlight:
        if lighttype == 'tb':
            cth = 1 - tb2 / 20 / 100 * 20
        if lighttype == 'topo':
            f = h5.File('./topo_fy4a_4km.nc', 'r')
            topo = f['topo'][:]
            topo = np.flip(topo.T, 0)
            f.close()
            topo = griddata.stb(sn, np.flip(lat_fy4a, 0), np.flip(lon_fy4a, 0),
                                np.flip(topo, 0), lat_gd, lon_gd)
            cth = topo
        if lighttype == 'topocth':
            f = h5.File('./topo_fy4a_4km.nc', 'r')
            topo = f['topo'][:]
            topo = np.flip(topo.T, 0)
            f.close()
            cth_file = re.sub(r'\.HDF', r'.NC', filepath)
            cth_file = re.sub(r'FDI', r'CTH', cth_file)
            cth_file = re.sub(r'L1', r'L2', cth_file)
            cth_file = re.sub(r'\/DISK\/', '/DISK/NOM/', cth_file)
            cth_file = re.sub(r'\/REGC\/', '/REGC/NOM/', cth_file)
            print(cth_file)
            f = h5.File(cth_file, 'r')
            cth = f['CTH'][:]
            cth_bln = f['geospatial_lat_lon_extent'].attrs[
                u'begin_line_number'][0]
            cth_eln = f['geospatial_lat_lon_extent'].attrs[u'end_line_number'][
                0]
            cth_bpn = f['geospatial_lat_lon_extent'].attrs[
                u'begin_pixel_number'][0]
            cth_epn = f['geospatial_lat_lon_extent'].attrs[
                u'end_pixel_number'][0]
            cth0 = lon_fy4a * 0 - 100
            cth0[cth_bln:cth_eln + 1, cth_bpn:cth_epn + 1] = cth
            cth = cth0
            f.close()
            topo0 = griddata.stb(sn, np.flip(lat_fy4a,
                                             0), np.flip(lon_fy4a, 0),
                                 np.flip(topo, 0), lat_gd, lon_gd)
            topo[np.where(cth > 0)] = cth[np.where(cth > 0)]
            topo = griddata.stb(sn, np.flip(lat_fy4a, 0), np.flip(lon_fy4a, 0),
                                np.flip(topo, 0), lat_gd, lon_gd)
            cth = topo
            cth[np.where(tb2 == miss)] = topo0[np.where(tb2 == miss)]

        if lighttype == 'tbtopo':
            cth = 1 - tb2 / 20 / 100 * 20
            f = h5.File('./topo_fy4a_4km.nc', 'r')
            topo = f['topo'][:]
            topo = np.flip(topo.T, 0)
            f.close()
            topo0 = griddata.stb(sn, np.flip(lat_fy4a,
                                             0), np.flip(lon_fy4a, 0),
                                 np.flip(topo, 0), lat_gd, lon_gd)
            topo[np.where(cth > 0)] = cth[np.where(cth > 0)]
            topo = griddata.stb(sn, np.flip(lat_fy4a, 0), np.flip(lon_fy4a, 0),
                                np.flip(topo, 0), lat_gd, lon_gd)
            # cth[np.where(tb2 == miss)] = topo0[np.where(tb2 == miss)]
            idout = np.where((tb2 - 273.15 < tbrg[0])
                             | (tb2 - 273.15 > tbrg[1]))
            cth[idout] = topo0[idout]

        lt = light.point(lon2, lat2, cth, np.array([-1, 1, 1]))
        if True:
            lt[lt < 0] = 0
            lt = lt + 0.3
            lt[lt > 1] = 1

        g = 5
        for i in range(0, 3):
            lt = cv2.filter2D(lt, -1, np.ones((g, g))) /\
                cv2.filter2D(np.ones(lt.shape), -1, np.ones((g, g)))

        tb4 = tb3 + 0
        tb4[:, :, 0] = tb4[:, :, 0] * lt
        tb4[:, :, 1] = tb4[:, :, 1] * lt
        tb4[:, :, 2] = tb4[:, :, 2] * lt
    # }}}

    ccc = colors.ListedColormap(ch8.tolist(), name='test1')
    return lon2, lat2, tb2, tb3, tb4, lat_fy4a, lon_fy4a, ccc
예제 #8
0
import cv2


lat_fy4a = './lut4k_1.tif',
lon_fy4a = './lut4k_2.tif',
lat_fy4a = gdal.Open(lat_fy4a).\
    ReadAsArray(0, 0, 2748, 2748)  # 纬度数据
lon_fy4a = gdal.Open(lon_fy4a).\
    ReadAsArray(0, 0, 2748, 2748)  # 经度数据

figname = 'in.tiff'
rgb = cv2.imread(figname)
r = rgb[:, :, 0]
g = rgb[:, :, 1]
b = rgb[:, :, 2]

lonlim = [-180, 180]
latlim = [-90, 90]

lat_gd = np.linspace(latlim[0], latlim[1], num=2000)
lon_gd = np.linspace(lonlim[0], lonlim[1], num=2000)

r2 = griddata.stb(3, np.flip(lat_fy4a, 0), np.flip(lon_fy4a, 0),
                  np.flip(r, 0), lat_gd, lon_gd)
g2 = griddata.stb(3, np.flip(lat_fy4a, 0), np.flip(lon_fy4a, 0),
                  np.flip(g, 0), lat_gd, lon_gd)
b2 = griddata.stb(3, np.flip(lat_fy4a, 0), np.flip(lon_fy4a, 0),
                  np.flip(b, 0), lat_gd, lon_gd)
rgb2 = np.stack((r2, g2, b2))
cv2.imwrite(figname+'.grid.tiff', rgb2)