Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rishi #45

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file not shown.
164 changes: 155 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,159 @@
# NASA Space Apps Challenge 2024 [Noida]

#### Team Name -
#### Problem Statement -
#### Team Leader Email -
#### Team Name - Tech Conqueror
#### Problem Statement - Landsat Reflectance Data: On the Fly and at Your
Fingertips
#### Team Leader Email - [email protected]


#### Solution Overview
Our solution is a satellite overpass notification and data retrieval platform focused on Landsat imagery. Designed for users needing timely and precise satellite-based surface reflectance data, this prototype aims to simplify satellite imagery access and enhance environmental monitoring, research, and planning applications. The solution allows users to specify a target location, check upcoming Landsat satellite overpass times, and view a 3x3 grid of Landsat pixels centered on that location. Additionally, users can set notifications to alert them before an overpass, and the platform provides options to receive alerts via email or SMS. This system brings the power of satellite observation directly to users in real-time, aiding anyone from environmental scientists to policymakers in making data-driven decisions based on timely satellite imagery.

The platform consists of three core components:

Target Location and Overpass Notification Setup
Real-time Landsat Pixel Data Retrieval
Automated Notifications
### How it Works
#### 1. Target Location and Overpass Notification Setup
Users begin by selecting or inputting a target location. This input can be a latitude/longitude coordinate or a direct selection on an interactive map. Once the location is set, our platform determines when the next Landsat satellite will pass over the area by querying services such as the CelesTrak API. CelesTrak provides orbital parameters that can be used to predict satellite positions, enabling us to determine overpass times based on user-defined coordinates. With the overpass time calculated, users can set lead times (e.g., 1 day, 1 hour) before the satellite's expected arrival and choose their preferred notification method, either email or SMS.

#### 2. Real-time Landsat Pixel Data Retrieval
The platform uses Google Earth Engine (GEE) or the USGS Earth Explorer API to fetch satellite imagery data from Landsat satellites. A 3x3 grid centered around the user-defined location is displayed, where each grid cell represents a Landsat pixel. This feature allows users to inspect nearby pixels and understand the local variations in surface reflectance. The grid data includes spectral reflectance values across multiple bands, and if available, surface temperature information derived from thermal infrared bands. This high-resolution, real-time grid visualization assists users in gaining insight into the spatial distribution of reflectance data in their area of interest.

The retrieval of Landsat data considers user-set parameters, such as cloud cover threshold and acquisition time range, ensuring that the data is relevant and high-quality. Users can opt for recent acquisitions or specify a time range for historical data, allowing for a flexible analysis suited to their needs.

#### 3. Automated Notifications
Upon setting a notification, Celery, a background task manager, schedules the notifications based on the user-defined lead time. Celery works in conjunction with Redis, a message broker, to ensure task reliability and timely notifications. Users are notified by their chosen method, either via email (using SendGrid) or SMS (using Twilio). Email notifications include the exact overpass time, while SMS notifications are sent in advance of the overpass as per the lead time preference. This ensures users are prepared to capture or analyze data as the satellite passes.

By providing an intuitive interface for tracking satellite imagery overpasses and automating data notifications, this solution bridges the gap between remote sensing data accessibility and real-time field application. This capability is particularly valuable for environmental researchers, agriculturalists, and climate scientists who rely on up-to-date, reliable, and precise data to make informed decisions. Our platform enables easier satellite data access while supporting accurate and timely analysis, making it a robust tool for a range of geospatial and environmental monitoring applications.





Execution Plan for Satellite Overpass Notification and Data Retrieval Platform
1. Repository Setup
Clone the Repository

bash
Copy code
git clone <repository-url>
cd <repository-directory>
Check Directory Structure
Ensure the repository has the following structure for smooth setup:

arduino
Copy code
├── project_folder/
│ ├── settings.py
│ ├── urls.py
│ ├── views.py
│ ├── tasks.py
│ ├── models.py
├── templates/
├── static/
├── Execution_Plan.pdf
├── requirements.txt
├── README.md
├── ...
2. Python Environment Setup
Set up a Python Virtual Environment

bash
Copy code
python3 -m venv myenv
source myenv/bin/activate # For Windows: myenv\Scripts\activate
Install Requirements
Install all dependencies:

bash
Copy code
pip install -r requirements.txt
3. Configure Celery and Redis for Background Tasks
Install Redis (if not already installed)
Follow instructions on Redis’s official website to install Redis on your system.

Start Redis Server

bash
Copy code
redis-server
Configure Celery in Django
Ensure that celery.py is configured correctly with Redis as the broker:

