block by renecnielsen c61d648478cb26a0e6b8

Space Stations

Full Screen

Space station orbit data in Two-Element Format. Data collected at 1:40am PDT August 8, 2015.

forked from syntagmatic‘s block: Space Stations

index.html

<!DOCTYPE html>
<meta charset="utf-8">
<title>Space Stations</title>
<style>
svg {
  font: 8px sans-serif;
}

.foreground path {
  fill: none;
  stroke: #222;
  stroke-opacity: 0.4;
  pointer-events: none;
  stroke-width: 1px;
}
 
.axis .title {
  font-size: 8px;
  font-weight: bold;
  text-transform: uppercase;
  transform: rotate(-12deg) translate(-5px,-6px);
}

.axis line,
.axis path {
  fill: none;
  stroke: #000;
  stroke-width: 1px;
}

.brush .extent {
  fill-opacity: .3;
  stroke: #fff;
  stroke-width: 1px;
}

pre {
  width: 900px;
  margin: 10px 30px;
  tab-size: 25;
  font-size: 12px;
  overflow: auto;
}
</style>
<body>
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.5/d3.min.js"></script>
<script>

var margin = {top: 50, right: 80, bottom: 20, left: 100},
    width = 960 - margin.left - margin.right,
    height = 340 - margin.top - margin.bottom;

var types = {
  "Number": {
    key: "Number",
    coerce: function(d) { return +d; },
    extent: d3.extent,
    within: function(d, extent) { return extent[0] <= d && d <= extent[1]; },
    defaultScale: d3.scale.linear().range([height, 0])
  },
  "String": {
    key: "String",
    coerce: String,
    extent: function (data) { return data.sort(); },
    within: function(d, extent, dim) { return extent[0] <= dim.scale(d) && dim.scale(d) <= extent[1]; },
    defaultScale: d3.scale.ordinal().rangePoints([0, height])
  },
  "Date": {
    key: "Date",
    coerce: function(d) { return new Date(d); },
    extent: d3.extent,
    within: function(d, extent) { return extent[0] <= d && d <= extent[1]; },
    defaultScale: d3.time.scale().range([0, height])
  }
};

var dimensions = [
  {
    key: "name",
    description: "Name",
    type: types["String"]
  },
  {
    key: "satelliteNumber",
    description: "SatelliteNumber",
    type: types["String"]
  },
  {
    key: "classification",
    description: "Classification",
    type: types["String"]
  },
  {
    key: "launchNumber",
    description: "Launch Number",
    type: types["Number"]
  },
  {
    key: "launchPiece",
    description: "Launch Piece",
    type: types["String"]
  },
  {
    key: "epochYear",
    description: "Epoch Year",
    type: types["String"]
  },
  {
    key: "epochDay",
    description: "Epoch Day",
    type: types["Number"],
    domain: [0,360]
  },
  {
    key: "inclination",
    description: "inclination",
    type: types["Number"],
    domain: [0,90]
  },
  {
    key: "rightAscension",
    description: "Right Ascension",
    type: types["Number"],
    domain: [0,360]
  },
  {
    key: "eccentricity",
    description: "Eccentricity",
    type: types["Number"],
    domain: [0,0.002]
  },
  {
    key: "perigee",
    description: "Perigee",
    type: types["Number"],
    domain: [0,360]
  },
  {
    key: "meanAnomaly",
    description: "Mean Anomaly",
    type: types["Number"],
    domain: [0,360]
  },
  {
    key: "meanMotion",
    description: "Mean Motion",
    type: types["Number"]
  },
  {
    key: "firstDerivMeanMotion",
    description: "First Deriv Mean Motion",
    type: types["Number"]
  }
];

var x = d3.scale.ordinal()
    .domain(dimensions.map(function(dim) { return dim.key; }))
    .rangePoints([0, width]);

var line = d3.svg.line()
    .defined(function(d) { return !isNaN(d[1]); });

var yAxis = d3.svg.axis()
    .orient("left");

