Skip to content

Commit

Permalink
Reformatting for proper linting
Browse files Browse the repository at this point in the history
  • Loading branch information
lunasilvestre committed Oct 6, 2023
1 parent ee808a8 commit a11b008
Show file tree
Hide file tree
Showing 10 changed files with 50 additions and 38 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ jobs:
- name: Lint with flake8
run: |
flake8 ee_lst/ tests/
flake8 modules/ tests/ examples/ validation/
- name: Check code formatting with black
run: |
black --check ee_lst/ tests/
black --check modules/ tests/ examples/ validation/
# - name: Run tests
# run: |
Expand Down
1 change: 0 additions & 1 deletion examples/example_1.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,3 @@ def add_ee_layer(self, ee_image_object, vis_params, name):
# region=geometry,
# fileFormat='GeoTIFF')
# task.start()

3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
setup(
name="ee_lst",
version="0.1.0",
description="Python library for Landsat Surface Temperature with Google Earth Engine",
description="Python library for Landsat Surface\
Temperature with Google Earth Engine",
author="Nelson Luna Silvestre",
author_email="lunasilvestre@mailbox.org",
url="https://github.com/lunasilvestre/ee_lst",
Expand Down
2 changes: 1 addition & 1 deletion tests/test_aster_bare_emiss.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def test_emiss_bare_band10():
test_image = load_test_image()

# Compute emissivity using the refactored function
result = ASTER_bare_emiss.emiss_bare_band10(test_image)
result = aster_bare_emiss.emiss_bare_band10(test_image)

# Compare the result with the expected output
expected_output = expected_output_emissivity()
Expand Down
2 changes: 1 addition & 1 deletion tests/test_compute_fvc.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def test_add_band():
test_image = load_test_image()

# Compute FVC using the refactored function
result = compute_FVC.add_band("L8", test_image) # Example for Landsat 8
result = compute_fvc.add_band("L8", test_image) # Example for Landsat 8

# Compare the result with the expected output
expected_output = expected_output_fvc()
Expand Down
2 changes: 1 addition & 1 deletion tests/test_compute_ndvi.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def test_add_band():
test_image = load_test_image()

# Compute NDVI using the refactored function
result = compute_NDVI.add_band("L8", test_image) # Example for Landsat 8
result = compute_ndvi.add_band("L8", test_image) # Example for Landsat 8

# Compare the result with the expected output
expected_output = expected_output_ndvi()
Expand Down
2 changes: 1 addition & 1 deletion tests/test_landsat_lst.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def test_compute_LST():
test_image = load_test_image()

# Compute LST using the refactored function
result = Landsat_LST.compute_LST("L8", test_image)
result = landsat_lst.compute_LST("L8", test_image)

# Compare the result with the expected output
expected_output = expected_LST_output()
Expand Down
2 changes: 1 addition & 1 deletion tests/test_ncep_tpw.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def test_add_band():
test_image = load_test_image()

# Compute TPW using the refactored function
result = NCEP_TPW.add_band(test_image)
result = ncep_tpw.add_band(test_image)

# Compare the result with the expected output
expected_output = expected_TPW_output()
Expand Down
34 changes: 22 additions & 12 deletions validation/example_1_service_account.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@

def initialize_services(service_account_file):
"""Initialize Earth Engine and Google Drive services."""
credentials = service_account.Credentials.from_service_account_file(service_account_file, scopes=SCOPES)
credentials = service_account.Credentials.from_service_account_file(
service_account_file, scopes=SCOPES)
ee.Initialize(credentials)
return build('drive', 'v3', credentials=credentials)

Expand Down Expand Up @@ -93,7 +94,9 @@ def download_files(service, folder_name, download_path):
done = False
while done is False:
status, done = downloader.next_chunk()
print(f"Downloaded {int(status.progress() * 100)}% of {file_name}")
msg = "Downloaded "
msg += f"{int(status.progress() * 100)}% of {file_name}"
print(msg)

print(f"All files downloaded to {download_path}")

Expand Down Expand Up @@ -121,14 +124,21 @@ def process_data(drive_service, folder_name):
cmap2 = ["F2F2F2", "EFC2B3", "ECB176", "E9BD3A", "E6E600", "63C600", "00A600"]

visualizations = [
{'bands': ['TPW'], 'min': 0.0, 'max': 60.0, 'palette': cmap1, 'description': 'TCWV'},
{'bands': ['TPWpos'], 'min': 0.0, 'max': 9.0, 'palette': cmap1, 'description': 'TCWVpos'},
{'bands': ['FVC'], 'min': 0.0, 'max': 1.0, 'palette': cmap2, 'description': 'FVC'},
{'bands': ['EM'], 'min': 0.9, 'max': 1.0, 'palette': cmap1, 'description': 'Emissivity'},
{'bands': ['B10'], 'min': 290, 'max': 320, 'palette': cmap1, 'description': 'TIR_BT'},
{'bands': ['LST'], 'min': 290, 'max': 320, 'palette': cmap1, 'description': 'LST'},
{'bands': ['TPW'], 'min': 0.0, 'max': 60.0, 'palette': cmap1,
'description': 'TCWV'},
{'bands': ['TPWpos'], 'min': 0.0, 'max': 9.0, 'palette': cmap1,
'description': 'TCWVpos'},
{'bands': ['FVC'], 'min': 0.0, 'max': 1.0, 'palette': cmap2,
'description': 'FVC'},
{'bands': ['EM'], 'min': 0.9, 'max': 1.0, 'palette': cmap1,
'description': 'Emissivity'},
{'bands': ['B10'], 'min': 290, 'max': 320, 'palette': cmap1,
'description': 'TIR_BT'},
{'bands': ['LST'], 'min': 290, 'max': 320, 'palette': cmap1,
'description': 'LST'},
{'bands': ['LST'], 'description': 'LST_Celsius_Raw'},
{'bands': ['SR_B4', 'SR_B3', 'SR_B2'], 'min': 0, 'max': 0.3, 'description': 'RGB'},
{'bands': ['SR_B4', 'SR_B3', 'SR_B2'], 'min': 0, 'max': 0.3,
'description': 'RGB'},
]

for vis in visualizations:
Expand Down Expand Up @@ -173,11 +183,11 @@ def process_data(drive_service, folder_name):

if __name__ == "__main__":
drive_service = initialize_services(service_account_file)

# Clean the folder in Google Drive
clean_folder(drive_service, folder_name)

process_data(drive_service, folder_name)

# Download files to the container
download_files(drive_service, folder_name, local_download_path)
36 changes: 19 additions & 17 deletions validation/geotiffs_comparison.py
Original file line number Diff line number Diff line change
@@ -1,32 +1,35 @@
import os
import rasterio
import rasterio as rst
import numpy as np


def compare_images(img_path1, img_path2):
with rasterio.open(img_path1) as src1, rasterio.open(img_path2) as src2:
with rst.open(img_path1) as src1, rst.open(img_path2) as src2:

# Check and report size difference
h1, w1 = src1.shape
h2, w2 = src2.shape

diff_h = abs(h1 - h2)
diff_w = abs(w1 - w2)

size_diff_percent = max(diff_h / max(h1, h2), diff_w / max(w1, w2)) * 100

print(f"Size difference: {size_diff_percent:.2f}%")
if size_diff_percent > 0.5:
raise ValueError("Size difference exceeds threshold!")

# Crop if necessary
target_h = min(h1, h2)
target_w = min(w1, w2)

start_row_1 = h1 - target_h
start_row_2 = h2 - target_h

data1 = src1.read(1, window=rasterio.windows.Window(0, start_row_1, target_w, target_h))
data2 = src2.read(1, window=rasterio.windows.Window(0, start_row_2, target_w, target_h))

data1 = src1.read(
1, window=rst.windows.Window(0, start_row_1, target_w, target_h))
data2 = src2.read(
1, window=rst.windows.Window(0, start_row_2, target_w, target_h))

# Calculate the difference
difference = data1 - data2
Expand All @@ -50,28 +53,27 @@ def compare_images(img_path1, img_path2):

# Optionally, save the difference as a new GeoTIFF
# output_path = "difference.tif"
# with rasterio.open(output_path, 'w', driver='GTiff',
# height=difference.shape[0], width=difference.shape[1], count=1,
# dtype=difference.dtype, crs=src1.crs, transform=src1.transform) as dst:
# with rst.open(output_path, 'w', driver='GTiff',
# height=difference.shape[0], width=difference.shape[1], count=1,
# dtype=difference.dtype, crs=src1.crs,
# transform=src1.transform) as dst:
# dst.write(difference, 1)

# print(f"Difference saved to {output_path}")



if __name__ == "__main__":
# img1_path = "./python_downloads/LST.tif"
# img2_path = "./nodejs_downloads/LST.tif"
# compare_images(img1_path, img2_path)

dir1 = './nodejs_downloads'
dir2 = './python_downloads'

for filename in os.listdir(dir1):
if filename.endswith(".tif"):
img1_path = os.path.join(dir1, filename)
img2_path = os.path.join(dir2, filename)

if os.path.exists(img2_path):
print(f"Comparing {filename}...")
compare_images(img1_path, img2_path)
Expand Down

0 comments on commit a11b008

Please sign in to comment.