Skip to content

Refactor of forward.py.#948

Merged
pgbrodrick merged 9 commits into
isofit:rte_refactorfrom
unbohn:refactor_ForwardModel
Apr 27, 2026
Merged

Refactor of forward.py.#948
pgbrodrick merged 9 commits into
isofit:rte_refactorfrom
unbohn:refactor_ForwardModel

Conversation

@unbohn

@unbohn unbohn commented Apr 25, 2026

Copy link
Copy Markdown
Collaborator

Initial draft of the forward.py refactoring. Same as #947, this is work in progress and more updates are to come.

Additional thoughts that came up during editing the code:

  • We should think about moving drdn_dsurface and analytical_model to forward.py as well. Currently, those live in the surface object, but take both surface and atmosphere RT quantities as input. Might be challenging though due to the class inherence between our different surface modules.
  • invert_algebraic() now requires the ForwardModel object as input to have access to functions like calc_atmosphere_quantities(). This should be fine, but we need to carefully check if this causes issues down the line.

@unbohn unbohn changed the title Initial refactor of forward.py. Refactor of forward.py. Apr 25, 2026
Comment thread isofit/inversion/inverse_simple.py Outdated
Comment thread isofit/inversion/inverse_simple.py Outdated
Comment thread isofit/inversion/inverse_simple.py Outdated
Comment thread isofit/core/forward.py Outdated
Comment thread isofit/core/forward.py Outdated
Comment thread isofit/core/forward.py Outdated
Comment thread isofit/core/forward.py
Comment thread isofit/core/forward.py Outdated
Comment thread isofit/core/forward.py
Comment thread isofit/inversion/inverse_simple.py Outdated
Comment thread isofit/core/forward.py Outdated
Comment thread isofit/core/forward.py Outdated
Comment thread isofit/inversion/inverse_simple.py Outdated

@pgbrodrick pgbrodrick left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comments are inline! In general looks good, just catching various calls / indexing pieces that don't align w/ the refactor - I'm sure I missed some that we'll catch once we can run.

One or two of the bug catches predate the refactor, just got caught with a careful read.

I've PR'd changes based on the above into unbohn#15 - if you concur with the comments, accept and then we can merge this in.

Comment thread isofit/inversion/inverse_simple.py Outdated
@@ -313,7 +302,6 @@ def invert_analytical(
# Use cached scaling factor from inital normalized inverse (outside of loop).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we take this chance I wonder to put Sa back inside of the inner loop here for AOE? As Phil mentioned before, even though we cache normalized inversion, technically it can change per iteration. It just doesn't right now because i=1. Please correct me if I'm wrong.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. @pgbrodrick @evan-greenbrg Any thoughts?

Comment thread isofit/core/forward.py
)
if not self.atmosphere.multipart_transmittance:
r = self.atmosphere.get(x_atmosphere, geom)
if self.atmosphere.atmosphere_mode == "rdn":

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO:

if possible, we should be handling this unit_mode conversion in atmosphere.py. I wonder if we could rearrange this slightly to abstract more into the atmosphere class?

Also petition to rename atmosphere_mode to something like unit_mode or the more verbose atmosphere_unit_mode

@brentwilder brentwilder Apr 27, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like we allow two modes: “transmittance” and “rdn”. We just need one if-statement in atmosphere.py to convert the whole LUT/interpolator object to be in rdn to have everything downstream already handled?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would be the most elegant solution. We just need to make sure that we don't lose accuracy when changing the order of resampling/converting between units.

Comment thread isofit/core/forward.py
L_dif_dif = 0

return (
r,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should return explicit arrays rather than the r object.

Comment thread isofit/core/forward.py
L_coupled = []

for key in self.atmosphere.coupling_terms:
L_coupled.append(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO:

find a way to abstract the unit conversions

Comment thread isofit/core/forward.py
L_dif_dir,
L_dir_dif,
L_dif_dif,
r,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could be s_alb directly

Comment thread isofit/core/forward.py
# These are moved from radiative_transfer.py and need all references checked

def calc_rdn(
def drdn_datmosphere(

@evan-greenbrg evan-greenbrg Apr 27, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it worth abstracting numerical derivatives for any statevector element now that it's in forward?

Comment thread isofit/core/forward.py

def drdn_dRTb(
self, x_RT, geom, rho_dir_dir, rho_dif_dir, rho_dir_dif, rho_dif_dif, Ls, rdn
def drdn_datmosphereb(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similarly, is it worth abstracting to any vector quantity if this now lives in forward?

@pgbrodrick pgbrodrick marked this pull request as ready for review April 27, 2026 19:59
@pgbrodrick pgbrodrick merged commit 85f1d03 into isofit:rte_refactor Apr 27, 2026
4 of 27 checks passed
@unbohn unbohn deleted the refactor_ForwardModel branch April 27, 2026 20:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants