<jupyter_start><jupyter_text>ENG DataCube V2 (a.k.a. GDF) - Use Example This example shows how to use the DataCube v2 to perform a query and generate an image from results. GDF Virtual MachineA [Virtual Machine](http://labs.christian-ariza.net/DataCubeV2.ova) with data cube software and data is available. The installed version is: (https://github.com/cronosnull/agdc-v2/tree/d42a5ac87916a0ca32ad3a5b41a7404657e6a30f)<jupyter_code>'''
Libraries import
'''
%matplotlib inline
from datetime import  date
from pprint import pprint
'''
Datacube modules: GDF, Analytics, and ExecutionEngine
Utils: (plot, writeToCSV...)
'''
from gdf import dt2secs, GDF 
from analytics import Analytics
from execution_engine import ExecutionEngine
from analytics_utils import writeToCSV, writeTXY_to_GeoTiff, plot
'''
Create intances of Analytics and ExecutionEngine classes
'''
a = Analytics()
e = ExecutionEngine()<jupyter_output>DEBUG:analytics:Initialise Analytics Module.<jupyter_text>Consulta<jupyter_code>'''
Query:
X=longitude
Y=latitude
T=Time (grouping function: transform "seconds since epoch" to...)
'''
start_date = dt2secs(date(year=2011,month=1,day=1))  #2011-01-01
end_date = dt2secs(date(year=2013, month=12, day=18)) #2013-12-18

dimensions = {'X': {'range': (147.0, 147.125)},
                  'Y': {'range': (-36.0, -36 +0.125)},
                  'T': {'range': (start_date, end_date),'grouping_function': a.gdf.solar_days_since_epoch}
                  }
'''
Create Array parameters:
      1. Sensor (Storage unit)
      2. List of variables (e.g. Bands)
      3. Query
      4. Name of the result (Using this name we can get the result after excecution)
'''
arrays = a.createArray('LS7ETM', ['B40'], dimensions, 'get_data')<jupyter_output>DEBUG:analytics:storage_type = LS7ETM<jupyter_text>ReductionSeveral reduction functions are available, some of them are: >'min', 'max', 'amin', 'amax', 'nanmin', 'nanmax', 'ptp', 'median', 'average', 'mean', 'std', 'var', 'nanmean', 'nanstd', 'nanvar', 'argmax', 'argmin', 'sum', 'prod', 'all', 'any'<jupyter_code>max_t = a.applyGenericReduction(arrays, ['T'], 'max(array1)', 'maxT')
median_t = a.applyGenericReduction(arrays, ['T'], 'median(array1)', 'medianT')
min_t = a.applyGenericReduction(arrays, ['T'], 'min(array1)', 'minT')<jupyter_output>DEBUG:analytics:function before = max(array1)<jupyter_text>ExecuteUntil now we create a execution plan, to execute this plan we use the ExecutionEngine instance:<jupyter_code>e.executePlan(a.plan)<jupyter_output>function = get_data
function = max(array1)
key = maxT
data key = get_data
['T', 'Y', 'X']
function = median(array1)
key = medianT
data key = get_data
['T', 'Y', 'X']
function = min(array1)
key = minT
data key = get_data
['T', 'Y', 'X']<jupyter_text>Get the results<jupyter_code>resultMedian=e.cache['medianT']
resultMax=e.cache['maxT']
resultMin=e.cache['minT']<jupyter_output><empty_output><jupyter_text>Plot resultsWe can plot the results. The following 3 images are the results of apply reduction with mean, max and min values. The fourth graphic is the result of the query (all 97 retrieved images)<jupyter_code>plot(resultMedian)
plot(resultMax)
plot(resultMin)
plot(e.cache['get_data'])

print("-----------------Resultado: --------------------------------")
pprint(e.cache['get_data']['array_result'].values()[0])<jupyter_output>-----------------Resultado: --------------------------------
array([[[ 3837.,  3941.,  3941., ...,  2452.,  2452.,  2698.],
        [ 3837.,  3871.,  3906., ...,  2487.,  2487.,  2768.],
        [ 3837.,  3871.,  3906., ...,  2557.,  2557.,  2838.],
        ..., 
        [ 3078.,  2903.,  2728., ...,   397.,   398.,   433.],
        [ 2833.,  2798.,  2763., ...,   397.,   433.,   433.],
        [ 2658.,  2588.,  2553., ...,   397.,   398.,   433.]],

       [[ 3642.,  3717.,  3755., ...,  2284.,  2284.,  2513.],
        [ 3717.,  3755.,  3831., ...,  2437.,  2437.,  2704.],
        [ 3717.,  3755.,  3868., ...,  2513.,  2513.,  2819.],
        ..., 
        [ 3157.,  3081.,  2967., ...,   162.,   123.,   123.],
        [ 3005.,  3043.,  3005., ...,   123.,   123.,   123.],
        [ 2624.,  2547.,  2433., ...,    84.,    84.,   123.]],

       [[ 3545.,  3505.,  3586., ...,  2285.,  2285.,  2655.],
        [ 3505.,  3586.,  3708., ...,  2408.,  2408.,  2860.],
        [ 3505.,  3586., [...]<jupyter_text>Exportar los resultados a Archivo<jupyter_code>writeTXY_to_GeoTiff(e.cache['get_data'], "salida2.tiff")
writeToCSV(resultMedian, "salida2.csv")<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1934201810554206, 'fraction_numerical': 0.09406049900640318, 'mean_word_length': 3.2695570216776626, 'pattern_counts': {'":': 0, '<': 24, '<?xml version=': 0, '>': 25, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '609199', 'license': 'Apache-2.0', 'n_tokens_mistral': 1898, 'n_tokens_neox': 1619, 'n_words': 396, 'path': 'docs/tutorial/eng/01_Tutorial DataCubeV2.ipynb', 'repo_name': 'OpenDatacubeIDEAM/cdcol-core', 'size': '4529'}