Commit 2d2af24b67a211ec7c0b1f8d0f360d7c215246a2
1 parent
18f38374
Exists in
master
and in
3 other branches
Add a basic orbits section.
Showing
4 changed files
with
135 additions
and
9 deletions
Show diff stats
No preview for this file type
... | ... | @@ -0,0 +1,12 @@ |
1 | +Name,Shape,Length | |
2 | +Time,"(744, 17)",12648 | |
3 | +XYZ_HCI,"(744, 3)",2232 | |
4 | +XYZ_IAU_SUN,"(744, 3)",2232 | |
5 | +XYZ_HEE,"(744, 3)",2232 | |
6 | +LON_HCI,"(744,)",744 | |
7 | +LAT_HCI,"(744,)",744 | |
8 | +LON_IAU_SUN,"(744,)",744 | |
9 | +LAT_IAU_SUN,"(744,)",744 | |
10 | +R,"(744,)",744 | |
11 | +StartTime,"(17,)",17 | |
12 | +StopTime,"(17,)",17 | |
0 | 13 | \ No newline at end of file | ... | ... |
web/run.py
... | ... | @@ -133,6 +133,13 @@ def render_view(view, context=None): |
133 | 133 | # dict(tpl_global_vars.items() + context.items()) |
134 | 134 | # ) |
135 | 135 | |
136 | +def datetime_from_list(time_list): | |
137 | + # Day Of Year starts at 0, but for our datetime parser it starts at 1 | |
138 | + doy = '{:03d}'.format(int(''.join(time_list[4:7])) + 1) | |
139 | + return datetime.datetime.strptime( | |
140 | + "%s%s%s" % (''.join(time_list[0:4]), doy, ''.join(time_list[7:])), | |
141 | + "%Y%j%H%M%S%f" | |
142 | + ) | |
136 | 143 | |
137 | 144 | # ROUTING ##################################################################### |
138 | 145 | |
... | ... | @@ -146,6 +153,7 @@ def home(): |
146 | 153 | @app.route("/inspect") |
147 | 154 | def analyze_cdf(): |
148 | 155 | cdf_to_inspect = get_path("../res/dummy.nc") |
156 | + cdf_to_inspect = get_path("../res/dummy_jupiter_coordinates.nc") | |
149 | 157 | |
150 | 158 | si = StringIO.StringIO() |
151 | 159 | cw = csv.DictWriter(si, fieldnames=['Name', 'Shape', 'Length']) |
... | ... | @@ -179,14 +187,8 @@ def get_csv(): |
179 | 187 | data_p = cdf_handle.variables['P_dyn'] |
180 | 188 | cw.writerow(('time', 'vrad', 'vtan', 'magn', 'pdyn')) |
181 | 189 | for time, datum_v, datum_b, datum_p in zip(times, data_v, data_b, data_p): |
182 | - # Day Of Year starts at 0, but for our datetime parser it starts at 1 | |
183 | - doy = '{:03d}'.format(int(''.join(time[4:7])) + 1) | |
184 | - d = datetime.datetime.strptime( | |
185 | - "%s%s%s" % (''.join(time[0:4]), doy, ''.join(time[7:])), | |
186 | - "%Y%j%H%M%S%f" | |
187 | - ) | |
188 | 190 | cw.writerow(( |
189 | - d.strftime("%Y-%m-%dT%H:%M:%S+00:00"), | |
191 | + datetime_from_list(time).strftime("%Y-%m-%dT%H:%M:%S+00:00"), | |
190 | 192 | datum_v[0], datum_v[1], |
191 | 193 | datum_b, datum_p |
192 | 194 | )) |
... | ... | @@ -194,6 +196,26 @@ def get_csv(): |
194 | 196 | |
195 | 197 | return si.getvalue() |
196 | 198 | |
199 | + | |
200 | +@app.route("/astral_coordinates.csv") | |
201 | +def get_astral_coordinates_csv(): | |
202 | + si = StringIO.StringIO() | |
203 | + cw = csv_writer(si) | |
204 | + | |
205 | + # Time, StartTime, StopTime, XYZ_HCI, XYZ_IAU_SUN, XYZ_HEE | |
206 | + cdf_handle = Dataset(get_path("../res/dummy_jupiter_coordinates.nc"), "r", format="NETCDF4") | |
207 | + times = cdf_handle.variables['Time'] | |
208 | + data_xyz_hci = cdf_handle.variables['XYZ_HCI'] | |
209 | + cw.writerow(('time', 'x_hci', 'y_hci')) | |
210 | + for time, datum_xyz_hci in zip(times, data_xyz_hci): | |
211 | + cw.writerow(( | |
212 | + datetime_from_list(time).strftime("%Y-%m-%dT%H:%M:%S+00:00"), | |
213 | + datum_xyz_hci[0], datum_xyz_hci[1] | |
214 | + )) | |
215 | + cdf_handle.close() | |
216 | + | |
217 | + return si.getvalue() | |
218 | + | |
197 | 219 | # MAIN ######################################################################## |
198 | 220 | |
199 | 221 | if __name__ == "__main__": | ... | ... |
web/view/home.html.jinja2
... | ... | @@ -12,6 +12,7 @@ |
12 | 12 | TODO |
13 | 13 | </p> |
14 | 14 | |
15 | +<section id="orbits"></section> | |
15 | 16 | <section id="time_series"></section> |
16 | 17 | |
17 | 18 | {% endblock %} |
... | ... | @@ -30,6 +31,11 @@ TODO |
30 | 31 | stroke: steelblue; |
31 | 32 | stroke-width: 1px; |
32 | 33 | } |
34 | + path.orbit { | |
35 | + fill: none; | |
36 | + stroke: steelblue; | |
37 | + stroke-width: 2px; | |
38 | + } | |
33 | 39 | </style> |
34 | 40 | {% endblock %} |
35 | 41 | |
... | ... | @@ -41,8 +47,8 @@ TODO |
41 | 47 | var swApp = (function (window, d3, $) { |
42 | 48 | |
43 | 49 | var $time_series = $("#time_series"); |
50 | + var $orbits = $("#orbits"); | |
44 | 51 | |
45 | - // fixme | |
46 | 52 | var plotTimeSeries = function(data, options) { |
47 | 53 | console.log("Init time series with data", data, options); |
48 | 54 | |
... | ... | @@ -119,8 +125,86 @@ var swApp = (function (window, d3, $) { |
119 | 125 | |
120 | 126 | }; |
121 | 127 | |
128 | + var plotOrbits = function(data, options) { | |
129 | + console.log("Init orbits with data", data, options); | |
130 | + | |
131 | + var xScale, yScale, xAxis, yAxis; | |
132 | + var line; | |
133 | + var svg, plotWrapper, path, sun; | |
134 | + var width, height; | |
135 | + var margin = { | |
136 | + top: 30, | |
137 | + right: 20, | |
138 | + bottom: 30, | |
139 | + left: 60 | |
140 | + }; | |
141 | + | |
142 | + // INIT SCALES | |
143 | + var extremum = 1.11 * d3.max(data, function (d) { | |
144 | + return Math.max(Math.abs(d.x), Math.abs(d.y)); | |
145 | + }); | |
146 | + | |
147 | + xScale = d3.scaleLinear().domain([-1 * extremum, extremum]); | |
148 | + yScale = d3.scaleLinear().domain([-1 * extremum, extremum]); | |
149 | + | |
150 | + xAxis = d3.axisBottom().ticks(10); | |
151 | + yAxis = d3.axisLeft().ticks(10); | |
152 | + | |
153 | + // INIT LINE | |
154 | + line = d3.line() | |
155 | + .x(function (d) { return xScale(d.x) }) | |
156 | + .y(function (d) { return yScale(d.y) }); | |
157 | + | |
158 | + // INIT SVG | |
159 | + svg = d3.select('#orbits').append('svg'); | |
160 | + | |
161 | + plotWrapper = svg.append('g'); | |
162 | + | |
163 | + // Sun | |
164 | + sun = plotWrapper.append("svg:circle"); | |
165 | + sun.append('svg:title').text("Sol"); | |
166 | + | |
167 | + // Orbit | |
168 | + path = plotWrapper.append('path') | |
169 | + .datum(data) | |
170 | + .classed('orbit', true); | |
171 | + | |
172 | + plotWrapper.append('g').classed('x axis', true); | |
173 | + plotWrapper.append('g').classed('y axis', true); | |
174 | + | |
175 | + width = $orbits.width() - margin.left - margin.right; | |
176 | + height = width * 1.0; | |
177 | + | |
178 | + xScale.range([0, width]); | |
179 | + yScale.range([height, 0]); | |
180 | + | |
181 | + svg.attr('width', width + margin.right + margin.left) | |
182 | + .attr('height', height + margin.top + margin.bottom); | |
183 | + | |
184 | + plotWrapper.attr('transform', 'translate(' + margin.left + ',' + margin.top + ')'); | |
185 | + | |
186 | + path.attr('d', line); | |
187 | + | |
188 | + sun.attr("cx", width / 2).attr("cy", height / 2).attr("r", 17).style("fill", "yellow"); | |
189 | + | |
190 | + xAxis.scale(xScale); | |
191 | + yAxis.scale(yScale); | |
192 | + | |
193 | + //if (width < 600) { xAxis.ticks(3); } | |
194 | + | |
195 | + svg.select('.x.axis') | |
196 | + .attr('transform', 'translate(0,' + height + ')') | |
197 | + .call(xAxis); | |
198 | + | |
199 | + svg.select('.y.axis') | |
200 | + .call(yAxis); | |
201 | + | |
202 | + | |
203 | + }; | |
204 | + | |
122 | 205 | return { |
123 | - plotTimeSeries: plotTimeSeries | |
206 | + plotTimeSeries: plotTimeSeries, | |
207 | + plotOrbits: plotOrbits | |
124 | 208 | }; |
125 | 209 | })(window, d3, jQuery); |
126 | 210 | |
... | ... | @@ -136,6 +220,14 @@ jQuery().ready(function($){ |
136 | 220 | swApp.plotTimeSeries(data['pdyn'], {}); |
137 | 221 | swApp.plotTimeSeries(data['magn'], {}); |
138 | 222 | }); |
223 | + d3.csv("{{ url_for('get_astral_coordinates_csv') }}", function(csv){ | |
224 | + var data = []; | |
225 | + csv.forEach(function (d) { | |
226 | + data.push({x: parseFloat(d['x_hci']), y: parseFloat(d['y_hci'])}); | |
227 | + }); | |
228 | + swApp.plotOrbits(data, {}); | |
229 | + }); | |
230 | + | |
139 | 231 | }); |
140 | 232 | </script> |
141 | 233 | ... | ... |