In this project, you'll use Python - and the skills we've developed throughout this course - to search for and explore close approaches of near-Earth objects (NEOs), using data from NASA/JPL's Center for Near Earth Object Studies.
create envirment
activate envirment
pip3 install -r requirement.txt
python3 main.py query --start-date 2020-01-01 --end-date 2020-12-31 --hazardous --min-diameter 0.25 --max-distance 0.1 --limit 5 --outfile results.json
- Occurs on a given date.
- Occurs on or after a given start date.
- Occurs on or before a given end date.
- Approaches Earth at a distance of at least (or at most) X astronomical units.
- Approaches Earth at a relative velocity of at least (or at most) Y kilometers per second.
- Has a diameter that is at least as large as (or at least as small as) Z kilometers.
- Is marked by NASA as potentially hazardous (or not).
Upon starting, the project contains several files and folders to help you get up and running:
.
├── README.md # This file.
├── main.py
├── models.py # Task 1.
├── read.py # Task 2a.
├── database.py # Task 2b and Task 3b.
├── filters.py # Task 3a and Task 3c.
├── write.py # Task 4.
├── helpers.py
├── data
│ ├── neos.csv
│ └── cad.json
└── tests
├── test-neos-2020.csv
├── test-cad-2020.json
├── test_*.py
├── ...
└── test_*.py
- A
NearEarthObject
class, to represent the data for a single near-Earth object.
- Check if info is null/empty.
- Check if info has required data is present or not if not then store None otherwise store value
- IsBlank(string) function to check string is Blank or not
- addCAD(approach) function to add new cad to neo object.
- NearEarthObject has variable designation, name, hazardous, diameter, approaches (list).
- A
CloseApproach
class, to represent the data for a single close approach of an NEO.
- Get rquired data from ** info and store into CloseApproach class variable.
- setNeo function is to set NearEarthObject class object function for that Approach.
extract.py
- store all NearEarthObject object in neos list.
- store all CloseApproach obeject in approaches list.
- neos_id is map to store neos list element index with NearEarthObject object designation.
load_neos(....) function
- Read the request csv using csv python library with DictReader function.
- Exract the required data from every row in csv file.
- create Object from that exracted data and append that object into neos list.
- update neos_id with designation and index of neos list.
load_approaches(....) function
- Open requested json file using json python lib. and read the data.
- json file fields are store in fields variable.
- fileds name and index store with variable key map.
- extract the required data fields using key and create CloseApproach object.
- check if desingation of that object is present or not in neos_id map.
- get that designation neo object from neos list using neos_id.
- set Neo object to CloseApproach object and vice versa.
- append that new CloseApproach object to approaches list.
filters.py
- Implement Date Class and write override get method of AttributeFilter.
- return date type object of that requested approach.
- Create Distance, Velocity, Hazardous, Diameter class and override get method and return required data for each class filter.
create_filter_function(..)
- Create class Object for requested filter using operator and value.
- append that created object to filters_map list.
database.py
get_neo_by_designation(..)
- return neo object for requested designation.
get_neo_by_name(..)
- return neo object for requested name.
query(...)
- Implement Query function for execute filters.
- every approach filter with reqeusted fillter and count.
- if approach is reutrn by after all filter class then append to result.
- convert iterator to list and return that list for request n elements.
- check if n is less than from iterator length.
write_to_csv
: Write a stream ofCloseApproach
objects to a specific CSV file.
- create file with requested name and open it.
- all requested filedsname store in variable and write header for that csv file.
- create a new variable with name "row" and append that required data with map from results.
- write every row in csv file.
write_to_json
: Write a stream ofCloseApproach
objects to a specific JSON file.
- create file with requested name and open it.
- intitalize dump_data list .
- create a new map variable with data and add required data and append to dump_data list.
- dump all dump_data data in json file.
$ python3 -m unittest
python3 -m unittest tests.test_query tests.test_limit
python3 -m unittest --verbose tests.test_query
python3 -m unittest --verbose tests.test_extract tests.test_database