python
Copy code
# In celery.py
app.conf.broker_url = 'redis://localhost:6379/0'
app.conf.result_backend = 'redis://localhost:6379/0'
Run Celery Worker
Open a new terminal and start the Celery worker:

bash
Copy code
celery -A project_folder worker -l info
4. Configure Email and SMS Services
Email Setup (SendGrid or SMTP)
Configure email settings in settings.py:

python
Copy code
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.sendgrid.net' # or your SMTP provider
EMAIL_PORT = 587
EMAIL_USE_TLS = True
EMAIL_HOST_USER = '<sendgrid_username>'
EMAIL_HOST_PASSWORD = '<sendgrid_password>'
SMS Setup (Twilio)
Add your Twilio account credentials to settings.py:

python
Copy code
TWILIO_ACCOUNT_SID = '<your_account_sid>'
TWILIO_AUTH_TOKEN = '<your_auth_token>'
TWILIO_PHONE_NUMBER = '<twilio_phone_number>'
5. Database Setup
Set up PostgreSQL Database
Create a PostgreSQL database and user, then add the database configurations in settings.py:

python
Copy code
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'your_db_name',
'USER': 'your_db_user',
'PASSWORD': 'your_db_password',
'HOST': 'localhost',
'PORT': '5432',
}
}
Run Migrations

bash
Copy code
python manage.py makemigrations
python manage.py migrate
6. Run Django Server
Start Development Server

bash
Copy code
python manage.py runserver
Access the Application
Open your browser and go to http://localhost:8000 to view the application.

7. Testing the Application
Set Up Test Data
Add initial data, including sample locations, by using the Django admin interface or through fixtures.

Test Notification Scheduling

Access the overpass time scheduling view.
Verify that notifications are scheduled and sent correctly according to lead times.
Verify Landsat Data Retrieval
Test the data retrieval views and ensure the 3x3 Landsat grid is fetched and displayed correctly.


## A Brief of the Prototype:
What is your solution? and how it works.

## Code Execution Instruction:
*[If your solution is **not** application based, you can ignore this para]

*The Repository must contain your **Execution Plan PDF**.
3 changes: 3 additions & 0 deletions SR_backend/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from .celery import app as celery_app

__all__ = ('celery_app',)
Binary file added SR_backend/__pycache__/__init__.cpython-312.pyc
Binary file not shown.
Binary file added SR_backend/__pycache__/celery.cpython-312.pyc
Binary file not shown.
Binary file added SR_backend/__pycache__/settings.cpython-312.pyc
Binary file not shown.
Binary file added SR_backend/__pycache__/urls.cpython-312.pyc
Binary file not shown.
Binary file added SR_backend/__pycache__/wsgi.cpython-312.pyc
Binary file not shown.
16 changes: 16 additions & 0 deletions SR_backend/asgi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""
ASGI config for SR_backend project.

It exposes the ASGI callable as a module-level variable named ``application``.

