-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #76 from WimDeMeester/master
Download oribital elements of comets and asteroids.
- Loading branch information
Showing
11 changed files
with
358 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
src/database/migrations/create_asteroids_orbital_elements_table.php.stub
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
|
||
use Illuminate\Support\Facades\Schema; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Database\Migrations\Migration; | ||
|
||
class CreateAsteroidsOrbitalElementsTable extends Migration | ||
{ | ||
/** | ||
* Run the migrations. | ||
*/ | ||
public function up() | ||
{ | ||
Schema::create( | ||
'asteroids_orbital_elements', | ||
function (Blueprint $table) { | ||
$table->integer('number'); | ||
$table->string('name'); | ||
$table->integer('epoch')->signed(); | ||
$table->float('a', 12, 8); | ||
$table->float('e', 12, 8); | ||
$table->float('i', 10, 5); | ||
$table->float('w', 10, 5); | ||
$table->float('node', 10, 5); | ||
$table->float('M', 15, 7); | ||
$table->float('H', 5, 2); | ||
$table->float('G', 5, 2); | ||
$table->string('ref'); | ||
} | ||
); | ||
} | ||
|
||
/** | ||
* Reverse the migrations. | ||
*/ | ||
public function down() | ||
{ | ||
Schema::dropIfExists('comets_orbital_elements'); | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
src/database/migrations/create_comets_orbital_elements_table.php.stub
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
use Illuminate\Support\Facades\Schema; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Database\Migrations\Migration; | ||
|
||
class CreateCometsOrbitalElementsTable extends Migration | ||
{ | ||
/** | ||
* Run the migrations. | ||
*/ | ||
public function up() | ||
{ | ||
Schema::create( | ||
'comets_orbital_elements', | ||
function (Blueprint $table) { | ||
$table->string('name')->primary(); | ||
$table->integer('epoch')->signed(); | ||
$table->float('q', 12, 8); | ||
$table->float('e', 10, 5); | ||
$table->float('i', 10, 5); | ||
$table->float('w', 10, 5); | ||
$table->float('node', 10, 5); | ||
$table->float('Tp', 15, 5); | ||
$table->string('ref'); | ||
} | ||
); | ||
|
||
} | ||
|
||
/** | ||
* Reverse the migrations. | ||
*/ | ||
public function down() | ||
{ | ||
Schema::dropIfExists('comets_orbital_elements'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
150 changes: 150 additions & 0 deletions
150
src/deepskylog/AstronomyLibrary/Commands/UpdateOrbitalElements.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
<?php | ||
|
||
namespace deepskylog\AstronomyLibrary\Commands; | ||
|
||
use deepskylog\AstronomyLibrary\Models\AsteroidsOrbitalElements; | ||
use deepskylog\AstronomyLibrary\Models\CometsOrbitalElements; | ||
use Illuminate\Console\Command; | ||
|
||
class UpdateOrbitalElements extends Command | ||
{ | ||
/** | ||
* The name and signature of the console command. | ||
* | ||
* @var string | ||
*/ | ||
protected $signature = 'astronomy:updateOrbitalElements'; | ||
|
||
/** | ||
* The console command description. | ||
* | ||
* @var string | ||
*/ | ||
protected $description = 'Updates the orbital elements of comets and asteroids.'; | ||
|
||
/** | ||
* Create a new command instance. | ||
*/ | ||
public function __construct() | ||
{ | ||
parent::__construct(); | ||
} | ||
|
||
/** | ||
* Execute the console command. | ||
* | ||
* @return mixed | ||
*/ | ||
public function handle() | ||
{ | ||
// Download new orbital elements for comets from the JPL website | ||
$contents = file_get_contents( | ||
'https://ssd.jpl.nasa.gov/dat/ELEMENTS.COMET' | ||
); | ||
|
||
// Remove the old entries | ||
CometsOrbitalElements::truncate(); | ||
|
||
$cnt = 0; | ||
// Loop over the orbital elements line by line | ||
foreach (preg_split("/((\r?\n)|(\r\n?))/", $contents) as $line) { | ||
if ($cnt > 1) { | ||
// The first 43 characters are the name | ||
$name = trim(substr($line, 0, 43)); | ||
// Character 44 - 51 is the epoch | ||
$epoch = intval(substr($line, 44, 8)) + 2400000.5; | ||
// Character 52 - 63 is q: perihelion distance in AU | ||
$q = floatval(substr($line, 52, 12)); | ||
// Character 64 - 75 is e, the eccentricity of the orbit | ||
$e = floatval(substr($line, 64, 11)); | ||
// Character 75 - 85 is i, the inclination of the orbit | ||
$i = floatval(substr($line, 75, 10)); | ||
// w: The argument of perihelion | ||
$w = floatval(substr($line, 85, 10)); | ||
// node: Longitude of the ascending node | ||
$node = floatval(substr($line, 95, 10)); | ||
// Tp: Time of perihelion passage | ||
$Tp = floatval(substr($line, 105, 15)); | ||
// Ref: The orbital solution reference | ||
$ref = trim(substr($line, 120)); | ||
|
||
if ($name != '') { | ||
CometsOrbitalElements::create( | ||
[ | ||
'name' => $name, | ||
'epoch' => $epoch, | ||
'q' => $q, | ||
'e' => $e, | ||
'i' => $i, | ||
'w' => $w, | ||
'node' => $node, | ||
'Tp' => $Tp, | ||
'ref' => $ref, | ||
] | ||
); | ||
} | ||
} | ||
$cnt++; | ||
} | ||
|
||
// Download new orbital elements for asteroids from the JPL website | ||
$contents = file_get_contents( | ||
'https://ssd.jpl.nasa.gov/dat/ELEMENTS.NUMBR' | ||
); | ||
|
||
// Remove the old entries | ||
AsteroidsOrbitalElements::truncate(); | ||
|
||
$cnt = 0; | ||
// Loop over the orbital elements line by line | ||
foreach (preg_split("/((\r?\n)|(\r\n?))/", $contents) as $line) { | ||
if ($cnt > 1) { | ||
// Character 0 - 6 is the number | ||
$number = intval(substr($line, 0, 6)); | ||
// Characters 7 - 25 is the name | ||
$name = trim(substr($line, 7, 18)); | ||
// Character 25 - 31 is the epoch | ||
$epoch = intval(substr($line, 25, 6)) + 2400000.5; | ||
// Character 31 - 42 is a: semi-major axis in AU | ||
$a = floatval(substr($line, 31, 11)); | ||
// Character 42 - 53 is e, the eccentricity of the orbit | ||
$e = floatval(substr($line, 42, 11)); | ||
// Character 53 - 63 is i, the inclination of the orbit | ||
$i = floatval(substr($line, 53, 10)); | ||
// w: The argument of perihelion | ||
$w = floatval(substr($line, 63, 10)); | ||
// node: Longitude of the ascending node | ||
$node = floatval(substr($line, 73, 10)); | ||
// M: Mean anomaly | ||
$M = floatval(substr($line, 83, 12)); | ||
// H: Absolute magnitude | ||
$H = floatval(substr($line, 95, 6)); | ||
// G: Magnitude slope parameter | ||
$G = floatval(substr($line, 101, 6)); | ||
// Ref: The orbital solution reference | ||
$ref = trim(substr($line, 107)); | ||
|
||
if ($name != '') { | ||
AsteroidsOrbitalElements::create( | ||
[ | ||
'number' => $number, | ||
'name' => $name, | ||
'epoch' => $epoch, | ||
'a' => $a, | ||
'e' => $e, | ||
'i' => $i, | ||
'w' => $w, | ||
'node' => $node, | ||
'M' => $M, | ||
'H' => $H, | ||
'G' => $G, | ||
'Tp' => $Tp, | ||
'ref' => $ref, | ||
] | ||
); | ||
} | ||
} | ||
$cnt++; | ||
} | ||
} | ||
} |
Oops, something went wrong.