-
Notifications
You must be signed in to change notification settings - Fork 39
adds docs for resample, MODIS projection #730
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,124 @@ | ||
| ## `resample` and projections with `ProjString` | ||
|
|
||
| Geospatial datasets will come in different [projections](https://proj.org/en/9.4/operations/projections/index.html) or coordinate reference systems (CRS) for many reasons. Here, we will focus on `MODIS SINUSOIDAL` and `EPSG`, and transformations between them. | ||
|
|
||
| Let's start by loading the neccesary packages: | ||
|
|
||
| ````@example modis | ||
| using Rasters, RasterDataSources, ArchGDAL | ||
| using DimensionalData | ||
| using DimensionalData.Lookups | ||
| using NaNStatistics | ||
| using CairoMakie | ||
| ```` | ||
|
|
||
| and let's load a test raster | ||
|
|
||
| ````@example modis | ||
| ras = Raster(WorldClim{BioClim}, 5) | ||
| ras_m = replace_missing(ras, missingval=NaN) | ||
| ```` | ||
|
|
||
| and let's also take a look | ||
|
|
||
| ````@example modis | ||
| fig = plot(ras_m; colorrange=(0,100)) | ||
| ```` | ||
|
|
||
| ### MODIS SINUSOIDAL PROJECTION | ||
|
|
||
| ````@example | ||
| # ? is this the right ProjString ?, do we need to shift lat, lon? | ||
| SINUSOIDAL_CRS = ProjString("+proj=sinu +lon_0=0 +x_0=0 +y_0=0 +a=6371007.181 +b=6371007.181 +units=m +no_defs") | ||
| ```` | ||
|
|
||
| and hence the `resample` is performed with | ||
|
|
||
| ````@example modis | ||
| ras_sin = resample(ras_m; size=(1440,720), crs=SINUSOIDAL_CRS, method="sum") | ||
| ```` | ||
|
|
||
| let's compare the total counts! | ||
|
|
||
| ````@example modis | ||
| nansum(ras_m), nansum(ras_sin) | ||
| ```` | ||
|
|
||
| and, how does this looks like? | ||
|
|
||
| ````@example modis | ||
| fig = plot(ras_sin; colorrange=(0,100)) | ||
| ```` | ||
|
|
||
| now, let's go back to `latitude` and `longitude` | ||
|
|
||
| ````@example modis | ||
| # ? also here, do we need to shift X, Y? | ||
| ras_epsg = resample(ras_sin; size=(1440,720), crs=EPSG(4326), method="sum") | ||
| ```` | ||
|
|
||
| and let's apply `shiftlocus` such that we can harmonize coordinates, which might be needed when building bigger datasets: | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what does this do, what does it mean to harmonize coordinates? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I usually need to match to other variables, which are in a specific Lon/lat range. |
||
|
|
||
| ````@example modis | ||
| locus_resampled = DimensionalData.shiftlocus(Center(), ras_epsg) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What happens if we delete these? would be nice to avoid There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. mmm... yes, but then we don't show how to do it. Which is needed, or at least I needed it 😄 . |
||
| ```` | ||
|
|
||
| and compare the total counts! | ||
|
|
||
| ````@example modis | ||
| nansum(ras_m), nansum(locus_resampled) | ||
| ```` | ||
|
|
||
| ````@example modis | ||
| fig = plot(ras_epsg; colorrange=(0,100)) | ||
| ```` | ||
|
|
||
| ### Construct a Raster from scratch natively in the sinusoidal projection | ||
|
|
||
| ````@example modis | ||
| x_range = range(-2.0015109355797417e7, 1.998725401355172e7, 1440) | ||
| y_range = range(9.979756529777847e6, -1.0007111969122082e7, 720) | ||
| ra_data = ras_sin.data; | ||
| nothing # hide | ||
| ```` | ||
|
|
||
| create the raster | ||
|
|
||
| ````@example modis | ||
| ras_scratch = Raster(ra_data, (X(x_range; sampling=Intervals(Start())), Y(y_range; sampling=Intervals(Start()))), | ||
| crs=SINUSOIDAL_CRS) | ||
| ```` | ||
|
|
||
| ::: warning | ||
| At the moment, you need to specify `sampling=Intervals(Start())` for `X` and `Y`. | ||
| ::: | ||
|
|
||
| and take a look | ||
|
|
||
| ````@example modis | ||
| fig = plot(ras_scratch; colorrange=(0,100)) | ||
| ```` | ||
|
|
||
| and the corresponding resampled projection | ||
|
|
||
| ````@example modis | ||
| ras_latlon = resample(ras_scratch; size=(1440,720), crs=EPSG(4326), method="sum") | ||
| locus_resampled = DimensionalData.shiftlocus(Center(), ras_latlon) | ||
| ```` | ||
|
|
||
| ````@example modis | ||
| fig = plot(ras_latlon; colorrange=(0,100)) | ||
| ```` | ||
|
|
||
| and compare the total counts again! | ||
|
|
||
| ````@example modis | ||
| nansum(ras_m), nansum(locus_resampled) | ||
| ```` | ||
|
|
||
| ::: danger | ||
| Note that all counts are a little bit off. Could we mitigate this a some more? | ||
| ::: | ||
|
|
||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Users will be wondering what the hell a ProjString is, we should explain that
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also @lazarusA why are you defining the ellipse here? That seems like a step too far. How about:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Those tiles come/are set with very specific numbers. I think I did some tests, and you not always get the same numbers. BTW, feel free to merge this into your PR, I will probably not finish this anytime soon.