#!/usr/bin/env python # -*- coding: utf-8 -*- # File : read_file.py # Author : Jingliang Hu # Date : 15.08.2018 14:05:08 # Last Modified Date: 15.08.2018 14:05:08 # Last Modified By : Yuanyuan Wang # Last modified: 15.08.2018 14:06:23 Yuanyuan Wang # added visualization # Last modified: 19.11.2025 Qi Zhang, Yi Wang # added geolocation import h5py import numpy as np import matplotlib.pyplot as plt # select one of the given files fileOfChoice = 'validation.h5' # show the variables in selected file fid = h5py.File(fileOfChoice,'r') print('INFO: The names of variables in the file of \''+fileOfChoice+'\':') print fid.keys() # load the data into memory print('INFO: Loading sentinel-1 data patches ...') s1 = np.array(fid['sen1']) print('INFO: Sentinel-1 data dimension:') print(s1.shape) print('INFO: Loading sentinel-2 data patches ...') s2 = np.array(fid['sen2']) print('INFO: Sentinel-2 data dimension:') print(s2.shape) print('INFO: Loading label ...') lab = np.array(fid['label']) print('INFO: Label dimension:') print(lab.shape) # visualization, plot the first pair of Sentinel-1 and Sentinel-2 patches of training.h5 plt.subplot(121) plt.imshow(10*np.log10(s1[0,:,:,4]),cmap=plt.cm.get_cmap('gray')) plt.colorbar() plt.title('Sentinel-1') plt.subplot(122) plt.imshow(s2[0,:,:,1],cmap=plt.cm.get_cmap('gray')) plt.colorbar() plt.title('Sentinel-2') plt.show() #%% # select one of the given files fileOfChoice = 'validation_geo.h5' # show the variables in selected file fid = h5py.File(fileOfChoice,'r') print('INFO: The names of variables in the file of \''+fileOfChoice+'\':') # load the data into memory print('INFO: Loading coordinate data ...') coord = np.array(fid['coord']) print('INFO: Coordinate data dimension:') print(coord.shape) # load the data into memory print('INFO: Loading epsg data ...') tfw = np.array(fid['tfw']) print('INFO: tfw data dimension:') print(tfw.shape) # load the data into memory print('INFO: Loading epsg data ...') epsg = np.array(fid['epsg']) print('INFO: epsg data dimension:') print(epsg.shape)