diff --git a/benchmarks/cloudmask/target/greene_v0.5/library.py b/benchmarks/cloudmask/target/greene_v0.5/library.py index 5041cde5..626a3990 100644 --- a/benchmarks/cloudmask/target/greene_v0.5/library.py +++ b/benchmarks/cloudmask/target/greene_v0.5/library.py @@ -1,5 +1,8 @@ import pandas as pd from datetime import datetime +from astral.sun import sun +from astral import LocationInfo +import plotly.express as px class SLSTRFileNameParser: def __init__(self, file_name): @@ -10,7 +13,7 @@ def parse_file_name(self): components = self.file_name.split('_') return { - "filename": file_name, + "filename": self.file_name, "mission_id": components[0], "data_source": components[1], "processing_level": components[2], @@ -65,18 +68,38 @@ def plot_gantt_chart(dataframe): # Show the chart fig.show() + def is_daytime(self, latitude, longitude): + # Extracting the date and time from the start_time in the file_info + datetime_obj = self.file_info["start_time"] + # Getting the location information + location = LocationInfo(latitude, longitude) + # Calculating the sunrise and sunset times for the given date and location + s = sun(location.observer, date=datetime_obj) + + # Checking if the timestamp is between sunrise and sunset + return s["sunrise"] < datetime_obj < s["sunset"] # Example usage with multiple file names -#file_names = [ -# "S3A_SL_2_LST____20151229T095534_20151229T114422_20160102T150019_6528_064_365______LN2_D_NT_001.SEN3", -# "S3B_SL_1_RBT_BW_20160101T120000_20160101T130000_20160101T140000_GLOBAL___________LN2_R_NT_002.SEN3", -# # Add more file names as needed -#] +# file_names = [ +# "S3A_SL_2_LST____20151229T095534_20151229T114422_20160102T150019_6528_064_365______LN2_D_NT_001.SEN3", +# "S3B_SL_1_RBT_BW_20160101T120000_20160101T130000_20160101T140000_GLOBAL___________LN2_R_NT_002.SEN3", +# # Add more file names as needed +# ] # Creating a DataFrame using the class method -#df = SLSTRFileNameParser.generate_dataframe(file_names) +# df = SLSTRFileNameParser.generate_dataframe(file_names) # Displaying the DataFrame -#print(df) +# print(df) + +# Plotting Gantt chart using the class method +# SLSTRFileNameParser.plot_gantt_chart(df) + +# Checking if timestamps are daytime using the class method +# latitude = 37.7749 # Replace with the latitude of the specific location +# longitude = -122.4194 # Replace with the longitude of the specific location + +# Assuming you want to check daytime for the first file in the DataFrame +# print(f"{df.iloc[0]['filename']} is daytime: {SLSTRFileNameParser(df.iloc[0]['filename']).is_daytime(latitude, longitude)}")