Skip to content

Commit

Permalink
markdown and cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
philiplinden committed Nov 5, 2023
1 parent 5530b73 commit 47deda1
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 61 deletions.
23 changes: 9 additions & 14 deletions repro/simulator.py → repro/hapke.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""simulator
"""hapke
This module emulates the behavior of the following MATLAB functions:
src/Hapke_Inverse_Function_Passive.m
Expand All @@ -9,24 +10,13 @@
from collections import namedtuple
from functools import partial
from typing import Callable

import numpy as np
from numpy.typing import ArrayLike
from pandas import Series
from scipy.optimize import fmin
from scipy.interpolate import interp1d

HFunction = namedtuple('HFunction', 'H H0')


def interpolate_series(data: Series, new_index: ArrayLike) -> Series:
x = data.index.values
y = data.values
f = interp1d(x, y, fill_value='extrapolate', bounds_error=False)
new_y = f(new_index)
return Series(data=new_y, index=new_index)


def ordinary_least_squares(x: float, y: Callable, yx: float) -> float:
"""Ordinary Least Squares Function.
Expand Down Expand Up @@ -134,6 +124,11 @@ def reflectance_to_ssa(
):
"""Estimate single-scattering albedo (SSA) from reflectance
TLDR; uses ordinary least squares to fit an SSA that produces the observed
reflectance when the SSA is fed back through the Hapke model.
Equivalent to src/Hapke_Lidar_SSA_function.m
Uses scipy.optimize.fmin (equivalent to MATLAB fminsearch) to minimize
ordinary least squares distance between SSA obtained from the supplied
reflectance, R, and the SSA from the estimated reflectance at each
Expand All @@ -142,7 +137,6 @@ def reflectance_to_ssa(
Hapke, B. (2012). Theory of reflectance and emittance spectroscopy
(2nd ed.). Cambridge University Press.
Equivalent to src/Hapke_Lidar_SSA_function.m
Default parameter values replicate src/Hapke_Inverse_Function_Passive.m
Args:
Expand All @@ -164,7 +158,8 @@ def reflectance_to_ssa(

w = []
for index, value in reflectance.items():
w0 = 0.5 # initial guess, ω₀
w0 = 0.5 # initial guess of SSA, ω₀

# turn bidrectional_reflectance() into the form y=f(x)
y = partial(
bidirectional_reflectance, P=asymmetry_factor, mu=mu, mu0=mu0, B=B
Expand Down
121 changes: 75 additions & 46 deletions repro/results.ipynb

Large diffs are not rendered by default.

12 changes: 11 additions & 1 deletion repro/spectra.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
from collections import namedtuple
from dataclasses import dataclass, field
from pathlib import Path
from typing import Any, List
from typing import List

import numpy as np
from numpy.typing import ArrayLike
import pandas as pd
from pandas import Series
from scipy.interpolate import interp1d

Range = namedtuple('Range', ['min', 'max'])

Expand Down Expand Up @@ -75,3 +77,11 @@ def get_normalization_factor(data: Series, normalization_index: float) -> float:
wavelength = data.index.values
norm_index = np.argmin(abs(wavelength - normalization_index))
return data.iloc[norm_index]


def interpolate_series(data: Series, new_index: ArrayLike) -> Series:
x = data.index.values
y = data.values
f = interp1d(x, y, fill_value='extrapolate', bounds_error=False)
new_y = f(new_index)
return Series(data=new_y, index=new_index)

0 comments on commit 47deda1

Please sign in to comment.