Dear FME users,
I’d like to calculate the median of all overlapping pixel values from 24 input raster bands.
Do you have an idea how to solve it? Can I use the transformer “RasterExpressionEvaluator”?
Thank you very much.
Konrad
Dear FME users,
I’d like to calculate the median of all overlapping pixel values from 24 input raster bands.
Do you have an idea how to solve it? Can I use the transformer “RasterExpressionEvaluator”?
Thank you very much.
Konrad
expressionevaluator has only A en B input.
B can have multiple raster but will be paired, so B's do not calculate between them.
You could use a wsc to sequentially calculate all B inputs with a updating A input.
Or first extract the overlapping bits, extract the data, process the data and rebuild raster.
The last time I did something like that was several years ago, where I coerced the rasters to points, aggregated the points on col, row keeping a list, and then sorted and analysed the list.
Note that this was for 24 1 band rasters, if you have a single raster with 24 bands, you can coerce the rasterer with bands as attributes and skip the aggregation step.
If I were to do it now, I would first look into coercing to pointclouds, and if that didn't lead anywhere, then experiment with the new python raster api.
Note that if you wanted the mean rather than the medium, then the RasterMosaicker with Overlapping values set to Average would be the way to go.
Thank you for all your inputs @jdh and @gio.
I’ve tried to calculate it with the transformer “RasterExpressionEvaluator”. I think it works, but the expressions are overloaded.
Here is the first line of the repeated code:
“@if(A23],(A0]+AA1]+A,2]+A]3]+A]4]+A]5]+A]6]+A]7]+A]8]+A]9]+A]10]+A+11]+AA12]+AA13]+AA14]+AA15]+AA16]+AA17]+AA18]+AA19]+AA20]+AA21]+AA22]+AA23])/24,A]0])”
Are there any ideas how to simplify the expressions? It's possible to have just one expression?
I’ve added some screenshots in the attachment.
Thank you very much. :)
Best regards. Konrad
The RasterCellCoercer mentioned by @jdh can help you along, just be aware that it can be very slow when dealing with large rasters. Apparently you can now coerce the raster to a point cloud, which should be a lot faster, but I've got no experience with that.
If you're no stranger to Python, I'd recommend looking into the new raster capabilities of the fmeobjects API. @takashi wrote some really nice sample code here, which could be a starting point:
https://knowledge.safe.com/questions/38000/python-fme-objects-api-for-raster-manipulation.html
Thank you for all your inputs @jdh and @gio.
I’ve tried to calculate it with the transformer “RasterExpressionEvaluator”. I think it works, but the expressions are overloaded.
Here is the first line of the repeated code:
“@if(A23],(A0]+AA1]+A,2]+A]3]+A]4]+A]5]+A]6]+A]7]+A]8]+A]9]+A]10]+A+11]+AA12]+AA13]+AA14]+AA15]+AA16]+AA17]+AA18]+AA19]+AA20]+AA21]+AA22]+AA23])/24,A]0])”
Are there any ideas how to simplify the expressions? It's possible to have just one expression?
I’ve added some screenshots in the attachment.
Thank you very much. :)
Best regards. Konrad
Hi @UBA_KP, if you need to calculate the "median" of 24 band values for each cell, the RasterExpressionEvaluator won't help you. Because, the transformer doesn't support list (array) manipulation, although it's necessary to create a list containing the 24 values and sort the list in order to compute the "median". e.g.
List: [1, 3, 1, 3, 2, 1] -> Sorted: [1, 1, 1, 2, 3, 3] -> Median: (1 + 2) / 2 = 1.5
See here to lean more about "median": https://en.wikipedia.org/wiki/Median
As @jdh and @david_r suggested, you can get individual grid points each of them has 24 band values as a list attribute with coercing the raster with the RasterCellCoercer. You can then use the ListSorter and the ExpressionEvaluator to calculate the median base on the list. Finally set the median value to z-coordinate to each point with the 3DForcer and re-create a raster with a NumericRasterizer.
However, the performance of coercing is not good. If you don't like the coercing approach, Python scripting could be a better solution, as @david_r mentioned.
Alternatively, this could also be a possible way.
Hi @UBA_KP, if you need to calculate the "median" of 24 band values for each cell, the RasterExpressionEvaluator won't help you. Because, the transformer doesn't support list (array) manipulation, although it's necessary to create a list containing the 24 values and sort the list in order to compute the "median". e.g.
List: [1, 3, 1, 3, 2, 1] -> Sorted: [1, 1, 1, 2, 3, 3] -> Median: (1 + 2) / 2 = 1.5
See here to lean more about "median": https://en.wikipedia.org/wiki/Median
As @jdh and @david_r suggested, you can get individual grid points each of them has 24 band values as a list attribute with coercing the raster with the RasterCellCoercer. You can then use the ListSorter and the ExpressionEvaluator to calculate the median base on the list. Finally set the median value to z-coordinate to each point with the 3DForcer and re-create a raster with a NumericRasterizer.
However, the performance of coercing is not good. If you don't like the coercing approach, Python scripting could be a better solution, as @david_r mentioned.
Alternatively, this could also be a possible way.
Hi @UBA_KP, if you need to calculate the "median" of 24 band values for each cell, the RasterExpressionEvaluator won't help you. Because, the transformer doesn't support list (array) manipulation, although it's necessary to create a list containing the 24 values and sort the list in order to compute the "median". e.g.
List: [1, 3, 1, 3, 2, 1] -> Sorted: [1, 1, 1, 2, 3, 3] -> Median: (1 + 2) / 2 = 1.5
See here to lean more about "median": https://en.wikipedia.org/wiki/Median
As @jdh and @david_r suggested, you can get individual grid points each of them has 24 band values as a list attribute with coercing the raster with the RasterCellCoercer. You can then use the ListSorter and the ExpressionEvaluator to calculate the median base on the list. Finally set the median value to z-coordinate to each point with the 3DForcer and re-create a raster with a NumericRasterizer.
However, the performance of coercing is not good. If you don't like the coercing approach, Python scripting could be a better solution, as @david_r mentioned.
Alternatively, this could also be a possible way.
Dear FME-Users,
I’ve done a mistake during the translation. Sorry, I’m german. :))) What I need is not the median but the running/moving average is what I’d like to calculate.
Now I repeat myself again:
I’ve tried to calculate it with the transformer RasterExpressionEvaluator. I think it works, but the expressions are overloaded because all raster have 73 bands.
Here is the first line from my code:
“@if(A:23],(A/0]+A1]+AA2]+A,3]+A]4]+A]5]+A]6]+A]7]+A]8]+A]9]+A]10]+A+11]+AA12]+A[13]+A[14]+A[15]+A[16]+A[17]+A[18]+A[19]+A[20]+A[21]+A[22]+A[23])/24,A+0])”
Here is the last line from my code:
“@if(Ay73],(A<50]+A/51]+A@52]+A753]+A[54]+A[55]+A[56]+A[57]+A[58]+A[59]+A[60]+A[61]+A[62]+A[63]+A[64]+A[65]+A[66]+A[67]+A[68]+A[69]+A[70]+A[71]+A[72]+A[73])/24,A+50])”
Are there any ideas how to simplify the expressions? It's possible to have just one expression?
After the transformer RasterExpressionEvaluator I’ve connected the transformer RasterToPolygonCoercer to generate vector data.
Thank you very much and best regards!
Konrad
moving average...
If you are using FME 2017.0+, the RasterMosaicker can be used to calculate the average of multiple band values, as @jdh suggested before. A possible way to get moving average in 73 bands for each moving range consisting of 24 bands is:
However, I cannot understand why the @if function appears in your expression examples. I don't think conditional operation is necessary to calculate average. If there is a specific reason for that a conditional operation is required, the procedure above should be modified (or could not be applied).
moving average...
If you are using FME 2017.0+, the RasterMosaicker can be used to calculate the average of multiple band values, as @jdh suggested before. A possible way to get moving average in 73 bands for each moving range consisting of 24 bands is:
However, I cannot understand why the @if function appears in your expression examples. I don't think conditional operation is necessary to calculate average. If there is a specific reason for that a conditional operation is required, the procedure above should be modified (or could not be applied).
moving average...
If you are using FME 2017.0+, the RasterMosaicker can be used to calculate the average of multiple band values, as @jdh suggested before. A possible way to get moving average in 73 bands for each moving range consisting of 24 bands is:
However, I cannot understand why the @if function appears in your expression examples. I don't think conditional operation is necessary to calculate average. If there is a specific reason for that a conditional operation is required, the procedure above should be modified (or could not be applied).
moving average...
If you are using FME 2017.0+, the RasterMosaicker can be used to calculate the average of multiple band values, as @jdh suggested before. A possible way to get moving average in 73 bands for each moving range consisting of 24 bands is:
However, I cannot understand why the @if function appears in your expression examples. I don't think conditional operation is necessary to calculate average. If there is a specific reason for that a conditional operation is required, the procedure above should be modified (or could not be applied).
band 0 contains the average of original 0 to 23 band,
band 1 contains the average of original 1 to 24 band,
band 2 contains the average of original 2 to 25 band,
...
and band 49 contains the average of original 49 to 72 band.
Is it your desired result theoretically?
moving average...
If you are using FME 2017.0+, the RasterMosaicker can be used to calculate the average of multiple band values, as @jdh suggested before. A possible way to get moving average in 73 bands for each moving range consisting of 24 bands is:
However, I cannot understand why the @if function appears in your expression examples. I don't think conditional operation is necessary to calculate average. If there is a specific reason for that a conditional operation is required, the procedure above should be modified (or could not be applied).
RasterCombiner
RasterCombiner
band 0 contains the average of original 0 to 23 band,
band 1 contains the average of original 1 to 24 band,
band 2 contains the average of original 2 to 25 band,
...
and band 49 contains the average of original 49 to 72 band.
Is it your desired result theoretically?
You're right, each band contains the moving average of other 24 bands. It means that I've to transform a raster containing 97 bands into a raster with includes 73 bands.
Thank you very much @takashi.
moving average...
If you are using FME 2017.0+, the RasterMosaicker can be used to calculate the average of multiple band values, as @jdh suggested before. A possible way to get moving average in 73 bands for each moving range consisting of 24 bands is:
However, I cannot understand why the @if function appears in your expression examples. I don't think conditional operation is necessary to calculate average. If there is a specific reason for that a conditional operation is required, the procedure above should be modified (or could not be applied).
I’ve added and connected the transformers “RasterBandCombiner”, “RasterExpressionEvaluator” and “RasterBandSeparator” because I’d like to calculate the moving average. Usually I've 73 input raster, for calculating the moving average it’s necessary to use 96 input raster. I’ve added 73 expressions for the “RasterExpressionEvaluator”, it’s a lot but it works. When I use the “RasterBandCombiner” I loose important attribute values. I know it’s possible to write attributes into a list, but I don’t know how to allocate them again. I also don’t know how to extract the last 73 attribute values from 96 values altogether. The background is that I need all names of 73 input data as string. It works fine without the transformers for the moving average. I’ve added a screenshot in the attachment for better comprehension.
Is there anyone who can help me?
Thank you and best regards!
Konrad
Best regards!
Konrad