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

Reconstruct slc from inteferograms #9

Merged
merged 20 commits into from
Oct 1, 2024
Merged

Reconstruct slc from inteferograms #9

merged 20 commits into from
Oct 1, 2024

Conversation

rogerkuou
Copy link
Member

@rogerkuou rogerkuou commented Sep 12, 2024

fix two issues:

@rogerkuou rogerkuou marked this pull request as ready for review September 13, 2024 08:20
@rogerkuou rogerkuou marked this pull request as draft September 13, 2024 08:27
@rogerkuou rogerkuou mentioned this pull request Sep 16, 2024
@rogerkuou rogerkuou marked this pull request as ready for review September 20, 2024 15:24
@rogerkuou
Copy link
Member Author

Hi @FreekvanLeijen, this PR is ready for review. After merging #15, all the changed files now are relevant for your review.
Just let me know if you need any help.

This was linked to issues Sep 20, 2024
@rogerkuou
Copy link
Member Author

Hi @meiertgrootes, this is the PR I talked about. I implemented a function for reconstructing radar imgs from interferograms (conj multiplication of two radar images), and provided slurm + python example scripts. Can you give it a look? Thanks!

examples/scripts/README.md Outdated Show resolved Hide resolved
examples/scripts/script_reslc.py Outdated Show resolved Hide resolved
examples/scripts/script_reslc.py Outdated Show resolved Hide resolved
examples/scripts/script_reslc.py Outdated Show resolved Hide resolved
examples/scripts/script_reslc.py Outdated Show resolved Hide resolved
Copy link
Contributor

@meiertgrootes meiertgrootes left a comment

Choose a reason for hiding this comment

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

No blocking comments from my side.
I would advise to consider restructuring/refactoring pydepsi, especia;lly io.py in the near future to ensure future maintainability.
Consider language choices where possible.

examples/scripts/README.md Outdated Show resolved Hide resolved
examples/scripts/README.md Outdated Show resolved Hide resolved
examples/scripts/README.md Outdated Show resolved Hide resolved
examples/scripts/exec_python.slurm Outdated Show resolved Hide resolved
examples/scripts/script_reslc.py Outdated Show resolved Hide resolved
pydepsi/io.py Outdated Show resolved Hide resolved
pydepsi/io.py Outdated Show resolved Hide resolved

# ++++ 5 - prf
pattern = r"Pulse_Repetition_Frequency \(computed, Hz\):" + SC_N_PATTERN
match = re.search(pattern, content)
Copy link
Contributor

Choose a reason for hiding this comment

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

There is a huge number of the regular expression searches here and in the following. I'd suggest moving this to a separate module and making a wrapper which calls them by name, allowing the correct implementation to be retrieved. This also makes one central place for keeping track of all these things and easily supports adding additional methods as needed.
Happy to discuss @rogerkuou

Copy link
Member Author

Choose a reason for hiding this comment

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

Hi @meiertgrootes, I like this idea! I added your suggestion as an item in issue #14. My thought is to build a static dict, mapping the attribute name and searching pattern. Let me know what you think.

pydepsi/io.py Outdated Show resolved Hide resolved
pydepsi/slc.py Outdated Show resolved Hide resolved
@rogerkuou
Copy link
Member Author

Thanks @meiertgrootes for the review! I made changes according to your comments. Only for the suggestion on RE pattern in read_metadata, I doced it in issue #14. I would tend to postpone the implementation of this one, because currently in pyDePSI there are too few cases we used metadata. I would wait for more use cases and decide on an optimal way.

@rogerkuou
Copy link
Member Author

Hi @FreekvanLeijen, thanks a lot for the review! Just to check, do you have more comments? I am implementing ps_selection now. It would be nice if this PR can be merged before I open another one.

Copy link

@FreekvanLeijen FreekvanLeijen left a comment

Choose a reason for hiding this comment

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

Looks good, couple of open issues. Before we can actually start using it the inclusion of the mother SLC, and the h2ph files (zeros for mother) are required.

