#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Sat Nov 27 18:07:14 2021 @author: Changyong.Cao@noaa.gov A barebone Python program to extract a small area from the VIIRS I1 band in h5 format. Output: display image on screen for the small area """ import h5py #, glob, sys, getopt, argparse, re, os #from osgeo import gdal, gdal_array, osr import numpy as np #from gisfunctions import GetGeographicInfo #from gisfunctions import GetDatasetList from matplotlib import pyplot as plt # from array import array # import sys # import os #LA Port: the center lat/lon of the area of interest #This needs to be changed depending on the input data: Plat=33.7185 Plon=-118.2673 I1='GIMGO-SVI01_npp_d20191001_t2055079_e2100482_b41080_c20211202181848054653_noac_ops.h5' f = h5py.File(I1, "r") print('h5file:',f.keys()) theLat="/All_Data/VIIRS-IMG-GEO_All/Latitude" theLon="/All_Data/VIIRS-IMG-GEO_All/Longitude" lat=f.get(theLat) lat=abs(np.array(lat)-Plat) lon=f.get(theLon) lon=abs(np.array(lon)-Plon) X=abs(lat+lon) Pmin=np.argwhere(X == np.min(X)) print(Pmin.shape) Cx=Pmin[0,0] Cy=Pmin[0,1] print(Cx,Cy) print(lat) b=1 img=f.get("/All_Data/VIIRS-I1-SDR_All/Radiance") plt.imshow(img,vmin=0,vmax=20,cmap="gray") ce=f.get("/All_Data/VIIRS-I1-SDR_All/RadianceFactors") print('c0:',ce[0],ce[1]) #img=np.subtract(img,ce[1])*ce[0] #img=(img+ce[1])*ce[0] #This is probably the correct equation: img=img*ce[0]+ce[1] s=300 x1=Cx-s if (x1 < 0): x1=1 x2=Cx+s if (x2 < 0): x2=1 y1=Cy-s if (y1 < 0): y1=1 y2=Cy+s if (y2< 0): y1=1 subimg=img[x1:x2,y1:y2] subimg=np.fliplr(subimg) subimg=np.flipud(subimg) #subimg=np.rot90(subimg,k=-1) plt.imshow(subimg,vmin=0,vmax=25,cmap="gray") lat=f.get(theLat) lat2=lat[x1,y1] lat1=lat[x2,y2] lon=f.get(theLon) lon1=lon[x1,y1] lon2=lon[x2,y2] print("location:",lon1,lat1,lon2,lat2)