From 0c5a85c614df27f05ef4343e1b0c9499e7103371 Mon Sep 17 00:00:00 2001 From: Ting Sun Date: Wed, 13 Dec 2023 21:20:56 +0000 Subject: [PATCH] Fix import typo and correct project name in README --- README.md | 16 ++++++++-------- example/case_run.py | 30 +++++++++++++++--------------- example/data_download.py | 2 +- example/minimum_case_run.py | 16 ++++++++-------- 4 files changed, 32 insertions(+), 32 deletions(-) diff --git a/README.md b/README.md index 75ac581..19fc0ad 100644 --- a/README.md +++ b/README.md @@ -8,14 +8,14 @@ More details can be found in [the model descrition paper](https://gmd.copernicus ## Package Description -This project focuses on patch-level building height and footprint mapping from Sentinel imagery. **SHAFT** is an abbreviation for **S**imultaneous building **H**eight **A**nd **F**ootprin**T** extraction from **S**entinel Imagery. +This project focuses on patch-level building height and footprint mapping from Sentinel imagery. **SHAFTS** is an abbreviation for **S**imultaneous building **H**eight **A**nd **F**ootprin**T** extraction from **S**entinel Imagery. ### Installation -SHAFT requires 64-bit `python` 3.7+ and can be installed with `pip` in command line prompt: +SHAFTS requires 64-bit `python` 3.7+ and can be installed with `pip` in command line prompt: ``` -python3 -m pip install shaft --upgrade +python3 -m pip install shafts --upgrade ``` We recommend users to install `gdal>=3.2.0` using `conda` first. @@ -23,7 +23,7 @@ Otherwise, installation may raise error about the environment variables of `gdal ### Data Download -The input data of SHAFT may include: +The input data of SHAFTS may include: - [Sentinel-1](https://sentinels.copernicus.eu/web/sentinel/missions/sentinel-1): VH band, VV band. @@ -31,14 +31,14 @@ The input data of SHAFT may include: - [SRTM](https://www2.jpl.nasa.gov/srtm/): DEM (optional). -SHAFT contains some functions which can download above data directly from [Google Earth Engine](https://earthengine.google.com/). +SHAFTS contains some functions which can download above data directly from [Google Earth Engine](https://earthengine.google.com/). Note that according to the [guidance](https://developers.google.com/earth-engine/guides/exporting) for exporting data from Google Earth Engine, we can not export data to any local devices directly. Thus, Google Drive is recommended as a destination where data are export and then we can download exported data to our local devices. An example for downloading Sentinel-2's image via `sentinel2_download_by_extent` is given as follows: ```python {cmd} -from shaft.utils.GEE_ops import sentinel2_download_by_extent +from shafts.utils.GEE_ops import sentinel2_download_by_extent # ---specify the spatial extent and year for Sentinel-2's images lon_min = -87.740 @@ -57,7 +57,7 @@ sentinel2_download_by_extent(lon_min=lon_min, lat_min=lat_min, lon_max=lon_max, year=year, dst_dir=dst_dir, file_name=file_name, dst=dst) ``` -Also, SHAFT gives functions such as `sentinel1_download`, `sentinel2_download` and `srtm_download` to download images in a batch way by a `.csv` file. +Also, SHAFTS gives functions such as `sentinel1_download`, `sentinel2_download` and `srtm_download` to download images in a batch way by a `.csv` file. ### Building Height and Footprint prediction @@ -88,7 +88,7 @@ If users want to generate building height and footprint maps without downloading An example usage can be given as follows: ```python {cmd} -from shaft.inference_gcloud import GBuildingMap +from shafts.inference_gcloud import GBuildingMap # ---specify the mapping extent by the minimum/maximum of longitude and latitude lon_min = -0.50 diff --git a/example/case_run.py b/example/case_run.py index b5a05ed..c4f30a3 100644 --- a/example/case_run.py +++ b/example/case_run.py @@ -1,6 +1,6 @@ import os import torch -from shaft.inference import pred_height_from_tiff_DL_patch, pred_height_from_tiff_DL_patch_MTL +from shafts.inference import pred_height_from_tiff_DL_patch, pred_height_from_tiff_DL_patch_MTL if __name__ == "__main__": @@ -42,7 +42,7 @@ "DEM": { "path": os.path.join(case_prefix, "infer_test_Glasgow", "raw_data", "Glasgow_srtm.tif"), "patch_size_ratio": 1.0, - } + } }, "output_prefix": "Glasgow", }, @@ -61,7 +61,7 @@ "DEM": { "path": os.path.join(case_prefix, "infer_test_Chicago", "raw_data", "Chicago_srtm.tif"), "patch_size_ratio": 1.0, - } + } }, "output_prefix": "Chicago", }, @@ -74,15 +74,15 @@ trained_record = { "STL": { - 100: os.path.join("check_pt_{0}_100m".format(backbone), "experiment_1", "checkpoint.pth.tar"), - 250: os.path.join("check_pt_{0}_250m".format(backbone), "experiment_1", "checkpoint.pth.tar"), - 500: os.path.join("check_pt_{0}_500m".format(backbone), "experiment_1", "checkpoint.pth.tar"), + 100: os.path.join("check_pt_{0}_100m".format(backbone), "experiment_1", "checkpoint.pth.tar"), + 250: os.path.join("check_pt_{0}_250m".format(backbone), "experiment_1", "checkpoint.pth.tar"), + 500: os.path.join("check_pt_{0}_500m".format(backbone), "experiment_1", "checkpoint.pth.tar"), 1000: os.path.join("check_pt_{0}_1000m".format(backbone), "experiment_1", "checkpoint.pth.tar") }, "MTL": { - 100: os.path.join("check_pt_{0}_100m_MTL".format(backbone), "experiment_1", "checkpoint.pth.tar"), - 250: os.path.join("check_pt_{0}_250m_MTL".format(backbone), "experiment_1", "checkpoint.pth.tar"), - 500: os.path.join("check_pt_{0}_500m_MTL".format(backbone), "experiment_1", "checkpoint.pth.tar"), + 100: os.path.join("check_pt_{0}_100m_MTL".format(backbone), "experiment_1", "checkpoint.pth.tar"), + 250: os.path.join("check_pt_{0}_250m_MTL".format(backbone), "experiment_1", "checkpoint.pth.tar"), + 500: os.path.join("check_pt_{0}_500m_MTL".format(backbone), "experiment_1", "checkpoint.pth.tar"), 1000: os.path.join("check_pt_{0}_1000m_MTL".format(backbone), "experiment_1", "checkpoint.pth.tar") } } @@ -113,9 +113,9 @@ pred_height_from_tiff_DL_patch(extent=extent, out_file=output_path, tif_ref=input_ref, patch_size=patch_size, predictor=model, trained_record=pt_path, resolution=output_res, s1_key=s1_key, s2_key=s2_key, - aux_feat_info=aux_feat_info, base_dir=tmp_dir, padding=padding, - batch_size=batch_size, tmp_suffix=None, activation=var_ref[target_var]["activation"], - log_scale=False, cuda_used=cuda_used, + aux_feat_info=aux_feat_info, base_dir=tmp_dir, padding=padding, + batch_size=batch_size, tmp_suffix=None, activation=var_ref[target_var]["activation"], + log_scale=False, cuda_used=cuda_used, v_min=var_ref[target_var]["min"], v_max=var_ref[target_var]["max"]) # ------do inference by MTL models @@ -126,12 +126,12 @@ output_height_file = "_".join([case_loc[loc]["output_prefix"], "height", backbone + "_MTL"]) + ".tif" output_height_path = os.path.join(output_dir, output_height_file) - pred_height_from_tiff_DL_patch_MTL(extent=extent, out_footprint_file=output_footprint_path, out_height_file=output_height_path, + pred_height_from_tiff_DL_patch_MTL(extent=extent, out_footprint_file=output_footprint_path, out_height_file=output_height_path, tif_ref=input_ref, patch_size=patch_size, predictor=model, trained_record=pt_path, resolution=output_res, s1_key=s1_key, s2_key=s2_key, - aux_feat_info=aux_feat_info, crossed=False, base_dir=tmp_dir, padding=padding, + aux_feat_info=aux_feat_info, crossed=False, base_dir=tmp_dir, padding=padding, batch_size=batch_size, tmp_suffix=None, log_scale=False, - cuda_used=cuda_used, + cuda_used=cuda_used, h_min=var_ref["height"]["min"], h_max=var_ref["height"]["max"], f_min=var_ref["footprint"]["min"], f_max=var_ref["footprint"]["max"]) diff --git a/example/data_download.py b/example/data_download.py index 8804da0..c173224 100644 --- a/example/data_download.py +++ b/example/data_download.py @@ -1,4 +1,4 @@ -from shaft.utils.GEE_ops import sentinel2_download_by_extent +from shafts.utils.GEE_ops import sentinel2_download_by_extent # ---specify the spatial extent and year for Sentinel-2's images diff --git a/example/minimum_case_run.py b/example/minimum_case_run.py index 93e17b4..41e9efe 100644 --- a/example/minimum_case_run.py +++ b/example/minimum_case_run.py @@ -1,6 +1,6 @@ import os import torch -from shaft.inference import pred_height_from_tiff_DL_patch, pred_height_from_tiff_DL_patch_MTL +from shafts.inference import pred_height_from_tiff_DL_patch, pred_height_from_tiff_DL_patch_MTL if __name__ == "__main__": @@ -20,8 +20,8 @@ f_max = 1.0 # ---specify the settings of cases - target_resolution = 100 # target resolution for building height and footprint mapping - target_extent = [-4.4786000, 55.6759000, -3.8828000, 56.0197000] # target extent for building height and footprint mapping + target_resolution = 100 # target resolution for building height and footprint mapping + target_extent = [-4.4786000, 55.6759000, -3.8828000, 56.0197000] # target extent for building height and footprint mapping # ------specify the path of input Sentinel data (note: please use the following format for input data specification) s1_key = "sentinel_1" # key which indicates the path of Sentinel-1's files @@ -29,7 +29,7 @@ input_img = { "50pt": { # use annual medians as aggregation operation for one year data - s1_key: os.path.join(case_prefix, "infer_test_Glasgow", "raw_data", "Glasgow_2020_sentinel_1.tif"), # path of input Sentinel-1 image + s1_key: os.path.join(case_prefix, "infer_test_Glasgow", "raw_data", "Glasgow_2020_sentinel_1.tif"), # path of input Sentinel-1 image s2_key: os.path.join(case_prefix, "infer_test_Glasgow", "raw_data", "Glasgow_2020_sentinel_2.tif"), # path of input Sentinel-2 image } } @@ -45,7 +45,7 @@ model = "SEResNet18" # name of pretrained models pretrained_model_path = os.path.join("check_pt_{0}_100m_MTL".format(backbone), "experiment_1", "checkpoint.pth.tar") # path of files of pretrained models input_patch_size = [20] # size of input sizes required by pretrained models - + # ---specify the common settings of prediction padding = 0.03 # padding size outside the target region (it is recommended that padding should not be smaller than 0.03) cuda_used = torch.cuda.is_available() # check whether CUDA can be used for prediction @@ -60,12 +60,12 @@ output_height_path = os.path.join(output_dir, output_height_file) # path of output building height files # ---start our prediction - pred_height_from_tiff_DL_patch_MTL(extent=target_extent, out_footprint_file=output_footprint_path, out_height_file=output_height_path, + pred_height_from_tiff_DL_patch_MTL(extent=target_extent, out_footprint_file=output_footprint_path, out_height_file=output_height_path, tif_ref=input_img, patch_size=input_patch_size, predictor=model, trained_record=pretrained_model_path, resolution=target_res_mapping[target_resolution], s1_key=s1_key, s2_key=s2_key, - aux_feat_info=aux_data, crossed=False, base_dir=tmp_dir, padding=padding, + aux_feat_info=aux_data, crossed=False, base_dir=tmp_dir, padding=padding, batch_size=batch_size, tmp_suffix=None, log_scale=False, - cuda_used=cuda_used, + cuda_used=cuda_used, h_min=h_min, h_max=h_max, f_min=f_min, f_max=f_max) \ No newline at end of file