def lookup(self, geoJsonGeometry, mode=None): result = [] filepath = os.path.join(self.imageDbPath, self.file) mean = self.zonalStatistics(geoJsonGeometry, filepath) if "month" == self.temporal_resolution_type: date = self.localDateByMonth() else: date = self.LocalDateByDay() geoJsonGeometry = ast.literal_eval(geoJsonGeometry) for i, j in zip(mean, date): count = [] count.append(j) count.append(float(i)) result.append(count) series = [{"position": 1, "type": "original", "id": "original", "label": "Valores originais"}] for filter in loader.getFilters(self.layer_id): if filter.id == "Bfast" and mode == "series": continue elif filter.id != "Bfast" and mode == "trend": continue filters = loader.getFilters(self.layer_id) bfastIndex = utils.findIndexByAttribute(filters, "id", filter.id) filteredValues = filters[bfastIndex].run(mean, None, None) filteredValues = filteredValues if type(filteredValues) == list else filteredValues.tolist() if len(filteredValues) == len(mean): series.append({"id": filter.id, "label": filter.label, "position": len(result[0]), "type": "filter"}) utils.joinArray(result, filteredValues) if mode == "trend": filters = loader.getFilters(self.layer_id) bfastIndex = utils.findIndexByAttribute(filters, "id", "Bfast") filteredValues = filters[bfastIndex].run(mean, None, None) filteredValues = filteredValues if type(filteredValues) == list else filteredValues.tolist() if len(filteredValues) == len(mean): series.append({"id": "Bfast", "label": "BFAST", "position": len(result[0]), "type": "trend"}) # 2 utils.joinArray(result, filteredValues) return {"series": series, "values": result}
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
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 }
def lookup(self, geoJsonGeometry, mode=None): result = [] filepath = os.path.join(self.imageDbPath, self.file) mean = self.zonalStatistics(geoJsonGeometry, filepath) if ('month' == self.temporal_resolution_type): date = self.localDateByMonth() else: date = self.LocalDateByDay() geoJsonGeometry = ast.literal_eval(geoJsonGeometry) for i, j in zip(mean, date): count = [] count.append(j) count.append(float(i)) result.append(count) series = [{ 'position': 1, 'type': 'original', 'id': 'original', 'label': 'Valores originais' }] for filter in loader.getFilters(self.layer_id): if filter.id == 'Bfast' and mode == 'series': continue elif filter.id != 'Bfast' and mode == 'trend': continue filters = loader.getFilters(self.layer_id) bfastIndex = utils.findIndexByAttribute(filters, 'id', filter.id) filteredValues = filters[bfastIndex].run(mean, None, None) filteredValues = filteredValues if type( filteredValues) == list else filteredValues.tolist() if len(filteredValues) == len(mean): series.append({ 'id': filter.id, 'label': filter.label, 'position': len(result[0]), 'type': 'filter' }) utils.joinArray(result, filteredValues) if mode == 'trend': filters = loader.getFilters(self.layer_id) bfastIndex = utils.findIndexByAttribute(filters, 'id', 'Bfast') filteredValues = filters[bfastIndex].run(mean, None, None) filteredValues = filteredValues if type( filteredValues) == list else filteredValues.tolist() if len(filteredValues) == len(mean): series.append({ 'id': "Bfast", 'label': 'BFAST', 'position': len(result[0]), #2 'type': 'trend' }) utils.joinArray(result, filteredValues) return { "series": series, "values": result }
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}