Feature to export spectrum
— Feature, 7th week, 8th week — 1 min read
In the radis app one of the most demanded feature
is to download the spectrum . Now it is possible to download the spectrum in the form of a csv file .
1@app.post("/download-txt")2async def download_txt(payload: Payload, background_tasks: BackgroundTasks):3 try:4 create_download_directory(DOWNLOADED_TXT_DIRECTORY)5 spectrum = calculate_spectrum(payload)6 file_name_txt = spectrum.get_name()7 file_name = f"{file_name_txt}.csv"8 file_path = f"{DOWNLOADED_TXT_DIRECTORY}/{file_name}"9 if payload.use_simulate_slit is True:10 print(" >> Applying simulate slit")11 spectrum.apply_slit(payload.simulate_slit, "nm")12 # returning the error response13 except radis.misc.warning.EmptyDatabaseError:14 return {"error": "No line in the specified wavenumber range"}15 except Exception as exc:16 print("Error", exc)17 return {"error": str(exc)}18 else:19
20 wunit = spectrum.get_waveunit()21 iunit = "default"22 spectrum.savetxt(file_path,payload.mode,wunit=wunit,Iunit=iunit)23 # running as a background task to delete the .spec file after giving the file response back24 background_tasks.add_task(delete_spec, file_path)25 return FileResponse(26 file_path, media_type="application/octet-stream", filename=file_name27 )
Thanks.