How to read geotiff files? How to get data in rectangular box from geotiff?

  Data, Python

The example provided here is to read a geotiff file; get data in the box and convert it to an array; get the corresponding latitude and longitude of the box.

import numpy as np
import rasterio
import rasterio.plot

#!pip install geotiff
#https://pypi.org/project/geotiff/
from geotiff import GeoTiff

# use rasterio to read geotiff file
data_name = "SPAM2005V3r2_global_P_TA_MAIZ_A.tif"
data_name1= 'SPAM2005V3r2_global_P_TI_MAIZ_I.tif'
tiff = rasterio.open(data_name)
rasterio.plot.show(tiff, title = "Maize")

#use GeoTiff read geotiff file
tiff_file=data_name
geo_tiff = GeoTiff(tiff_file, band=0)
geo_tiff1 = GeoTiff(data_name1, band=0)

# get data in a box
area_box =[(-100,65),(-70,35)]
wgs_84_box = geo_tiff.get_bBox_wgs_84(area_box)
array = geo_tiff.read_box(wgs_84_box,outer_points=2)
array1 = geo_tiff1.read_box(wgs_84_box,outer_points=2)

# get the coordinate of the data in the box
lon_array, lat_array = geo_tiff.get_coord_arrays(wgs_84_box,outer_points=2)