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

fix: latlon handling in inference dataset #65

Closed
wants to merge 4 commits into from
Closed

Conversation

kvantricht
Copy link
Contributor

@kvantricht kvantricht commented May 21, 2024

@gabrieltseng the inference dataset had a bug in latlon handling. Only "worked" for square patches but even then contained a bug. This should go through a meshgrid. Made a fix for this. I'm not really familiar with einops.rearrange so please check if I did this the right way. One approved, we should be ok to move this right into main.

@kvantricht
Copy link
Contributor Author

kvantricht commented May 21, 2024

FYI there's something more to be fixed about this. There's a failing test revealing that combine_predictions no longer works. It appears that this worked only because lat and lon were treated in another way. I am not yet sure how to fix this.

@gabrieltseng
Copy link
Collaborator

Thanks @kvantricht ! I will take a look

@kvantricht
Copy link
Contributor Author

@gabrieltseng whenever we make this fix, it's very important to crosscheck compatibility with

values = np.swapaxes(ds[org_band].values.reshape((num_timesteps, -1)), 0, 1)

We're suffering already for 3 days in the inference pipeline figuring out what's going on and one of the issues we face is inconsistency between the lat/lon values and the EO data values, because np.swapaxes works differently from np.transpose. It's crucial that throughout all inputs the flattening of the images has been done consistently.

@kvantricht
Copy link
Contributor Author

@gabrieltseng i'm working on this one, because it's the cause of failing tests in my updated inference dataset. What I'm wondering: why in combine_predictions are we transforming back to Pandas dataframe? It's a mess now that lat/lon are back in good shape.

@kvantricht
Copy link
Contributor Author

@gabrieltseng i'm working on this one, because it's the cause of failing tests in my updated inference dataset. What I'm wondering: why in combine_predictions are we transforming back to Pandas dataframe? It's a mess now that lat/lon are back in good shape.

when doing a search for when this combine_predictions is actually used, I can only find it in tests, where still the dataframe is again reassembled to an xarray.DataArray(). So in reality, the DataFrame seems never to be used by itself. So I'm going to try for now to avoid that step which is going to be easier.

@kvantricht
Copy link
Contributor Author

@gabrieltseng i'm working on this one, because it's the cause of failing tests in my updated inference dataset. What I'm wondering: why in combine_predictions are we transforming back to Pandas dataframe? It's a mess now that lat/lon are back in good shape.

when doing a search for when this combine_predictions is actually used, I can only find it in tests, where still the dataframe is again reassembled to an xarray.DataArray(). So in reality, the DataFrame seems never to be used by itself. So I'm going to try for now to avoid that step which is going to be easier.

The only test that in that case no longer makes a lot of sense as it is now is this one: https://github.com/WorldCereal/presto-worldcereal/blob/main/tests/test_dataset.py#L69

This test was taken from openmapflow. Also here I don't fully get what kind of inference is supposed to be tested here. If it's a true flattened 2D inference test, and if flat_lat and flat_lon are size 5, you'd in fact need 25 predictions belonging to the grid constructed by flat_lat and flat_lon by using a meshgrid.

I've already adapted comlbine_predictions to work with the gridded data as xr.DataArray so it no longer returns a DataFrame. The other tests are working. The above would need to be adapted to test the DataArray instead of a derived DataFrame.

What I'd need from @gabrieltseng is some insights into whether or not I'm overlooking something on the need of working with a dataframe instead. Will be pushing some changes to the branch to make the discussion more concrete.

@kvantricht
Copy link
Contributor Author

So the proposed changes including the fixes of the test are in another PR, addressed specifically in 817da45

@kvantricht
Copy link
Contributor Author

Fix has been applied as part of #103. No more need for this PR.

@kvantricht kvantricht closed this Sep 10, 2024
@kvantricht kvantricht deleted the latlon-bugfix branch September 10, 2024 09:18
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.

2 participants