Skip to content

Commit

Permalink
Merge pull request #76 from WimDeMeester/master
Browse files Browse the repository at this point in the history
Download oribital elements of comets and asteroids.
  • Loading branch information
WimDeMeester authored Mar 29, 2021
2 parents 2de6196 + b3d8857 commit d660853
Show file tree
Hide file tree
Showing 11 changed files with 358 additions and 6 deletions.
20 changes: 20 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,26 @@

All notable changes to `laravel-astronomy-library` will be documented in this file.

## Version 6.0

### Added

- Methods and classes to download the orbital elements of comets and asteroids.

### Changed

- Renamed the console command

```bash
php artisan deltat:update
```

to

```bash
php artisan astronomy:updateDeltat
```

## Version 5.6

### Added
Expand Down
4 changes: 4 additions & 0 deletions docs/docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,7 @@ The formulae to convert between NELM and SQM are taken from the Telescope Limiti
| 0.35 | < 0.5 | The detection of the object is quite difficult |
| 0.50 | < 1.0 | The detection of the object is easy |
| 1.00 | | The detection of the object is very easy |

## Orbital elements

The orbital elements of the comets and the asteroids are downloaded from the [JPL site](https://ssd.jpl.nasa.gov/?sb_elem).
52 changes: 48 additions & 4 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,21 @@ php artisan migrate

The database table with the delta t values can be updated using the following command:

``` bash
php artisan deltat:update
```bash
php artisan astronomy:updateDeltat
```

A job is automatically scheduled every 4 months to update the delta t value. This job can be executed using:
A job is automatically scheduled every 4 months to update the delta t value.

The database tables with the orbital elements of the comets and the asteroids can be updated using the followong command:

```bash
php artisan astronomy:updateOrbitalElements
```

A job is automatically scheduled every Monday at 04:30 to update the orbital elements of the comets and the asteroids.

These jobs can be executed using:

``` bash
php artisan schedule:run
Expand Down Expand Up @@ -542,6 +552,40 @@ $mercury->calculateDiameter($date);
$diameter = $mercury->getDiameter();
```

## Orbital elements of comets and asteroids

The orbital elements of comets and asteroids are kept in the database tables:

+ asteroids_orbital_elements
+ comets_orbital_elements

The orbital elements for the comets can be accessed from laravel using the **CometsOrbitalElements** class. The information available in the class is:

+ name
+ epoch
+ q: The perihelion distance in AU
+ e: The eccentricity of the orbit
+ i: The inclination of the orbit
+ w: The argument of perihelion
+ node: Longitude of the ascending node
+ Tp: Time of perihelion passage in YYYYMMDD.DDD
+ Ref: The orbital solution reference

The orbital elements for the asteroids can be accessed from laravel using the **AsteroidsOrbitalElements** class. The information available in the class is:

+ number
+ name
+ epoch
+ a: The semi-major axis in AU
+ e: The eccentricity of the orbit
+ i: The inclination of the orbit
+ w: The argument of perihelion
+ node: Longitude of the ascending node
+ M: Mean anomaly
+ H: Absolute magnitude
+ G: Magnitude slope parameter
+ Ref: The orbital solution reference

## Change log

Please see the [changelog](changelog.md) for more information on what has changed recently.
Expand Down Expand Up @@ -579,4 +623,4 @@ GPLv3. Please see the [license file](LICENSE) for more information.
[link-travis]: https://travis-ci.org/deepskylog/laravel-astronomy-library
[link-styleci]: https://styleci.io/repos/255550499
[link-author]: https://github.com/DeepskyLog
[link-contributors]: https://github.com/DeepskyLog/laravel-astronomy-library/graphs/contributors
[link-contributors]: https://github.com/DeepskyLog/laravel-astronomy-library/graphs/contributors
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');
}
}
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');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace deepskylog\AstronomyLibrary;

use deepskylog\AstronomyLibrary\Commands\UpdateDeltaTTable;
use deepskylog\AstronomyLibrary\Commands\UpdateOrbitalElements;
use Illuminate\Support\ServiceProvider;

class AstronomyLibraryServiceProvider extends ServiceProvider
Expand Down Expand Up @@ -34,6 +35,24 @@ public function boot()
],
'migrations'
);
$this->publishes(
[
__DIR__.'/../../database/migrations/create_comets_orbital_elements_table.php.stub' => database_path(
'migrations/'.date('Y_m_d_His', time())
.'_create_comets_orbital_elements_table.php'
),
],
'migrations'
);
$this->publishes(
[
__DIR__.'/../../database/migrations/create_asteroids_orbital_elements_table.php.stub' => database_path(
'migrations/'.date('Y_m_d_His', time())
.'_create_asteroids_orbital_elements_table.php'
),
],
'migrations'
);
$this->publishes(
[
__DIR__.'/../../database/migrations/create_constellation_boundaries_table.php.stub' => database_path(
Expand Down Expand Up @@ -118,5 +137,6 @@ protected function bootForConsole()

// Registering package commands.
$this->commands([UpdateDeltaTTable::class]);
$this->commands([UpdateOrbitalElements::class]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class UpdateDeltaTTable extends Command
*
* @var string
*/
protected $signature = 'deltat:update';
protected $signature = 'astronomy:updateDeltat';

/**
* The console command description.
Expand Down
150 changes: 150 additions & 0 deletions src/deepskylog/AstronomyLibrary/Commands/UpdateOrbitalElements.php
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++;
}
}
}
Loading

0 comments on commit d660853

Please sign in to comment.