This section gives:¶
- Some basic intro to python, and OOP.
- Data types - what is nan?
- Lists, dictionaries, dataframes.
- Numpy.
- Plotting - line, image.
- Different kinds of data.
- Visualize data and show what it means.
</font>
How variables work¶
x = 5
print(x)
print(type(x))
x = "IUCAA"
print(x)
print(type(x))
5 <class 'int'> IUCAA <class 'str'>
print(x)
print(type(x))
IUCAA <class 'str'>
x = ["Stars", "Galaxies", "Quasars"]
print(x)
print(type(x))
['Stars', 'Galaxies', 'Quasars'] <class 'list'>
# Add new element
x.append(42)
x = {"Mass": 2e30, "Radius": 6.9e9, "Type": "G2V", "Surface Temperature": 5778}
print(x)
print(type(x))
{'Mass': 2e+30, 'Radius': 6900000000.0, 'Type': 'G2V', 'Surface Temperature': 5778} <class 'dict'>
# Add new element
x["Luminosity"] = "1 solar luminos"
Using functions¶
x = 7
y = 9
z = x+y*(x-1)**3
print(z)
1951
def fun(v1,v2):
return v1+v2*(v1-1)**3
print(fun(x,y))
1951
Objects¶
x = 2
help(x)
Help on int object: class int(object) | int(x=0) -> integer | int(x, base=10) -> integer | | Convert a number or string to an integer, or return 0 if no arguments | are given. If x is a number, return x.__int__(). For floating point | numbers, this truncates towards zero. | | If x is not a number or if base is given, then x must be a string, | bytes, or bytearray instance representing an integer literal in the | given base. The literal can be preceded by '+' or '-' and be surrounded | by whitespace. The base defaults to 10. Valid bases are 0 and 2-36. | Base 0 means to interpret the base from the string as an integer literal. | >>> int('0b100', base=0) | 4 | | Methods defined here: | | __abs__(self, /) | abs(self) | | __add__(self, value, /) | Return self+value. | | __and__(self, value, /) | Return self&value. | | __bool__(self, /) | self != 0 | | __ceil__(...) | Ceiling of an Integral returns itself. | | __divmod__(self, value, /) | Return divmod(self, value). | | __eq__(self, value, /) | Return self==value. | | __float__(self, /) | float(self) | | __floor__(...) | Flooring an Integral returns itself. | | __floordiv__(self, value, /) | Return self//value. | | __format__(...) | default object formatter | | __ge__(self, value, /) | Return self>=value. | | __getattribute__(self, name, /) | Return getattr(self, name). | | __getnewargs__(...) | | __gt__(self, value, /) | Return self>value. | | __hash__(self, /) | Return hash(self). | | __index__(self, /) | Return self converted to an integer, if self is suitable for use as an index into a list. | | __int__(self, /) | int(self) | | __invert__(self, /) | ~self | | __le__(self, value, /) | Return self<=value. | | __lshift__(self, value, /) | Return self<<value. | | __lt__(self, value, /) | Return self<value. | | __mod__(self, value, /) | Return self%value. | | __mul__(self, value, /) | Return self*value. | | __ne__(self, value, /) | Return self!=value. | | __neg__(self, /) | -self | | __new__(*args, **kwargs) from builtins.type | Create and return a new object. See help(type) for accurate signature. | | __or__(self, value, /) | Return self|value. | | __pos__(self, /) | +self | | __pow__(self, value, mod=None, /) | Return pow(self, value, mod). | | __radd__(self, value, /) | Return value+self. | | __rand__(self, value, /) | Return value&self. | | __rdivmod__(self, value, /) | Return divmod(value, self). | | __repr__(self, /) | Return repr(self). | | __rfloordiv__(self, value, /) | Return value//self. | | __rlshift__(self, value, /) | Return value<<self. | | __rmod__(self, value, /) | Return value%self. | | __rmul__(self, value, /) | Return value*self. | | __ror__(self, value, /) | Return value|self. | | __round__(...) | Rounding an Integral returns itself. | Rounding with an ndigits argument also returns an integer. | | __rpow__(self, value, mod=None, /) | Return pow(value, self, mod). | | __rrshift__(self, value, /) | Return value>>self. | | __rshift__(self, value, /) | Return self>>value. | | __rsub__(self, value, /) | Return value-self. | | __rtruediv__(self, value, /) | Return value/self. | | __rxor__(self, value, /) | Return value^self. | | __sizeof__(...) | Returns size in memory, in bytes | | __str__(self, /) | Return str(self). | | __sub__(self, value, /) | Return self-value. | | __truediv__(self, value, /) | Return self/value. | | __trunc__(...) | Truncating an Integral returns itself. | | __xor__(self, value, /) | Return self^value. | | bit_length(...) | int.bit_length() -> int | | Number of bits necessary to represent self in binary. | >>> bin(37) | '0b100101' | >>> (37).bit_length() | 6 | | conjugate(...) | Returns self, the complex conjugate of any int. | | from_bytes(...) from builtins.type | int.from_bytes(bytes, byteorder, *, signed=False) -> int | | Return the integer represented by the given array of bytes. | | The bytes argument must be a bytes-like object (e.g. bytes or bytearray). | | The byteorder argument determines the byte order used to represent the | integer. If byteorder is 'big', the most significant byte is at the | beginning of the byte array. If byteorder is 'little', the most | significant byte is at the end of the byte array. To request the native | byte order of the host system, use `sys.byteorder' as the byte order value. | | The signed keyword-only argument indicates whether two's complement is | used to represent the integer. | | to_bytes(...) | int.to_bytes(length, byteorder, *, signed=False) -> bytes | | Return an array of bytes representing an integer. | | The integer is represented using length bytes. An OverflowError is | raised if the integer is not representable with the given number of | bytes. | | The byteorder argument determines the byte order used to represent the | integer. If byteorder is 'big', the most significant byte is at the | beginning of the byte array. If byteorder is 'little', the most | significant byte is at the end of the byte array. To request the native | byte order of the host system, use `sys.byteorder' as the byte order value. | | The signed keyword-only argument determines whether two's complement is | used to represent the integer. If signed is False and a negative integer | is given, an OverflowError is raised. | | ---------------------------------------------------------------------- | Data descriptors defined here: | | denominator | the denominator of a rational number in lowest terms | | imag | the imaginary part of a complex number | | numerator | the numerator of a rational number in lowest terms | | real | the real part of a complex number
All variables in python are objects.¶
Every "variable" in python has some associated functions.
Possible to have custom data structure?
</font>
class number:
def __init__(self,value):
self.value = value
def __add__(self,value):
return number(self.value+value.value)
def __str__(self):
return str(self.value)
a = number(2)
b = number(3)
c = a+b
print(c)
5
Inheritance¶
class Celestial:
def __init__(self,ra,dec,distance):
self.ra = ra
self.dec = dec
self.distance = distance
class Star(Celestial):
def __init__(self,ra,dec,startype,distance):
super(Star,self).__init__(ra,dec,distance)
self.startype=startype
def info(self):
print(f"A Star of type {self.startype}")
print(f"Plane of sky position:{self.ra} deg,{self.dec} deg")
print(f"Distance from Earth: {self.distance} pc")
sirius = Star(101.2833,-16.7161,"a1v",2.64)
sirius.info()
A Star of type a1v Plane of sky position:101.2833 deg,-16.7161 deg Distance from Earth: 2.64 pc
Numerical compute operations¶
Scientific workflow needs array manipulation, and work with matrices. How is this done?
Use packages
Packages can be thought to be python files which have a bunch of functions. These functions can be called in our script and used on our variables, or "objects".
</font>
Package list we will be using:
- $\color{#219ebc}{Numpy}$: Array manipulation, operations and our bread & butter.
- $\color{#ffb703}{Matplotlib}$: Visualization - plotting graphs and making images.
- $\color{#ef476f}{Astropy}$: FITS loading and manipulation.
- $\color{#76c893}{Pandas}$: Data loader, and basic data manipulation.
- $\color{#d08c60}{Scikit-learn}$: Machine learning package.
- $\color{#dc2f02}{Pytorch}$: Deep learning package.
</font>
import numpy as np
from matplotlib import pyplot as plt
x = np.linspace(-50,50,1000)
print(x)
print(type(x))
[-50. -49.8998999 -49.7997998 -49.6996997 -49.5995996 -49.4994995 -49.3993994 -49.2992993 -49.1991992 -49.0990991 -48.998999 -48.8988989 -48.7987988 -48.6986987 -48.5985986 -48.4984985 -48.3983984 -48.2982983 -48.1981982 -48.0980981 -47.997998 -47.8978979 -47.7977978 -47.6976977 -47.5975976 -47.4974975 -47.3973974 -47.2972973 -47.1971972 -47.0970971 -46.996997 -46.8968969 -46.7967968 -46.6966967 -46.5965966 -46.4964965 -46.3963964 -46.2962963 -46.1961962 -46.0960961 -45.995996 -45.8958959 -45.7957958 -45.6956957 -45.5955956 -45.4954955 -45.3953954 -45.2952953 -45.1951952 -45.0950951 -44.99499499 -44.89489489 -44.79479479 -44.69469469 -44.59459459 -44.49449449 -44.39439439 -44.29429429 -44.19419419 -44.09409409 -43.99399399 -43.89389389 -43.79379379 -43.69369369 -43.59359359 -43.49349349 -43.39339339 -43.29329329 -43.19319319 -43.09309309 -42.99299299 -42.89289289 -42.79279279 -42.69269269 -42.59259259 -42.49249249 -42.39239239 -42.29229229 -42.19219219 -42.09209209 -41.99199199 -41.89189189 -41.79179179 -41.69169169 -41.59159159 -41.49149149 -41.39139139 -41.29129129 -41.19119119 -41.09109109 -40.99099099 -40.89089089 -40.79079079 -40.69069069 -40.59059059 -40.49049049 -40.39039039 -40.29029029 -40.19019019 -40.09009009 -39.98998999 -39.88988989 -39.78978979 -39.68968969 -39.58958959 -39.48948949 -39.38938939 -39.28928929 -39.18918919 -39.08908909 -38.98898899 -38.88888889 -38.78878879 -38.68868869 -38.58858859 -38.48848849 -38.38838839 -38.28828829 -38.18818819 -38.08808809 -37.98798799 -37.88788789 -37.78778779 -37.68768769 -37.58758759 -37.48748749 -37.38738739 -37.28728729 -37.18718719 -37.08708709 -36.98698699 -36.88688689 -36.78678679 -36.68668669 -36.58658659 -36.48648649 -36.38638639 -36.28628629 -36.18618619 -36.08608609 -35.98598599 -35.88588589 -35.78578579 -35.68568569 -35.58558559 -35.48548549 -35.38538539 -35.28528529 -35.18518519 -35.08508509 -34.98498498 -34.88488488 -34.78478478 -34.68468468 -34.58458458 -34.48448448 -34.38438438 -34.28428428 -34.18418418 -34.08408408 -33.98398398 -33.88388388 -33.78378378 -33.68368368 -33.58358358 -33.48348348 -33.38338338 -33.28328328 -33.18318318 -33.08308308 -32.98298298 -32.88288288 -32.78278278 -32.68268268 -32.58258258 -32.48248248 -32.38238238 -32.28228228 -32.18218218 -32.08208208 -31.98198198 -31.88188188 -31.78178178 -31.68168168 -31.58158158 -31.48148148 -31.38138138 -31.28128128 -31.18118118 -31.08108108 -30.98098098 -30.88088088 -30.78078078 -30.68068068 -30.58058058 -30.48048048 -30.38038038 -30.28028028 -30.18018018 -30.08008008 -29.97997998 -29.87987988 -29.77977978 -29.67967968 -29.57957958 -29.47947948 -29.37937938 -29.27927928 -29.17917918 -29.07907908 -28.97897898 -28.87887888 -28.77877878 -28.67867868 -28.57857858 -28.47847848 -28.37837838 -28.27827828 -28.17817818 -28.07807808 -27.97797798 -27.87787788 -27.77777778 -27.67767768 -27.57757758 -27.47747748 -27.37737738 -27.27727728 -27.17717718 -27.07707708 -26.97697698 -26.87687688 -26.77677678 -26.67667668 -26.57657658 -26.47647648 -26.37637638 -26.27627628 -26.17617618 -26.07607608 -25.97597598 -25.87587588 -25.77577578 -25.67567568 -25.57557558 -25.47547548 -25.37537538 -25.27527528 -25.17517518 -25.07507508 -24.97497497 -24.87487487 -24.77477477 -24.67467467 -24.57457457 -24.47447447 -24.37437437 -24.27427427 -24.17417417 -24.07407407 -23.97397397 -23.87387387 -23.77377377 -23.67367367 -23.57357357 -23.47347347 -23.37337337 -23.27327327 -23.17317317 -23.07307307 -22.97297297 -22.87287287 -22.77277277 -22.67267267 -22.57257257 -22.47247247 -22.37237237 -22.27227227 -22.17217217 -22.07207207 -21.97197197 -21.87187187 -21.77177177 -21.67167167 -21.57157157 -21.47147147 -21.37137137 -21.27127127 -21.17117117 -21.07107107 -20.97097097 -20.87087087 -20.77077077 -20.67067067 -20.57057057 -20.47047047 -20.37037037 -20.27027027 -20.17017017 -20.07007007 -19.96996997 -19.86986987 -19.76976977 -19.66966967 -19.56956957 -19.46946947 -19.36936937 -19.26926927 -19.16916917 -19.06906907 -18.96896897 -18.86886887 -18.76876877 -18.66866867 -18.56856857 -18.46846847 -18.36836837 -18.26826827 -18.16816817 -18.06806807 -17.96796797 -17.86786787 -17.76776777 -17.66766767 -17.56756757 -17.46746747 -17.36736737 -17.26726727 -17.16716717 -17.06706707 -16.96696697 -16.86686687 -16.76676677 -16.66666667 -16.56656657 -16.46646647 -16.36636637 -16.26626627 -16.16616617 -16.06606607 -15.96596597 -15.86586587 -15.76576577 -15.66566567 -15.56556557 -15.46546547 -15.36536537 -15.26526527 -15.16516517 -15.06506507 -14.96496496 -14.86486486 -14.76476476 -14.66466466 -14.56456456 -14.46446446 -14.36436436 -14.26426426 -14.16416416 -14.06406406 -13.96396396 -13.86386386 -13.76376376 -13.66366366 -13.56356356 -13.46346346 -13.36336336 -13.26326326 -13.16316316 -13.06306306 -12.96296296 -12.86286286 -12.76276276 -12.66266266 -12.56256256 -12.46246246 -12.36236236 -12.26226226 -12.16216216 -12.06206206 -11.96196196 -11.86186186 -11.76176176 -11.66166166 -11.56156156 -11.46146146 -11.36136136 -11.26126126 -11.16116116 -11.06106106 -10.96096096 -10.86086086 -10.76076076 -10.66066066 -10.56056056 -10.46046046 -10.36036036 -10.26026026 -10.16016016 -10.06006006 -9.95995996 -9.85985986 -9.75975976 -9.65965966 -9.55955956 -9.45945946 -9.35935936 -9.25925926 -9.15915916 -9.05905906 -8.95895896 -8.85885886 -8.75875876 -8.65865866 -8.55855856 -8.45845846 -8.35835836 -8.25825826 -8.15815816 -8.05805806 -7.95795796 -7.85785786 -7.75775776 -7.65765766 -7.55755756 -7.45745746 -7.35735736 -7.25725726 -7.15715716 -7.05705706 -6.95695696 -6.85685686 -6.75675676 -6.65665666 -6.55655656 -6.45645646 -6.35635636 -6.25625626 -6.15615616 -6.05605606 -5.95595596 -5.85585586 -5.75575576 -5.65565566 -5.55555556 -5.45545546 -5.35535536 -5.25525526 -5.15515516 -5.05505506 -4.95495495 -4.85485485 -4.75475475 -4.65465465 -4.55455455 -4.45445445 -4.35435435 -4.25425425 -4.15415415 -4.05405405 -3.95395395 -3.85385385 -3.75375375 -3.65365365 -3.55355355 -3.45345345 -3.35335335 -3.25325325 -3.15315315 -3.05305305 -2.95295295 -2.85285285 -2.75275275 -2.65265265 -2.55255255 -2.45245245 -2.35235235 -2.25225225 -2.15215215 -2.05205205 -1.95195195 -1.85185185 -1.75175175 -1.65165165 -1.55155155 -1.45145145 -1.35135135 -1.25125125 -1.15115115 -1.05105105 -0.95095095 -0.85085085 -0.75075075 -0.65065065 -0.55055055 -0.45045045 -0.35035035 -0.25025025 -0.15015015 -0.05005005 0.05005005 0.15015015 0.25025025 0.35035035 0.45045045 0.55055055 0.65065065 0.75075075 0.85085085 0.95095095 1.05105105 1.15115115 1.25125125 1.35135135 1.45145145 1.55155155 1.65165165 1.75175175 1.85185185 1.95195195 2.05205205 2.15215215 2.25225225 2.35235235 2.45245245 2.55255255 2.65265265 2.75275275 2.85285285 2.95295295 3.05305305 3.15315315 3.25325325 3.35335335 3.45345345 3.55355355 3.65365365 3.75375375 3.85385385 3.95395395 4.05405405 4.15415415 4.25425425 4.35435435 4.45445445 4.55455455 4.65465465 4.75475475 4.85485485 4.95495495 5.05505506 5.15515516 5.25525526 5.35535536 5.45545546 5.55555556 5.65565566 5.75575576 5.85585586 5.95595596 6.05605606 6.15615616 6.25625626 6.35635636 6.45645646 6.55655656 6.65665666 6.75675676 6.85685686 6.95695696 7.05705706 7.15715716 7.25725726 7.35735736 7.45745746 7.55755756 7.65765766 7.75775776 7.85785786 7.95795796 8.05805806 8.15815816 8.25825826 8.35835836 8.45845846 8.55855856 8.65865866 8.75875876 8.85885886 8.95895896 9.05905906 9.15915916 9.25925926 9.35935936 9.45945946 9.55955956 9.65965966 9.75975976 9.85985986 9.95995996 10.06006006 10.16016016 10.26026026 10.36036036 10.46046046 10.56056056 10.66066066 10.76076076 10.86086086 10.96096096 11.06106106 11.16116116 11.26126126 11.36136136 11.46146146 11.56156156 11.66166166 11.76176176 11.86186186 11.96196196 12.06206206 12.16216216 12.26226226 12.36236236 12.46246246 12.56256256 12.66266266 12.76276276 12.86286286 12.96296296 13.06306306 13.16316316 13.26326326 13.36336336 13.46346346 13.56356356 13.66366366 13.76376376 13.86386386 13.96396396 14.06406406 14.16416416 14.26426426 14.36436436 14.46446446 14.56456456 14.66466466 14.76476476 14.86486486 14.96496496 15.06506507 15.16516517 15.26526527 15.36536537 15.46546547 15.56556557 15.66566567 15.76576577 15.86586587 15.96596597 16.06606607 16.16616617 16.26626627 16.36636637 16.46646647 16.56656657 16.66666667 16.76676677 16.86686687 16.96696697 17.06706707 17.16716717 17.26726727 17.36736737 17.46746747 17.56756757 17.66766767 17.76776777 17.86786787 17.96796797 18.06806807 18.16816817 18.26826827 18.36836837 18.46846847 18.56856857 18.66866867 18.76876877 18.86886887 18.96896897 19.06906907 19.16916917 19.26926927 19.36936937 19.46946947 19.56956957 19.66966967 19.76976977 19.86986987 19.96996997 20.07007007 20.17017017 20.27027027 20.37037037 20.47047047 20.57057057 20.67067067 20.77077077 20.87087087 20.97097097 21.07107107 21.17117117 21.27127127 21.37137137 21.47147147 21.57157157 21.67167167 21.77177177 21.87187187 21.97197197 22.07207207 22.17217217 22.27227227 22.37237237 22.47247247 22.57257257 22.67267267 22.77277277 22.87287287 22.97297297 23.07307307 23.17317317 23.27327327 23.37337337 23.47347347 23.57357357 23.67367367 23.77377377 23.87387387 23.97397397 24.07407407 24.17417417 24.27427427 24.37437437 24.47447447 24.57457457 24.67467467 24.77477477 24.87487487 24.97497497 25.07507508 25.17517518 25.27527528 25.37537538 25.47547548 25.57557558 25.67567568 25.77577578 25.87587588 25.97597598 26.07607608 26.17617618 26.27627628 26.37637638 26.47647648 26.57657658 26.67667668 26.77677678 26.87687688 26.97697698 27.07707708 27.17717718 27.27727728 27.37737738 27.47747748 27.57757758 27.67767768 27.77777778 27.87787788 27.97797798 28.07807808 28.17817818 28.27827828 28.37837838 28.47847848 28.57857858 28.67867868 28.77877878 28.87887888 28.97897898 29.07907908 29.17917918 29.27927928 29.37937938 29.47947948 29.57957958 29.67967968 29.77977978 29.87987988 29.97997998 30.08008008 30.18018018 30.28028028 30.38038038 30.48048048 30.58058058 30.68068068 30.78078078 30.88088088 30.98098098 31.08108108 31.18118118 31.28128128 31.38138138 31.48148148 31.58158158 31.68168168 31.78178178 31.88188188 31.98198198 32.08208208 32.18218218 32.28228228 32.38238238 32.48248248 32.58258258 32.68268268 32.78278278 32.88288288 32.98298298 33.08308308 33.18318318 33.28328328 33.38338338 33.48348348 33.58358358 33.68368368 33.78378378 33.88388388 33.98398398 34.08408408 34.18418418 34.28428428 34.38438438 34.48448448 34.58458458 34.68468468 34.78478478 34.88488488 34.98498498 35.08508509 35.18518519 35.28528529 35.38538539 35.48548549 35.58558559 35.68568569 35.78578579 35.88588589 35.98598599 36.08608609 36.18618619 36.28628629 36.38638639 36.48648649 36.58658659 36.68668669 36.78678679 36.88688689 36.98698699 37.08708709 37.18718719 37.28728729 37.38738739 37.48748749 37.58758759 37.68768769 37.78778779 37.88788789 37.98798799 38.08808809 38.18818819 38.28828829 38.38838839 38.48848849 38.58858859 38.68868869 38.78878879 38.88888889 38.98898899 39.08908909 39.18918919 39.28928929 39.38938939 39.48948949 39.58958959 39.68968969 39.78978979 39.88988989 39.98998999 40.09009009 40.19019019 40.29029029 40.39039039 40.49049049 40.59059059 40.69069069 40.79079079 40.89089089 40.99099099 41.09109109 41.19119119 41.29129129 41.39139139 41.49149149 41.59159159 41.69169169 41.79179179 41.89189189 41.99199199 42.09209209 42.19219219 42.29229229 42.39239239 42.49249249 42.59259259 42.69269269 42.79279279 42.89289289 42.99299299 43.09309309 43.19319319 43.29329329 43.39339339 43.49349349 43.59359359 43.69369369 43.79379379 43.89389389 43.99399399 44.09409409 44.19419419 44.29429429 44.39439439 44.49449449 44.59459459 44.69469469 44.79479479 44.89489489 44.99499499 45.0950951 45.1951952 45.2952953 45.3953954 45.4954955 45.5955956 45.6956957 45.7957958 45.8958959 45.995996 46.0960961 46.1961962 46.2962963 46.3963964 46.4964965 46.5965966 46.6966967 46.7967968 46.8968969 46.996997 47.0970971 47.1971972 47.2972973 47.3973974 47.4974975 47.5975976 47.6976977 47.7977978 47.8978979 47.997998 48.0980981 48.1981982 48.2982983 48.3983984 48.4984985 48.5985986 48.6986987 48.7987988 48.8988989 48.998999 49.0990991 49.1991992 49.2992993 49.3993994 49.4994995 49.5995996 49.6996997 49.7997998 49.8998999 50. ] <class 'numpy.ndarray'>
gauss = np.exp(-x**2/100.0)
print(gauss)
[1.38879439e-11 1.53485501e-11 1.69593705e-11 1.87354905e-11 2.06934725e-11 2.28514965e-11 2.52295142e-11 2.78494161e-11 3.07352160e-11 3.39132500e-11 3.74123958e-11 4.12643108e-11 4.55036924e-11 5.01685615e-11 5.53005724e-11 6.09453493e-11 6.71528551e-11 7.39777913e-11 8.14800350e-11 8.97251142e-11 9.87847260e-11 1.08737300e-10 1.19668614e-10 1.31672458e-10 1.44851365e-10 1.59317399e-10 1.75193016e-10 1.92611999e-10 2.11720473e-10 2.32678010e-10 2.55658827e-10 2.80853093e-10 3.08468340e-10 3.38731003e-10 3.71888089e-10 4.08208981e-10 4.47987410e-10 4.91543583e-10 5.39226490e-10 5.91416415e-10 6.48527650e-10 7.11011437e-10 7.79359158e-10 8.54105792e-10 9.35833652e-10 1.02517644e-09 1.12282362e-09 1.22952520e-09 1.34609681e-09 1.47342529e-09 1.61247472e-09 1.76429285e-09 1.93001819e-09 2.11088755e-09 2.30824424e-09 2.52354696e-09 2.75837931e-09 3.01446017e-09 3.29365481e-09 3.59798691e-09 3.92965156e-09 4.29102926e-09 4.68470098e-09 5.11346446e-09 5.58035175e-09 6.08864812e-09 6.64191241e-09 7.24399895e-09 7.89908125e-09 8.61167735e-09 9.38667727e-09 1.02293724e-08 1.11454873e-08 1.21412135e-08 1.32232468e-08 1.43988257e-08 1.56757747e-08 1.70625493e-08 1.85682850e-08 2.02028497e-08 2.19769005e-08 2.39019435e-08 2.59903996e-08 2.82556737e-08 3.07122294e-08 3.33756695e-08 3.62628218e-08 3.93918315e-08 4.27822595e-08 4.64551888e-08 5.04333374e-08 5.47411799e-08 5.94050776e-08 6.44534171e-08 6.99167600e-08 7.58280013e-08 8.22225404e-08 8.91384626e-08 9.66167345e-08 1.04701412e-07 1.13439862e-07 1.22883000e-07 1.33085546e-07 1.44106291e-07 1.56008392e-07 1.68859673e-07 1.82732964e-07 1.97706441e-07 2.13864010e-07 2.31295700e-07 2.50098093e-07 2.70374774e-07 2.92236814e-07 3.15803288e-07 3.41201818e-07 3.68569161e-07 3.98051823e-07 4.29806727e-07 4.64001909e-07 5.00817265e-07 5.40445351e-07 5.83092217e-07 6.28978313e-07 6.78339435e-07 7.31427739e-07 7.88512813e-07 8.49882819e-07 9.15845703e-07 9.86730476e-07 1.06288857e-06 1.14469531e-06 1.23255138e-06 1.32688453e-06 1.42815122e-06 1.53683849e-06 1.65346584e-06 1.77858733e-06 1.91279368e-06 2.05671459e-06 2.21102115e-06 2.37642839e-06 2.55369799e-06 2.74364112e-06 2.94712149e-06 3.16505851e-06 3.39843067e-06 3.64827907e-06 3.91571123e-06 4.20190500e-06 4.50811274e-06 4.83566575e-06 5.18597893e-06 5.56055561e-06 5.96099278e-06 6.38898650e-06 6.84633763e-06 7.33495783e-06 7.85687598e-06 8.41424476e-06 9.00934777e-06 9.64460685e-06 1.03225899e-05 1.10460190e-05 1.18177790e-05 1.26409266e-05 1.35186998e-05 1.44545276e-05 1.54520410e-05 1.65150832e-05 1.76477217e-05 1.88542602e-05 2.01392509e-05 2.15075081e-05 2.29641220e-05 2.45144731e-05 2.61642474e-05 2.79194526e-05 2.97864343e-05 3.17718939e-05 3.38829064e-05 3.61269398e-05 3.85118750e-05 4.10460261e-05 4.37381630e-05 4.65975333e-05 4.96338865e-05 5.28574984e-05 5.62791974e-05 5.99103908e-05 6.37630932e-05 6.78499556e-05 7.21842962e-05 7.67801316e-05 8.16522102e-05 8.68160464e-05 9.22879569e-05 9.80850969e-05 1.04225500e-04 1.10728117e-04 1.17612860e-04 1.24900643e-04 1.32613428e-04 1.40774275e-04 1.49407384e-04 1.58538153e-04 1.68193223e-04 1.78400537e-04 1.89189396e-04 2.00590513e-04 2.12636079e-04 2.25359821e-04 2.38797068e-04 2.52984818e-04 2.67961805e-04 2.83768573e-04 3.00447549e-04 3.18043118e-04 3.36601701e-04 3.56171837e-04 3.76804269e-04 3.98552025e-04 4.21470509e-04 4.45617596e-04 4.71053720e-04 4.97841975e-04 5.26048215e-04 5.55741155e-04 5.86992476e-04 6.19876934e-04 6.54472474e-04 6.90860340e-04 7.29125194e-04 7.69355239e-04 8.11642338e-04 8.56082143e-04 9.02774223e-04 9.51822198e-04 1.00333387e-03 1.05742138e-03 1.11420132e-03 1.17379489e-03 1.23632807e-03 1.30193173e-03 1.37074182e-03 1.44289948e-03 1.51855128e-03 1.59784928e-03 1.68095129e-03 1.76802098e-03 1.85922806e-03 1.95474848e-03 2.05476457e-03 2.15946526e-03 2.26904622e-03 2.38371006e-03 2.50366653e-03 2.62913269e-03 2.76033311e-03 2.89750004e-03 3.04087363e-03 3.19070214e-03 3.34724206e-03 3.51075841e-03 3.68152485e-03 3.85982393e-03 4.04594729e-03 4.24019581e-03 4.44287989e-03 4.65431958e-03 4.87484480e-03 5.10479558e-03 5.34452218e-03 5.59438536e-03 5.85475656e-03 6.12601804e-03 6.40856315e-03 6.70279647e-03 7.00913401e-03 7.32800339e-03 7.65984404e-03 8.00510734e-03 8.36425683e-03 8.73776834e-03 9.12613019e-03 9.52984333e-03 9.94942149e-03 1.03853913e-02 1.08382925e-02 1.13086780e-02 1.17971139e-02 1.23041800e-02 1.28304695e-02 1.33765891e-02 1.39431594e-02 1.45308147e-02 1.51402032e-02 1.57719870e-02 1.64268421e-02 1.71054587e-02 1.78085406e-02 1.85368061e-02 1.92909870e-02 2.00718294e-02 2.08800933e-02 2.17165523e-02 2.25819940e-02 2.34772198e-02 2.44030445e-02 2.53602963e-02 2.63498169e-02 2.73724612e-02 2.84290968e-02 2.95206042e-02 3.06478766e-02 3.18118192e-02 3.30133493e-02 3.42533960e-02 3.55328999e-02 3.68528123e-02 3.82140956e-02 3.96177223e-02 4.10646748e-02 4.25559451e-02 4.40925340e-02 4.56754510e-02 4.73057135e-02 4.89843464e-02 5.07123814e-02 5.24908566e-02 5.43208155e-02 5.62033070e-02 5.81393840e-02 6.01301032e-02 6.21765240e-02 6.42797082e-02 6.64407186e-02 6.86606187e-02 7.09404716e-02 7.32813391e-02 7.56842810e-02 7.81503540e-02 8.06806107e-02 8.32760987e-02 8.59378595e-02 8.86669278e-02 9.14643298e-02 9.43310827e-02 9.72681933e-02 1.00276657e-01 1.03357456e-01 1.06511559e-01 1.09739920e-01 1.13043477e-01 1.16423148e-01 1.19879835e-01 1.23414420e-01 1.27027760e-01 1.30720693e-01 1.34494030e-01 1.38348560e-01 1.42285042e-01 1.46304207e-01 1.50406759e-01 1.54593367e-01 1.58864671e-01 1.63221275e-01 1.67663748e-01 1.72192624e-01 1.76808395e-01 1.81511518e-01 1.86302406e-01 1.91181429e-01 1.96148916e-01 2.01205148e-01 2.06350359e-01 2.11584738e-01 2.16908422e-01 2.22321497e-01 2.27823998e-01 2.33415906e-01 2.39097146e-01 2.44867589e-01 2.50727046e-01 2.56675272e-01 2.62711960e-01 2.68836743e-01 2.75049191e-01 2.81348813e-01 2.87735051e-01 2.94207282e-01 3.00764819e-01 3.07406905e-01 3.14132716e-01 3.20941358e-01 3.27831870e-01 3.34803217e-01 3.41854296e-01 3.48983929e-01 3.56190868e-01 3.63473792e-01 3.70831305e-01 3.78261938e-01 3.85764150e-01 3.93336324e-01 4.00976768e-01 4.08683716e-01 4.16455329e-01 4.24289692e-01 4.32184817e-01 4.40138640e-01 4.48149025e-01 4.56213762e-01 4.64330568e-01 4.72497087e-01 4.80710892e-01 4.88969485e-01 4.97270297e-01 5.05610689e-01 5.13987956e-01 5.22399323e-01 5.30841950e-01 5.39312930e-01 5.47809295e-01 5.56328013e-01 5.64865990e-01 5.73420074e-01 5.81987056e-01 5.90563668e-01 5.99146590e-01 6.07732450e-01 6.16317824e-01 6.24899239e-01 6.33473179e-01 6.42036079e-01 6.50584338e-01 6.59114310e-01 6.67622316e-01 6.76104639e-01 6.84557533e-01 6.92977222e-01 7.01359901e-01 7.09701743e-01 7.17998899e-01 7.26247503e-01 7.34443672e-01 7.42583511e-01 7.50663115e-01 7.58678574e-01 7.66625972e-01 7.74501396e-01 7.82300934e-01 7.90020680e-01 7.97656737e-01 8.05205222e-01 8.12662267e-01 8.20024021e-01 8.27286659e-01 8.34446379e-01 8.41499409e-01 8.48442008e-01 8.55270472e-01 8.61981134e-01 8.68570369e-01 8.75034600e-01 8.81370296e-01 8.87573976e-01 8.93642218e-01 8.99571655e-01 9.05358983e-01 9.11000959e-01 9.16494410e-01 9.21836232e-01 9.27023394e-01 9.32052942e-01 9.36921999e-01 9.41627771e-01 9.46167546e-01 9.50538700e-01 9.54738700e-01 9.58765100e-01 9.62615554e-01 9.66287806e-01 9.69779705e-01 9.73089194e-01 9.76214324e-01 9.79153248e-01 9.81904226e-01 9.84465626e-01 9.86835925e-01 9.89013712e-01 9.90997689e-01 9.92786670e-01 9.94379587e-01 9.95775486e-01 9.96973530e-01 9.97973001e-01 9.98773299e-01 9.99373944e-01 9.99774575e-01 9.99974950e-01 9.99974950e-01 9.99774575e-01 9.99373944e-01 9.98773299e-01 9.97973001e-01 9.96973530e-01 9.95775486e-01 9.94379587e-01 9.92786670e-01 9.90997689e-01 9.89013712e-01 9.86835925e-01 9.84465626e-01 9.81904226e-01 9.79153248e-01 9.76214324e-01 9.73089194e-01 9.69779705e-01 9.66287806e-01 9.62615554e-01 9.58765100e-01 9.54738700e-01 9.50538700e-01 9.46167546e-01 9.41627771e-01 9.36921999e-01 9.32052942e-01 9.27023394e-01 9.21836232e-01 9.16494410e-01 9.11000959e-01 9.05358983e-01 8.99571655e-01 8.93642218e-01 8.87573976e-01 8.81370296e-01 8.75034600e-01 8.68570369e-01 8.61981134e-01 8.55270472e-01 8.48442008e-01 8.41499409e-01 8.34446379e-01 8.27286659e-01 8.20024021e-01 8.12662267e-01 8.05205222e-01 7.97656737e-01 7.90020680e-01 7.82300934e-01 7.74501396e-01 7.66625972e-01 7.58678574e-01 7.50663115e-01 7.42583511e-01 7.34443672e-01 7.26247503e-01 7.17998899e-01 7.09701743e-01 7.01359901e-01 6.92977222e-01 6.84557533e-01 6.76104639e-01 6.67622316e-01 6.59114310e-01 6.50584338e-01 6.42036079e-01 6.33473179e-01 6.24899239e-01 6.16317824e-01 6.07732450e-01 5.99146590e-01 5.90563668e-01 5.81987056e-01 5.73420074e-01 5.64865990e-01 5.56328013e-01 5.47809295e-01 5.39312930e-01 5.30841950e-01 5.22399323e-01 5.13987956e-01 5.05610689e-01 4.97270297e-01 4.88969485e-01 4.80710892e-01 4.72497087e-01 4.64330568e-01 4.56213762e-01 4.48149025e-01 4.40138640e-01 4.32184817e-01 4.24289692e-01 4.16455329e-01 4.08683716e-01 4.00976768e-01 3.93336324e-01 3.85764150e-01 3.78261938e-01 3.70831305e-01 3.63473792e-01 3.56190868e-01 3.48983929e-01 3.41854296e-01 3.34803217e-01 3.27831870e-01 3.20941358e-01 3.14132716e-01 3.07406905e-01 3.00764819e-01 2.94207282e-01 2.87735051e-01 2.81348813e-01 2.75049191e-01 2.68836743e-01 2.62711960e-01 2.56675272e-01 2.50727046e-01 2.44867589e-01 2.39097146e-01 2.33415906e-01 2.27823998e-01 2.22321497e-01 2.16908422e-01 2.11584738e-01 2.06350359e-01 2.01205148e-01 1.96148916e-01 1.91181429e-01 1.86302406e-01 1.81511518e-01 1.76808395e-01 1.72192624e-01 1.67663748e-01 1.63221275e-01 1.58864671e-01 1.54593367e-01 1.50406759e-01 1.46304207e-01 1.42285042e-01 1.38348560e-01 1.34494030e-01 1.30720693e-01 1.27027760e-01 1.23414420e-01 1.19879835e-01 1.16423148e-01 1.13043477e-01 1.09739920e-01 1.06511559e-01 1.03357456e-01 1.00276657e-01 9.72681933e-02 9.43310827e-02 9.14643298e-02 8.86669278e-02 8.59378595e-02 8.32760987e-02 8.06806107e-02 7.81503540e-02 7.56842810e-02 7.32813391e-02 7.09404716e-02 6.86606187e-02 6.64407186e-02 6.42797082e-02 6.21765240e-02 6.01301032e-02 5.81393840e-02 5.62033070e-02 5.43208155e-02 5.24908566e-02 5.07123814e-02 4.89843464e-02 4.73057135e-02 4.56754510e-02 4.40925340e-02 4.25559451e-02 4.10646748e-02 3.96177223e-02 3.82140956e-02 3.68528123e-02 3.55328999e-02 3.42533960e-02 3.30133493e-02 3.18118192e-02 3.06478766e-02 2.95206042e-02 2.84290968e-02 2.73724612e-02 2.63498169e-02 2.53602963e-02 2.44030445e-02 2.34772198e-02 2.25819940e-02 2.17165523e-02 2.08800933e-02 2.00718294e-02 1.92909870e-02 1.85368061e-02 1.78085406e-02 1.71054587e-02 1.64268421e-02 1.57719870e-02 1.51402032e-02 1.45308147e-02 1.39431594e-02 1.33765891e-02 1.28304695e-02 1.23041800e-02 1.17971139e-02 1.13086780e-02 1.08382925e-02 1.03853913e-02 9.94942149e-03 9.52984333e-03 9.12613019e-03 8.73776834e-03 8.36425683e-03 8.00510734e-03 7.65984404e-03 7.32800339e-03 7.00913401e-03 6.70279647e-03 6.40856315e-03 6.12601804e-03 5.85475656e-03 5.59438536e-03 5.34452218e-03 5.10479558e-03 4.87484480e-03 4.65431958e-03 4.44287989e-03 4.24019581e-03 4.04594729e-03 3.85982393e-03 3.68152485e-03 3.51075841e-03 3.34724206e-03 3.19070214e-03 3.04087363e-03 2.89750004e-03 2.76033311e-03 2.62913269e-03 2.50366653e-03 2.38371006e-03 2.26904622e-03 2.15946526e-03 2.05476457e-03 1.95474848e-03 1.85922806e-03 1.76802098e-03 1.68095129e-03 1.59784928e-03 1.51855128e-03 1.44289948e-03 1.37074182e-03 1.30193173e-03 1.23632807e-03 1.17379489e-03 1.11420132e-03 1.05742138e-03 1.00333387e-03 9.51822198e-04 9.02774223e-04 8.56082143e-04 8.11642338e-04 7.69355239e-04 7.29125194e-04 6.90860340e-04 6.54472474e-04 6.19876934e-04 5.86992476e-04 5.55741155e-04 5.26048215e-04 4.97841975e-04 4.71053720e-04 4.45617596e-04 4.21470509e-04 3.98552025e-04 3.76804269e-04 3.56171837e-04 3.36601701e-04 3.18043118e-04 3.00447549e-04 2.83768573e-04 2.67961805e-04 2.52984818e-04 2.38797068e-04 2.25359821e-04 2.12636079e-04 2.00590513e-04 1.89189396e-04 1.78400537e-04 1.68193223e-04 1.58538153e-04 1.49407384e-04 1.40774275e-04 1.32613428e-04 1.24900643e-04 1.17612860e-04 1.10728117e-04 1.04225500e-04 9.80850969e-05 9.22879569e-05 8.68160464e-05 8.16522102e-05 7.67801316e-05 7.21842962e-05 6.78499556e-05 6.37630932e-05 5.99103908e-05 5.62791974e-05 5.28574984e-05 4.96338865e-05 4.65975333e-05 4.37381630e-05 4.10460261e-05 3.85118750e-05 3.61269398e-05 3.38829064e-05 3.17718939e-05 2.97864343e-05 2.79194526e-05 2.61642474e-05 2.45144731e-05 2.29641220e-05 2.15075081e-05 2.01392509e-05 1.88542602e-05 1.76477217e-05 1.65150832e-05 1.54520410e-05 1.44545276e-05 1.35186998e-05 1.26409266e-05 1.18177790e-05 1.10460190e-05 1.03225899e-05 9.64460685e-06 9.00934777e-06 8.41424476e-06 7.85687598e-06 7.33495783e-06 6.84633763e-06 6.38898650e-06 5.96099278e-06 5.56055561e-06 5.18597893e-06 4.83566575e-06 4.50811274e-06 4.20190500e-06 3.91571123e-06 3.64827907e-06 3.39843067e-06 3.16505851e-06 2.94712149e-06 2.74364112e-06 2.55369799e-06 2.37642839e-06 2.21102115e-06 2.05671459e-06 1.91279368e-06 1.77858733e-06 1.65346584e-06 1.53683849e-06 1.42815122e-06 1.32688453e-06 1.23255138e-06 1.14469531e-06 1.06288857e-06 9.86730476e-07 9.15845703e-07 8.49882819e-07 7.88512813e-07 7.31427739e-07 6.78339435e-07 6.28978313e-07 5.83092217e-07 5.40445351e-07 5.00817265e-07 4.64001909e-07 4.29806727e-07 3.98051823e-07 3.68569161e-07 3.41201818e-07 3.15803288e-07 2.92236814e-07 2.70374774e-07 2.50098093e-07 2.31295700e-07 2.13864010e-07 1.97706441e-07 1.82732964e-07 1.68859673e-07 1.56008392e-07 1.44106291e-07 1.33085546e-07 1.22883000e-07 1.13439862e-07 1.04701412e-07 9.66167345e-08 8.91384626e-08 8.22225404e-08 7.58280013e-08 6.99167600e-08 6.44534171e-08 5.94050776e-08 5.47411799e-08 5.04333374e-08 4.64551888e-08 4.27822595e-08 3.93918315e-08 3.62628218e-08 3.33756695e-08 3.07122294e-08 2.82556737e-08 2.59903996e-08 2.39019435e-08 2.19769005e-08 2.02028497e-08 1.85682850e-08 1.70625493e-08 1.56757747e-08 1.43988257e-08 1.32232468e-08 1.21412135e-08 1.11454873e-08 1.02293724e-08 9.38667727e-09 8.61167735e-09 7.89908125e-09 7.24399895e-09 6.64191241e-09 6.08864812e-09 5.58035175e-09 5.11346446e-09 4.68470098e-09 4.29102926e-09 3.92965156e-09 3.59798691e-09 3.29365481e-09 3.01446017e-09 2.75837931e-09 2.52354696e-09 2.30824424e-09 2.11088755e-09 1.93001819e-09 1.76429285e-09 1.61247472e-09 1.47342529e-09 1.34609681e-09 1.22952520e-09 1.12282362e-09 1.02517644e-09 9.35833652e-10 8.54105792e-10 7.79359158e-10 7.11011437e-10 6.48527650e-10 5.91416415e-10 5.39226490e-10 4.91543583e-10 4.47987410e-10 4.08208981e-10 3.71888089e-10 3.38731003e-10 3.08468340e-10 2.80853093e-10 2.55658827e-10 2.32678010e-10 2.11720473e-10 1.92611999e-10 1.75193016e-10 1.59317399e-10 1.44851365e-10 1.31672458e-10 1.19668614e-10 1.08737300e-10 9.87847260e-11 8.97251142e-11 8.14800350e-11 7.39777913e-11 6.71528551e-11 6.09453493e-11 5.53005724e-11 5.01685615e-11 4.55036924e-11 4.12643108e-11 3.74123958e-11 3.39132500e-11 3.07352160e-11 2.78494161e-11 2.52295142e-11 2.28514965e-11 2.06934725e-11 1.87354905e-11 1.69593705e-11 1.53485501e-11 1.38879439e-11]
# plt.plot(x,gauss)
# plt.plot(x,gauss,color='red')
plt.plot(x,gauss,color='red',linestyle='--')
plt.xlabel("X-value")
plt.ylabel("f(x)")
plt.title("Gaussian function")
Text(0.5, 1.0, 'Gaussian function')
Image visualization¶
Let us define a 2-D Gaussian of the form: $$e^{-(x-5)^2/25-(y-5)^2/25}+e^{-(x+5)^2/25-(y+5)^2/25}$$
</font>
x = np.linspace(-10,10,1000)
y = np.linspace(-10,10,1000)
xx,yy = np.meshgrid(x,y)
doublegauss = np.exp(-(xx-5)**2/25.0-(yy-5)**2/25.0)+np.exp(-(xx+5)**2/25.0-(yy+5)**2/25.0)
plt.imshow(doublegauss,cmap='RdYlBu_r',origin='lower')
<matplotlib.image.AxesImage at 0x7f2a42e73be0>
plt.figure(figsize=(10,8))
plt.contourf(x,y,doublegauss,100,cmap='RdYlBu_r')
plt.colorbar()
<matplotlib.colorbar.Colorbar at 0x7f2a41b53f28>
Not a number¶
NaN is a special floating point value meant to reperesent anything that is "not a number" or "not data".
</font>
n1 = float("nan")
n2 = float("Nan")
n3 = float("NaN")
n4 = float("NAN")
n5 = np.nan
print(n1, n2, n3, n4,n5)
nan nan nan nan nan
print(n1 == 0)
print(n1 == 100)
print(n2 < 0)
False False False
print(n5 == n5)
False
Can we visualize astro data?¶
Astrophysics data is generally available in FITS format. Think of them as a file with multiple "shelves".
- Each data set - for example, one wavelength of observation - can be put in one shelf.
- Each shelf has a "data" and a "header".
- Header contains information on the satellite, location of object, Field of view, resolution, etc.
- Data contains the actual counts.
We are going to use $\color{#ef476f}{Astropy}$ for this!
</font>
from astropy.io import fits
!mkdir Data/
!wget https://www.lmsal.com/solarsoft/irisa/data/level2_compressed/2014/10/22/20141022_081850_3860261381/iris_l2_20141022_081850_3860261381_SDO.tar.gz
--2021-05-30 18:40:50-- https://www.lmsal.com/solarsoft/irisa/data/level2_compressed/2014/10/22/20141022_081850_3860261381/iris_l2_20141022_081850_3860261381_SDO.tar.gz Resolving www.lmsal.com (www.lmsal.com)... 166.21.250.149 Connecting to www.lmsal.com (www.lmsal.com)|166.21.250.149|:443... connected. HTTP request sent, awaiting response... 302 Found Location: https://iris.aws.lmsal.com/data/level2_compressed/2014/10/22/20141022_081850_3860261381/iris_l2_20141022_081850_3860261381_SDO.tar.gz [following] --2021-05-30 18:40:52-- https://iris.aws.lmsal.com/data/level2_compressed/2014/10/22/20141022_081850_3860261381/iris_l2_20141022_081850_3860261381_SDO.tar.gz Resolving iris.aws.lmsal.com (iris.aws.lmsal.com)... 54.192.66.40, 54.192.66.129, 54.192.66.111, ... Connecting to iris.aws.lmsal.com (iris.aws.lmsal.com)|54.192.66.40|:443... connected. HTTP request sent, awaiting response... 200 OK Length: 6317064603 (5.9G) [application/x-tar] Saving to: ‘iris_l2_20141022_081850_3860261381_SDO.tar.gz’ iris_l2_20141022_08 100%[===================>] 5.88G 1.99MB/s in 51m 17s 2021-05-30 19:32:10 (1.96 MB/s) - ‘iris_l2_20141022_081850_3860261381_SDO.tar.gz’ saved [6317064603/6317064603] tar: Data: Not found in archive tar: Exiting with failure status due to previous errors
!tar -xvf iris_l2_20141022_081850_3860261381_SDO.tar.gz
aia_l2_20141022_081850_3860261381_131.fits aia_l2_20141022_081850_3860261381_211.fits aia_l2_20141022_081850_3860261381_335.fits aia_l2_20141022_081850_3860261381_304.fits aia_l2_20141022_081850_3860261381_94.fits aia_l2_20141022_081850_3860261381_193.fits aia_l2_20141022_081850_3860261381_1700.fits aia_l2_20141022_081850_3860261381_171.fits aia_l2_20141022_081850_3860261381_1600.fits
aia = fits.open("aia_l2_20141022_081850_3860261381_171.fits")
print(aia.info())
Filename: aia_l2_20141022_081850_3860261381_171.fits No. Name Ver Type Cards Dimensions Format 0 PRIMARY 1 PrimaryHDU 147 (472, 470, 2987) int16 1 1 ImageHDU 27 (20, 2987) float64 2 1 TableHDU 28 2987R x 4C [A0, A0, A0, A100] None
aia[0].header
SIMPLE = T / Written by IDL: Sat May 16 21:17:17 2020 BITPIX = 16 / Number of bits per data pixel NAXIS = 3 / Number of data axes NAXIS1 = 472 / NAXIS2 = 470 / NAXIS3 = 2987 / EXTEND = T / FITS data may contain extensions DATE = '2020-05-17' / Creation UTC (CCCC-MM-DD) date of FITS header COMMENT FITS (Flexible Image Transport System) format is defined in 'Astronomy COMMENT and Astrophysics', volume 376, page 359; bibcode 2001A&A...376..359H TELESCOP= ' ' / INSTRUME= 'AIA_3 ' / DATA_LEV= 2.00000 / LVL_NUM = 2.00000 / VER_RF2 = 'A2I-2018-05-18' / DATE_RF2= '2020-05-16T22:32:19.556' / DATA_SRC= 1.00000 / ORIGIN = 'SDO AIA_3 171' / BLD_VERS= 'V8R6X ' / LUTID = 0 / OBSID = '20141022_081850_3860261381' / OBS_DESC= ' ' / OBSLABEL= ' ' / OBSTITLE= ' ' / DATE_OBS= '2014-10-22T08:08:59.340' / DATE_END= '2014-10-22T18:18:47.340' / STARTOBS= '2014-10-22T08:18:50.590' / ENDOBS = '2014-10-22T18:08:31.246' / OBSREP = 1 / CAMERA = 3 / STATUS = ' ' / BTYPE = ' ' / BUNIT = ' ' / BSCALE = 1.00 / BZERO = 0 / HLZ = ' ' / SAA = ' ' / SAT_ROT = 45.0001 / DSUN_OBS= 148876070843. / TR_MODE = ' ' / FOVY = 382.000011206 / FOVX = 383.200011253 / XCEN = -249.189 / YCEN = -302.089 / SUMSPTRL= 1 / SUMSPAT = 1 / EXPTIME = 1.85838086065 / EXPMIN = 0.234813004732 / EXPMAX = 2.00020790100 / DATAMEAN= 933.197 / DATARMS = 1056.33 / DATAMEDN= 593.284 / DATAMIN = -1182.16 / DATAMAX = 18980.8 / DATAVALS= 662636080 / MISSVALS= 0 / NSATPIX = 0 / NSPIKES = 0 / TOTVALS = 662636080 / PERCENTD= 100.000 / DATASKEW= 3.87836 / DATAKURT= 30.4687 / DATAP01 = 54.0981 / DATAP10 = 149.153 / DATAP25 = 283.913 / DATAP75 = 1170.06 / DATAP90 = 2189.26 / DATAP95 = 2967.73 / DATAP98 = 3927.73 / DATAP99 = 4686.64 / NEXP = 2987 / MISSRAS = 0 / PC1_1 = 0.699094 / PC1_2 = 0.715059 / PC2_1 = -0.715059 / PC2_2 = 0.699094 / PC3_1 = 0.00000 / PC3_2 = 0.00000 / NWIN = 1 / TDET1 = 'SJI ' / TDESC1 = '171_THIN' / TWAVE1 = 171 / TDMEAN1 = 933.197 / TDRMS1 = 1056.33 / TDMEDN1 = 593.284 / TDMIN1 = -1182.16 / TDMAX1 = 18980.8 / TDVALS1 = 662636080 / TMISSV1 = 0 / TSATPX1 = 0 / TSPIKE1 = 0 / TTOTV1 = 662636080 / TPCTD1 = 100.000 / TDSKEW1 = 3.87836 / TDKURT1 = 30.4687 / TDP01_1 = 54.0981 / TDP10_1 = 149.153 / TDP25_1 = 283.913 / TDP75_1 = 1170.06 / TDP90_1 = 2189.26 / TDP95_1 = 2967.73 / TDP98_1 = 3927.73 / TDP99_1 = 4686.64 / TSR1 = 1 / TER1 = 470 / TSC1 = 1 / TEC1 = 472 / CDELT1 = 0.600000023842 / CDELT2 = 0.600000023842 / CDELT3 = 12.2531815137 / CRPIX1 = 237.000 / CRPIX2 = 236.000 / CRPIX3 = 1494.00 / CRVAL1 = -249.189 / CRVAL2 = -302.089 / CRVAL3 = 17576.7500000 / CTYPE1 = 'HPLN-TAN' / CTYPE2 = 'HPLT-TAN' / CTYPE3 = 'Time ' / CUNIT1 = 'arcsecs ' / CUNIT2 = 'arcsecs ' / CUNIT3 = 'seconds ' / KEYWDDOC= 'http: ' / HISTORY FITSHEAD2STRUCT run at: Sat Nov 4 05:33:30 2017 HISTORY mreadfits_shm VERSION: 1.20 HISTORY read_sdo VERSION: 2.10 HISTORY read_sdo xll,xyy,nx,ny: 1192,1192,1192,1192,1192,1192,1192,1192,1192,11 HISTORY read_sdo Orig FILE: /SUM4/D624152183/S00000/image_lev1.fits HISTORY read_sdo Orig DATE: 2014-10-26T05:09:46 HISTORY read_sdo fovx,fovy: 535.34368,450.21624 HISTORY read_sdo Orig CRPIX1,CRPIX2: 2054.5901,2047.5400 HISTORY read_sdo Orig CDELT1,CDELT2: 0.59948900,0.59948900 HISTORY read_sdo Orig CROTA2: 0.019268000 HISTORY ssw_service_track_fov VERSION: 2.10 HISTORY ssw_service_track_fov jobid: ssw_service_171103_114718_21895 HISTORY ssw_service_track_fov ref_info: @2014/10/22 13:13:40.500 HISTORY ssw_service_track_fov xll,xyy,nx,ny: 1192,1159,893,751 HISTORY ssw_service_track_fov fovx,fovy: 535.000,450.000 HISTORY ssw_service_track_fov Orig CRPIX1&2: 2054.5901,2047.5400 HISTORY ssw_service_track_fov CFITSIO adjusted HISTORY FITSHEAD2STRUCT run at: Tue Nov 7 02:09:19 2017 HISTORY mreadfits_shm VERSION: 1.20 HISTORY read_sdo VERSION: 2.10 HISTORY FITSHEAD2STRUCT run at: Sat May 16 20:36:50 2020 HISTORY mreadfits_shm VERSION: 1.20 HISTORY read_sdo VERSION: 2.10 HISTORY IRIS-AIA RF2
aiadata = aia[0].data
aiahead = aia[0].header
print(aiadata.shape)
(2987, 470, 472)
from astropy.wcs import WCS
wcs = WCS(aiahead)
print(wcs)
WCS Keywords Number of WCS axes: 3 CTYPE : 'HPLN-TAN' 'HPLT-TAN' 'Time' CRVAL : -0.06921916666666666 -0.0839136111111111 17576.75 CRPIX : 237.0 236.0 1494.0 PC1_1 PC1_2 PC1_3 : 0.699094 0.715059 0.0 PC2_1 PC2_2 PC2_3 : -0.715059 0.699094 0.0 PC3_1 PC3_2 PC3_3 : 0.0 0.0 1.0 CDELT : 0.00016666667328944445 0.00016666667328944445 12.2531815137 NAXIS : 472 470 2987
WARNING: FITSFixedWarning: 'unitfix' made the change 'Changed units: 'arcsecs' -> 'arcsec', 'arcsecs' -> 'arcsec', 'seconds' -> 's'. [astropy.wcs.wcs]
#Plot at first time step.
ind = 50
plt.figure(figsize=(8,8))
plt.subplot(projection = wcs.dropaxis(-1))
plt.imshow(np.log10(aiadata[ind]),cmap='Blues_r')
<matplotlib.image.AxesImage at 0x7f207e3e09b0>
aia1 = fits.open("aia_l2_20141022_081850_3860261381_171.fits")
aiadata1 = aia1[0].data
wcs1 = WCS(aia1[0].header)
aia2 = fits.open("aia_l2_20141022_081850_3860261381_1700.fits")
aiadata2 = aia2[0].data
wcs2 = WCS(aia2[0].header)
index = -50
tmp_aiadata1 = np.log10(aiadata1[index])
tmp_aiadata2 = np.log10(aiadata2[index])
plt.figure(figsize=(10,10))
plt.imshow(tmp_aiadata2,origin='lower',cmap='Reds_r',alpha=1.0)
plt.imshow(tmp_aiadata1,origin='lower',cmap='Blues_r',alpha=0.7)
<matplotlib.image.AxesImage at 0x7f20776f8cc0>
def nanptp(x):
return np.nanmax(x)-np.nanmin(x)
index = -10
aia1 = fits.open("aia_l2_20141022_081850_3860261381_171.fits") # Red
aiadata1 = np.log10(aia1[0].data[index])
aiadata1 = 255*(aiadata1-np.nanmin(aiadata1))/nanptp(aiadata1)
aia2 = fits.open("aia_l2_20141022_081850_3860261381_193.fits") # Green
aiadata2 = np.log10(aia2[0].data[index])
aiadata2 = 255*(aiadata2-np.nanmin(aiadata2))/nanptp(aiadata2)
aia3 = fits.open("aia_l2_20141022_081850_3860261381_131.fits") # Blue
aiadata3 = np.log10(aia3[0].data[index])
aiadata3 = 255*(aiadata3-np.nanmin(aiadata3))/nanptp(aiadata3)
tmp_aiadata = np.asarray([aiadata1,aiadata2,aiadata3]).transpose(1,2,0).astype(int)
plt.figure(figsize=(10,10))
plt.imshow(tmp_aiadata,origin='lower', interpolation='nearest')
<matplotlib.image.AxesImage at 0x7f2076dd7978>
Fourier transform¶
Fourier transform breaks down a signal into sinusoids of various frequencies. This may be done in 1D or 2D or 3D. We now see a cute example of the effect of FFT on an image
</font>
aia1 = fits.open("aia_l2_20141022_081850_3860261381_171.fits")
aiadata1 = aia1[0].data
wcs1 = WCS(aia1[0].header)
WARNING: FITSFixedWarning: 'unitfix' made the change 'Changed units: 'arcsecs' -> 'arcsec', 'arcsecs' -> 'arcsec', 'seconds' -> 's'. [astropy.wcs.wcs]
index = -50
tmp_aiadata1 = np.log10(aiadata1[index])
plt.figure(figsize=(6,6))
plt.imshow(tmp_aiadata1,origin='lower',cmap='hot')
<matplotlib.image.AxesImage at 0x7f2077b4b9e8>
tmp_aiadata1_fft = np.fft.fft2(tmp_aiadata1)
tmp_aiadata1_fft_amp,tmp_aiadata1_fft_phase = np.abs(tmp_aiadata1_fft),np.angle(tmp_aiadata1_fft)
plt.figure(figsize=(12,6))
plt.subplot(1,2,1)
plt.imshow(np.log10(tmp_aiadata1_fft_amp),origin='lower',cmap='hot')
plt.title("Amplitude")
plt.subplot(1,2,2)
plt.imshow(tmp_aiadata1_fft_phase,origin='lower',cmap='hot')
plt.title("Phase")
Text(0.5, 1.0, 'Phase')
tmp_aiadata1_fft = np.fft.fft2(tmp_aiadata1)
tmp_aiadata1_fft_amp,tmp_aiadata1_fft_phase = np.abs(tmp_aiadata1_fft),np.angle(tmp_aiadata1_fft)
plt.figure(figsize=(12,6))
plt.subplot(1,2,1)
plt.imshow(np.fft.fftshift(np.log10(tmp_aiadata1_fft_amp)),origin='lower',cmap='hot')
plt.title("Amplitude")
plt.subplot(1,2,2)
plt.imshow(np.fft.fftshift(tmp_aiadata1_fft_phase),origin='lower',cmap='hot')
plt.title("Phase")
Text(0.5, 1.0, 'Phase')
tmp_aiadata1_ifft = np.abs(np.fft.ifft2(tmp_aiadata1_fft_amp*np.exp(1j*tmp_aiadata1_fft_phase)))
plt.figure(figsize=(12,6))
plt.subplot(1,2,1)
plt.imshow(tmp_aiadata1_ifft,origin='lower',cmap='hot')
plt.title("Inverse FT")
plt.subplot(1,2,2)
plt.imshow(tmp_aiadata1,origin='lower',cmap='hot')
plt.title("Original")
Text(0.5, 1.0, 'Original')
Filtering: High and Low pass filters¶
xx,yy = np.meshgrid(np.linspace(-5,5,tmp_aiadata2.shape[0]),np.linspace(-5,5,tmp_aiadata2.shape[1]))
highpassfilter = 1-np.exp(-15*(xx)**2-16*(yy)**2).T
plt.figure(figsize=(12,6))
plt.subplot(1,2,1)
plt.imshow(highpassfilter,origin='lower',cmap='gray')
plt.title("High pass filter, Fourier space")
plt.subplot(1,2,2)
plt.imshow(np.log10(np.fft.fftshift(tmp_aiadata1_fft_amp)),origin='lower',cmap='hot')
plt.title("AIA data: Fourier amplitude")
Text(0.5, 1.0, 'Filter in Fourier space')
Question: What does high pass filter give us?¶
highpassfilter = np.fft.fftshift(highpassfilter)
tmp_aiadata1_ifft = np.abs(np.fft.ifft2(highpassfilter*tmp_aiadata1_fft_amp*np.exp(1j*tmp_aiadata1_fft_phase)))
plt.figure(figsize=(12,6))
plt.subplot(1,2,1)
plt.imshow(tmp_aiadata1_ifft,origin='lower',cmap='hot')
plt.title("Inverse FT high pass filter")
plt.subplot(1,2,2)
plt.imshow(tmp_aiadata1,origin='lower',cmap='hot')
plt.title("Original")
Text(0.5, 1.0, 'Original')
xx,yy = np.meshgrid(np.linspace(-5,5,tmp_aiadata1.shape[0]),np.linspace(-5,5,tmp_aiadata1.shape[1]))
lowpassfilter = np.exp(-16*(xx)**2-16*(yy)**2).T
plt.figure(figsize=(12,6))
plt.subplot(1,2,1)
plt.imshow(lowpassfilter,origin='lower',cmap='gray')
plt.title("Low pass filter: Fourier space")
plt.subplot(1,2,2)
plt.imshow(np.log10(np.fft.fftshift(tmp_aiadata1_fft_amp)),origin='lower',cmap='hot')
plt.title("AIA amplitude: Fourier space")
Text(0.5, 1.0, 'AIA amplitude: Fourier space')
lowpassfilter = np.fft.fftshift(lowpassfilter)
tmp_aiadata1_ifft = np.abs(np.fft.ifft2(lowpassfilter*tmp_aiadata1_fft_amp*np.exp(1j*tmp_aiadata1_fft_phase)))
plt.figure(figsize=(12,6))
plt.subplot(1,2,1)
plt.imshow(tmp_aiadata1_ifft,origin='lower',cmap='hot')
plt.title("Inverse FT low pass filter")
plt.subplot(1,2,2)
plt.imshow(tmp_aiadata1,origin='lower',cmap='hot')
plt.title("Original")
Text(0.5, 1.0, 'Original')
Visualizing data frames¶
Not all astro data comes in fits format. Sometimes, tabulated data is saved as `csv' or Comma Separated Values. Think of these as Excel sheets with the column names as some variable, and rows representing different observations of these variables.
$\color{#76c893}{Pandas}$ is the go-to library for working with such data. Let's see how this works out.
</font>
First, I have some data downloaded already. Let's get it from Google drive.
!gdown --id 1D7OZ_ibIjl-2clagDXHBgiX_-BxAycmK Data/
Downloading... From: https://drive.google.com/uc?id=1D7OZ_ibIjl-2clagDXHBgiX_-BxAycmK To: /content/Skyserver_12_15_2020 3 45 07 AM.csv 82.5MB [00:01, 80.8MB/s]
import pandas as pd
Data = pd.read_csv("Skyserver_12_15_2020 3 45 07 AM.csv",comment="#")
Data.head()
objid | ra | dec | u | g | r | i | z | run | rerun | camcol | field | specobjid | class | redshift | plate | mjd | fiberid | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | 1237678877245244171 | 318.951692 | 9.315146 | 19.51665 | 18.50036 | 17.95667 | 17.53139 | 17.32035 | 7777 | 301 | 5 | 53 | 819657923239110656 | GALAXY | 0.114299 | 728 | 52520 | 10 |
1 | 1237668332026986542 | 217.940001 | 14.608378 | 19.13548 | 18.55482 | 17.95603 | 17.68272 | 17.63717 | 5322 | 301 | 3 | 56 | 6154252554903769088 | QSO | 1.802680 | 5466 | 56033 | 304 |
2 | 1237664092899115053 | 129.948221 | 25.213328 | 19.54955 | 18.19434 | 17.83220 | 17.51329 | 17.47054 | 4335 | 301 | 3 | 130 | 2173034979993348096 | GALAXY | 0.070813 | 1930 | 53347 | 175 |
3 | 1237654604252119048 | 160.357788 | 3.567886 | 17.72343 | 16.65830 | 16.23667 | 16.07098 | 16.02797 | 2126 | 301 | 1 | 275 | 649647859372681216 | STAR | 0.000570 | 577 | 52367 | 13 |
4 | 1237661360769400880 | 226.001700 | 38.619699 | 16.60500 | 15.66234 | 15.39406 | 15.29443 | 15.29302 | 3699 | 301 | 2 | 227 | 5817649714997514240 | STAR | -0.000184 | 5167 | 56066 | 454 |
Data['ra'].values.shape
(500000,)
Data.columns
Index(['objid', 'ra', 'dec', 'u', 'g', 'r', 'i', 'z', 'run', 'rerun', 'camcol', 'field', 'specobjid', 'class', 'redshift', 'plate', 'mjd', 'fiberid'], dtype='object')
Data.hist(column = ["u","g","r","i","z"],figsize=(12,12),bins=30)
array([[<matplotlib.axes._subplots.AxesSubplot object at 0x7ffab0a47c10>, <matplotlib.axes._subplots.AxesSubplot object at 0x7ffab0a0de90>], [<matplotlib.axes._subplots.AxesSubplot object at 0x7ffab09c52d0>, <matplotlib.axes._subplots.AxesSubplot object at 0x7ffab097a850>], [<matplotlib.axes._subplots.AxesSubplot object at 0x7ffab0930dd0>, <matplotlib.axes._subplots.AxesSubplot object at 0x7ffab08f0390>]], dtype=object)
Why is magnitude negative? Let's check
Data['i'].min()
-9999.0
-9999.0 or any such number represents missing data. Hence, we have two options:
- Drop rows where the value is this filler value.
- Interpolate across these values.
</font>
I don't like interpolation, so I will drop the rows.
#First, replace with nan
Data = Data.replace(-9999.0,np.nan)
Data.dropna(inplace=True)
Data['i'].min()
7.652014
Data.hist(column = ["u","g","r","i","z"],figsize=(12,12),bins=30)
array([[<matplotlib.axes._subplots.AxesSubplot object at 0x7ffab05b6290>, <matplotlib.axes._subplots.AxesSubplot object at 0x7ffaafb48dd0>], [<matplotlib.axes._subplots.AxesSubplot object at 0x7ffaafaf9f90>, <matplotlib.axes._subplots.AxesSubplot object at 0x7ffaafaba650>], [<matplotlib.axes._subplots.AxesSubplot object at 0x7ffaafa6ec50>, <matplotlib.axes._subplots.AxesSubplot object at 0x7ffaafa31210>]], dtype=object)
Exercise¶
Make a video with as many frames of this data as you like (there are 2500 or so frames), and as many passbands as you like, and submit. You may use any wavelength and any colormap you like. You will need to add the frame number on the title and keep updating it in the video. As a hint, use the `celluloid' library for making the vide.
from celluloid import Camera
# Write code to load data, take frame and then make video.
# Check the example code here and adapt it: https://github.com/jwkvam/celluloid.
fig = plt.figure(figsize=(8,8))
camera = Camera(fig)
for ind in np.arange(10):
val = np.log10(aiadata[ind])
plt.imshow(val,cmap='Blues_r',clim=(np.nanpercentile(np.log10(aiadata),5),np.nanpercentile(np.log10(aiadata),99)),origin='lower')
camera.snap()
/home/uvishal/.local/lib/python3.6/site-packages/ipykernel_launcher.py:7: RuntimeWarning: divide by zero encountered in log10 import sys /home/uvishal/.local/lib/python3.6/site-packages/ipykernel_launcher.py:7: RuntimeWarning: invalid value encountered in log10 import sys
from IPython.display import HTML
animation = camera.animate()
HTML(animation.to_html5_video())