diff --git a/lightcurve.png b/lightcurve.png new file mode 100644 index 0000000..12af2e9 Binary files /dev/null and b/lightcurve.png differ diff --git a/main.py b/main.py index e97c5c6..4d5f51c 100644 --- a/main.py +++ b/main.py @@ -1,9 +1,16 @@ -from flask import Flask, jsonify, request +import atexit +from flask import Flask, jsonify, request, send_file from supabase_py import create_client from flask_cors import CORS +import io +import matplotlib.pyplot as plt +import matplotlib +import lightkurve as lk +import logging app = Flask(__name__) CORS(app) +matplotlib.use('Agg') # Initialize Supabase client SUPABASE_URL = 'https://qwbufbmxkjfaikoloudl.supabase.co' @@ -69,5 +76,30 @@ def craft_structure(): return jsonify({'status': 'proceed', 'message': 'Structure crafted successfully'}), 200 + +# Set up logging +logging.basicConfig(level=logging.INFO) +logger = logging.getLogger(__name__) + +@app.route('/generate_lightcurve_image', methods=['POST']) +def generate_lightcurve_image(): + try: + tic_id = request.json.get('tic_id') + if not tic_id: + raise ValueError('TIC ID not provided') + + # Download lightcurve and create image + lc = lk.search_lightcurve(f"TIC {tic_id}").download().PDCSAP_FLUX + ax = lc.plot() + image_path = 'lightcurve.png' + ax.figure.savefig(image_path) + + # Send image file to the frontend + return send_file(image_path, mimetype='image/png') + + except Exception as e: + logger.exception('Error generating lightcurve image') + return jsonify({'status': 'error', 'message': str(e)}), 500 + if __name__ == '__main__': app.run(debug=True) \ No newline at end of file