Skip to content

add spectral residuals - #41

Open
marchett2 wants to merge 5 commits into
emit-sds:devfrom
marchett2:add_spec_res
Open

add spectral residuals#41
marchett2 wants to merge 5 commits into
emit-sds:devfrom
marchett2:add_spec_res

Conversation

@marchett2

Copy link
Copy Markdown

No description provided.

@marchett2
marchett2 marked this pull request as ready for review February 26, 2025 20:40

@vatsal-j vatsal-j left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Mainly need to update docstrings for changed functions

Comment thread src/Datasets.jl
Comment thread src/SpectralUnmixing.jl
Comment thread src/SpectralUnmixing.jl
Comment thread src/SpectralUnmixing.jl
Comment thread unmix.jl
@vatsal-j

Copy link
Copy Markdown
Member

Also, there aren't any conflicts but should sanity check the Manifest.toml changes by deleting it and running Pkg.resolve right @pgbrodrick ?

@pgbrodrick pgbrodrick mentioned this pull request May 2, 2025
@pgbrodrick

Copy link
Copy Markdown
Member

Given recent PRs, we can now rebase and remove the Manifest.toml. @marchett2 , can you support that along with handling the @vatsal-j 's review comments, or do you need a hand?

@marchett2

Copy link
Copy Markdown
Author

Yes, I will handle the docstring updates asap. Vatsal will help with Manifest.toml.

@marchett2

Copy link
Copy Markdown
Author

Just pushed changes to update docstrings (except for unmix.jl, since I didn't see any). Also in this update:

--Addition of nnls as another optimization option in unmix_pixel
--Addition of an option to get a subsample in prepare_options instead of generating the full list of combinations. When the number of classes > 7, the full list cannot be held in memory.

Let me know if I missed anything.

@vatsal-j vatsal-j left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Most of this looks good, and thank you for the docstring updates, they also help me to understand functionally what's changing! As I understand it, the main changes are related to unmix_line() returning the spectral residuals. To my eye it looks good, I assume this has been tested and works?

One minor question is why we check the length of results in write_line_results() for the spectral residuals? If we're always outputting spec residuals from unmix_line() without a flag controlling it, they should always be present in results, otherwise something is wrong, right?

There are also a couple other features being added here. For future reference, these should definitely have their own separate PRs so they are easier to track.

The NNLS addition looks fine. Are the Glob and HDF5 packages related to that too?

The change to prepare_options() also looks fine to me, but worth asking if subsampling should even be an option if we run out of memory, or if it should just do it by default if class number > 7 (also, is there a better way of doing this down the line?). The argument handling also needs to be better (i.e. prepare_options() needing a seed value even if subsample == false.

There are some other comments I've thrown in that are minor and I can take care of when I rebase and resolve conflicts. After that I think this should be fine to merge, especially if we know the new functionality works and is useful in the ongoing fractional cover work, with the caveat that this will break some backwards compatibility (like in the example notebook) and might open some more issues down the line (which is fine).

Comment thread src/Datasets.jl
Comment thread src/SpectralUnmixing.jl
- A tuple containing:
- `refl./ norm::Matrix{Float64}`: A matrix of scaled reflectance data with same dimensions as `refl`.
- `norm::Matrix{Float64}`: A matrix of normalization coefficients corresponding to `refl`. Is used to get
unscaled coefficients for spectral residuals. If criteria == "none", the 1 is returned as normalization

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Minor typo here (should be "then* 1 is returned..."). I can fix.

Comment thread src/SpectralUnmixing.jl Outdated
Comment thread Project.toml
EllipsisNotation = "da5c29d0-fa7d-589e-88eb-ea29b0a81949"
GDAL = "add2ef01-049f-52c4-9ee2-e494f65e021a"
Glob = "c27321d9-0574-5035-807b-f59d2c89b15c"
HDF5 = "f67ccb44-e63f-5c2f-98bd-6dc0ccc4ba2f"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Maybe I missed where they are being used in this update, but why are we adding Glob and HDF5 to the package?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I added these b/c I have other scripts (to run validation and simulation unmixing) that I created but never checked in. I just used this environment to run these scripts. Feel free to delete, and I will figure out how to get a new environment going (I am still very unfamiliar with Julia).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Sounds good. I also have been having a time trying to grasp Julia's environment and package management 😄

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@marchett2 Is JLLWrappers also a package we can remove from the Project.toml?

@marchett2

Copy link
Copy Markdown
Author

RE: The change to prepare_options() also looks fine to me, but worth asking if subsampling should even be an option if we run out of memory, or if it should just do it by default if class number > 7 (also, is there a better way of doing this down the line?). The argument handling also needs to be better (i.e. prepare_options() needing a seed value even if subsample == false.

Yes for both. I can make the change for the seed, but I will leave the decision to you and Phil if you'd like to change this function for class number > 7.

@vatsal-j

vatsal-j commented May 7, 2025

Copy link
Copy Markdown
Member

Yes for both. I can make the change for the seed, but I will leave the decision to you and Phil if you'd like to change this function for class number > 7.

Ok sounds good, for this case does it make sense to make the seed an optional argument and use a default value? Or does having a default seed sort of defeat the purpose.

@pgbrodrick thoughts on this? Also the subsampling option vs mandatory thing? We can (and should) probably move this discussion to a separate issue as well.

@marchett2

Copy link
Copy Markdown
Author

RE: prepare_options. I ended up simply moving the seed activation inside the if statement such that it will only be used when subsample = True. We can keep the default seed value. I swapped the two parts of the if statement for subsampling to be cleaner (if subsample ... else).

@vatsal-j

vatsal-j commented May 9, 2025

Copy link
Copy Markdown
Member

Perfect!

Comment thread src/SpectralUnmixing.jl
end

# Prepare combinations if relevant
if subsample

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@marchett2 - This looks like it will get handled within unmix_pixel - can you help me with the rationale for pulling it up here (I recall there was one, just not seeing it clearly here when reviewing)? Is it for simulations or something else? If so, we should remove from unmix_pixel so that it's not redundant.

@pgbrodrick

Copy link
Copy Markdown
Member

Hey All, thanks for the forward progress here. Lets go ahead and just raise an exception if the class number is > 7 for now, and toss in an issue for good ways to pre-compute & generalize this (we should be able to estimate the array size and terminate if it gets to big in advance...but lets save that for separate.

Subsampling needs to be retained...threw in an inline comment, I'm not sure right now why exactly it's getting moved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants