Hello All, I tried to extract a single band (specifically, B3B2) using Raster → Bands extractor. The extraction claimed to be successful - .csv file has been written and new product appeared. However, the CSV file contains some garbage like:
883008 0.82240695978494 0.8756214
978495 0.91560537883009 0.7956432
i.e., “feature ID” is not ascending number and some rows are empty. Most of the file is correct though.
Second, attempting to create an image of the extracted band SNAP runs forever. Canceling the process gives the following diagnostics:
java.util.concurrent.CancellationException: Process terminated by user.
[catch] at org.esa.snap.rcp.actions.window.OpenImageViewAction$1.done(OpenImageViewAction.java:228)
at java.security.AccessController.doPrivileged(Native Method)
Am I doing anything wrong or these are known bugs?
As I mentioned, I need to export B3B2 band - not B2 - as it is directly related to bathymetry, I need to export several thousand pixels, so specifying them manually is not possible. (If there is a way to import locations at which pixel values will be exported, I’d be grateful for explanation.) Thus, the only option I see is to export all pixels and then programmatically find the ones I need. However, saved CSV file contains garbage (I use S2TBX version 8.0.4 on Windows 10). I tried to save ALL bands, and the saved huge file also contains garbage.
The thread you referred to has no mentioning of incorrectly saved CSV files - possibly the bug was introduced in latest versions of SNAP.
Another way how you can extract values to CSV is by creating a mask. Either draw the geometry on the image or import a shapefile or specify the WKT (Right click on image → “Geometry from WKT”).
Then select this mask and right click on image and select “Export Mask Pixels”. You can actually define the mask also by expression or value range.
You can store the data either to the clipboard or to a file (file is preferred if the number of pixels gets bigger).
Thank you - the reply sounds promising. Yes, the B3B2 band is virtual and is a ratio of logs of corresponding bands. Unfortunately, I do not understand how to use in my case Band Maths, or how to create a mask, or how to prepare well-known-text. Could you please refer to specific parts of the manual, related tutorials, or just explain in detail what should I do (any approach would do). I’m a novice with SNAP.
Forgot to ask: although the spatial subset that I have is 2657x1385, the properties show that the raster is 2657x4155=2657x1385x3. The saved image as TIFF also has height of 4155. Where these 3 come from?
I prepared the mask using Mask manager, f(x), with the expression:
LAT > 18.289 && LAT < 18.414 && LON > -65.0650 && LON < -64.8135
The mask almost covers the subset, but seems ok. Clicking on the image opens the menu, but “Export Mask Pixels” is inactive. Should I save a mask somehow to make it a separate band?
Under “Vector Data” there are only “pins”, “ground_control_points” and “geometry”. The latter opens an empty window.
Correction about “Export Mask Pixels”: it is inactive only in “Extracted bands”. In full product it is active and did save all points in a mask. Took very long, as the action saved all bands, while I needed only latitude, longitude and B3B2 band. It doesn’t seem to give a chance to choose values to save.
Maybe there are other ways to save what I need? (I will reprocess the saved file, of course, but it’s awkward.)
I did create a subset (only B3B2 band) using “Extract bands”. As I mentioned above, in this product (it is virtual and has “” in front of the name which means that it hasn’t been saved on disk, as I understand) when I click on the image, “Export Mask Pixels” is not active. Do I have to save it and reload to make this item active? Will the product have raster that holds geo-coordinates?
Actually, when I save it and open as a new product, SNAP says that it is already opened, and do I want to open it as a separate product. I do want, but it appears with “[*]” in front, as other virtual products.
Sorry to raise the question again, but when I’m repeating all the processing now, including creation of a mask that covers all the subset, “File → Export → Other → Mask pixels” is greyed out, so the pixel values under the mask cannot be saved. Obviously, last time I did some operation that made it possible without noticing it. “Vector data” under the Product tree does not have “geometry”, only “pins” and “ground_control_points”, both empty. Could you please help? I am lost.
All I need is just save all pixels of one band (or all bands) in a readable/parseable form.
I’m not sure what you mean. Choosing “Raster → Subset”? The band I “subsetted” is not virtual, but “Mask pixels” option remains unavailable.
I wonder if anybody ever tried to save band values together with their lat-lon’s in a readable form?
resample the S2 bans to the same resolution–>calculate B3B2 with BandMaths–> draw a geometry ->export pixels within the geometry in CSV. Lat/lon are saved here (see pic)
2 . resample the S2 bans to the same resolution–>calculate B3B2 with BandMaths–>use the Raster/Subset function and select the spatial subset by lat/lon and the bands you wat to export in dimap–>from the new image save as CSV. You will only have lat lon in the CSV if you have created the bands as @marpet explained above.
This is exactly what I am doing. The mask is created using Mask manager and an expression defining limits for lat/lon. “File → Export → Other → Mask pixels” is still greyed out. The only detail that I might be missing is “select the mask”. How should I do this?
I’m sorry, but what does “geometry” mean? The mask itself? The cursor should be a “hand” or anything else? Currently with hand, nothing changes color, and all I can do is to move the image. In Mask manager the current mask is selected (tickmark on the left).