"imag": slc_recon_output["complex"].imag.astype(np.float16),
}
)
slc_recon_output = slc_recon_output.drop_vars(["complex", "amplitude", "phase"])

Choose a reason for hiding this comment

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

Question: so in sarxarray.from_binary we create these complex, amplitude and phase variables. And here we drop them again. In general, I do not think we should save these variables to .zarr files anyway (are we?). They can be computed on the fly from the real and image part, right?

So to consider: change sarxarray.from_binary to remove the amplitude, phase, complex. Can be done later on the fly.

Copy link
Member Author

Choose a reason for hiding this comment

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

Hi Freek,
By using sarxarray.from_binary, the following happens to the three variables:

  • complex is what is originally saved in binary file, we create a task map instruct how to read it
  • for phase/amplitude, we create a task map of how to derive them from complex

Therfore, regarding your comments about compute amplitude, phase, and complex on the fly, actually it is already what we are doing. These three values are "lazy" variables, which means they are not actually computed until they are needed. In Line 133, what we drop here are simply task graphs of how to create them, so not redundant computation are involved. They will not be saved into Zarr.

In the current reslc implementation, we create task graphs of how to derive real and imag from complex. When writing the restored SLCs to the disk, what happened is the complex number will be read into the memory, sparated in to real and imag, and written to disk. The separation operation is not costy. Therefore comparing directly writing complex to disk, we almost have no efficiency loss.

By saying this, I think what we need is not to remove the three variable from sarxarray.from_binary, but to create a new function (I am thinking sarxarray.from_zarr) to directly create task graphs to get complex, amplitude and phase from real and imag fields.

pydepsi/io.py Outdated Show resolved Hide resolved
pydepsi/io.py Outdated Show resolved Hide resolved
pydepsi/io.py Outdated Show resolved Hide resolved
pydepsi/io.py Show resolved Hide resolved
# Rechunk and write as zarr
slc_recon_output = slc_recon_output.chunk({"azimuth": writing_chunks[0], "range": writing_chunks[1]})
if overwrite_zarr:
slc_recon.to_zarr("nl_veenweiden_s1_dsc_t037.zarr", mode="w")

Choose a reason for hiding this comment

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

Two things:

  • I do not see the mother image being written to cpxfloat16. Can we add?
  • How about the h2ph file. Add to this .zarr, or a separate one? To discuss.

Copy link
Member Author

@rogerkuou rogerkuou Sep 27, 2024

Choose a reason for hiding this comment

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

Hi Freek,
as we discussed on Tuesday, I have put these two action points in issue #22, since they need to be tested on Spider. I will work on them after finishing issue #10 (ps selection).
For now the script only output non-mother SLCs in np.float16, with real and imag part separate. Just to confirm, as we discussed on Tuesday, there is no cpxfloat16 available in numpy (I think you meant np.complex32? anyhow neither exists in numpy, see here the explaination) so we are going to store real and imag part separately, both in np.float16.

Choose a reason for hiding this comment

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

Hi Ou,
Sorry, I should be more clear in my writing. With cpxfloat16 I meant the 'concept' of storing the complex data in float16 format, indeed the real and imaginary part separately. So as you described.

pydepsi/io.py Outdated Show resolved Hide resolved
pydepsi/io.py Outdated Show resolved Hide resolved
pydepsi/io.py Outdated Show resolved Hide resolved
@rogerkuou
Copy link
Member Author

Hi @FreekvanLeijen, thanks a lot for the review! I adapted most of your comments!

There are several things I decided to put them into the todo lists, they are:

With this info, would you like to take another look and see if there are other things you want to add? Or some things you think should be fixed in this PR?

@rogerkuou
Copy link
Member Author

Thanks @FreekvanLeijen for approval, will merge.

@rogerkuou rogerkuou merged commit 7a35d05 into main Oct 1, 2024
9 checks passed
@rogerkuou rogerkuou deleted the re-slc branch January 10, 2025 12:11
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.

Example python script for SLC createtion Re-slc function
3 participants