For more information on this file, see
https://docs.djangoproject.com/en/5.1/howto/deployment/asgi/
"""

import os

from django.core.asgi import get_asgi_application

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "SR_backend.settings")

application = get_asgi_application()
9 changes: 9 additions & 0 deletions SR_backend/celery.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from __future__ import absolute_import, unicode_literals
import os
from celery import Celery

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'your_project.settings')

app = Celery('your_project')
app.config_from_object('django.conf:settings', namespace='CELERY')
app.autodiscover_tasks()
138 changes: 138 additions & 0 deletions SR_backend/settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
from pathlib import Path
# import ee
# import os
# from dotenv import load_dotenv

# Load environment variables from the .env file
# load_dotenv()

# # Get service account email and private key path from environment variables
# SERVICE_ACCOUNT = os.getenv("GEE_SERVICE_ACCOUNT")
# PRIVATE_KEY_PATH = os.getenv("GEE_PRIVATE_KEY_PATH")

# # Initialize Earth Engine with the Service Account credentials using the key file path
# credentials = ee.ServiceAccountCredentials(SERVICE_ACCOUNT, PRIVATE_KEY_PATH)
# ee.Initialize(credentials)

# Django settings
BASE_DIR = Path(__file__).resolve().parent.parent


SECRET_KEY = "django-insecure-%%44dv42)-9!ro5mo8n6#pfo42vq(+da-=ukyx1&lumq8=57^i"

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []


# Application definition

INSTALLED_APPS = [
"django.contrib.admin",
"django.contrib.auth",
"django.contrib.contenttypes",
"django.contrib.sessions",
"django.contrib.messages",
"django.contrib.staticfiles",
'rest_framework',
'api_location',
]

MIDDLEWARE = [
"django.middleware.security.SecurityMiddleware",
"django.contrib.sessions.middleware.SessionMiddleware",
"django.middleware.common.CommonMiddleware",
"django.middleware.csrf.CsrfViewMiddleware",
"django.contrib.auth.middleware.AuthenticationMiddleware",
"django.contrib.messages.middleware.MessageMiddleware",
"django.middleware.clickjacking.XFrameOptionsMiddleware",
]

ROOT_URLCONF = "SR_backend.urls"

TEMPLATES = [
{
"BACKEND": "django.template.backends.django.DjangoTemplates",
"DIRS": [],
"APP_DIRS": True,
"OPTIONS": {
"context_processors": [
"django.template.context_processors.debug",
"django.template.context_processors.request",
"django.contrib.auth.context_processors.auth",
"django.contrib.messages.context_processors.messages",
],
},
},
]

WSGI_APPLICATION = "SR_backend.wsgi.application"


# Database
# https://docs.djangoproject.com/en/5.1/ref/settings/#databases

DATABASES = {
"default": {
"ENGINE": "django.db.backends.sqlite3",
"NAME": BASE_DIR / "db.sqlite3",
}
}


# Password validation
# https://docs.djangoproject.com/en/5.1/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
{
"NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator",
},
{
"NAME": "django.contrib.auth.password_validation.MinimumLengthValidator",
},
{
"NAME": "django.contrib.auth.password_validation.CommonPasswordValidator",
},
{
"NAME": "django.contrib.auth.password_validation.NumericPasswordValidator",
},
]


# Internationalization
# https://docs.djangoproject.com/en/5.1/topics/i18n/

LANGUAGE_CODE = "en-us"

TIME_ZONE = "UTC"

USE_I18N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/5.1/howto/static-files/

STATIC_URL = "static/"

# Default primary key field type
# https://docs.djangoproject.com/en/5.1/ref/settings/#default-auto-field

DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"

CORS_ALLOWED_ORIGINS = [
"http://localhost:8000",
"http://127.0.0.1:8000",
]


# your_project/settings.py
CELERY_BROKER_URL = 'redis://localhost:6379/0'
CELERY_RESULT_BACKEND = 'redis://localhost:6379/0'

# Email configurations for SendGrid
EMAIL_BACKEND = "sendgrid_backend.SendgridBackend"
SENDGRID_API_KEY = "your_sendgrid_api_key"

7 changes: 7 additions & 0 deletions SR_backend/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from django.contrib import admin
from django.urls import path, include

urlpatterns = [
path('admin/', admin.site.urls),
path('api/', include('api_location.urls')), # Include your app URLs here
]
16 changes: 16 additions & 0 deletions SR_backend/wsgi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""
WSGI config for SR_backend project.

It exposes the WSGI callable as a module-level variable named ``application``.

For more information on this file, see
https://docs.djangoproject.com/en/5.1/howto/deployment/wsgi/
"""

import os

from django.core.wsgi import get_wsgi_application

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "SR_backend.settings")

application = get_wsgi_application()
Empty file added api_location/__init__.py
Empty file.
Binary file added api_location/__pycache__/__init__.cpython-312.pyc
Binary file not shown.
Binary file added api_location/__pycache__/admin.cpython-312.pyc
Binary file not shown.
Binary file added api_location/__pycache__/apps.cpython-312.pyc
Binary file not shown.
Binary file added api_location/__pycache__/models.cpython-312.pyc
Binary file not shown.
Binary file added api_location/__pycache__/serializers.cpython-312.pyc
Binary file not shown.
Binary file added api_location/__pycache__/tasks.cpython-312.pyc
Binary file not shown.
Binary file added api_location/__pycache__/urls.cpython-312.pyc
Binary file not shown.
Binary file added api_location/__pycache__/views.cpython-312.pyc
Binary file not shown.
15 changes: 15 additions & 0 deletions api_location/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from django.contrib import admin
from .models import Location

@admin.register(Location)
class LocationAdmin(admin.ModelAdmin):
list_display = ('place_name', 'latitude', 'longitude') # Fields to display in the list view
search_fields = ('place_name',) # Add search capability on place_name
list_filter = ('latitude', 'longitude') # Optional: filter options for latitude and longitude

# Optionally customize the form layout if desired
fieldsets = (
(None, {
'fields': ('place_name', 'latitude', 'longitude')
}),
)
6 changes: 6 additions & 0 deletions api_location/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.apps import AppConfig


class ApiLocationConfig(AppConfig):
default_auto_field = "django.db.models.BigAutoField"
name = "api_location"
Loading