In [1]:
import pandas as pd
import bqplot
import us

names = ["date", "city", "state", "country", "shape", "duration_seconds",
         "duration_reported", "description", "report_date", "latitude",
         "longitude"]

fn = "/srv/nbgrader/data/ufo-scrubbed-geocoded-time-standardized.csv"
ufo = pd.read_csv(fn, names = names, parse_dates = ["date", "report_date"])

abbr_to_fits = us.states.mapping('abbr', 'fips')
ufo["fips"] = ufo["state"].apply(lambda a: int(abbr_to_fits.get(str(a).upper(), -1)))
fips_count = ufo.groupby("fips")["duration_seconds"].count()

map_styles = {'scales': {'projection': bqplot.AlbersUSA(),
                         'color': bqplot.ColorScale(colors=["red", "blue"])},
              'color': fips_count.to_dict()}
states_map = bqplot.Map(map_data=bqplot.topo_load('map_data/USStatesMap.json'),
        **map_styles)
map_fig = bqplot.Figure(marks=[states_map], title='USA')

In [2]:
map_fig



In [3]:
fips_count.to_dict()


Out[3]:
{-1: 9394,
 1: 691,
 2: 354,
 4: 2689,
 5: 666,
 6: 9655,
 8: 1505,
 9: 968,
 10: 183,
 11: 99,
 12: 4200,
 13: 1347,
 15: 353,
 16: 554,
 17: 2645,
 18: 1386,
 19: 707,
 20: 653,
 21: 914,
 22: 598,
 23: 633,
 24: 911,
 25: 1358,
 26: 2071,
 27: 1081,
 28: 415,
 29: 1576,
 30: 510,
 31: 405,
 32: 905,
 33: 535,
 34: 1512,
 35: 815,
 36: 3219,
 37: 1869,
 38: 138,
 39: 2425,
 40: 766,
 41: 1845,
 42: 2582,
 44: 290,
 45: 1076,
 46: 196,
 47: 1193,
 48: 3677,
 49: 743,
 50: 307,
 51: 1393,
 53: 4268,
 54: 486,
 55: 1333,
 56: 205,
 72: 33}

In [4]:
import yt

In [5]:
ds = yt.load("/srv/nbgrader/data/IsolatedGalaxy/galaxy0030/galaxy0030")


yt : [INFO     ] 2017-11-23 18:36:13,691 Parameters: current_time              = 0.0060000200028298
yt : [INFO     ] 2017-11-23 18:36:13,692 Parameters: domain_dimensions         = [32 32 32]
yt : [INFO     ] 2017-11-23 18:36:13,693 Parameters: domain_left_edge          = [ 0.  0.  0.]
yt : [INFO     ] 2017-11-23 18:36:13,695 Parameters: domain_right_edge         = [ 1.  1.  1.]
yt : [INFO     ] 2017-11-23 18:36:13,696 Parameters: cosmological_simulation   = 0.0

In [6]:
ds.index.grid_left_edge


