import pandas as pd
import math
import numpy as np
df = pd.read_csv('data/hip4.csv', sep='|')
df['vmag'].describe()
count 516.000000 mean 3.137287 std 0.831301 min -1.440000 25% 2.787500 50% 3.410000 75% 3.762500 max 3.990000 Name: vmag, dtype: float64
df.plot.scatter(x='RA', y='Dec', color='DarkBlue');
df['RAh'] = df['RA'] / 15.
df.plot.scatter(x='RAh', y='Dec');
df.plot.scatter(x='RAh', y='Dec', s=df['vmag']*5, alpha=0.7);
for idx,row in df.iterrows():
print(idx,row['RA'])
0 349.35755018 1 156.09891874 2 93.71390194 3 30.0009367 4 201.30589832 5 59.74124892 6 323.49530361 7 341.63267663 8 300.14747226 9 87.87246934 10 66.00902233 11 109.20762844 12 130.02556894 13 182.9131309 14 337.31730866 15 237.7397573 16 137.81986611 17 350.7429228 18 290.97146411 19 62.16530527 20 303.8679927 21 89.78662719 22 290.65952718 23 135.16146765 24 30.85912643 25 99.17082883 26 115.95196716 27 314.29338184 28 131.17129209 29 17.0960837 30 115.31198612 31 270.16131466 32 69.07975243 33 167.14748181 34 22.81242306 35 241.70180197 36 43.564427 37 6.55048418 38 115.45498347 39 255.07252582 40 290.41823037 41 318.95581976 42 244.93519958 43 60.78907003 44 187.01004828 45 233.88141398 46 126.41529546 47 226.27960699 48 202.76111861 49 170.25184266 50 144.96389156 51 103.53314518 52 44.10668245 53 138.59080529 54 299.07665069 55 184.97663096 56 28.38235506 57 347.58928308 58 227.98400434 59 2.35224949 60 148.19149028 61 209.6698807 62 131.50689464 63 298.11818257 64 220.76484284 65 239.22119438 66 56.45663804 67 14.18790699 68 248.36443409 69 243.85944228 70 335.41374983 71 269.06324389 72 82.8030645 73 69.54529558 74 86.82118054 75 188.37101041 76 63.5003388 77 153.68447399 78 278.80182442 79 95.52852147 80 189.42636588 81 239.11247598 82 275.92402821 83 159.32606984 84 133.76192355 85 56.04814541 86 56.07969347 87 271.88562824 88 273.44086963 89 188.11712896 90 67.14346805 91 297.04255658 92 158.20281305 93 221.96552567 94 156.52293768 95 209.56785278 96 30.51166929 97 264.86621847 98 247.72850509 99 139.71111394 100 172.85120199 101 156.96977108 102 68.88779874 103 235.68599269 104 354.3904487 105 114.70783872 106 289.27545794 107 303.40792782 108 48.01783332 109 233.7007926 110 163.32766612 111 47.37345463 112 nan 113 220.28716819 114 107.18676883 115 163.3731926 116 147.74871542 117 111.43198371 118 311.91888574 119 321.66678212 120 309.90939395 121 84.68652211 122 42.67413655 123 65.73344722 124 331.75197729 125 252.44629764 126 130.15656369 127 126.43435936 128 56.29851422 129 87.82980343 130 83.40631813 131 337.82239898 132 292.42641389 133 286.17055765 134 97.20447548 135 136.03883562 136 266.97322515 137 27.86504416 138 318.69727757 139 245.48018203 140 343.15360192 141 325.36863801 142 221.56246594 143 51.79217049 144 268.38178961 145 316.23273251 146 56.21884811 147 53.23509009 148 89.88145972 149 237.70371344 150 89.10132627 151 298.82819233 152 271.8375861 153 118.05435622 154 73.5628985 155 49.87904033 156 269.44096106 157 349.28955677 158 146.31178147 159 325.02225935 160 75.61950025 161 28.98680207 162 176.51305887 163 9.24277921 164 72.80152507 165 130.89811451 166 347.36150879 167 296.84693842 168 211.09760837 169 313.70241509 170 234.66410153 171 231.95771631 172 236.54672877 173 337.20750231 174 271.65782832 175 64.94805793 176 142.88154025 177 309.38695734 178 176.40236386 179 57.29054669 180 345.48019377 181 22.87080776 182 116.31376631 183 253.64627156 184 42.49578911 185 266.43334347 186 152.64748785 187 51.20349011 188 195.56573968 189 142.67547063 190 234.25607748 191 262.77490395 192 103.1972503 193 130.07337168 194 21.00604671 195 185.34088036 196 177.67202553 197 79.40166225 198 24.49792651 199 86.11656241 200 109.52336162 201 304.5134103 202 217.95774098 203 116.11195237 204 135.90649494 205 230.45181856 206 253.08397295 207 4.85701265 208 169.83551103 209 34.12708452 210 214.85096972 211 64.47341068 212 275.25974572 213 302.17441713 214 86.73895728 215 173.25107936 216 237.40527375 217 264.39677181 218 67.15388879 219 124.12895101 220 284.43241556 221 145.28799116 222 332.54924902 223 282.51997462 224 149.2156452 225 55.81231706 226 299.68911516 227 342.5004181 228 102.46027285 229 110.0307889 230 342.42046735 231 276.74345947 232 26.02136441 233 225.48663804 234 342.13832136 235 169.61981385 236 105.42979876 237 151.83313948 238 250.72391068 239 207.40419934 240 40.82551897 241 119.19475729 242 17.14693197 243 228.87543241 244 12.27125262 245 154.27469564 246 154.17251805 247 137.74210535 248 286.56229139 249 266.61549553 250 28.27041595 251 240.03058543 252 311.2398153 253 60.17008591 254 311.32195263 255 340.36531181 256 22.0914236 257 228.07167982 258 207.3762392 259 67.16531219 260 154.27085535 261 193.90201366 262 332.71359131 263 83.78449043 264 131.6943593 265 203.673978 266 230.67036465 267 291.37396941 268 28.59868107 269 101.3226398 270 127.56679232 271 81.11923774 272 117.32357809 273 63.60596306 274 168.56017036 275 16.52127713 276 286.73517629 277 258.038233 278 269.75665662 279 183.85603795 280 46.29373754 281 261.34858274 282 93.71956952 283 68.49882684 284 158.0061825 285 231.2324337 286 153.43449551 287 78.2328046 288 343.6626635 289 9.83165567 290 260.50243371 291 56.80929799 292 284.73593568 293 211.59278733 294 112.3078263 295 226.01775793 296 102.04807134 297 302.82610327 298 244.58016994 299 275.32883578 300 322.16489595 301 230.34306833 302 354.83742516 303 318.23408977 304 254.41779418 305 72.45890935 306 76.36521705 307 267.4643802 308 76.62862102 309 220.62785433 310 281.41397083 311 99.44029869 312 143.21802191 313 257.19677111 314 142.80564072 315 258.76189282 316 140.26441169 317 224.79041254 318 87.7398034 319 134.80349479 320 254.65512817 321 258.75801735 322 173.94553448 323 162.40596699 324 133.84868687 325 309.39162365 326 274.4072049 327 288.13814581 328 100.98304088 329 155.58251355 330 305.25269347 331 292.68035529 332 218.01982421 333 191.57029013 334 75.49222507 335 95.07827982 336 105.75613986 337 182.53135773 338 55.7311754 339 328.48189202 340 32.38550383 341 230.1822884 342 167.41608092 343 252.96766195 344 199.7302224 345 266.89617137 346 286.3525518 347 271.45218586 348 59.50720862 349 146.4629267 350 84.41118447 351 331.44593869 352 187.4665965 353 102.48390349 354 340.75053573 355 146.7755734 356 46.19912598 357 59.46342138 358 322.88966951 359 245.29717718 360 111.78780121 361 194.00767051 362 239.71300283 363 44.5654818 364 287.44097404 365 334.62574257 366 95.73996302 367 229.72787007 368 29.69113269 369 296.24350878 370 56.87110065 371 326.75952199 372 195.54483557 373 261.32498828 374 262.96050661 375 58.53299363 376 238.78670013 377 121.88625899 378 3.30895828 379 248.97066423 380 276.99278955 381 6.41334183 382 250.32282132 383 82.06135971 384 233.78525156 385 262.60823708 386 183.78648733 387 258.66192687 388 76.96264146 389 247.55525697 390 265.86823714 391 83.85825475 392 222.71990536 393 200.15027321 394 190.41667557 395 160.73927802 396 245.99794523 397 243.58652601 398 275.24842337 399 296.56487567 400 109.28568399 401 262.69099501 402 189.29618208 403 161.69217542 404 74.24840098 405 208.6713175 406 224.63314193 407 21.45251267 408 84.91224975 409 89.93015897 410 188.59680864 411 28.65978771 412 236.06664914 413 229.25196591 414 285.65301428 415 83.18255798 416 183.95194937 417 182.08976505 418 241.35931206 419 168.52671705 420 208.88514539 421 45.56991279 422 249.28970847 423 346.1900702 424 311.55180091 425 140.52845511 426 111.02377104 427 319.64408982 428 345.94305575 429 257.59442659 430 178.45725536 431 6.57028075 432 265.62199908 433 326.04641808 434 221.24687869 435 165.4599615 436 218.87688163 437 220.48239101 438 240.08338225 439 252.54268738 440 204.97196962 441 2.29204036 442 83.00166562 443 269.15157439 444 10.12661349 445 305.55708346 446 136.99907126 447 200.98091604 448 233.67162293 449 120.89612561 450 139.27261834 451 190.38002079 452 14.17708808 453 177.26615977 454 30.97466283 455 47.04220716 456 263.73335321 457 222.67664751 458 86.93911641 459 17.43248991 460 340.66639531 461 2.09653333 462 211.67218608 463 283.81631956 464 10.89678452 465 31.79285757 466 154.99234054 467 141.8968826 468 95.6749475 469 37.94614689 470 306.41187347 471 131.17582214 472 99.42792641 473 252.16610742 474 89.88237261 475 264.32969072 476 125.62860299 477 206.8856088 478 107.09785853 479 165.93265365 480 276.04310967 481 51.08061889 482 193.5068041 483 122.38314727 484 85.18968672 485 332.05781838 486 84.05338572 487 138.30100329 488 81.57290804 489 81.28278416 490 263.40219373 491 187.79137202 492 113.65001898 493 104.65644451 494 152.09358075 495 219.91412833 496 310.3579727 497 191.93049537 498 344.41177323 499 116.33068263 500 247.35194804 501 201.2983523 502 68.98000195 503 186.64975585 504 297.6945086 505 210.95601898 506 88.79287161 507 24.42813204 508 114.82724194 509 78.63446353 510 79.17206517 511 279.23410832 512 219.92041034 513 213.91811403 514 95.98787763 515 101.28854105
import matplotlib.pyplot as plt
# ra, dec here must be in radians with -π < ra < π
plt.figure()
ax = plt.subplot(111, projection="mollweide")
ax.set_title("HIP bright stars")
ax.grid(True)
ra = np.radians(df['RA'] - 180.0)
dec = np.radians(df['Dec'])
ax.scatter(ra,dec, s=df['vmag']*5, color='black', alpha=0.5)
plt.show()
help(ax.scatter)
Help on method scatter in module matplotlib.axes._axes: scatter(x, y, s=None, c=None, marker=None, cmap=None, norm=None, vmin=None, vmax=None, alpha=None, linewidths=None, verts=<deprecated parameter>, edgecolors=None, *, plotnonfinite=False, data=None, **kwargs) method of matplotlib.axes._subplots.MollweideAxesSubplot instance A scatter plot of *y* vs. *x* with varying marker size and/or color. Parameters ---------- x, y : float or array-like, shape (n, ) The data positions. s : float or array-like, shape (n, ), optional The marker size in points**2. Default is ``rcParams['lines.markersize'] ** 2``. c : array-like or list of colors or color, optional The marker colors. Possible values: - A scalar or sequence of n numbers to be mapped to colors using *cmap* and *norm*. - A 2-D array in which the rows are RGB or RGBA. - A sequence of colors of length n. - A single color format string. Note that *c* should not be a single numeric RGB or RGBA sequence because that is indistinguishable from an array of values to be colormapped. If you want to specify the same RGB or RGBA value for all points, use a 2-D array with a single row. Otherwise, value- matching will have precedence in case of a size matching with *x* and *y*. If you wish to specify a single color for all points prefer the *color* keyword argument. Defaults to `None`. In that case the marker color is determined by the value of *color*, *facecolor* or *facecolors*. In case those are not specified or `None`, the marker color is determined by the next color of the ``Axes``' current "shape and fill" color cycle. This cycle defaults to :rc:`axes.prop_cycle`. marker : `~.markers.MarkerStyle`, default: :rc:`scatter.marker` The marker style. *marker* can be either an instance of the class or the text shorthand for a particular marker. See :mod:`matplotlib.markers` for more information about marker styles. cmap : str or `~matplotlib.colors.Colormap`, default: :rc:`image.cmap` A `.Colormap` instance or registered colormap name. *cmap* is only used if *c* is an array of floats. norm : `~matplotlib.colors.Normalize`, default: None If *c* is an array of floats, *norm* is used to scale the color data, *c*, in the range 0 to 1, in order to map into the colormap *cmap*. If *None*, use the default `.colors.Normalize`. vmin, vmax : float, default: None *vmin* and *vmax* are used in conjunction with the default norm to map the color array *c* to the colormap *cmap*. If None, the respective min and max of the color array is used. It is deprecated to use *vmin*/*vmax* when *norm* is given. alpha : float, default: None The alpha blending value, between 0 (transparent) and 1 (opaque). linewidths : float or array-like, default: :rc:`lines.linewidth` The linewidth of the marker edges. Note: The default *edgecolors* is 'face'. You may want to change this as well. edgecolors : {'face', 'none', *None*} or color or sequence of color, default: :rc:`scatter.edgecolors` The edge color of the marker. Possible values: - 'face': The edge color will always be the same as the face color. - 'none': No patch boundary will be drawn. - A color or sequence of colors. For non-filled markers, the *edgecolors* kwarg is ignored and forced to 'face' internally. plotnonfinite : bool, default: False Set to plot points with nonfinite *c*, in conjunction with `~matplotlib.colors.Colormap.set_bad`. Returns ------- `~matplotlib.collections.PathCollection` Other Parameters ---------------- **kwargs : `~matplotlib.collections.Collection` properties See Also -------- plot : To plot scatter plots when markers are identical in size and color. Notes ----- * The `.plot` function will be faster for scatterplots where markers don't vary in size or color. * Any or all of *x*, *y*, *s*, and *c* may be masked arrays, in which case all masks will be combined and only unmasked points will be plotted. * Fundamentally, scatter works with 1-D arrays; *x*, *y*, *s*, and *c* may be input as N-D arrays, but within scatter they will be flattened. The exception is *c*, which will be flattened only if its size matches the size of *x* and *y*. .. note:: In addition to the above described arguments, this function can take a *data* keyword argument. If such a *data* argument is given, the following arguments can also be string ``s``, which is interpreted as ``data[s]`` (unless this raises an exception): *x*, *y*, *s*, *linewidths*, *edgecolors*, *c*, *facecolor*, *facecolors*, *color*. Objects passed as **data** must support item access (``data[s]``) and membership test (``s in data``).
df['vmag'].hist(bins=100)
<AxesSubplot:>
from sqlalchemy import create_engine, text
engine = create_engine('postgresql://hebl:@localhost:5432/catalogue', echo=False)
df2 = pd.read_sql("SELECT HIP,RAdeg,RAhms,Dedeg,DEdms, vmag,pmra,pmde,bv FROM hip.catalogue WHERE vmag < 5", engine)
df2
hip | radeg | rahms | dedeg | dedms | vmag | pmra | pmde | bv | |
---|---|---|---|---|---|---|---|---|---|
0 | 122 | 0.399379 | 00 01 35.85 | -77.065294 | -77 03 55.1 | 4.78 | -56.52 | -176.95 | 1.254 |
1 | 154 | 0.489965 | 00 01 57.59 | -6.013972 | -06 00 50.3 | 4.37 | 46.62 | -41.32 | 1.631 |
2 | 301 | 0.934885 | 00 03 44.37 | -17.335970 | -17 20 09.5 | 4.55 | 28.57 | -7.28 | -0.047 |
3 | 355 | 1.125510 | 00 04 30.12 | -10.509494 | -10 30 34.2 | 4.99 | -6.49 | -11.88 | 1.619 |
4 | 443 | 1.333941 | 00 05 20.15 | -5.707833 | -05 42 28.2 | 4.61 | -8.29 | 88.19 | 1.029 |
... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
1603 | 118131 | 359.439790 | 23 57 45.55 | 25.141479 | +25 08 29.3 | 4.63 | -36.06 | -32.25 | 1.584 |
1604 | 118209 | 359.668377 | 23 58 40.41 | -3.555807 | -03 33 20.9 | 4.88 | -56.52 | -72.34 | 0.930 |
1605 | 118243 | 359.752207 | 23 59 00.53 | 55.754941 | +55 45 17.8 | 4.88 | 9.26 | -5.09 | -0.071 |
1606 | 118268 | 359.827510 | 23 59 18.60 | 6.863594 | +06 51 48.9 | 4.03 | 148.49 | -112.16 | 0.419 |
1607 | 118322 | 359.978792 | 23 59 54.91 | -65.577078 | -65 34 37.5 | 4.49 | 48.63 | -22.33 | -0.075 |
1608 rows × 9 columns
df2.index= df2['hip']
df2
hip | radeg | rahms | dedeg | dedms | vmag | pmra | pmde | bv | |
---|---|---|---|---|---|---|---|---|---|
hip | |||||||||
122 | 122 | 0.399379 | 00 01 35.85 | -77.065294 | -77 03 55.1 | 4.78 | -56.52 | -176.95 | 1.254 |
154 | 154 | 0.489965 | 00 01 57.59 | -6.013972 | -06 00 50.3 | 4.37 | 46.62 | -41.32 | 1.631 |
301 | 301 | 0.934885 | 00 03 44.37 | -17.335970 | -17 20 09.5 | 4.55 | 28.57 | -7.28 | -0.047 |
355 | 355 | 1.125510 | 00 04 30.12 | -10.509494 | -10 30 34.2 | 4.99 | -6.49 | -11.88 | 1.619 |
443 | 443 | 1.333941 | 00 05 20.15 | -5.707833 | -05 42 28.2 | 4.61 | -8.29 | 88.19 | 1.029 |
... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
118131 | 118131 | 359.439790 | 23 57 45.55 | 25.141479 | +25 08 29.3 | 4.63 | -36.06 | -32.25 | 1.584 |
118209 | 118209 | 359.668377 | 23 58 40.41 | -3.555807 | -03 33 20.9 | 4.88 | -56.52 | -72.34 | 0.930 |
118243 | 118243 | 359.752207 | 23 59 00.53 | 55.754941 | +55 45 17.8 | 4.88 | 9.26 | -5.09 | -0.071 |
118268 | 118268 | 359.827510 | 23 59 18.60 | 6.863594 | +06 51 48.9 | 4.03 | 148.49 | -112.16 | 0.419 |
118322 | 118322 | 359.978792 | 23 59 54.91 | -65.577078 | -65 34 37.5 | 4.49 | 48.63 | -22.33 | -0.075 |
1608 rows × 9 columns
del df2['hip']
df2['xy'] = df2['rahms'] + ' ' + df2['dedms']
df2.loc[118131]
radeg 359.44 rahms 23 57 45.55 dedeg 25.1415 dedms +25 08 29.3 vmag 4.63 pmra -36.06 pmde -32.25 bv 1.584 xy 23 57 45.55 +25 08 29.3 Name: 118131, dtype: object
df2.iloc[1600]
radeg 356.764 rahms 23 47 03.39 dedeg 58.6519 dedms +58 39 06.7 vmag 4.88 pmra 60.7 pmde 56.69 bv 1.122 xy 23 47 03.39 +58 39 06.7 Name: 117301, dtype: object
df2
radeg | rahms | dedeg | dedms | vmag | pmra | pmde | bv | xy | |
---|---|---|---|---|---|---|---|---|---|
hip | |||||||||
122 | 0.399379 | 00 01 35.85 | -77.065294 | -77 03 55.1 | 4.78 | -56.52 | -176.95 | 1.254 | 00 01 35.85 -77 03 55.1 |
154 | 0.489965 | 00 01 57.59 | -6.013972 | -06 00 50.3 | 4.37 | 46.62 | -41.32 | 1.631 | 00 01 57.59 -06 00 50.3 |
301 | 0.934885 | 00 03 44.37 | -17.335970 | -17 20 09.5 | 4.55 | 28.57 | -7.28 | -0.047 | 00 03 44.37 -17 20 09.5 |
355 | 1.125510 | 00 04 30.12 | -10.509494 | -10 30 34.2 | 4.99 | -6.49 | -11.88 | 1.619 | 00 04 30.12 -10 30 34.2 |
443 | 1.333941 | 00 05 20.15 | -5.707833 | -05 42 28.2 | 4.61 | -8.29 | 88.19 | 1.029 | 00 05 20.15 -05 42 28.2 |
... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
118131 | 359.439790 | 23 57 45.55 | 25.141479 | +25 08 29.3 | 4.63 | -36.06 | -32.25 | 1.584 | 23 57 45.55 +25 08 29.3 |
118209 | 359.668377 | 23 58 40.41 | -3.555807 | -03 33 20.9 | 4.88 | -56.52 | -72.34 | 0.930 | 23 58 40.41 -03 33 20.9 |
118243 | 359.752207 | 23 59 00.53 | 55.754941 | +55 45 17.8 | 4.88 | 9.26 | -5.09 | -0.071 | 23 59 00.53 +55 45 17.8 |
118268 | 359.827510 | 23 59 18.60 | 6.863594 | +06 51 48.9 | 4.03 | 148.49 | -112.16 | 0.419 | 23 59 18.60 +06 51 48.9 |
118322 | 359.978792 | 23 59 54.91 | -65.577078 | -65 34 37.5 | 4.49 | 48.63 | -22.33 | -0.075 | 23 59 54.91 -65 34 37.5 |
1608 rows × 9 columns