Statistical API resolution specification

Hello,

I noticed that the number of processing units and the sample count changes if I do not specify resolution in my statistical API response, so I am wondering what is the default resolution if you do not specify it? I was expecting it to be the same as the bands you are inputting.

I input a polygon projected in a UTM (it is about 70 x 80 meters across) and use bands 2, 3, 4, 8, SCL and a datamask. When I do not specify resolution as (10, 10), I get 65536 sample count pixels and it takes more processing units. Whereas, when I add the resolution (like the code below), I get a sample count of 5688 (which is closer to the number of pixels I should have over my AOI) and the processing units drastically decrease. So I was wondering what is happening when resolution is not specified that the number of pixels and processing units increase in a statistical API call?
Thanks for your help!

request = SentinelHubStatistical(
aggregation=SentinelHubStatistical.aggregation(
evalscript=evalscript,
time_interval=time_interval,
aggregation_interval=“P1D”,
resolution=(10, 10)
),
input_data = [
SentinelHubStatistical.input_data(
data_collection=DataCollection.SENTINEL2_L2A,
maxcc=0.8
)
],
geometry = aoi,
config = config
)

1 Like

Hi, can you share the full request with us. With the AOI and the time range used. I suspect it might be something to do with the default image size used when it is not specified, checking the API reference docs, this is 512, 512 pixels if your AOI was a box. However, the number of samples still seems too high so I would also be interested in the output projection too as it might be the case that the units you require are in degrees.

I can definitely do that. Below is my script that I use. I have also attached a kml of the AOI I have been testing. Since it is a kml, it uses a WGS 84, however that is not the projection I use when I make this call to the API. I use a shapefile to read my geometry and the projection is in EPSG:32613. However, I cannot upload a different type of file so I’ve included the print out of my AOI’s geomoetry (when it is correctly in its UTM projection) if that is easier for you to test with.
Thanks for your help!

stats_test_border.kml (4.0 KB)

evalscript = """
    //VERSION=3
    function setup() {
        return {
            input: ["B02", "B03", "B04", "B08", "SCL","dataMask"],
            output: [
                { id: "output_bands", bands: ["output_B02", "output_B03", "output_B04", "output_B08"], sampleType: "FLOAT32"},
                { id: "ndvi", bands: 1, sampleType: "FLOAT32" },
                { id: "dataMask", bands: 1, sampleType: "UINT8" },
                { id: "cloudCoverage", bands: 1, sampleType: "UINT8" },
            ]
        };
    }

    function evaluatePixel(sample) {       
        // Calculate NDVI
        let ndvi = (sample.B08 - sample.B04) / (sample.B08 + sample.B04)
        var validNDVIMask = 1
    
        // Handle division by zero
        if (sample.B08 + sample.B04 == 0 ){
            validNDVIMask = 0;
        }
    
        // Exclude cloud pixels
        let cloudMask = 1;
        if (sample.SCL === 3 || sample.SCL === 8 || sample.SCL === 9 || sample.SCL === 10 || sample.SCL === 11){
            cloudMask = 0;
        }
    
        return {
            ndvi: [ndvi],
            output_bands: [sample.B02, sample.B03, sample.B04, sample.B08],  // Return the original bands
            cloudCoverage: [100 - cloudMask * 100],  // Convert cloud mask to percentage
            // Exclude nodata pixels, pixels where ndvi is not defined
            dataMask: [sample.dataMask * validNDVIMask]
        };
    }
    """
request = SentinelHubStatistical(
        aggregation=SentinelHubStatistical.aggregation(
            evalscript=evalscript,
            time_interval=('2024-05-01', '2024-10-31'),
            aggregation_interval="P1D",
            resolution=(10, 10) 
        ),
        input_data = [
            SentinelHubStatistical.input_data(
                data_collection=DataCollection.SENTINEL2_L2A,
                maxcc=0.8
            )
        ],
        geometry = aoi,
        config = config
    )

    response = request.get_data()

AOI Geometry

Geometry(POLYGON ((537751.5530324389 5806350.09949859, 537740.3580038802 5806352.007493882, 537728.3590258308 5806352.83848151, 537716.5449896152 5806353.115516269, 537707.590990192 5806352.839525326, 537698.0840301961 5806352.191456223, 537693.1929957604 5806351.085555152, 537688.0240061702 5806349.05349395, 537684.4240031217 5806345.361473532, 537679.440005533 5806339.178519539, 537675.6549776255 5806333.270496038, 537672.333016151 5806329.762484845, 537668.6409842765 5806327.086466269, 537665.8719901113 5806325.610521656, 537661.2559884749 5806324.502531826, 537653.871984685 5806325.147455892, 537639.5659817323 5806327.086484578, 537609.5680328247 5806333.640523548, 537563.2330147338 5806344.070553555, 537489.2999824136 5806361.32948848, 537455.6099752531 5806368.713506471, 537418.3209667058 5806377.943472665, 537341.6190254269 5806395.666538379, 537329.1579833919 5806399.266537625, 537321.774009921 5806403.049471579, 537317.4359809281 5806406.281547896, 537315.1290159265 5806408.864513658, 537312.9130059853 5806415.510496696, 537312.4520330677 5806419.017486089, 537312.7290171522 5806423.909506806, 537315.1280283628 5806434.247482824, 537320.0200028731 5806445.692481592, 537323.9889950682 5806452.43155362, 537339.7729776248 5806470.153503954, 537363.0330300005 5806498.028485604, 537387.0309944373 5806524.426529834, 537403.0909927611 5806540.948553347, 537413.9829932202 5806552.947517196, 537423.85899789 5806565.869484823, 537434.3810032529 5806582.206543185, 537439.0889991915 5806590.605523643, 537444.2569800572 5806600.112470212, 537448.4379746951 5806611.34751894, 537451.0879744902 5806623.372478654, 537451.6409727717 5806629.464509823, 537451.4569922626 5806637.679536443, 537449.3339686957 5806674.691523714, 537447.9490340285 5806692.782482471, 537446.1960231066 5806723.980551119, 537443.8880277097 5806770.777546953, 537442.7810299053 5806801.143489155, 537442.8730195615 5806810.835493985, 537444.0730289662 5806817.019549614, 537445.1799928222 5806821.727466026, 537449.3339920596 5806828.003536852, 537452.1030325724 5806830.58749444, 537456.8099777382 5806833.818476412, 537462.9020270488 5806835.664560669, 537473.0549755307 5806836.679514774, 537485.0539762268 5806836.772510578, 537499.1540113648 5806837.796469065, 537513.6680077717 5806843.140463962, 537522.7129816294 5806848.494498271, 537541.1730135729 5806860.678538218, 537563.2329880659 5806876.092510431, 537611.5059900663 5806911.166463784, 537626.0079997213 5806924.088533008, 537633.8430113399 5806932.488499809, 537641.3200205086 5806942.733477976, 537645.7499673411 5806952.609533021, 537650.9189751615 5806964.331536283, 537663.0099876332 5806990.545520965, 537672.2400036796 5807008.174462272, 537686.1780334649 5807032.357474733, 537697.2540170654 5807050.540551295, 537706.1150316608 5807064.57047616, 537714.97599382 5807076.569472755, 537722.543995904 5807083.307455554, 537729.5590330577 5807087.368543195, 537735.2820093185 5807089.399460293, 537744.6960063609 5807090.691517926, 537802.4769865414 5807092.168494366, 537937.2359924302 5807093.552498097, 538002.6830328122 5807094.600532701, 538014.4650249253 5807093.675564251, 538020.4720238619 5807090.671466865, 538025.5549880576 5807086.512499036, 538028.0959876513 5807080.968457793, 538028.5580250737 5807076.116469312, 538029.3520329529 5807069.554459034, 538029.7130238715 5807035.002465234, 538031.1060159793 5806809.911509629, 538031.8439688592 5806708.381516995, 538032.7670105501 5806622.63456333, 538033.2289956162 5806550.730475481, 538034.2439780114 5806439.139490259, 538034.9819890751 5806356.531551383, 538034.7060015678 5806327.178504894, 538033.1359997048 5806317.118543288, 538031.8440206057 5806313.149559292, 538029.2600197658 5806309.642560479, 538025.9369712146 5806306.59548313, 538022.2450147746 5806304.380492733, 538019.2910067653 5806303.642525088, 538011.9070133638 5806302.258527385, 538002.8619918218 5806302.164502013, 537944.1580143513 5806301.427562024, 537885.6400068825 5806301.241481238, 537833.6740328395 5806301.058543082, 537805.7069671061 5806303.827531042, 537796.5689728062 5806305.395477799, 537786.6009895374 5806308.718484068, 537780.6010048713 5806311.210464031, 537774.5099927105 5806315.271511376, 537770.6330183104 5806319.241556241, 537768.2330270845 5806322.287562636, 537766.1099892402 5806326.716466095, 537761.9570135952 5806337.423506422, 537757.8950016466 5806344.161466324, 537754.4800184686 5806348.039518392, 537751.5530324389 5806350.09949859)), crs=CRS('32613'))

Thanks, I had a look at this, and for sure it is because the default image size used for analysis is 512 x 512 pixels. Running the AOI in Process API means that you are running your analysis at 1.4m which is obviously not required when analysing Sentinel-2 data.

Thank you for your explanation! I am glad to know what the difference was.