Parsing Hierarchy : 100%|██████████| 173/173 [00:00<00:00, 30857.52it/s]
yt : [INFO     ] 2017-11-23 18:36:13,718 Gathering a field list (this may take a moment.)
Out[6]:
YTArray([[ 0.        ,  0.        ,  0.        ],
       [ 0.25      ,  0.21875   ,  0.25      ],
       [ 0.5       ,  0.21875   ,  0.25      ],
       [ 0.21875   ,  0.5       ,  0.25      ],
       [ 0.5       ,  0.5       ,  0.25      ],
       [ 0.25      ,  0.25      ,  0.5       ],
       [ 0.5       ,  0.25      ,  0.5       ],
       [ 0.25      ,  0.5       ,  0.5       ],
       [ 0.5       ,  0.5       ,  0.5       ],
       [ 0.5       ,  0.5       ,  0.5       ],
       [ 0.5       ,  0.5       ,  0.5       ],
       [ 0.5       ,  0.5       ,  0.5       ],
       [ 0.5       ,  0.5       ,  0.5       ],
       [ 0.50976562,  0.5       ,  0.5       ],
       [ 0.50976562,  0.5       ,  0.50585938],
       [ 0.50976562,  0.53515625,  0.50585938],
       [ 0.52148438,  0.53515625,  0.50585938],
       [ 0.52148438,  0.54101562,  0.52539062],
       [ 0.52734375,  0.53515625,  0.50585938],
       [ 0.50976562,  0.5       ,  0.50585938],
       [ 0.50976562,  0.5       ,  0.5       ],
       [ 0.5       ,  0.5       ,  0.5       ],
       [ 0.5       ,  0.5       ,  0.5       ],
       [ 0.5       ,  0.5       ,  0.50585938],
       [ 0.50634766,  0.50244141,  0.50585938],
       [ 0.50488281,  0.5       ,  0.50585938],
       [ 0.5       ,  0.50390625,  0.50585938],
       [ 0.5       ,  0.5       ,  0.5       ],
       [ 0.28125   ,  0.5       ,  0.5       ],
       [ 0.3359375 ,  0.5       ,  0.5       ],
       [ 0.40625   ,  0.5       ,  0.5       ],
       [ 0.4453125 ,  0.5       ,  0.5       ],
       [ 0.44921875,  0.52539062,  0.50390625],
       [ 0.46289062,  0.52734375,  0.5       ],
       [ 0.48242188,  0.52539062,  0.5       ],
       [ 0.46875   ,  0.54492188,  0.5078125 ],
       [ 0.45703125,  0.52539062,  0.51953125],
       [ 0.47851562,  0.52539062,  0.5       ],
       [ 0.46484375,  0.52539062,  0.5       ],
       [ 0.45898438,  0.52539062,  0.50585938],
       [ 0.48242188,  0.52539062,  0.52539062],
       [ 0.47070312,  0.52539062,  0.51953125],
       [ 0.47851562,  0.52539062,  0.52539062],
       [ 0.47851562,  0.5       ,  0.5       ],
       [ 0.49023438,  0.5       ,  0.5       ],
       [ 0.49658203,  0.51025391,  0.50048828],
       [ 0.49462891,  0.5       ,  0.5       ],
       [ 0.49584961,  0.5       ,  0.5       ],
       [ 0.49584961,  0.50048828,  0.5       ],
       [ 0.49584961,  0.5012207 ,  0.5       ],
       [ 0.49804688,  0.5012207 ,  0.5       ],
       [ 0.49633789,  0.50341797,  0.5       ],
       [ 0.49658203,  0.5012207 ,  0.50073242],
       [ 0.49658203,  0.50244141,  0.50073242],
       [ 0.49780273,  0.5012207 ,  0.50146484],
       [ 0.5       ,  0.28125   ,  0.5       ],
       [ 0.5       ,  0.3359375 ,  0.5       ],
       [ 0.5       ,  0.40625   ,  0.5       ],
       [ 0.50195312,  0.44140625,  0.50585938],
       [ 0.5       ,  0.45117188,  0.5       ],
       [ 0.515625  ,  0.44335938,  0.5       ],
       [ 0.53125   ,  0.46289062,  0.5       ],
       [ 0.53125   ,  0.49023438,  0.5       ],
       [ 0.53125   ,  0.4609375 ,  0.515625  ],
       [ 0.53125   ,  0.47265625,  0.515625  ],
       [ 0.53125   ,  0.48046875,  0.515625  ],
       [ 0.53125   ,  0.48632812,  0.53125   ],
       [ 0.54101562,  0.484375  ,  0.515625  ],
       [ 0.53710938,  0.48046875,  0.53320312],
       [ 0.5       ,  0.47460938,  0.50195312],
       [ 0.5       ,  0.47949219,  0.5       ],
       [ 0.50292969,  0.4765625 ,  0.50195312],
       [ 0.50195312,  0.48779297,  0.50048828],
       [ 0.5       ,  0.48974609,  0.5       ],
       [ 0.5       ,  0.49609375,  0.50976562],
       [ 0.5       ,  0.49414062,  0.5       ],
       [ 0.5       ,  0.49707031,  0.5       ],
       [ 0.28125   ,  0.28125   ,  0.5       ],
       [ 0.3359375 ,  0.3359375 ,  0.5       ],
       [ 0.46484375,  0.37890625,  0.50390625],
       [ 0.40625   ,  0.40625   ,  0.5       ],
       [ 0.49609375,  0.44335938,  0.50585938],
       [ 0.44921875,  0.453125  ,  0.5       ],
       [ 0.4765625 ,  0.47753906,  0.5       ],
       [ 0.49755859,  0.48925781,  0.50097656],
       [ 0.49023438,  0.49121094,  0.5       ],
       [ 0.49609375,  0.48828125,  0.50341797],
       [ 0.49633789,  0.49389648,  0.5       ],
       [ 0.49487305,  0.49926758,  0.5       ],
       [ 0.49731445,  0.49609375,  0.5       ],
       [ 0.49755859,  0.49609375,  0.5       ],
       [ 0.49487305,  0.49707031,  0.5       ],
       [ 0.49682617,  0.49682617,  0.5       ],
       [ 0.5       ,  0.5       ,  0.28125   ],
       [ 0.5       ,  0.5       ,  0.3359375 ],
       [ 0.5       ,  0.5       ,  0.40234375],
       [ 0.5       ,  0.5       ,  0.453125  ],
       [ 0.5       ,  0.5       ,  0.4765625 ],
       [ 0.5       ,  0.5       ,  0.49121094],
       [ 0.5       ,  0.5       ,  0.49682617],
       [ 0.50170898,  0.5       ,  0.49804688],
       [ 0.50170898,  0.50219727,  0.49853516],
       [ 0.50219727,  0.50219727,  0.4987793 ],
       [ 0.50170898,  0.50219727,  0.49951172],
       [ 0.50292969,  0.50219727,  0.49951172],
       [ 0.265625  ,  0.5       ,  0.28125   ],
       [ 0.3359375 ,  0.5       ,  0.328125  ],
       [ 0.40234375,  0.5       ,  0.40625   ],
       [ 0.45117188,  0.5       ,  0.45117188],
       [ 0.49804688,  0.5       ,  0.47265625],
       [ 0.47460938,  0.5       ,  0.4765625 ],
       [ 0.49316406,  0.50195312,  0.48730469],
       [ 0.48925781,  0.50244141,  0.49658203],
       [ 0.49072266,  0.5       ,  0.49072266],
       [ 0.49926758,  0.50048828,  0.49560547],
       [ 0.49487305,  0.5       ,  0.49926758],
       [ 0.49707031,  0.5       ,  0.49707031],
       [ 0.49609375,  0.50219727,  0.49951172],
       [ 0.49658203,  0.5       ,  0.49853516],
       [ 0.5       ,  0.265625  ,  0.28125   ],
       [ 0.5       ,  0.3203125 ,  0.328125  ],
       [ 0.5       ,  0.3984375 ,  0.40625   ],
       [ 0.546875  ,  0.41796875,  0.4453125 ],
       [ 0.546875  ,  0.453125  ,  0.41796875],
       [ 0.546875  ,  0.4375    ,  0.4375    ],
       [ 0.546875  ,  0.4921875 ,  0.41796875],
       [ 0.546875  ,  0.48046875,  0.41796875],
       [ 0.55859375,  0.46875   ,  0.43359375],
       [ 0.5       ,  0.4609375 ,  0.4453125 ],
       [ 0.5       ,  0.44921875,  0.47460938],
       [ 0.51367188,  0.47265625,  0.46289062],
       [ 0.51367188,  0.47460938,  0.45703125],
       [ 0.52734375,  0.47070312,  0.46679688],
       [ 0.51367188,  0.46679688,  0.46875   ],
       [ 0.5       ,  0.47460938,  0.47753906],
       [ 0.5       ,  0.49023438,  0.49072266],
       [ 0.50488281,  0.49560547,  0.48974609],
       [ 0.50488281,  0.49169922,  0.49365234],
       [ 0.50488281,  0.49511719,  0.49365234],
       [ 0.50488281,  0.49511719,  0.49462891],
       [ 0.50488281,  0.49707031,  0.49267578],
       [ 0.50488281,  0.49853516,  0.49316406],
       [ 0.5       ,  0.49560547,  0.49707031],
       [ 0.50317383,  0.4987793 ,  0.49902344],
       [ 0.265625  ,  0.28125   ,  0.28125   ],
       [ 0.328125  ,  0.3359375 ,  0.328125  ],
       [ 0.4140625 ,  0.40625   ,  0.40625   ],
       [ 0.49414062,  0.43945312,  0.48632812],
       [ 0.45703125,  0.4765625 ,  0.46875   ],
       [ 0.48632812,  0.44921875,  0.453125  ],
       [ 0.45117188,  0.4921875 ,  0.453125  ],
       [ 0.44921875,  0.453125  ,  0.47851562],
       [ 0.46289062,  0.484375  ,  0.45507812],
       [ 0.484375  ,  0.46484375,  0.45703125],
       [ 0.47265625,  0.47851562,  0.46484375],
       [ 0.47265625,  0.45898438,  0.47070312],
       [ 0.4765625 ,  0.47265625,  0.46289062],
       [ 0.4765625 ,  0.47070312,  0.46679688],
       [ 0.47363281,  0.48535156,  0.49414062],
       [ 0.47363281,  0.48339844,  0.49707031],
       [ 0.48242188,  0.48535156,  0.48632812],
       [ 0.48144531,  0.48339844,  0.49121094],
       [ 0.47753906,  0.4921875 ,  0.48632812],
       [ 0.48632812,  0.47558594,  0.47753906],
       [ 0.49511719,  0.49707031,  0.48632812],
       [ 0.49755859,  0.49560547,  0.48828125],
       [ 0.49169922,  0.48974609,  0.49414062],
       [ 0.49023438,  0.49169922,  0.49072266],
       [ 0.49560547,  0.49853516,  0.49951172],
       [ 0.49707031,  0.49707031,  0.49853516],
       [ 0.49658203,  0.49755859,  0.49707031],
       [ 0.49902344,  0.49560547,  0.49755859],
       [ 0.49804688,  0.49609375,  0.49853516]]) code_length