var svg = d3.select("body").append("svg")
    .attr("width", width + margin.left + margin.right)
    .attr("height", height + margin.top + margin.bottom)
  .append("g")
    .attr("transform", "translate(" + margin.left + "," + margin.top + ")");

var output = d3.select("body").append("pre");

var foreground = svg.append("g")
  .attr("class", "foreground");

var axes = svg.selectAll(".axis")
    .data(dimensions)
  .enter().append("g")
    .attr("class", "axis")
    .attr("transform", function(d) { return "translate(" + x(d.key) + ")"; });

d3.csv("stations.csv", function(error, data) {
  if (error) throw error;

  data.forEach(function(d) {
    dimensions.forEach(function(p) {
      d[p.key] = p.type.coerce(d[p.key]);
    });
  });

  // type/dimension default setting happens here
  dimensions.forEach(function(dim) {
    if (!("domain" in dim)) {
      // detect domain using dimension type's extent function
      dim.domain = d3.functor(dim.type.extent)(data.map(function(d) { return d[dim.key]; }));

      // TODO - this line only works because the data encodes data with integers
      // Sorting/comparing should be defined at the type/dimension level
      dim.domain.sort(function(a,b) {
        return a - b;
      });
    }
    if (!("scale" in dim)) {
      // use type's default scale for dimension
      dim.scale = dim.type.defaultScale.copy();
    }
    dim.scale.domain(dim.domain);
  });

  foreground.selectAll("path")
      .data(data)
    .enter().append("path")
      .attr("d", draw)
      .style("stroke", function(d) { return "#6ac"; });

  axes.append("g")
      .attr("class", "axis")
      .each(function(d) {
        var renderAxis = "axis" in d
          ? d.axis.scale(d.scale)  // custom axis
          : yAxis.scale(d.scale);  // default axis
        d3.select(this).call(renderAxis);
      })
    .append("text")
      .attr("class", "title")
      .attr("text-anchor", "start")
      .text(function(d) { return "description" in d ? d.description : d.key; });

  // Add and store a brush for each axis.
  axes.append("g")
      .attr("class", "brush")
      .each(function(d) {
        d3.select(this).call(d.brush = d3.svg.brush()
          .y(d.scale)
          .on("brushstart", brushstart)
          .on("brush", brush));
      })
    .selectAll("rect")
      .attr("x", -8)
      .attr("width", 16);

  output.text(d3.tsv.format(data));

  function draw(d) {
    return line(dimensions.map(function(dim) {
      return [x(dim.key), dim.scale(d[dim.key])];
    }));
  }

  function brushstart() {
    d3.event.sourceEvent.stopPropagation();
  }

  // Handles a brush event, toggling the display of foreground lines.
  function brush() {
    var actives = dimensions.filter(function(p) { return !p.brush.empty(); }),
        extents = actives.map(function(p) { return p.brush.extent(); });

    var selected = [];

    d3.selectAll(".foreground path").style("display", function(d) {
      if (actives.every(function(dim, i) {
          // test if point is within extents for each active brush
          return dim.type.within(d[dim.key], extents[i], dim);
        })) {
        selected.push(d);
        return null;
      }
      return "none";
    });

    output.text(d3.tsv.format(selected));
  }
});

</script>

parse.html

<!DOCTYPE html>
<meta charset="utf-8">
<style>

body {
  background: #fcfcfa;
}

text {
  font-family: Menlo, monospace;
}

</style>
<body>
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.5/d3.min.js"></script>
<script>
d3.text("stations.txt", function(error, tledata) {
  tleparse(tledata);
});

