Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file not shown.
Binary file not shown.
2 changes: 1 addition & 1 deletion FLiESANN/FLiESANN.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
from .determine_ctype import determine_ctype
from .prepare_FLiES_ANN_inputs import prepare_FLiES_ANN_inputs
from .run_FLiES_ANN_inference import run_FLiES_ANN_inference
from .process_FLiES_ANN import process_FLiES_ANN
from .process_FLiES_ANN import FLiESANN
from .generate_FLiES_inputs_table import generate_FLiES_inputs_table
from .process_FLiES_table import process_FLiES_table
11 changes: 9 additions & 2 deletions FLiESANN/process_FLiES_ANN.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@
from solar_apparent_time import solar_day_of_year_for_area, solar_hour_of_day_for_area
from sun_angles import calculate_SZA_from_DOY_and_hour
from koppengeiger import load_koppen_geiger
from NASADEM import NASADEM, NASADEMConnection

from .constants import *
from .determine_atype import determine_atype
from .determine_ctype import determine_ctype
from .run_FLiES_ANN_inference import run_FLiES_ANN_inference

def process_FLiES_ANN(
def FLiESANN(
albedo: Union[Raster, np.ndarray],
COT: Union[Raster, np.ndarray] = None,
AOT: Union[Raster, np.ndarray] = None,
Expand All @@ -28,6 +29,7 @@ def process_FLiES_ANN(
day_of_year: Union[Raster, np.ndarray] = None,
hour_of_day: Union[Raster, np.ndarray] = None,
GEOS5FP_connection: GEOS5FP = None,
NASADEM_connection: NASADEMConnection = NASADEM,
resampling: str = "cubic",
ANN_model=None,
model_filename=DEFAULT_MODEL_FILENAME,
Expand Down Expand Up @@ -141,6 +143,9 @@ def process_FLiES_ANN(
resampling=resampling
)

if elevation_km is None and geometry is not None:
elevation_km = NASADEM.elevation_km(geometry=geometry)

# Preprocess COT and determine aerosol/cloud types
COT = np.clip(COT, 0, None) # Ensure COT is non-negative
COT = rt.where(COT < 0.001, 0, COT) # Set very small COT values to 0
Expand Down Expand Up @@ -224,4 +229,6 @@ def process_FLiES_ANN(
for key in results.keys():
results[key] = rt.Raster(results[key], geometry=geometry)

return results
return results

FLiESANN = FLiESANN
4 changes: 2 additions & 2 deletions FLiESANN/process_FLiES_table.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import pandas as pd

from .process_FLiES_ANN import process_FLiES_ANN
from .process_FLiES_ANN import FLiESANN

def process_FLiES_table(FLiES_inputs_df: pd.DataFrame) -> pd.DataFrame:
FLiES_results = process_FLiES_ANN(
FLiES_results = FLiESANN(
day_of_year=FLiES_inputs_df.doy,
albedo=FLiES_inputs_df.albedo,
COT=FLiES_inputs_df.COT,
Expand Down
2 changes: 1 addition & 1 deletion FLiESANN/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.3.0
1.4.0
139 changes: 139 additions & 0 deletions Processing FLiES with a raster and default parameters.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Running FLiES for an ECOSTRESS Scene\n",
"\n",
"This is an example of running the artificial neural network emulator of the Forest Light Environmental Simulator (FLiES) corresponding to an ECOsystem Spaceborne Thermal Radiometer Experiment on Space Station (ECOSTRESS) scene."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from os.path import join\n",
"from datetime import datetime, date, time\n",
"from dateutil import parser\n",
"import rasters as rt\n",
"from geos5fp import GEOS5FP\n",
"from koppengeiger import load_koppen_geiger\n",
"from solar_apparent_time import UTC_to_solar\n",
"import sun_angles\n",
"from FLiESANN import process_FLiES_ANN\n",
"from matplotlib.colors import LinearSegmentedColormap\n",
"import logging\n",
"logging.disable(logging.CRITICAL)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Here's an example ECOSTRESS albedo scene."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"albedo_filename = \"ECOv002_L2T_STARS_11SPS_20240728_0712_01_albedo.tif\"\n",
"albedo_cmap = LinearSegmentedColormap.from_list(name=\"albedo\", colors=[\"black\", \"white\"])\n",
"albedo = rt.Raster.open(albedo_filename, cmap=albedo_cmap)\n",
"albedo"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Let's get the acquisition time of the scene."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"time_UTC = parser.parse(albedo_filename.split(\"_\")[6])\n",
"longitude = albedo.geometry.centroid_latlon.x\n",
"latitude = albedo.geometry.centroid_latlon.y\n",
"time_solar = UTC_to_solar(time_UTC, longitude)\n",
"doy_solar = time_solar.timetuple().tm_yday\n",
"hour_of_day_solar = time_solar.hour + time_solar.minute / 60 + time_solar.second / 3600\n",
"print(f\"{time_UTC:%Y-%m-%d %H:%M:%S} UTC\")\n",
"print(f\"{time_solar:%Y-%m-%d %H:%M:%S} solar apparent time at longitude {longitude}\")\n",
"print(f\"day of year {doy_solar} at longitude {longitude}\")\n",
"print(f\"hour of day {hour_of_day_solar} at longitude {longitude}\")\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"geometry = albedo.geometry\n",
"geometry"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"FLiES_results = process_FLiES_ANN(\n",
" geometry=geometry,\n",
" time_UTC=time_UTC,\n",
" albedo=albedo\n",
")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"Rg = FLiES_results[\"Rg\"]\n",
"Rg.cmap = \"bwr\"\n",
"Rg"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "FLiESANN",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.16"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
8,665 changes: 0 additions & 8,665 deletions Processing FLiES with a raster.ipynb

This file was deleted.

64 changes: 64 additions & 0 deletions processing_FLiES_with_raster_and_default_parameters.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# %% [markdown]
# # Running FLiES for an ECOSTRESS Scene
#
# This is an example of running the artificial neural network emulator of the Forest Light Environmental Simulator (FLiES) corresponding to an ECOsystem Spaceborne Thermal Radiometer Experiment on Space Station (ECOSTRESS) scene.

# %%
from os.path import join
from datetime import datetime, date, time
from dateutil import parser
import rasters as rt
from geos5fp import GEOS5FP
from koppengeiger import load_koppen_geiger
from solar_apparent_time import UTC_to_solar
import sun_angles
from FLiESANN import FLiESANN
from matplotlib.colors import LinearSegmentedColormap
import logging
logging.disable(logging.CRITICAL)

# %% [markdown]
# Here's an example ECOSTRESS albedo scene.

# %%
albedo_filename = "ECOv002_L2T_STARS_11SPS_20240728_0712_01_albedo.tif"
albedo_cmap = LinearSegmentedColormap.from_list(name="albedo", colors=["black", "white"])
albedo = rt.Raster.open(albedo_filename, cmap=albedo_cmap)
albedo

# %% [markdown]
# Let's get the acquisition time of the scene.

# %%
time_UTC = parser.parse(albedo_filename.split("_")[6])
longitude = albedo.geometry.centroid_latlon.x
latitude = albedo.geometry.centroid_latlon.y
time_solar = UTC_to_solar(time_UTC, longitude)
doy_solar = time_solar.timetuple().tm_yday
hour_of_day_solar = time_solar.hour + time_solar.minute / 60 + time_solar.second / 3600
print(f"{time_UTC:%Y-%m-%d %H:%M:%S} UTC")
print(f"{time_solar:%Y-%m-%d %H:%M:%S} solar apparent time at longitude {longitude}")
print(f"day of year {doy_solar} at longitude {longitude}")
print(f"hour of day {hour_of_day_solar} at longitude {longitude}")


# %%
geometry = albedo.geometry
geometry

# %%
FLiES_results = FLiESANN(
geometry=geometry,
time_UTC=time_UTC,
albedo=albedo
)

# %%
Rg = FLiES_results["Rg"]
Rg.cmap = "bwr"
Rg

# %%



5 changes: 3 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ requires = ["setuptools>=60", "setuptools-scm>=8.0", "wheel"]

[project]
name = "FLiESANN"
version = "1.3.0"
version = "1.4.0"
description = "Forest Light Environmental Simulator (FLiES) Radiative Transfer Model Artificial Neural Network (ANN) Implementation in Python"
readme = "README.md"
authors = [
Expand All @@ -17,6 +17,8 @@ dependencies = [
"geos5fp",
"keras==2.15",
"koppengeiger",
"MCD12C1-2019-v006",
"NASADEM>=1.1.1",
"netCDF4",
"numpy<2",
"pandas",
Expand All @@ -32,7 +34,6 @@ requires-python = ">=3.10"
[project.optional-dependencies]
dev = [
"build",
"MCD12C1-2019-v006",
"pytest>=6.0",
"pytest-cov",
"jupyter",
Expand Down