In [7]:
ds.r[:].max("density", axis="x").plot()


yt : [INFO     ] 2017-11-23 18:36:15,489 Projection completed
yt : [INFO     ] 2017-11-23 18:36:15,495 xlim = 0.000000 1.000000
yt : [INFO     ] 2017-11-23 18:36:15,496 ylim = 0.000000 1.000000
yt : [INFO     ] 2017-11-23 18:36:15,502 Making a fixed resolution buffer of (('gas', 'density')) 800 by 800

Out[7]:


In [8]:
ds.domain_left_edge, ds.domain_right_edge


Out[8]:
(YTArray([ 0.,  0.,  0.]) code_length, YTArray([ 1.,  1.,  1.]) code_length)

In [9]:
ds.r[0.45:0.55, 0.45:0.55, 0.45:0.55].max("density", axis="z").plot()


yt : [INFO     ] 2017-11-23 18:36:17,608 Projection completed
yt : [INFO     ] 2017-11-23 18:36:17,610 xlim = 0.450000 0.550000
yt : [INFO     ] 2017-11-23 18:36:17,611 ylim = 0.450000 0.550000
yt : [INFO     ] 2017-11-23 18:36:17,613 Making a fixed resolution buffer of (('gas', 'density')) 800 by 800

Out[9]:


In [10]:
ds.r[:]["density"].in_units("Msun / kpc**3")


Out[10]:
YTArray([  7.28103608e+00,   7.29921182e+00,   7.29654424e+00, ...,
         1.66785569e+06,   2.35761291e+06,   1.62272618e+07]) Msun/kpc**3

In [11]:
ds.r[:].mean("density")


Out[11]:
1.404787210277918e-26 g/cm**3

In [12]:
ds.r[:].mean("density", axis="z", weight="density").plot()


yt : [INFO     ] 2017-11-23 18:36:19,634 Projection completed
yt : [INFO     ] 2017-11-23 18:36:19,637 xlim = 0.000000 1.000000
yt : [INFO     ] 2017-11-23 18:36:19,638 ylim = 0.000000 1.000000
yt : [INFO     ] 2017-11-23 18:36:19,640 Making a fixed resolution buffer of (('gas', 'density')) 800 by 800

Out[12]:


In [13]:
ds.r[:].profile("density", "temperature").plot()


Out[13]:


In [14]:
ds.r[:]["cell_mass"] / ds.r[:]["cell_volume"]


Out[14]:
YTArray([  1.44822664e+43,   1.45184186e+43,   1.45131127e+43, ...,
         3.31743040e+48,   4.68938455e+48,   3.22766604e+49]) g/code_length**3

