Skip to content

Commit bdf2e4d

Browse files
keflavichadrn
authored andcommitted
add saving
1 parent 0db2e9b commit bdf2e4d

File tree

1 file changed

+61
-1
lines changed

1 file changed

+61
-1
lines changed

tutorials/position-velocity-diagrams/PVDiagramPlotting.ipynb

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22
"cells": [
33
{
44
"cell_type": "markdown",
5+
"id": "ec28e7e2",
56
"metadata": {},
67
"source": [
7-
"# Extracting and Plotting Position-Velocity Diagrams\n",
8+
"fig.savefig(\"saved_pvdiagram.png\", bbox_inches='tight')fig.savefig(\"saved_pvdiagram.png\", bbox_inches='tight')fig.savefig(\"saved_pvdiagram.png\", bbox_inches='tight')fig.savefig(\"saved_pvdiagram.png\", bbox_inches='tight')fig.savefig(\"saved_pvdiagram.png\", bbox_inches='tight')fig.savefig(\"saved_pvdiagram.png\", bbox_inches='tight')fig.savefig(\"saved_pvdiagram.png\", bbox_inches='tight')fig.savefig(\"saved_pvdiagram.png\", bbox_inches='tight')# Extracting and Plotting Position-Velocity Diagrams\n",
89
"\n",
910
"## Authors\n",
1011
"Adam Ginsburg, Eric Koch\n",
@@ -25,6 +26,7 @@
2526
},
2627
{
2728
"cell_type": "markdown",
29+
"id": "5b7f1268",
2830
"metadata": {},
2931
"source": [
3032
"### Header material\n",
@@ -35,6 +37,7 @@
3537
{
3638
"cell_type": "code",
3739
"execution_count": null,
40+
"id": "9f9d06e1",
3841
"metadata": {},
3942
"outputs": [],
4043
"source": [
@@ -54,6 +57,7 @@
5457
},
5558
{
5659
"cell_type": "markdown",
60+
"id": "d44ca9f9",
5761
"metadata": {},
5862
"source": [
5963
"Retrieve and open a cube from astropy-data:"
@@ -62,6 +66,7 @@
6266
{
6367
"cell_type": "code",
6468
"execution_count": null,
69+
"id": "f51a1376",
6570
"metadata": {},
6671
"outputs": [],
6772
"source": [
@@ -71,6 +76,7 @@
7176
},
7277
{
7378
"cell_type": "markdown",
79+
"id": "b205d98a",
7480
"metadata": {},
7581
"source": [
7682
"We show a single channel from the cube to visualize the data spatially.\n",
@@ -80,6 +86,7 @@
8086
{
8187
"cell_type": "code",
8288
"execution_count": null,
89+
"id": "7b2db3eb",
8390
"metadata": {},
8491
"outputs": [],
8592
"source": [
@@ -88,6 +95,7 @@
8895
},
8996
{
9097
"cell_type": "markdown",
98+
"id": "9e946c8c",
9199
"metadata": {},
92100
"source": [
93101
"# PV Extraction from Pixel Coordinates\n",
@@ -100,6 +108,7 @@
100108
{
101109
"cell_type": "code",
102110
"execution_count": null,
111+
"id": "7cc19bc3",
103112
"metadata": {},
104113
"outputs": [],
105114
"source": [
@@ -108,6 +117,7 @@
108117
},
109118
{
110119
"cell_type": "markdown",
120+
"id": "5e83296d",
111121
"metadata": {},
112122
"source": [
113123
"Then we can overplot it on our figure, now with WCS shown. The plotting uses [WCSAxes](https://docs.astropy.org/en/stable/visualization/wcsaxes/index.html)"
@@ -116,6 +126,7 @@
116126
{
117127
"cell_type": "code",
118128
"execution_count": null,
129+
"id": "1b5e2815",
119130
"metadata": {},
120131
"outputs": [],
121132
"source": [
@@ -126,13 +137,15 @@
126137
},
127138
{
128139
"cell_type": "markdown",
140+
"id": "b0d00e33",
129141
"metadata": {},
130142
"source": [
131143
"`spacing` gives the separation between these points in pixels; we finely sampled by picking one-pixel spacing."
132144
]
133145
},
134146
{
135147
"cell_type": "markdown",
148+
"id": "cea5c40f",
136149
"metadata": {},
137150
"source": [
138151
"We can then extract the pv diagram, specifying the same spacing."
@@ -141,6 +154,7 @@
141154
{
142155
"cell_type": "code",
143156
"execution_count": null,
157+
"id": "99297938",
144158
"metadata": {},
145159
"outputs": [],
146160
"source": [
@@ -150,6 +164,7 @@
150164
},
151165
{
152166
"cell_type": "markdown",
167+
"id": "65b62bb8",
153168
"metadata": {},
154169
"source": [
155170
"and plot it. `pvdiagram` is a `PrimaryHDU` object, so we need to grab the data separately from the header and convert the header to a WCS object:"
@@ -158,6 +173,7 @@
158173
{
159174
"cell_type": "code",
160175
"execution_count": null,
176+
"id": "9c602ebf",
161177
"metadata": {},
162178
"outputs": [],
163179
"source": [
@@ -172,6 +188,7 @@
172188
},
173189
{
174190
"cell_type": "markdown",
191+
"id": "e4179ebc",
175192
"metadata": {},
176193
"source": [
177194
"Changing units to the more commonly used km/s and more readable arcminutes can be done with [wcsaxes tools](https://docs.astropy.org/en/stable/visualization/wcsaxes/controlling_axes.html):"
@@ -180,6 +197,7 @@
180197
{
181198
"cell_type": "code",
182199
"execution_count": null,
200+
"id": "9bebb46f",
183201
"metadata": {},
184202
"outputs": [],
185203
"source": [
@@ -201,6 +219,7 @@
201219
},
202220
{
203221
"cell_type": "markdown",
222+
"id": "ec773f53",
204223
"metadata": {},
205224
"source": [
206225
"We can put all this together:"
@@ -209,6 +228,7 @@
209228
{
210229
"cell_type": "code",
211230
"execution_count": null,
231+
"id": "ea8c2fd2",
212232
"metadata": {},
213233
"outputs": [],
214234
"source": [
@@ -221,6 +241,7 @@
221241
{
222242
"cell_type": "code",
223243
"execution_count": null,
244+
"id": "4a3ba59a",
224245
"metadata": {},
225246
"outputs": [],
226247
"source": [
@@ -245,13 +266,15 @@
245266
},
246267
{
247268
"cell_type": "markdown",
269+
"id": "f04373b1",
248270
"metadata": {},
249271
"source": [
250272
"# PV Extraction from Sky Coordinates"
251273
]
252274
},
253275
{
254276
"cell_type": "markdown",
277+
"id": "f7643042",
255278
"metadata": {},
256279
"source": [
257280
"We can also make paths using celestial coordinates by passing coordinates defined in an`~astropy.coordinates.SkyCoord` object to `~pvextractor.Path`."
@@ -260,6 +283,7 @@
260283
{
261284
"cell_type": "code",
262285
"execution_count": null,
286+
"id": "4f0f1d40",
263287
"metadata": {},
264288
"outputs": [],
265289
"source": [
@@ -269,6 +293,7 @@
269293
{
270294
"cell_type": "code",
271295
"execution_count": null,
296+
"id": "b3299ae2",
272297
"metadata": {},
273298
"outputs": [],
274299
"source": [
@@ -277,6 +302,7 @@
277302
},
278303
{
279304
"cell_type": "markdown",
305+
"id": "27c2224d",
280306
"metadata": {},
281307
"source": [
282308
"We can plot again; the coordinates will be automatically determined"
@@ -285,6 +311,7 @@
285311
{
286312
"cell_type": "code",
287313
"execution_count": null,
314+
"id": "2d3f42c3",
288315
"metadata": {},
289316
"outputs": [],
290317
"source": [
@@ -296,6 +323,7 @@
296323
{
297324
"cell_type": "code",
298325
"execution_count": null,
326+
"id": "65c46371",
299327
"metadata": {},
300328
"outputs": [],
301329
"source": [
@@ -306,6 +334,7 @@
306334
{
307335
"cell_type": "code",
308336
"execution_count": null,
337+
"id": "cbfa2a87",
309338
"metadata": {},
310339
"outputs": [],
311340
"source": [
@@ -330,6 +359,7 @@
330359
},
331360
{
332361
"cell_type": "markdown",
362+
"id": "2bca4a13",
333363
"metadata": {},
334364
"source": [
335365
"We can also change the aspect ratio of the PV diagram:"
@@ -338,6 +368,7 @@
338368
{
339369
"cell_type": "code",
340370
"execution_count": null,
371+
"id": "fcf34393",
341372
"metadata": {},
342373
"outputs": [],
343374
"source": [
@@ -363,13 +394,15 @@
363394
},
364395
{
365396
"cell_type": "markdown",
397+
"id": "e8deae20",
366398
"metadata": {},
367399
"source": [
368400
"## PV Extraction with Spatial Averaging"
369401
]
370402
},
371403
{
372404
"cell_type": "markdown",
405+
"id": "0824ae9d",
373406
"metadata": {},
374407
"source": [
375408
"`~pvextractor.Path` allows you to specify a `width` to average over, which specifies a spatial range around the path to average over:"
@@ -378,6 +411,7 @@
378411
{
379412
"cell_type": "code",
380413
"execution_count": null,
414+
"id": "91f5420f",
381415
"metadata": {},
382416
"outputs": [],
383417
"source": [
@@ -387,6 +421,7 @@
387421
{
388422
"cell_type": "code",
389423
"execution_count": null,
424+
"id": "bb057443",
390425
"metadata": {},
391426
"outputs": [],
392427
"source": [
@@ -395,6 +430,7 @@
395430
},
396431
{
397432
"cell_type": "markdown",
433+
"id": "1cf3ccc5",
398434
"metadata": {},
399435
"source": [
400436
"We can plot this path as a set of patches to show where we averaged. The default spacing is 1 pixel,so we plot 1-pixel chunks."
@@ -403,6 +439,7 @@
403439
{
404440
"cell_type": "code",
405441
"execution_count": null,
442+
"id": "9a866a1f",
406443
"metadata": {},
407444
"outputs": [],
408445
"source": [
@@ -434,6 +471,7 @@
434471
},
435472
{
436473
"cell_type": "markdown",
474+
"id": "d70082ef",
437475
"metadata": {},
438476
"source": [
439477
"We can also have more widely spaced chunks.\n",
@@ -444,6 +482,7 @@
444482
{
445483
"cell_type": "code",
446484
"execution_count": null,
485+
"id": "98faa709",
447486
"metadata": {},
448487
"outputs": [],
449488
"source": [
@@ -475,6 +514,7 @@
475514
},
476515
{
477516
"cell_type": "markdown",
517+
"id": "c8203c9d",
478518
"metadata": {},
479519
"source": [
480520
"## Saving\n",
@@ -485,11 +525,31 @@
485525
{
486526
"cell_type": "code",
487527
"execution_count": null,
528+
"id": "d59d2ff3",
488529
"metadata": {},
489530
"outputs": [],
490531
"source": [
491532
"pvdiagram.writeto(\"saved_pvdiagram.fits\", overwrite=True)"
492533
]
534+
},
535+
{
536+
"cell_type": "markdown",
537+
"id": "560c2f93-ee95-4d60-825a-83ec9f3acba7",
538+
"metadata": {},
539+
"source": [
540+
"We can also save the figure as a png or pdf:"
541+
]
542+
},
543+
{
544+
"cell_type": "code",
545+
"execution_count": null,
546+
"id": "74de9f99-e2fd-411f-9249-a39fa0b35908",
547+
"metadata": {},
548+
"outputs": [],
549+
"source": [
550+
"fig.savefig(\"saved_pvdiagram.png\", bbox_inches='tight')\n",
551+
"fig.savefig(\"saved_pvdiagram.pdf\", bbox_inches='tight')"
552+
]
493553
}
494554
],
495555
"metadata": {

0 commit comments

Comments
 (0)