landsat_tif = prefix_remote / Path(the_file) download(str(landsat_tif), dest_folder=dest_folder) name_dict[key] = str(a301.data_dir / prefix_local / the_file) the_file = Path(f"{root}MTL.txt") mtl_file = prefix_remote / the_file download(str(mtl_file), dest_folder=dest_folder) name_dict['mtl'] = str(a301.data_dir / prefix_local / the_file) # %% [markdown] {"nbgrader": {"grade": false, "grade_id": "cell-dd09edb695c92076", "locked": true, "schema_version": 1, "solution": false}} # # This cell reads in your affine transform, metadata and profile # # Using red band file for transform/profile information (arbitrary) # %% {"nbgrader": {"grade": false, "grade_id": "cell-daebc17375c70921", "locked": true, "schema_version": 1, "solution": false}} metadata = landsat_metadata(name_dict['mtl']) satellite = metadata.SPACECRAFT_ID with rasterio.open(name_dict['red']) as raster: big_transform = raster.transform big_profile = raster.profile zone = metadata.UTM_ZONE crs = cartopy.crs.UTM(zone, southern_hemisphere=False) p_utm = Proj(crs.proj4_init) p_lonlat = Proj(proj='latlong', datum='WGS84') # %% [markdown] {"nbgrader": {"grade": false, "grade_id": "cell-cef7282b3b40dd6f", "locked": true, "schema_version": 1, "solution": false}} # # This cell gets the right reflection function for your satellite # %% {"nbgrader": {"grade": false, "grade_id": "cell-df3ceb3d365ce669", "locked": true, "schema_version": 1, "solution": false}} refl_dict = {'LANDSAT_7': calc_refl_457, 'LANDSAT_8': calc_reflc_8}
from matplotlib import pyplot as plt from skimage import data, img_as_float from skimage import exposure june_2015 = a301.test_dir / Path('landsat8/LC80470262015165LGN02') may_2015 = a301.test_dir / Path("landsat_2018_05_13") data_dir = may_2015 data_dir = june_2015 tiff_file = list(data_dir.glob("*B1.TIF"))[0] meta_file = list(data_dir.glob("*MTL.txt"))[0] #jpeg_file=list(data_dir.glob("*T1.jpg"))[0] help(img_as_float) # In[2]: out = landsat_metadata(meta_file) meta_dict = out.__dict__ with pil_image.open(tiff_file) as img: tiff_meta_dict = {TAGS[key]: img.tag[key] for key in img.tag.keys()} ch1 = img_as_float(img) img_eq = exposure.equalize_hist(ch1) # In[3]: plt.hist(ch1.ravel()) # In[4]: plt.imshow(ch1)
# # Here is the correct orientation # In[3]: Image('images/LC08_L1TP_232091_20160108_20170405_01_T1.png',width=400) # # Make two different crs versions (epsg and zone) # # Note the different lower limits on y # In[4]: meta_dict=landsat_metadata(mtl_file).__dict__ zone=meta_dict['UTM_ZONE'] epsg_code=crs.to_epsg() print(f'we are in zone {zone} with epsg_code {epsg_code}') cartopy_crs_code=cartopy.crs.epsg(epsg_code) cartopy_crs_zone = cartopy.crs.UTM(zone, southern_hemisphere=False) print(f"North zone y limits from the cartopy epsg constructor {cartopy_crs_code.y_limits}") cartopy_crs=cartopy_crs_zone print(f"North zone y limits from cartopy UTM constructor {cartopy_crs_zone.y_limits}") # # Show that we can get the correct coastline # In[5]:
# # Question A: define your own version of file_dict # # In the next cell create a version of file_dict with the same structure as mine, but with your filenames substituted # for mine # %% {"deletable": false, "nbgrader": {"checksum": "b996f3c4dda7d99b6eafc8eb406c6dbe", "grade": true, "grade_id": "cell-fc9e612b0aa125e8", "locked": false, "points": 4, "schema_version": 1, "solution": true}} # YOUR CODE HERE raise NotImplementedError() # %% [markdown] {"deletable": false, "editable": false, "nbgrader": {"checksum": "9c203c221c48c22c6bae77781d739b39", "grade": false, "grade_id": "cell-dd09edb695c92076", "locked": true, "schema_version": 1, "solution": false}} # # This cell reads in your affine transform, metadata and profile # # Using red band file for transform/profile information (arbitrary) # %% {"deletable": false, "editable": false, "nbgrader": {"checksum": "df87b1b62c70bc362823c4adb4309837", "grade": false, "grade_id": "cell-daebc17375c70921", "locked": true, "schema_version": 1, "solution": false}} metadata=landsat_metadata(file_dict['spring']['filenames']['mtl']) zone = metadata.UTM_ZONE crs = cartopy.crs.UTM(zone, southern_hemisphere=False) p_utm=Proj(crs.proj4_init) p_lonlat=Proj(proj='latlong',datum='WGS84') file_dict['satellite']=metadata.SPACECRAFT_ID # %% [markdown] {"deletable": false, "editable": false, "nbgrader": {"checksum": "92c3aa1b32a0b1f90621c3b0ef97b099", "grade": false, "grade_id": "cell-cef7282b3b40dd6f", "locked": true, "schema_version": 1, "solution": false}} # # This cell gets the right reflection and radiance functions for your satellite # # See [the library listing](https://clouds.eos.ubc.ca/~phil/courses/atsc301/codedoc/full_listing.html) for the function signatures. # %% {"deletable": false, "editable": false, "nbgrader": {"checksum": "57225c558d2128d4992783a5acd2f00f", "grade": false, "grade_id": "cell-df3ceb3d365ce669", "locked": true, "schema_version": 1, "solution": false}} refl_dict={'LANDSAT_7':calc_refl_457,'LANDSAT_8':calc_reflc_8} radiance_dict={'LANDSAT_7':calc_radiance_457,'LANDSAT_8':calc_radiance_8} satellite=metadata.SPACECRAFT_ID