Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Harmonize and interpolate wavelengths for optimization #1

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
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
20 changes: 20 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: CI
on: [push]

jobs:
miniconda:
name: Setup and test
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: ["ubuntu-latest"]
steps:
- uses: actions/checkout@v4
- name: Python Linter
uses: sunnysid3up/python-linter@master
with:
source: "snowlaps"
mypy-options: "--ignore-missing-imports --show-error-codes"
pylint-options: "--rcfile=setup.cfg"
isort-options: "-w 100"
django: true
29 changes: 22 additions & 7 deletions snowlaps/snowlaps.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@

"""

from datetime import datetime
import joblib
import numpy as np
import pandas as pd
from typing import Union
import joblib
import tensorflow as tf
import time
import pysolar
import pytz
from timezonefinder import TimezoneFinder
from datetime import datetime
import sklearn.preprocessing
import tensorflow as tf
import time
from timezonefinder import TimezoneFinder
from typing import Union


class SnowlapsEmulator:
Expand Down Expand Up @@ -150,6 +150,7 @@ def optimize(
nb_optimization_repeats: int = 20,
optimizer: tf.keras.optimizers = tf.keras.optimizers.Adagrad(learning_rate=1.0),
optimization_init: Union[list, None] = None,
optimization_wavelengths: np.ndarray = np.arange(355, 1365, 10),
gradient_mask: list = [0.0, 1.0, 1.0, 1.0, 1.0, 1.0],
sza_list: Union[list, None] = None,
spectra_metadata_path: Union[str, None] = None,
Expand Down Expand Up @@ -185,6 +186,11 @@ def optimize(
Default to None and random initialisations.
:type optimization_init: list, optional

:param optimization_wavelengths: An array containing the wavelengths over which to optimize.
Default to the range used in Chevrollier et al 2024, i.e.
np.arange(355, 1365, 10).
:type optimization_wavelengths: np.ndarray, optional

:param gradient_mask: Boolean mask to enable (1) or freeze (0) the optimization of each
input variable of the emulator. Default to SZA frozen and all other
variables enabled, as SZA is either given or computed.
Expand Down Expand Up @@ -223,7 +229,8 @@ def optimize(
"""

def get_minimum_MAE_index(sub_df: pd.Series) -> int:
"""Get the global index of the minimum MAE of each batch
"""
Get the global index of the minimum MAE of each batch

:return: the global index.
:rtype: int
Expand All @@ -238,6 +245,14 @@ def get_minimum_MAE_index(sub_df: pd.Series) -> int:
return global_index

albedo_spectra = self.read_data(albedo_spectra_path)
albedo_spectra_wavelengths = albedo_spectra.index.values

# harmonize emulator, input albedo and optimization wavelengths
if set(optimization_wavelengths).issubset(set(albedo_spectra_wavelengths)):
albedo_spectra_mask = np.isin(
optimization_wavelengths, albedo_spectra_wavelengths
)
emulator_mask = np.isin(self.emulator_wavelengths, optimization_wavelengths)

if sza_list is None and spectra_metadata_path is not None:
self.spectra_metadata = self.read_data(spectra_metadata_path)
Expand Down