In [15]:
import h5py

In [16]:
f = h5py.File("data-readonly/single_dicom.h5", "r")

In [17]:
data = f["/scan"][:]
data.shape


Out[17]:
(36, 512, 512)

In [18]:
import numpy as np
rand = np.random.random((36, 512, 512))

In [19]:
ds = yt.load_uniform_grid({'response': (data, "ft"), 'random': rand}, [36, 512, 512],
                          length_unit = 15.0 * yt.units.cm,
                          geometry = ("cartesian", ("y", "z", "x")),
                    bbox = np.array([ [0.0, 1.0], [0.0, 1.0], [0.0, 1.0]]))


yt : [INFO     ] 2017-11-23 18:36:23,345 Parameters: current_time              = 0.0
yt : [INFO     ] 2017-11-23 18:36:23,346 Parameters: domain_dimensions         = [ 36 512 512]
yt : [INFO     ] 2017-11-23 18:36:23,347 Parameters: domain_left_edge          = [ 0.  0.  0.]
yt : [INFO     ] 2017-11-23 18:36:23,348 Parameters: domain_right_edge         = [ 1.  1.  1.]
yt : [INFO     ] 2017-11-23 18:36:23,350 Parameters: cosmological_simulation   = 0.0

In [20]:
ds.domain_width.in_units("cm")


Out[20]:
YTArray([ 15.,  15.,  15.]) cm

In [21]:
ds.r[:].max("response", axis="y").plot().set_unit("response", "m")


yt : [INFO     ] 2017-11-23 18:36:24,242 Projection completed
yt : [INFO     ] 2017-11-23 18:36:24,244 xlim = 0.000000 1.000000
yt : [INFO     ] 2017-11-23 18:36:24,245 ylim = 0.000000 1.000000
yt : [INFO     ] 2017-11-23 18:36:24,246 Making a fixed resolution buffer of (('stream', 'response')) 800 by 800

Out[21]:


In [22]:
ds.r[:].max("random", axis="z").plot()


yt : [INFO     ] 2017-11-23 18:36:27,110 Projection completed
yt : [INFO     ] 2017-11-23 18:36:27,113 xlim = 0.000000 1.000000
yt : [INFO     ] 2017-11-23 18:36:27,114 ylim = 0.000000 1.000000
yt : [INFO     ] 2017-11-23 18:36:27,115 Making a fixed resolution buffer of (('stream', 'random')) 800 by 800

Out[22]:


In [23]:
new_data = ds.r[ ::256j, ::256j, ::256j ]["response"]

In [24]:
%matplotlib inline

In [25]:
import matplotlib.pyplot as plt

In [26]:
plt.imshow(new_data.sum(axis=1))


Out[26]:
<matplotlib.image.AxesImage at 0x7f6044f817b8>

In [27]:
new_data.shape


Out[27]:
(256, 256, 256)

In [28]:
newer_data = ds.r[0.5, ::256j, ::256j]["response"]
newer_data.shape


yt : [INFO     ] 2017-11-23 18:36:30,839 Making a fixed resolution buffer of (response) 256 by 256
Out[28]:
(256, 256)

In [ ]: