Exemple #1
0
    def getQualityValues(self, longitude, latitude):
        datasourceInstance = loader.getDatasource(self.quality_layer)
        qvalues = utils.oneArray(
            datasourceInstance.lookup(
                str({
                    "type": "Point",
                    "coordinates": [longitude, latitude]
                }))["values"])

        qvalues = [int(i) for i in qvalues]

        return qvalues
Exemple #2
0
def clipValuesByYear(startYear, endYear, timeserieValues, datesStr):

	dates = [datetime.strptime(x, "%Y-%m-%d") for x in datesStr]

	#Pega apenas os valores entre startYear e endYear
	startYearDt = datetime.strptime(str(startYear)+"-01-01", "%Y-%m-%d")
	startYearIndex = utils.findIndex(dates, startYearDt)
	endYearDt = datetime.strptime(str(endYear)+"-12-31", "%Y-%m-%d")
	endYearIndex = utils.findIndex(dates, endYearDt)

	return {
		'values': utils.oneArray(timeserieValues[startYearIndex:endYearIndex]),
		'dates': dates[startYearIndex:endYearIndex]
	}
Exemple #3
0
def clipValuesByYear(startYear, endYear, timeserieValues, datesStr):

    dates = [datetime.strptime(x, "%Y-%m-%d") for x in datesStr]

    #Pega apenas os valores entre startYear e endYear
    startYearDt = datetime.strptime(str(startYear) + "-01-01", "%Y-%m-%d")
    startYearIndex = utils.findIndex(dates, startYearDt)
    endYearDt = datetime.strptime(str(endYear) + "-12-31", "%Y-%m-%d")
    endYearIndex = utils.findIndex(dates, endYearDt)

    return {
        'values': utils.oneArray(timeserieValues[startYearIndex:endYearIndex]),
        'dates': dates[startYearIndex:endYearIndex]
    }
Exemple #4
0
	def calcTrend(self, resultMean):
		filters = loader.getFilters(self.layer_id);

		bfastIndex = utils.findIndexByAttribute(filters, 'id', 'Bfast')
		origSeriesProp = utils.findIndexByAttribute(resultMean['series'], 'type', 'original');
		
		originalValues = utils.oneArray(resultMean['values'], resultMean['series'][origSeriesProp]['position']-1)
		filteredValues = filters[bfastIndex].run(originalValues, None, None);
		filteredValues = filteredValues if type(filteredValues) == list else filteredValues.tolist();
		
		result = {
			'series': {
				'id': "Bfast",
				'label': 'BFAST',
				'position': len(resultMean['values'][0])+1,
				'type': 'trend'
			},
			'values': filteredValues
		}
		
		return result
Exemple #5
0
def run(layerId, longitude, latitude):

	datasourceInstance = loader.getDatasource(layerId)	

	timeserieData = datasourceInstance.lockup(longitude, latitude)
	
	values = utils.oneArray(timeserieData)
	
	position = 1
	series = [{'id': 'original', 'label': 'Valores originais', 'position': 1}];
	
	for filter in loader.getFilters(layerId):

		filteredValues = filter.run(values, longitude, latitude);	
		if len(filteredValues) == len(values):
			position += 1
			series.append({ 'id': filter.id, 'label': filter.label, 'position': position })
			utils.joinArray(timeserieData, filteredValues)

	return {
		'series': series,
		'values': timeserieData
	}
Exemple #6
0
def trend(layerId, startYear, endYear, interpolation, groupData, timeChange, timeChangeUnits, geoJsonGeometry):
	
	#Obtem a série
	datasourceInstance = loader.getDatasource(layerId)
	timeserieData = datasourceInstance.lookup(geoJsonGeometry, mode="series")

	#Obtem as datas
	datesStr = utils.oneArray(timeserieData["values"], 0)

	#Obtem os valores entre os anos startYear e endYear
	clippedValues = bfast_utils.clipValuesByYear(startYear, endYear, timeserieData["values"], datesStr)

	values = clippedValues['values']
	dates = clippedValues['dates']
	startDate = dates[0]
	endDate = dates[-1]

	#Encontra o indice do filtro(se houver) e do bfast
	filters = loader.getFilters(layerId)
	bfastIndex = utils.findIndexByAttribute(filters, 'id', 'Bfast')
	
	# O filtro já foi calculado na datasource
	interpolation = interpolation if interpolation != "original" else 'STRING_NOT_FOUND';
	interpolationIndex, interpolationPos = next(((i, item['position']) for i, item in enumerate(timeserieData["series"]) if item['id'] == interpolation), (-1, -1))

	#Inicializa preparação do objeto de resposta
	series = [{'id':'Bfast', 'label':'BFAST', 'position':1, 'type':'trend'}]

	#Se há filtro selecionado, executa e adiciona ao objeto de resposta
	if interpolationPos != -1:
		values = utils.oneArray(timeserieData["values"], interpolationPos)
		series.append({'id':timeserieData["series"][interpolationIndex]["id"], 'label': timeserieData["series"][interpolationIndex]["label"], 'position': 2, 'type': 'filter'})

	else:
		series.append({'id':'original', 'label':'Valores Originais', 'position':2, 'type':'original'})

	#Agrupa os valores
	groupedData = bfast_utils.groupData(dates, values, groupData)
	values = groupedData['values']
	frequency = groupedData['frequency']
	dates = groupedData['dates']
	
	#Calcula o valor do parâmetro h(minimal segment size) para o bfast
	minimalSegmentSize = bfast_utils.calculateMinimalSegmentSize(len(values), timeChange, timeChangeUnits, frequency)
	#Executa o BFAST
	result = []
	if bfastIndex != -1:
		result = filters[bfastIndex].run(values, None, None, minimalSegmentSize, frequency, startDate, endDate)
	else:
		raise IndexError("Bfast filter could not be found.")

	#Acrescenta ao resultado as datas, os valores da tendência e os valores originais (agrupados ou não)
	datesList = [[i] for i in dates]
	utils.joinArray(datesList, result)
	result = datesList
	utils.joinArray(result, values)
	
	return {
		'series': series,
		'values': result
	}
Exemple #7
0
	def getQualityValues(self, longitude, latitude):
		datasourceInstance = loader.getDatasource(self.quality_layer)
		return utils.oneArray( datasourceInstance.lockup(longitude, latitude) )
Exemple #8
0
def trend(layerId, startYear, endYear, interpolation, groupData, timeChange,
          timeChangeUnits, geoJsonGeometry):

    # Obtem a série
    datasourceInstance = loader.getDatasource(layerId)
    timeserieData = datasourceInstance.lookup(geoJsonGeometry, mode="series")

    # Obtem as datas
    datesStr = utils.oneArray(timeserieData["values"], 0)

    # Obtem os valores entre os anos startYear e endYear
    clippedValues = bfast_utils.clipValuesByYear(startYear, endYear,
                                                 timeserieData["values"],
                                                 datesStr)

    values = clippedValues['values']
    dates = clippedValues['dates']
    startDate = dates[0]
    endDate = dates[-1]

    # Encontra o indice do filtro(se houver) e do bfast
    filters = loader.getFilters(layerId)
    bfastIndex = utils.findIndexByAttribute(filters, 'id', 'Bfast')

    # O filtro já foi calculado na datasource
    interpolation = interpolation if interpolation != "original" else 'STRING_NOT_FOUND'
    interpolationIndex, interpolationPos = next(
        ((i, item['position'])
         for i, item in enumerate(timeserieData["series"])
         if item['id'] == interpolation), (-1, -1))

    # Inicializa preparação do objeto de resposta
    series = [{
        'id': 'Bfast',
        'label': 'BFAST',
        'position': 1,
        'type': 'trend'
    }]

    # Se há filtro selecionado, executa e adiciona ao objeto de resposta
    if interpolationPos != -1:
        values = utils.oneArray(timeserieData["values"], interpolationPos)
        series.append({
            'id':
            timeserieData["series"][interpolationIndex]["id"],
            'label':
            timeserieData["series"][interpolationIndex]["label"],
            'position':
            2,
            'type':
            'filter'
        })

    else:
        series.append({
            'id': 'original',
            'label': 'Valores Originais',
            'position': 2,
            'type': 'original'
        })

    # Agrupa os valores
    groupedData = bfast_utils.groupData(dates, values, groupData)
    values = groupedData['values']
    frequency = groupedData['frequency']
    dates = groupedData['dates']

    # Calcula o valor do parâmetro h(minimal segment size) para o bfast
    minimalSegmentSize = bfast_utils.calculateMinimalSegmentSize(
        len(values), timeChange, timeChangeUnits, frequency)
    # Executa o BFAST
    result = []
    if bfastIndex != -1:
        result = filters[bfastIndex].run(values, None, None,
                                         minimalSegmentSize, frequency,
                                         startDate, endDate)
    else:
        raise IndexError("Bfast filter could not be found.")

    # Acrescenta ao resultado as datas, os valores da tendência e os valores originais (agrupados ou não)
    datesList = [[i] for i in dates]
    utils.joinArray(datesList, result)
    result = datesList
    utils.joinArray(result, values)

    return {'series': series, 'values': result}