function tleparse(data) {
  console.log(data);

  var lines = data.split("\n");
  console.log(lines);

  var objects = [];
  lines.forEach(function(line) {
    if (line.length == 0) return;

    if (line[0] == "1") {
      var obj = objects[objects.length-1];
      obj.satelliteNumber = line.slice(2,7);
      obj.classification = line.slice(7,8);
      obj.launchYear = line.slice(9,11);
      obj.launchNumber = line.slice(11,14);
      obj.launchPiece = line.slice(14,17);
      obj.epochYear = line.slice(18,20);
      obj.epochDay = line.slice(20,32);
      obj.firstDerivMeanMotion = line.slice(33,43);
      obj.secondDerivMeanMotion = line.slice(44,52);
      obj.bstarDragTerm = line.slice(53,61);
      obj.ephemerisType = line.slice(62,63);
      obj.elementNumber = line.slice(65,68);
      return; 
    }

    if (line[0] == "2") {
      var obj = objects[objects.length-1];
      obj.inclination = line.slice(8,16);
      obj.rightAscension = line.slice(17,25);
      obj.eccentricity = "." + line.slice(26,33);
      obj.perigee = line.slice(34,42);
      obj.meanAnomaly = line.slice(43,51);
      obj.meanMotion = line.slice(52,63);
      obj.revolutionNumberAtEpoch = line.slice(63,68);

      // trim whitespace
      for (var k in obj) obj[k] = obj[k].trim();

      return; 
    }
    
    objects.push({
      name: line
    });
  });
  console.log(objects);

  d3.select("body").append("pre").text(d3.csv.format(objects));
};
</script>

stations.csv

name,satelliteNumber,classification,launchYear,launchNumber,launchPiece,epochYear,epochDay,firstDerivMeanMotion,secondDerivMeanMotion,bstarDragTerm,ephemerisType,elementNumber,inclination,rightAscension,eccentricity,perigee,meanAnomaly,meanMotion,revolutionNumberAtEpoch
ISS (ZARYA),25544,U,98,067,A,15,220.14201569,.00006366,00000-0,99981-4,0,999,51.6445,184.6193,.0001190,50.9632,60.9475,15.55044901,95612
TIANGONG 1,37820,U,11,053,A,15,220.22582222,.00016885,00000-0,18235-3,0,999,42.7666,324.0133,.0013347,19.7325,62.5589,15.63234916,22146
SPINSAT,40314,U,98,067,FL,15,219.88718309,.00019559,00000-0,22242-3,0,999,51.6398,180.8824,.0004739,308.0564,52.0002,15.62302813,9074
FLOCK 1B-27,40422,U,98,067,FN,15,220.10831557,.00087761,00000-0,46759-3,0,999,51.6375,170.0695,.0003407,293.3518,155.6084,15.79679430,3427
FLOCK 1B-28,40423,U,98,067,FP,15,219.24788283,.05567779,12028-4,14293-2,0,999,51.6133,170.3484,.0007348,241.2767,118.7501,16.27910103,3419
FLOCK 1B-21,40427,U,98,067,FQ,15,220.17244066,.00113418,00000-0,60632-3,0,999,51.6348,169.6742,.0002024,341.5914,147.4219,15.79505042,3431
FLOCK 1B-22,40428,U,98,067,FR,15,220.12069744,.00092140,00000-0,51130-3,0,999,51.6365,170.9091,.0002544,336.4498,114.1655,15.78763696,3429
FLOCK 1B-10,40429,U,98,067,FS,15,220.20119405,.00195474,25025-4,64353-3,0,999,51.6296,168.3836,.0005910,26.6978,67.1007,15.90077971,3430
FLOCK 1D-1,40451,U,98,067,FU,15,220.14503916,.00106360,00000-0,55029-3,0,999,51.6355,170.3030,.0005794,339.2305,116.0448,15.80231569,3428
FLOCK 1D-2,40452,U,98,067,FV,15,220.13593804,.00048791,00000-0,41130-3,0,999,51.6406,176.3296,.0005769,338.6049,117.4290,15.69293657,3420
FLOCK 1B-5,40453,U,98,067,FW,15,220.14430539,.00846207,33415-3,18664-2,0,999,51.6321,169.5124,.0003592,196.6100,260.4302,15.97464509,3428
FLOCK 1B-6,40454,U,98,067,FX,15,220.10653247,.00070361,00000-0,43756-3,0,999,51.6379,171.6254,.0004407,309.2972,117.2228,15.76302694,3425
GEARRS-1,40456,U,98,067,FZ,15,220.08687398,.00093676,00000-0,60028-3,0,999,51.6402,173.2145,.0003283,299.4823,60.5849,15.75508462,3424
MICROMAS,40457,U,98,067,GA,15,213.38588329,.08885032,12472-4,72013-3,0,999,51.6142,195.6182,.0009646,310.7124,49.3640,16.38908268,3333
FLOCK 1B-11,40459,U,98,067,GC,15,220.11423693,.00094249,00000-0,49145-3,0,999,51.6331,170.8590,.0004498,7.7931,80.5822,15.80118750,3428
FLOCK 1B-12,40460,U,98,067,GD,15,220.12252502,.00077437,00000-0,48610-3,0,999,51.6384,173.2120,.0003439,322.3731,126.4640,15.76055417,3425
PROGRESS-M 28M,40713,U,15,031,A,15,196.49011771,.00017741,00000-0,26492-3,0,999,51.6454,302.6810,.0001491,236.5964,219.1604,15.55119641,192
FLOCK 1E-2,40722,U,98,067,GE,15,220.11343167,.00031733,00000-0,43197-3,0,999,51.6447,184.4829,.0005135,13.0644,72.6838,15.57251292,393
FLOCK 1E-1,40723,U,98,067,GF,15,220.11372066,.00019842,00000-0,27526-3,0,999,51.6445,184.4849,.0005713,15.9180,70.3039,15.57028627,388
FLOCK 1E-4,40724,U,98,067,GG,15,220.18578455,.00024122,00000-0,33633-3,0,999,51.6444,184.1797,.0002100,296.1008,166.7338,15.56772043,389
FLOCK 1E-3,40725,U,98,067,GH,15,220.17802303,.00051732,00000-0,69111-3,0,999,51.6451,184.1524,.0002786,290.2356,163.3131,15.57535029,386
FLOCK 1E-7,40726,U,98,067,GJ,15,220.11922285,.00034520,00000-0,47527-3,0,999,51.6424,184.5207,.0004681,28.9647,58.3644,15.56904589,373
FLOCK 1E-8,40727,U,98,067,GK,15,220.11970685,.00023065,00000-0,32182-3,0,999,51.6436,184.5209,.0004433,30.1090,58.2085,15.56774590,372
FLOCK 1E-5,40728,U,98,067,GL,15,219.36079981,.00022565,00000-0,31601-3,0,999,51.6437,188.3143,.0004907,359.1287,155.1719,15.56686820,361
FLOCK 1E-6,40729,U,98,067,GM,15,220.11920196,.00031964,00000-0,44197-3,0,999,51.6410,184.5197,.0004850,6.7269,80.9401,15.56827685,374
FLOCK 1E-9,40736,U,98,067,GN,15,220.12226089,.00030092,00000-0,41998-3,0,999,51.6437,184.5426,.0003596,51.4864,36.0323,15.56613949,371
FLOCK 1E-10,40737,U,98,067,GP,15,220.12270863,.00029481,00000-0,41125-3,0,999,51.6412,184.5423,.0003173,54.6051,35.0032,15.56639211,372
FLOCK 1E-11,40738,U,98,067,GQ,15,220.11930394,.00054644,00000-0,73959-3,0,999,51.6422,184.5180,.0003342,336.1890,114.6566,15.57160402,354
FLOCK 1E-12,40739,U,98,067,GR,15,220.12022914,.00029150,00000-0,40523-3,0,999,51.6402,184.5271,.0004092,357.8220,89.5522,15.56735331,355
FLOCK 1E-13,40740,U,98,067,GS,15,220.12066207,.00036910,00000-0,50983-3,0,999,51.6420,184.5321,.0004835,33.5129,53.6960,15.56783334,353
FLOCK 1E-14,40741,U,98,067,GT,15,220.12224720,.00027177,00000-0,37929-3,0,999,51.6429,184.5333,.0004267,31.5300,59.4600,15.56668076,352
ARKYD-3R,40742,U,98,067,GU,15,220.11211696,.00052881,00000-0,69940-3,0,999,51.6452,184.4780,.0004844,56.1585,29.2269,15.57786679,352
CENTENNIAL 1,40743,U,98,067,GV,15,220.11578127,.00036444,00000-0,49428-3,0,999,51.6437,184.4998,.0004568,57.7461,28.6359,15.57282221,352
SOYUZ-TMA 17M,40744,U,15,035,A,15,204.58592506,.00046589,00000-0,68003-3,0,999,51.6451,262.2726,.0001334,294.5630,156.6060,15.55189487,11

stations.txt

ISS (ZARYA)             
1 25544U 98067A   15220.14201569  .00006366  00000-0  99981-4 0  9999
2 25544  51.6445 184.6193 0001190  50.9632  60.9475 15.55044901956123
TIANGONG 1              
1 37820U 11053A   15220.22582222  .00016885  00000-0  18235-3 0  9995
2 37820  42.7666 324.0133 0013347  19.7325  62.5589 15.63234916221464
SPINSAT                 
1 40314U 98067FL  15219.88718309  .00019559  00000-0  22242-3 0  9998
2 40314  51.6398 180.8824 0004739 308.0564  52.0002 15.62302813 90746
FLOCK 1B-27             
1 40422U 98067FN  15220.10831557  .00087761  00000-0  46759-3 0  9995
2 40422  51.6375 170.0695 0003407 293.3518 155.6084 15.79679430 34270
FLOCK 1B-28             
1 40423U 98067FP  15219.24788283  .05567779  12028-4  14293-2 0  9997
2 40423  51.6133 170.3484 0007348 241.2767 118.7501 16.27910103 34192
FLOCK 1B-21             
1 40427U 98067FQ  15220.17244066  .00113418  00000-0  60632-3 0  9995
2 40427  51.6348 169.6742 0002024 341.5914 147.4219 15.79505042 34313
FLOCK 1B-22             
1 40428U 98067FR  15220.12069744  .00092140  00000-0  51130-3 0  9990
2 40428  51.6365 170.9091 0002544 336.4498 114.1655 15.78763696 34294
FLOCK 1B-10             
1 40429U 98067FS  15220.20119405  .00195474  25025-4  64353-3 0  9993
2 40429  51.6296 168.3836 0005910  26.6978  67.1007 15.90077971 34305
FLOCK 1D-1              
1 40451U 98067FU  15220.14503916  .00106360  00000-0  55029-3 0  9993
2 40451  51.6355 170.3030 0005794 339.2305 116.0448 15.80231569 34286
FLOCK 1D-2              
1 40452U 98067FV  15220.13593804  .00048791  00000-0  41130-3 0  9999
2 40452  51.6406 176.3296 0005769 338.6049 117.4290 15.69293657 34209
FLOCK 1B-5              
1 40453U 98067FW  15220.14430539  .00846207  33415-3  18664-2 0  9998
2 40453  51.6321 169.5124 0003592 196.6100 260.4302 15.97464509 34280
FLOCK 1B-6              
1 40454U 98067FX  15220.10653247  .00070361  00000-0  43756-3 0  9990
2 40454  51.6379 171.6254 0004407 309.2972 117.2228 15.76302694 34253
GEARRS-1                
1 40456U 98067FZ  15220.08687398  .00093676  00000-0  60028-3 0  9998
2 40456  51.6402 173.2145 0003283 299.4823  60.5849 15.75508462 34243
MICROMAS                
1 40457U 98067GA  15213.38588329  .08885032  12472-4  72013-3 0  9998
2 40457  51.6142 195.6182 0009646 310.7124  49.3640 16.38908268 33335
FLOCK 1B-11             
1 40459U 98067GC  15220.11423693  .00094249  00000-0  49145-3 0  9995
2 40459  51.6331 170.8590 0004498   7.7931  80.5822 15.80118750 34283
FLOCK 1B-12             
1 40460U 98067GD  15220.12252502  .00077437  00000-0  48610-3 0  9993
2 40460  51.6384 173.2120 0003439 322.3731 126.4640 15.76055417 34257
PROGRESS-M 28M          
1 40713U 15031A   15196.49011771  .00017741  00000-0  26492-3 0  9993
2 40713  51.6454 302.6810 0001491 236.5964 219.1604 15.55119641  1925
FLOCK 1E-2              
1 40722U 98067GE  15220.11343167  .00031733  00000-0  43197-3 0  9995
2 40722  51.6447 184.4829 0005135  13.0644  72.6838 15.57251292  3930
FLOCK 1E-1              
1 40723U 98067GF  15220.11372066  .00019842  00000-0  27526-3 0  9991
2 40723  51.6445 184.4849 0005713  15.9180  70.3039 15.57028627  3885
FLOCK 1E-4              
1 40724U 98067GG  15220.18578455  .00024122  00000-0  33633-3 0  9992
2 40724  51.6444 184.1797 0002100 296.1008 166.7338 15.56772043  3893
FLOCK 1E-3              
1 40725U 98067GH  15220.17802303  .00051732  00000-0  69111-3 0  9991
2 40725  51.6451 184.1524 0002786 290.2356 163.3131 15.57535029  3864
FLOCK 1E-7              
1 40726U 98067GJ  15220.11922285  .00034520  00000-0  47527-3 0  9991
2 40726  51.6424 184.5207 0004681  28.9647  58.3644 15.56904589  3730
FLOCK 1E-8              
1 40727U 98067GK  15220.11970685  .00023065  00000-0  32182-3 0  9992
2 40727  51.6436 184.5209 0004433  30.1090  58.2085 15.56774590  3722
FLOCK 1E-5              
1 40728U 98067GL  15219.36079981  .00022565  00000-0  31601-3 0  9996
2 40728  51.6437 188.3143 0004907 359.1287 155.1719 15.56686820  3618
FLOCK 1E-6              
1 40729U 98067GM  15220.11920196  .00031964  00000-0  44197-3 0  9992
2 40729  51.6410 184.5197 0004850   6.7269  80.9401 15.56827685  3742
FLOCK 1E-9              
1 40736U 98067GN  15220.12226089  .00030092  00000-0  41998-3 0  9998
2 40736  51.6437 184.5426 0003596  51.4864  36.0323 15.56613949  3716
FLOCK 1E-10             
1 40737U 98067GP  15220.12270863  .00029481  00000-0  41125-3 0  9990
2 40737  51.6412 184.5423 0003173  54.6051  35.0032 15.56639211  3728
FLOCK 1E-11             
1 40738U 98067GQ  15220.11930394  .00054644  00000-0  73959-3 0  9991
2 40738  51.6422 184.5180 0003342 336.1890 114.6566 15.57160402  3545
FLOCK 1E-12             
1 40739U 98067GR  15220.12022914  .00029150  00000-0  40523-3 0  9998
2 40739  51.6402 184.5271 0004092 357.8220  89.5522 15.56735331  3556
FLOCK 1E-13             
1 40740U 98067GS  15220.12066207  .00036910  00000-0  50983-3 0  9996
2 40740  51.6420 184.5321 0004835  33.5129  53.6960 15.56783334  3537
FLOCK 1E-14             
1 40741U 98067GT  15220.12224720  .00027177  00000-0  37929-3 0  9993
2 40741  51.6429 184.5333 0004267  31.5300  59.4600 15.56668076  3527
ARKYD-3R                
1 40742U 98067GU  15220.11211696  .00052881  00000-0  69940-3 0  9999
2 40742  51.6452 184.4780 0004844  56.1585  29.2269 15.57786679  3525
CENTENNIAL 1            
1 40743U 98067GV  15220.11578127  .00036444  00000-0  49428-3 0  9991
2 40743  51.6437 184.4998 0004568  57.7461  28.6359 15.57282221  3520
SOYUZ-TMA 17M           
1 40744U 15035A   15204.58592506  .00046589  00000-0  68003-3 0  9997
2 40744  51.6451 262.2726 0001334 294.5630 156.6060 15.55189487   119