else: season = "fall" root = "LE07_L1TP_047026_20141110_20160904_01_T1_" prefix_remote = Path('landsat_scenes/l7_vancouver/fall') prefix_local = Path("landsat7/vancouver/fall") name_dict = dict() for key, band_num in landsat_band_dict.items(): name_dict[key] = f"{root}B{band_num}.TIF" dest_folder = a301.data_dir / prefix_local dest_folder.mkdir(parents=True, exist_ok=True) for key, the_file in name_dict.items(): 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
# ## plotting Vancouver on a map # # # ### Step 1: Use [cartopy](http://scitools.org.uk/cartopy/docs/latest/index.html) to make a LAEA map of BC including Vancouver. # # **The cell below uses [context.py](https://github.com/phaustin/a301_code/blob/master/notebooks/context.py) to find # the path to data_dir. It is held in the variable context.data_dir** # %% from context import data_dir from a301.utils.data_read import download read_data = False if read_data: filename = "MYD021KM.A2013222.2105.061.2018047235850.hdf" download(filename) local_file = Path.cwd() / Path(filename) to_file = data_dir / Path(filename) local_file.rename(to_file) # %% [markdown] # **This cell sets up the datum and the LAEA projection, with the tangent point at the North Pole and the central meridian at -90 degrees west of Greenwich** # %% import cartopy.crs as ccrs import matplotlib.pyplot as plt import cartopy from pathlib import Path import pprint import numpy as np
import a301 import json from a301.utils.data_read import download import a301 import pprint import shutil from pyhdf.SD import SD, SDC import json import pprint import cartopy read_data = False if read_data: filename_M3 = 'MYD03.A2013222.2105.006.2013223155808.hdf' download(filename_M3) for filename in [filename_M3, filename_M2]: local_file = Path.cwd() / Path(filename) to_file = a301.data_dir / Path(filename) print(f'copy {local_file} to {to_file}') shutil.copy(local_file, to_file) # In[2]: import cartopy.crs as ccrs import matplotlib.pyplot as plt import cartopy from pathlib import Path import pprint import numpy as np import pdb
# [matplotlib imshow](https://matplotlib.org/examples/images_contours_and_fields/image_demo.html) function to display the raw image # # If you don't have a MYD021KM file you can grab mine by changing # # get_data=False # # to True in the next cell. # # # In[2]: get_data = False if get_data: modis_file = "MYD021KM.A2013222.2105.061.2018047235850.hdf" download(modis_file) # # Reading modis data # The general layout of a Modis data file is given in the [modis users guide](https://www.dropbox.com/s/ckd3dv4n7nxc9p0/modis_users_guide.pdf?dl=0) but we'll only need a fraction of the information in that manual. Modis data is written in [hdf4 format](https://portal.hdfgroup.org/display/HDF4/HDF4), which in python can be read with the [pyhdf module](http://hdfeos.github.io/pyhdf/modules/SD.html#sd-module-key-features). # # # ## Installing pyhdf # # So far we have used the [anaconda default channel](https://conda.io/docs/user-guide/tasks/manage-channels.html) to install miniconda and other libraries. Not every conda package is in the default channel. For example, I have my own channel called [phaustin](https://anaconda.org/phaustin/repo) which I use to distribute software I write. Much of the conda software for the scientific community is distributed in the [conda-forge channel](https://conda-forge.org/) -- this includes the pyhdf module. # # To install pyhdf from the conda-forge channel, the conda command looks like: # # conda install -c conda-forge pyhdf # # On Macs, you will also need to update your jpeg library to match pyhdf: