def capturarNegro(): data = request.get_json() data['errorBd'] = "" data['errorCapturaN'] = "" data['espectroNegro'] = "" sensorTierraVIS = data["sensorTierraVIS"] sensorTierraNIR = data["sensorTierraNIR"] nombreMisionCrear = data["nombreMisionCrear"] tiempoIntegracion = data["tiempoIntegracion"] numeroCapturas = data["numeroCapturas"] rel_path = '/tmp/archivoTemporalNegro.txt' filePath = FileManagement.to_relative(rel_path) negroCapturado = [] if os.path.exists(filePath): os.remove(filePath) else: print("Can not delete the file as it doesn't exists") try: negroCapturado = capturarNegroRpi(sensorTierraVIS, sensorTierraNIR, tiempoIntegracion, numeroCapturas) valores_espectros.espectroNegro = getFilesNegro(negroCapturado) makeImageD(valores_espectros.espectroNegro) rel_path = "/tmp/imagenEspectroD.png" filePath = FileManagement.to_relative(rel_path) with open(filePath, "rb") as image_file: encoded_string = base64.b64encode(image_file.read()) encoded_string = encoded_string.decode("utf-8") # print(encoded_string) data['espectroNegro'] = encoded_string except Exception as errorCapturaN: data['errorCapturaN'] = "T" raise errorCapturaN return json.dumps(data)
def makeImageG(ejeYMakeImage, rutaImagen, lat, lon, alt): # global wavelenghtsLista ejeY = "" ejeX = "" espectrocor = [] wavecor = [] ejeXMakeImage = wavelenghtsLista ejeY = np.array(ejeYMakeImage, dtype=np.float32) ejeX = np.array(ejeXMakeImage, dtype=np.float32) for i in range(230, 890): espectrocor.append(ejeY[i]) for i in range(230, 890): wavecor.append(ejeX[i]) plt.figure(1) ax = plt.subplot(111) plt.plot(wavecor, espectrocor)#, label='Negro') ax.set_ylim(min(espectrocor), max(espectrocor)) plt.legend() # rutaImagen= "D:/Tesis/Api/Flask/imagenEspectroC%s.png" %(str(j)) resultadoMakeImage= plt.savefig(rutaImagen, format="jpg") plt.cla() plt.clf() plt.close() rel_path = '/testy/base.jpg' filePath = FileManagement.to_relative(rel_path) piexif.transplant(filePath, rutaImagen) set_gps_location(rutaImagen, lat, lon, alt) return resultadoMakeImage
def makeImageC(ejeYMakeImage, j): ejeY = "" ejeX = "" espectrocor = [] wavecor = [] # global wavelenghtsLista ejeXMakeImage = wavelenghtsLista ejeY = np.array(ejeYMakeImage, dtype=np.float32) ejeX = np.array(ejeXMakeImage, dtype=np.float32) for i in range(230, 890): espectrocor.append(ejeY[i]) for i in range(230, 890): wavecor.append(ejeX[i]) plt.figure(1) ax = plt.subplot(111) plt.plot(wavecor, espectrocor)#, label='Negro') ax.set_ylim(min(espectrocor), max(espectrocor)) plt.legend() rutaImagen= "/tmp/imagenEspectroC%s.png" %(str(datetime.datetime.now())[18:19]) filePath = FileManagement.to_relative(rutaImagen) resultadoMakeImage= plt.savefig(filePath, format="png") plt.cla() plt.clf() plt.close() return filePath
def guardarNegro(): data = request.get_json() data['errorBd'] = "" relPathSrc = '/tmp/archivoTemporalNegro.txt' relPathDes = '/tmp/archivoNegro.txt' filePathSrc = FileManagement.to_relative(relPathSrc) filePathDes = FileManagement.to_relative(relPathDes) try: copyfile(filePathSrc, filePathDes) SpectreManagement.guardarNegro(valores_espectros.id_espectros, [], valores_espectros.espectroNegro, [], [], valores_sensores.idSensorTierraVIS) except Exception as errorBd: data['errorBd'] = "T" raise errorBd return json.dumps(data)
def getFilesNegro(negroCapturado): negroCapturadoLista = [] # Guardar txt de la captura rel_path = '/tmp/archivoTemporalNegro.txt' filePath = FileManagement.to_relative(rel_path) appendFile = open(filePath, 'w') for i in range(len(negroCapturado)): appendFile.write(str(negroCapturado[i])) appendFile.close() # abrir txt de la captura y gyardar en [] rel_path = '/tmp/archivoTemporalNegro.txt' filePath = FileManagement.to_relative(rel_path) with open(filePath, "r") as negrovis: for line in negrovis: line = line[0:4] negroCapturadoLista.append(line) return negroCapturadoLista
def capturarBlanco(): valores_sensores.sumaBlanco = 0 blancoCapturado = [] # obtener datos del json data = request.get_json() data['errorBd'] = "" data['errorCapturaB'] = "" data['espectroBlanco'] = "" sensorTierraVIS = data["sensorTierraVIS"] sensorTierraNIR = data["sensorTierraNIR"] nombreMisionCrear = data["nombreMisionCrear"] tiempoIntegracion = data["tiempoIntegracion"] numeroCapturas = data["numeroCapturas"] rel_path = '/tmp/archivoTemporalBlanco.txt' filePath = FileManagement.to_relative(rel_path) if os.path.exists(filePath): os.remove(filePath) else: print("Can not delete the file as it doesn't exists") try: # Comandar sensores para captura blancoCapturado = capturarBlancoRpi(sensorTierraVIS, sensorTierraNIR, tiempoIntegracion, numeroCapturas) # construir imagen valores_espectros.espectroBlanco = getFilesBlanco(blancoCapturado) for i in range(0, len(valores_espectros.espectroBlanco)): valores_sensores.sumaBlanco += float( valores_espectros.espectroBlanco[i]) print("limiteCalibracion = " + str(valores_sensores.sumaBlanco)) # print(a) makeImageW(valores_espectros.espectroBlanco) rel_path = "/tmp/imagenEspectroW.png" filePath = FileManagement.to_relative(rel_path) with open(filePath, "rb") as image_file: encoded_string = base64.b64encode(image_file.read()) encoded_string = encoded_string.decode("utf-8") # print(encoded_string) data['espectroBlanco'] = encoded_string except Exception as errorCapturaB: data['errorCapturaB'] = "T" raise errorCapturaB return json.dumps(data) return json.dumps(data)
def getFilesBlanco(blancoCapturado): blancoCapturadoLista=[] # guardar txt de la captura rel_path = '/tmp/archivoTemporalBlanco.txt' filePath = FileManagement.to_relative(rel_path) appendFile = open(filePath, 'w') for i in range(len(blancoCapturado)): appendFile.write(str(blancoCapturado[i])) appendFile.close() #blanco capturado es un array de strings de tamaño 14336 que al escribirse por #líneas en el archivo queda de 1024----14336/14 # abrir txt capura y guardar en [] rel_path = '/tmp/archivoTemporalBlanco.txt' filePath = FileManagement.to_relative(rel_path) with open(filePath, "r") as blancovis: for line in blancovis: line = line[0:4] blancoCapturadoLista.append(line) # print(blancoCapturadoLista) return blancoCapturadoLista
def guardarBlanco(): data = request.get_json() data['errorBd'] = "" relPathSrc = '/tmp/archivoTemporalBlanco.txt' relPathDes = '/tmp/archivoBlanco.txt' filePathSrc = FileManagement.to_relative(relPathSrc) filePathDes = FileManagement.to_relative(relPathDes) try: copyfile(filePathSrc, filePathDes) print(valores_espectros.espectroBlanco) SpectreManagement.guardarBlanco(valores_espectros.id_espectros, valores_espectros.espectroBlanco, [], [], [], valores_sensores.idSensorTierraVIS) except Exception as errorBd: data['errorBd'] = "T" print("Error de DB en guardarBlanco: ", errorBd) return json.dumps(data) raise errorBd return json.dumps(data)
def guardarTodos(): data = request.get_json() data['errorBd'] = "" nombreMisionCrear = data['nombreMisionCrear'] ruta = str(data['ruta']) filePath = FileManagement.to_relative(ruta) usuario = str(data['usuario']) try: if os.path.isdir(filePath): data['errorCarpeta'] = "" idsWaypoints = [] idsEspectros = [] latlonsWaypoints = [] conn = conexion() daoMision = DaoMision(conn) mision = daoMision.getMisionNombre(nombreMisionCrear) idMision = mision.id altura = mision.elevacion daoWaypoints = DaoWaypoints(conn) waypointsList = daoWaypoints.getAllWaypoints2(idMision) print(waypointsList[0].id, waypointsList[1].id) #272" lista de obj for i in range(0, len(waypointsList)): idsWaypoints.append(waypointsList[i].id) latlonsWaypoints.append(waypointsList[i].latlon) print(idsWaypoints) # print("J") print(latlonsWaypoints) for i in range(0, len(idsWaypoints)): daoEspway = DaoEspway(conn) espway = daoEspway.getEspwayWaypoint(idsWaypoints[i]) idEspectro = espway.espectros_id idsEspectros.append(idEspectro) for i in range(0, len(idsEspectros)): latlons = latlonsWaypoints[i].split(",") rutaG = filePath daoEspectros = DaoEspectros(conn) espectro = daoEspectros.getEspectros(idsEspectros[i]) resultado = espectro.resultado rutaG += "/Usuario(" + usuario + ")" + "Mision(" + nombreMisionCrear + ")" + "WaypointNumber(" + str( i) + ")" # filePath = FileManagement.to_relative(rutaG) generate(resultado, rutaG, float(latlons[0]), float(latlons[1]), altura) conn.close() else: data['errorCarpeta'] = "T" except Exception as errorBd: data['errorBd'] = "T" print("Error en guardarTodos: ", errorBd) raise errorBd finally: return json.dumps(data)
def getFilesVuelo(vueloCapturado): vueloCapturadoLista=[] # guardar txt de la captura rel_path = '/tmp/archivoTemporalVuelo.txt' filePath = FileManagement.to_relative(rel_path) appendFile = open(filePath, 'w') for i in range(len(vueloCapturado)): appendFile.write(str(vueloCapturado[i])) appendFile.close() with open(filePath, "r") as blancovis: for line in blancovis: line = line[0:4] vueloCapturadoLista.append(line) return vueloCapturadoLista
def makeImageW(ejeYMakeImage): global wavelenghtsLista ejeXMakeImage = wavelenghtsLista print(len(ejeXMakeImage)) print(len(ejeYMakeImage)) # print(ejeXMakeImage) ejeY = np.array(ejeYMakeImage, dtype=np.float32) ejeX = np.array(ejeXMakeImage, dtype=np.float32) plt.figure(1) ax = plt.subplot(111) plt.plot(ejeX, ejeY)#, label='Negro') ax.set_ylim(min(ejeY), max(ejeY)) plt.legend() rutaImagen= "/tmp/imagenEspectroW.png" filePath = FileManagement.to_relative(rutaImagen) resultadoMakeImage= plt.savefig(filePath, format="png") plt.cla() plt.clf() plt.close() return resultadoMakeImage
def guardarEspectro(): data = request.get_json() data['errorBd'] = "" nombreMisionCrear = data['nombreMisionCrear'] waypointSeleccionado = data['waypointSeleccionado'] ruta = str(data['ruta']) usuario = str(data['usuario']) filePath = FileManagement.to_relative(ruta) try: if os.path.isdir(filePath): conn = conexion() daoMision = DaoMision(conn) mision = daoMision.getMisionNombre(nombreMisionCrear) idMision = mision.id altura = mision.elevacion daoWaypoints = DaoWaypoints(conn) wayp = daoWaypoints.getWaypointByNumber(waypointSeleccionado, idMision) idWayp = wayp.id latlon = wayp.latlon.split(",") daoEspway = DaoEspway(conn) espway = daoEspway.getEspwayWaypoint(idWayp) idEspectro = espway.espectros_id daoEspectros = DaoEspectros(conn) espectro = daoEspectros.getEspectros(idEspectro) resultado = espectro.resultado conn.close() filePath += "/Usuario(" + usuario + ")" + "Mision(" + nombreMisionCrear + ")" + "Waypoint(" + waypointSeleccionado + ")" generate(resultado, filePath, float(latlon[0]), float(latlon[1]), altura) else: data['errorCarpeta'] = "T" except Exception as errorBd: data['errorBd'] = "T" raise errorBd finally: return json.dumps(data)
def sensoresVuelo(sensorVueloVIS, sensorVueloNIR, tiempoIntegracion, numeroCapturas, aux): global counter try: if aux == "C": print("capturando Vuelo") start_time_A = time.time() # x = "D:/subtext/splitTest0/Quieto 1 feb/cult2/2mt0.txt" # D:\Tesis\Api\Flask\testy\cult2 if counter > 6: counter = 0 x = "/testy/cult2/inten%s.txt" %(counter) file_path = FileManagement.to_relative(x) with open(file_path, 'r') as f: intensitiesFlask = f.read() # sts.runInParallel(read_VIS(b, c), read_NIR(a, c)) #DOUBLE # #sts.runInParallel(read_VIS) # SINGLE # if queueTierra.full(): # If both the NIR and VIS spectra have been acquired successfully # # print(queue.qsize()) # The queue size should be 2 # wavelengths_NIR, intensities_NIR, wavelengths_VIS, intensities_VIS = sts.assign_spectra(queue, init_wl_NIR, init_wl_VIS) # SINGLE # else: # print("Queue not full") end_time_A = time.time() duration = end_time_A - start_time_A print("Acquisition for {} seconds".format(duration)) duration = str(duration) success = "Success" counter += 1 pass else: intensitiesFlask = "" counter = 0 # a, b, c = calibrarSensores(sensorVueloVIS, sensorVueloNIR, tiempoIntegracion, numeroCapturas) pass pass except Exception as errorCalibrarSensoresTierra: print("error captura/calibracion") raise errorCalibrarSensoresTierra return intensitiesFlask
from PIL import Image import piexif from fractions import Fraction from Daos.Conexion import * from Daos.AccesoDatos.DaoEspectros import DaoEspectros from Daos.AccesoDatos.Logica.Espectros import Espectros from file_management import FileManagement import random wavelenghtsLista = [] wavecor = [] espectrocor = [] espectrocor2 = [] rel_path = '\\testy\cult2\wavevis.txt' wav = FileManagement.to_relative(rel_path) with open(wav, "r") as wavevis: for line in wavevis: line = line[:-4] wavelenghtsLista.append(line) def to_deg(value, loc): """convert decimal coordinates into degrees, munutes and seconds tuple Keyword arguments: value is float gps-value, loc is direction list ["S", "N"] or ["W", "E"] return: tuple like (25, 13, 48.343 ,'N') """ if value < 0: loc_value = loc[0] elif value > 0: loc_value = loc[1] else: