コード例 #1
0
def readTxt(latitude, longitude, sm):
    # read each line of weather data
    # transfer the time to sun angles
    # save the data
    f = open("testseattle.txt", "r")
    lines = f.readlines()
    data = np.zeros([4709, 7])
    i = 0
    for line in lines:
        month = int(line.splitlines()[0].split(",")[0])
        date = int(line.splitlines()[0].split(",")[1])
        time = float(line.splitlines()[0].split(",")[2])
        dir = int(line.splitlines()[0].split(",")[3])
        dif = int(line.splitlines()[0].split(",")[4])
        al, az = time_to_sun_angles.timeToAltitudeAzimuth(
            date, month, time, latitude, longitude, sm)
        if (dir > 10) or (dif > 10):
            data[i] = np.array([dir, dif, al, az, month, date, time])
            i = i + 1
    return data
コード例 #2
0
def read_one_image(log_process, log_base, sky_map, input_dim, output_dim,
                   dir_ab4, dir_ab0, dir_sky, dir_npy, file_name):
    # load an image (numpy arrays) from a txt file
    im = np.load(dir_ab4 + file_name).astype(np.float64)
    im_resized = cv2.resize(im, (IMAGE_SIZE[1], IMAGE_SIZE[0]))
    # im_resized = im
    sun_im = np.load(dir_ab0 + file_name[:-4] + "_ab0.npy").astype(np.float64)
    sun_im_resized = cv2.resize(sun_im, (IMAGE_SIZE[1], IMAGE_SIZE[0]))
    # sun_im_resized = sun_im
    sky_im = np.load(dir_sky + file_name).astype(np.float64)
    sky_im_resized = cv2.resize(sky_im, (IMAGE_SIZE[1], IMAGE_SIZE[0]))
    # sky_im_resized = sky_im

    # create a new image frame and store all image information in this frame
    image_frame = np.zeros(
        (IMAGE_SIZE[1] * IMAGE_SIZE[0], input_dim + output_dim),
        dtype='float32')

    file = file_name.split('/')[0]
    # get month, date and time from file name
    month, date, standard_time = get_month_date(file)
    dir, dif = get_dir_dif((file))

    # read image pixel by pixel, reorganize the data
    # return image with shape(PIXELS, 6(px, py, altitude, azimuth, ave_luminance(empty for now), real_luminance))
    for i in range(IMAGE_SIZE[1] * IMAGE_SIZE[0]):
        index1, index2 = np.unravel_index(i, (IMAGE_SIZE[0], IMAGE_SIZE[1]))

        full_im_lum = im_resized[index1, index2]
        sun_patch_lum = sun_im_resized[index1, index2]
        sky_lum = sky_im_resized[index1, index2]

        if log_process == True:
            if full_im_lum < 1:
                image_frame[i, -1] = sys.float_info.min
            else:
                image_frame[i, -1] = math.log(full_im_lum,
                                              log_base)  # save sun patch image

            if sun_patch_lum < 1:
                image_frame[i, -2] = sys.float_info.min
            else:
                image_frame[i, -2] = math.log(sun_patch_lum,
                                              log_base)  # save sun patch image

            if sky_map:
                if sky_lum < 1:
                    image_frame[i, -3] = sys.float_info.min
                else:
                    image_frame[i, -3] = math.log(
                        sky_lum, log_base)  # save sky luminance panorama image

        else:
            image_frame[i, -1] = full_im_lum
            image_frame[i, -2] = sun_patch_lum
            if sky_map:
                image_frame[i, -3] = sky_lum

        image_frame[i, 0:2] = index1, index2  # save px, py
        image_frame[i, 2:4] = time_to_sun_angles.timeToAltitudeAzimuth(
            date, month, standard_time, LATITUDE, LONGITUDE,
            SM)  # save altitude, azimuth
        image_frame[i, 4:6] = dir, dif  # save direct and diffuse irradiances

    # save this image
    dir_path = dir_npy + file_name + '.npy'
    np.save(dir_path, image_frame)
    return image_frame