File: loading_data.rst

package info (click to toggle)
yt 4.4.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 18,084 kB
  • sloc: python: 132,484; ansic: 5,628; cpp: 1,588; javascript: 352; makefile: 138; sh: 43; csh: 36
file content (3440 lines) | stat: -rw-r--r-- 126,351 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
.. _loading-data:

Loading Data
============

This section contains information on how to load data into yt, as well as
some important caveats about different data formats.

.. _loading-sample-data:

Sample Data
-----------

The yt community has provided a large number of sample datasets, which are
accessible from https://yt-project.org/data/ .  yt also provides a helper
function, ``yt.load_sample``, that can load from a set of sample datasets.  The
quickstart notebooks in this documentation utilize this.

The files are, in general, named identically to their listings on the data
catalog page.  For instance, you can load ``IsolatedGalaxy`` by executing:

.. code-block:: python

   import yt

   ds = yt.load_sample("IsolatedGalaxy")

To find a list of all available datasets, you can call ``load_sample`` without
any arguments, and it will return a list of the names that can be supplied:

.. code-block:: python

   import yt

   yt.load_sample()

This will return a list of possible filenames; more information can be accessed on the data catalog.


.. _loading-archived-data:

Archived Data
-------------

If your data is stored as a (compressed) tar file, you can access the contained
dataset directly without extracting the tar file.
This can be achieved using the ``load_archive`` function:

.. code-block:: python

   import yt

   ds = yt.load_archive("IsolatedGalaxy.tar.gz", "IsolatedGalaxy/galaxy0030/galaxy0030")

The first argument is the path to the archive file, the second one is the path to the file to load
in the archive. Subsequent arguments are passed to ``yt.load``.

The functionality requires the package `ratarmount <https://github.com/mxmlnkn/ratarmount/>`_ to be installed.
Under the hood, yt will mount the archive as a (read-only) filesystem. Note that this requires the
entire archive to be read once to compute the location of each file in the archive; subsequent accesses
will be much faster.
All archive formats supported by `ratarmount <https://github.com/mxmlnkn/ratarmount>`__ should be loadable, provided
the dependencies are installed; this includes ``tar``, ``tar.gz`` and tar.bz2`` formats.

.. _loading-hdf5-data:

Simple HDF5 Data
----------------

.. note::

   This wrapper takes advantage of the functionality described in
   :doc:`Loading_Data_via_Functions`
   but the basics of setting up function handlers,
   guessing fields, etc, are handled by yt.

Using the function :func:`yt.loaders.load_hdf5_file`, you can load a generic
set of fields from an HDF5 file and have a fully-operational yt dataset.  For
instance, in the yt sample data repository, we have the `UniGrid
Data <https://yt-project.org/data/UnigridData.tar.gz>`_ dataset (~1.6GB).  This dataset includes the file ``turb_vels.h5`` with this structure:

.. code-block:: bash

   $ h5ls -r h5ls -r ./UnigridData/turb_vels.h5

   /                        Group
   /Bx                      Dataset {256, 256, 256}
   /By                      Dataset {256, 256, 256}
   /Bz                      Dataset {256, 256, 256}
   /Density                 Dataset {256, 256, 256}
   /MagneticEnergy          Dataset {256, 256, 256}
   /Temperature             Dataset {256, 256, 256}
   /turb_x-velocity         Dataset {256, 256, 256}
   /turb_y-velocity         Dataset {256, 256, 256}
   /turb_z-velocity         Dataset {256, 256, 256}
   /x-velocity              Dataset {256, 256, 256}
   /y-velocity              Dataset {256, 256, 256}
   /z-velocity              Dataset {256, 256, 256}

In versions of yt prior to 4.1, these could be loaded into memory individually
and then accessed *en masse* by the :func:`yt.loaders.load_uniform_grid`
function.  Introduced in version 4.1, however, was the ability to provide the
filename and then allow yt to identify the available fields and even subset
them into chunks to preserve memory.  Only those requested fields will be
loaded at the time of the request, and they will be subset into chunks to avoid
over-allocating for reduction operations.

To use the auto-loader, call :func:`~yt.loaders.load_hdf5_file` with the name
of the file.  Optionally, you can specify the root node of the file to probe
for fields -- for instance, if all of the fields are stored under ``/grid`` (as
they are in output from the ytdata frontend).  You can also provide the
expected bounding box, which will otherwise default to 0..1 in all dimensions,
the names of fields to make available (by default yt will probe for them) and
the number of chunks to subdivide the file into.  If the number of chunks is
not specified it defaults to trying to keep the size of each individual chunk
no more than $64^3$ zones.

To load the above file, we would use the function as follows:

.. code-block:: python

   import yt

   ds = yt.load_hdf5_file("UnigridData/turb_vels.h5")

At this point, we now have a dataset that we can do all of our normal
operations on, and all of the known yt derived fields will be available.

.. _loading-amrvac-data:

AMRVAC Data
-----------

To load data to yt, simply use

.. code-block::

  import yt
  ds = yt.load("output0010.dat")


.. rubric:: Dataset geometry & periodicity

Starting from AMRVAC 2.2, and datfile format 5, a geometry flag
(e.g. "Cartesian_2.5D", "Polar_2D", "Cylindrical_1.5D"...) was added
to the datfile header.  yt will fall back to a cartesian mesh if the
geometry flag is not found.  For older datfiles however it is possible
to provide it externally with the ``geometry_override`` parameter.

.. code-block:: python

  # examples
  ds = yt.load("output0010.dat", geometry_override="polar")
  ds = yt.load("output0010.dat", geometry_override="cartesian")

Note that ``geometry_override`` has priority over any ``geometry`` flag
present in recent datfiles, which means it can be used to force ``r``
VS ``theta`` 2D plots in polar geometries (for example), but this may
produce unpredictable behaviour and comes with no guarantee.

A ``ndim``-long ``periodic`` boolean array was also added to improve
compatibility with yt. See http://amrvac.org/md_doc_fileformat.html
for details.

.. rubric:: Auto-setup for derived fields

Yt will attempt to mimic the way AMRVAC internally defines kinetic energy,
pressure, and sound speed. To see a complete list of fields that are defined after
loading, one can simply type

.. code-block:: python

  print(ds.derived_field_list)

Note that for adiabatic (magneto-)hydrodynamics, i.e. ``(m)hd_energy = False`` in
AMRVAC, additional input data is required in order to setup some of these fields.
This is done by passing the corresponding parfile(s) at load time

.. code-block:: python

  # example using a single parfile
  ds = yt.load("output0010.dat", parfiles="amrvac.par")

  # ... or using multiple parfiles
  ds = yt.load("output0010.dat", parfiles=["amrvac.par", "modifier.par"])

In case more than one parfile is passed, yt will create a single namelist by
replicating AMRVAC's rules (see "Using multiple par files"
http://amrvac.org/md_doc_commandline.html).


.. rubric:: Unit System

AMRVAC only supports dimensionless fields and as such, no unit system
is ever attached to any given dataset.  yt however defines physical
quantities and give them units. As is customary in yt, the default
unit system is ``cgs``, e.g. lengths are read as "cm" unless specified
otherwise.

The user has two ways to control displayed units, through
``unit_system`` (``"cgs"``, ``"mks"`` or ``"code"``) and
``units_override``. Example:

.. code-block:: python

  units_override = dict(length_unit=(100.0, "au"), mass_unit=yt.units.mass_sun)
  ds = yt.load("output0010.dat", units_override=units_override, unit_system="mks")

To ensure consistency with normalisations as used in AMRVAC we only allow
overriding a maximum of three units. Allowed unit combinations at the moment are

.. code-block:: none

  {numberdensity_unit, temperature_unit, length_unit}
  {mass_unit, temperature_unit, length_unit}
  {mass_unit, time_unit, length_unit}
  {numberdensity_unit, velocity_unit, length_unit}
  {mass_unit, velocity_unit, length_unit}

Appropriate errors are thrown for other combinations.


.. rubric:: Partially supported and unsupported features

* a maximum of 100 dust species can be read by yt at the moment.
  If your application needs this limit increased, please report an issue
  https://github.com/yt-project/yt/issues
* particle data: currently not supported (but might come later)
* staggered grids (AMRVAC 2.2 and later): yt logs a warning if you load
  staggered datasets, but the flag is currently ignored.
* "stretched grids" are being implemented in yt, but are not yet
  fully-supported.  (Previous versions of this file suggested they would
  "never" be supported, which we hope to prove incorrect once we finish
  implementing stretched grids in AMR.  At present, stretched grids are
  only supported on a single level of refinement.)

.. note::

   Ghost cells exist in .dat files but never read by yt.

.. _loading-art-data:

ART Data
--------

ART data has been supported in the past by Christopher Moody and is currently
cared for by Kenza Arraki.  Please contact the ``yt-dev`` mailing list if you
are interested in using yt for ART data, or if you are interested in assisting
with development of yt to work with ART data.

To load an ART dataset you can use the ``yt.load`` command and provide it the
gas mesh file. It will search for and attempt to find the complementary dark
matter and stellar particle header and data files. However, your simulations may
not follow the same naming convention.

.. code-block:: python

   import yt

   ds = yt.load("D9p_500/10MpcBox_HartGal_csf_a0.500.d")


It will search for and attempt to find the complementary dark matter and stellar
particle header and data files. However, your simulations may not follow the
same naming convention.

For example, the single snapshot given in the sample data has a series of files
that look like this:

.. code-block:: none

   10MpcBox_HartGal_csf_a0.500.d  #Gas mesh
   PMcrda0.500.DAT                #Particle header
   PMcrs0a0.500.DAT               #Particle data (positions,velocities)
   stars_a0.500.dat               #Stellar data (metallicities, ages, etc.)

The ART frontend tries to find the associated files matching the
above, but if that fails you can specify ``file_particle_header``,
``file_particle_data``, and ``file_particle_stars``, in addition to
specifying the gas mesh. Note that the ``pta0.500.dat`` or ``pt.dat``
file containing particle time steps is not loaded by yt.

You also have the option of gridding particles and assigning them onto the
meshes.  This process is in beta, and for the time being, it's probably best to
leave ``do_grid_particles=False`` as the default.

To speed up the loading of an ART file, you have a few options. You can turn
off the particles entirely by setting ``discover_particles=False``. You can
also only grid octs up to a certain level, ``limit_level=5``, which is useful
when debugging by artificially creating a 'smaller' dataset to work with.

Finally, when stellar ages are computed we 'spread' the ages evenly within a
smoothing window. By default this is turned on and set to 10Myr. To turn this
off you can set ``spread=False``, and you can tweak the age smoothing window
by specifying the window in seconds, ``spread=1.0e7*365*24*3600``.

There is currently preliminary support for dark matter only ART data. To load a
dataset use the ``yt.load`` command and provide it the particle data file. It
will search for the complementary particle header file.

.. code-block:: python

   import yt

   ds = yt.load("PMcrs0a0.500.DAT")

Important: This should not be used for loading just the dark matter
data for a 'regular' hydrodynamical data set as the units and IO are
different!


.. _loading-artio-data:

ARTIO Data
----------

ARTIO data has a well-specified internal parameter system and has few free
parameters.  However, for optimization purposes, the parameter that provides
the most guidance to yt as to how to manage ARTIO data is ``max_range``.  This
governs the maximum number of space-filling curve cells that will be used in a
single "chunk" of data read from disk.  For small datasets, setting this number
very large will enable more data to be loaded into memory at any given time;
for very large datasets, this parameter can be left alone safely.  By default
it is set to 1024; it can in principle be set as high as the total number of
SFC cells.

To load ARTIO data, you can specify a command such as this:

.. code-block:: python

   ds = load("./A11QR1/s11Qzm1h2_a1.0000.art")

.. _loading-athena-data:

Athena Data
-----------

Athena 4.x VTK data is supported and cared for by John ZuHone. Both uniform grid
and SMR datasets are supported.

.. note::

   yt also recognizes Fargo3D data written to VTK files as
   Athena data, but support for Fargo3D data is preliminary.

Loading Athena datasets is slightly different depending on whether
your dataset came from a serial or a parallel run. If the data came
from a serial run or you have joined the VTK files together using the
Athena tool ``join_vtk``, you can load the data like this:

.. code-block:: python

   import yt

   ds = yt.load("kh.0010.vtk")

The filename corresponds to the file on SMR level 0, whereas if there
are multiple levels the corresponding files will be picked up
automatically, assuming they are laid out in ``lev*`` subdirectories
under the directory where the base file is located.

For parallel datasets, yt assumes that they are laid out in
directories named ``id*``, one for each processor number, each with
``lev*`` subdirectories for additional refinement levels. To load this
data, call ``load`` with the base file in the ``id0`` directory:

.. code-block:: python

   import yt

   ds = yt.load("id0/kh.0010.vtk")

which will pick up all of the files in the different ``id*`` directories for
the entire dataset.

The default unit system in yt is cgs ("Gaussian") units, but Athena data is not
normally stored in these units, so the code unit system is the default unit
system for Athena data. This means that answers to field queries from data
objects and plots of data will be expressed in code units. Note that the default
conversions from these units will still be in terms of cgs units, e.g. 1
``code_length`` equals 1 cm, and so on. If you would like to provided different
conversions, you may supply conversions for length, time, and mass to ``load``
using the ``units_override`` functionality:

.. code-block:: python

   import yt

   units_override = {
       "length_unit": (1.0, "Mpc"),
       "time_unit": (1.0, "Myr"),
       "mass_unit": (1.0e14, "Msun"),
   }

   ds = yt.load("id0/cluster_merger.0250.vtk", units_override=units_override)

This means that the yt fields, e.g. ``("gas","density")``,
``("gas","velocity_x")``, ``("gas","magnetic_field_x")``, will be in cgs units
(or whatever unit system was specified), but the Athena fields, e.g.,
``("athena","density")``, ``("athena","velocity_x")``,
``("athena","cell_centered_B_x")``, will be in code units.

The default normalization for various magnetic-related quantities such as
magnetic pressure, Alfven speed, etc., as well as the conversion between
magnetic code units and other units, is Gaussian/CGS, meaning that factors
of :math:`4\pi` or :math:`\sqrt{4\pi}` will appear in these quantities, e.g.
:math:`p_B = B^2/8\pi`. To use the Lorentz-Heaviside normalization instead,
in which the factors of :math:`4\pi` are dropped (:math:`p_B = B^2/2), for
example), set ``magnetic_normalization="lorentz_heaviside"`` in the call to
``yt.load``:

.. code-block:: python

    ds = yt.load(
        "id0/cluster_merger.0250.vtk",
        units_override=units_override,
        magnetic_normalization="lorentz_heaviside",
    )

Some 3D Athena outputs may have large grids (especially parallel datasets
subsequently joined with the ``join_vtk`` script), and may benefit from being
subdivided into "virtual grids". For this purpose, one can pass in the
``nprocs`` parameter:

.. code-block:: python

   import yt

   ds = yt.load("sloshing.0000.vtk", nprocs=8)

which will subdivide each original grid into ``nprocs`` grids. Note that this
parameter is independent of the number of MPI tasks assigned to analyze the data
set in parallel (see :ref:`parallel-computation`), and ideally should be (much)
larger than this.

.. note::

    Virtual grids are only supported (and really only necessary) for 3D data.

Alternative values for the following simulation parameters may be specified
using a ``parameters`` dict, accepting the following keys:

* ``gamma``: ratio of specific heats, Type: Float. If not specified,
  :math:`\gamma = 5/3` is assumed.
* ``geometry``: Geometry type, currently accepts ``"cartesian"`` or
  ``"cylindrical"``. Default is ``"cartesian"``.
* ``periodicity``: Is the domain periodic? Type: Tuple of boolean values
  corresponding to each dimension. Defaults to ``True`` in all directions.
* ``mu``: mean molecular weight, Type: Float. If not specified, :math:`\mu = 0.6`
  (for a fully ionized primordial plasma) is assumed.

.. code-block:: python

   import yt

   parameters = {
       "gamma": 4.0 / 3.0,
       "geometry": "cylindrical",
       "periodicity": (False, False, False),
   }

   ds = yt.load("relativistic_jet_0000.vtk", parameters=parameters)

.. rubric:: Caveats

* yt primarily works with primitive variables. If the Athena dataset contains
  conservative variables, the yt primitive fields will be generated from the
  conserved variables on disk.
* Special relativistic datasets may be loaded, but at this time not all of
  their fields are fully supported. In particular, the relationships between
  quantities such as pressure and thermal energy will be incorrect, as it is
  currently assumed that their relationship is that of an ideal a
  :math:`\gamma`-law equation of state. This will be rectified in a future
  release.
* Domains may be visualized assuming periodicity.
* Particle list data is currently unsupported.

.. _loading-athena-pp-data:

Athena++ Data
-------------

Athena++ HDF5 data is supported and cared for by John ZuHone. Uniform-grid, SMR,
and AMR datasets in cartesian coordinates are fully supported. Support for
curvilinear coordinates and/or non-constant grid cell sizes exists, but is preliminary.

The default unit system in yt is cgs ("Gaussian") units, but Athena++ data is
not normally stored in these units, so the code unit system is the default unit
system for Athena++ data. This means that answers to field queries from data
objects and plots of data will be expressed in code units. Note that the default
conversions from these units will still be in terms of cgs units, e.g. 1
``code_length`` equals 1 cm, and so on. If you would like to provided different
conversions, you may supply conversions for length, time, and mass to ``load``
using the ``units_override`` functionality:

.. code-block:: python

   import yt

   units_override = {
       "length_unit": (1.0, "Mpc"),
       "time_unit": (1.0, "Myr"),
       "mass_unit": (1.0e14, "Msun"),
   }

   ds = yt.load("AM06/AM06.out1.00400.athdf", units_override=units_override)

This means that the yt fields, e.g. ``("gas","density")``,
``("gas","velocity_x")``, ``("gas","magnetic_field_x")``, will be in cgs units
(or whatever unit system was specified), but the Athena fields, e.g.,
``("athena_pp","density")``, ``("athena_pp","vel1")``, ``("athena_pp","Bcc1")``,
will be in code units.

The default normalization for various magnetic-related quantities such as
magnetic pressure, Alfven speed, etc., as well as the conversion between
magnetic code units and other units, is Gaussian/CGS, meaning that factors
of :math:`4\pi` or :math:`\sqrt{4\pi}` will appear in these quantities, e.g.
:math:`p_B = B^2/8\pi`. To use the Lorentz-Heaviside normalization instead,
in which the factors of :math:`4\pi` are dropped (:math:`p_B = B^2/2), for
example), set ``magnetic_normalization="lorentz_heaviside"`` in the call to
``yt.load``:

.. code-block:: python

    ds = yt.load(
        "AM06/AM06.out1.00400.athdf",
        units_override=units_override,
        magnetic_normalization="lorentz_heaviside",
    )

Alternative values for the following simulation parameters may be specified
using a ``parameters`` dict, accepting the following keys:

* ``gamma``: ratio of specific heats, Type: Float. If not specified,
  :math:`\gamma = 5/3` is assumed.
* ``geometry``: Geometry type, currently accepts ``"cartesian"`` or
  ``"cylindrical"``. Default is ``"cartesian"``.
* ``periodicity``: Is the domain periodic? Type: Tuple of boolean values
  corresponding to each dimension. Defaults to ``True`` in all directions.
* ``mu``: mean molecular weight, Type: Float. If not specified, :math:`\mu = 0.6`
  (for a fully ionized primordial plasma) is assumed.

.. rubric:: Caveats

* yt primarily works with primitive variables. If the Athena++ dataset contains
  conservative variables, the yt primitive fields will be generated from the
  conserved variables on disk.
* Special relativistic datasets may be loaded, but at this time not all of their
  fields are fully supported. In particular, the relationships between
  quantities such as pressure and thermal energy will be incorrect, as it is
  currently assumed that their relationship is that of an ideal
  :math:`\gamma`-law equation of state. This will be rectified in a future
  release.
* Domains may be visualized assuming periodicity.

.. _loading-parthenon-data:

Parthenon Data
--------------

Parthenon HDF5 data is supported and cared for by Forrest Glines and Philipp Grete.
The Parthenon framework is the basis for various downstream codes, e.g.,
`AthenaPK <https://github.com/parthenon-hpc-lab/athenapk>`_,
`Phoebus <https://github.com/lanl/phoebus>`_,
`KHARMA <https://github.com/AFD-Illinois/kharma>`_,
RIOT, and the
`parthenon-hydro <https://github.com/parthenon-hpc-lab/parthenon-hydro>`_ miniapp.
Support for these codes is handled through the common Parthenon frontend with
specifics described in the following.
Note that only AthenaPK data is currently automatically converted to the
standard fields known by yt.
For other codes, the raw data of the fields stored in the output file is accessible
and a conversion between those fields and yt standard fields needs to be done manually.

   .. rubric:: Caveats

* Reading particle data from Parthenon output is currently not supported.
* Spherical and cylindrical coordinates only work for AthenaPK data.
* Only periodic boundary conditions are properly handled. Calculating quantities requiring
larger stencils (like derivatives) will be incorrect at mesh boundaries that are not periodic.

AthenaPK
^^^^^^^^

Fluid data on uniform-grid, SMR, and AMR datasets in Cartesian coordinates are fully supported.

AthenaPK data may contain information on units in the output (when specified
via the ``<units>`` block in the input file when the simulation was originally run).
If that information is present, it will be used by yt.
Otherwise the default unit system will be the code unit
system with conversion of 1 ``code_length`` equalling 1 cm, and so on (given yt's default
cgs/"Gaussian" unit system).  If you would like to provided different
conversions, you may supply conversions for length, time, and mass to ``load``
using the ``units_override`` functionality:

.. code-block:: python

   import yt

   units_override = {
       "length_unit": (1.0, "Mpc"),
       "time_unit": (1.0, "Myr"),
       "mass_unit": (1.0e14, "Msun"),
   }

   ds = yt.load("parthenon.restart.final.rhdf", units_override=units_override)

This means that the yt fields, e.g. ``("gas","density")``,
``("gas","velocity_x")``, ``("gas","magnetic_field_x")``, will be in cgs units
(or whatever unit system was specified), but the AthenaPK fields, e.g.,
``("parthenon","prim_density")``, ``("parthenon","prim_velocity_1")``,
``("parthenon","prim_magnetic_field_1")``, will be in code units.

The default normalization for various magnetic-related quantities such as
magnetic pressure, Alfven speed, etc., as well as the conversion between
magnetic code units and other units, is Gaussian/CGS, meaning that factors
of :math:`4\pi` or :math:`\sqrt{4\pi}` will appear in these quantities, e.g.
:math:`p_B = B^2/8\pi`. To use the Lorentz-Heaviside normalization instead,
in which the factors of :math:`4\pi` are dropped (:math:`p_B = B^2/2), for
example), set ``magnetic_normalization="lorentz_heaviside"`` in the call to
``yt.load``:

.. code-block:: python

    ds = yt.load(
        "parthenon.restart.final.rhdf",
        units_override=units_override,
        magnetic_normalization="lorentz_heaviside",
    )

Alternative values (i.e., overriding the default ones stored in the simulation
output) for the following simulation parameters may be specified
using a ``parameters`` dict, accepting the following keys:

* ``gamma``: ratio of specific heats, Type: Float. If not specified,
  :math:`\gamma = 5/3` is assumed.
* ``mu``: mean molecular weight, Type: Float. If not specified, :math:`\mu = 0.6`
  (for a fully ionized primordial plasma) is assumed.

Other Parthenon based codes
^^^^^^^^^^^^^^^^^^^^^^^^^^^

As mentioned above, a default conversion from code fields to yt fields (e.g.,
from a density field to ``("gas","density")``) is currently not available --
though more specialized frontends may be added in the future.

All raw data of a Parthenon-based simulation output is available through
the ``("parthenon","NAME")`` fields where ``NAME`` varies between codes
and the respective code documentation should be consulted.

One option to manually convert those raw fields to the standard yt fields
is by adding derived fields, e.g., for the field named "``mass.density``"
that is stored in cgs units on disk:

.. code-block:: python

    from yt import derived_field


    @derived_field(name="density", units="g*cm**-3", sampling_type="cell")
    def _density(field, data):
        return data[("parthenon", "mass.density")] * yt.units.g / yt.units.cm**3

Moreover, an ideal equation of state is assumed with the following parameters,
which may be specified using a ``parameters`` dict, accepting the following keys:

* ``gamma``: ratio of specific heats, Type: Float. If not specified,
  :math:`\gamma = 5/3` is assumed.
* ``mu``: mean molecular weight, Type: Float. If not specified, :math:`\mu = 0.6`
  (for a fully ionized primordial plasma) is assumed.


.. _loading-orion-data:

AMReX / BoxLib Data
-------------------

AMReX and BoxLib share a frontend, since
the file format is nearly identical.  yt has been tested with AMReX/BoxLib
data generated by Orion, Nyx, Maestro, Castro, IAMR, and
WarpX. Currently it is cared for by a combination of Andrew Myers,
Matthew Turk, and Mike Zingale.

To load an AMReX/BoxLib dataset, you can use the ``yt.load`` command on
the plotfile directory name.  In general, you must also have the
``inputs`` file in the base directory, but Maestro, Castro, Nyx, and WarpX will get
all the necessary parameter information from the ``job_info`` file in
the plotfile directory.  For instance, if you were in a
directory with the following files:

.. code-block:: none

   inputs
   pltgmlcs5600/
   pltgmlcs5600/Header
   pltgmlcs5600/Level_0
   pltgmlcs5600/Level_0/Cell_H
   pltgmlcs5600/Level_1
   pltgmlcs5600/Level_1/Cell_H
   pltgmlcs5600/Level_2
   pltgmlcs5600/Level_2/Cell_H
   pltgmlcs5600/Level_3
   pltgmlcs5600/Level_3/Cell_H
   pltgmlcs5600/Level_4
   pltgmlcs5600/Level_4/Cell_H

You would feed it the filename ``pltgmlcs5600``:

.. code-block:: python

   import yt

   ds = yt.load("pltgmlcs5600")

For Maestro, Castro, Nyx, and WarpX, you would not need the ``inputs`` file, and you
would have a ``job_info`` file in the plotfile directory.

.. rubric:: Caveats

* yt does not read the Maestro base state (although you can have Maestro
  map it to a full Cartesian state variable before writing the plotfile
  to get around this).  E-mail the dev list if you need this support.
* yt supports AMReX/BoxLib particle data stored in the standard format used
  by Nyx and WarpX, and optionally Castro. It currently does not support the ASCII particle
  data used by Maestro and Castro.
* For Maestro, yt aliases either "tfromp" or "tfromh to" ``temperature``
  depending on the value of the ``use_tfromp`` runtime parameter.
* For Maestro, some velocity fields like ``velocity_magnitude`` or
  ``mach_number`` will always use the on-disk value, and not have yt
  derive it, due to the complex interplay of the base state velocity.

Viewing raw fields in WarpX
^^^^^^^^^^^^^^^^^^^^^^^^^^^

Most AMReX/BoxLib codes output cell-centered data. If the underlying discretization
is not cell-centered, then fields are typically averaged to cell centers before
they are written to plot files for visualization. WarpX, however, has the option
to output the raw (i.e., not averaged to cell centers) data as well.  If you
run your WarpX simulation with ``warpx.plot_raw_fields = 1`` in your inputs
file, then you should get an additional ``raw_fields`` subdirectory inside your
plot file. When you load this dataset, yt will have additional on-disk fields
defined, with the "raw" field type:

.. code-block:: python

    import yt

    ds = yt.load("Laser/plt00015/")
    print(ds.field_list)

The raw fields in WarpX are nodal in at least one direction. We define a field
to be "nodal" in a given direction if the field data is defined at the "low"
and "high" sides of the cell in that direction, rather than at the cell center.
Instead of returning one field value per cell selected, nodal fields return a
number of values, depending on their centering. This centering is marked by
a ``nodal_flag`` that describes whether the fields is nodal in each dimension.
``nodal_flag = [0, 0, 0]`` means that the field is cell-centered, while
``nodal_flag = [0, 0, 1]`` means that the field is nodal in the z direction
and cell centered in the others, i.e. it is defined on the z faces of each cell.
``nodal_flag = [1, 1, 0]`` would mean that the field is centered in the z direction,
but nodal in the other two, i.e. it lives on the four cell edges that are normal
to the z direction.

.. code-block:: python

    ds.index
    ad = ds.all_data()
    print(ds.field_info["raw", "Ex"].nodal_flag)
    print(ad["raw", "Ex"].shape)
    print(ds.field_info["raw", "Bx"].nodal_flag)
    print(ad["raw", "Bx"].shape)
    print(ds.field_info["raw", "Bx"].nodal_flag)
    print(ad["raw", "Bx"].shape)

Here, the field ``('raw', 'Ex')`` is nodal in two directions, so four values per cell
are returned, corresponding to the four edges in each cell on which the variable
is defined. ``('raw', 'Bx')`` is nodal in one direction, so two values are returned
per cell. The standard, averaged-to-cell-centers fields are still available.

Currently, slices and data selection are implemented for nodal fields. Projections,
volume rendering, and many of the analysis modules will not work.

.. _loading-pluto-data:

Pluto Data (AMR)
----------------

Support for Pluto AMR data is provided through the Chombo frontend, which
is currently maintained by Andrew Myers. Pluto output files that don't use
the Chombo HDF5 format are currently not supported. To load a Pluto dataset,
you can use the ``yt.load`` command on the ``*.hdf5`` files. For example, the
KelvinHelmholtz sample dataset is a directory that contains the following
files:

.. code-block:: none

   data.0004.hdf5
   pluto.ini

To load it, you can navigate into that directory and do:

.. code-block:: python

   import yt

   ds = yt.load("data.0004.hdf5")

The ``pluto.ini`` file must also be present alongside the HDF5 file.
By default, all of the Pluto fields will be in code units.


.. _loading-idefix-data:

Idefix, Pluto VTK and Pluto XDMF Data
-------------------------------------

Support for Idefix ``.dmp``, ``.vtk`` data is provided through the ``yt_idefix``
extension.
It also supports monogrid ``.vtk`` and ``.h5`` data from Pluto.
See `the PyPI page <https://pypi.org/project/yt-idefix/>`_ for details.


.. _loading-enzo-data:

Enzo Data
---------

Enzo data is fully supported and cared for by Matthew Turk.  To load an Enzo
dataset, you can use the ``yt.load`` command and provide it the dataset name.
This would be the name of the output file, and it
contains no extension.  For instance, if you have the following files:

.. code-block:: none

   DD0010/
   DD0010/data0010
   DD0010/data0010.index
   DD0010/data0010.cpu0000
   DD0010/data0010.cpu0001
   DD0010/data0010.cpu0002
   DD0010/data0010.cpu0003

You would feed the ``load`` command the filename ``DD0010/data0010`` as
mentioned.

.. code-block:: python

   import yt

   ds = yt.load("DD0010/data0010")

.. rubric:: Caveats

* There are no major caveats for Enzo usage
* Units should be correct, if you utilize standard unit-setting routines.  yt
  will notify you if it cannot determine the units, although this
  notification will be passive.
* 2D and 1D data are supported, but the extraneous dimensions are set to be
  of length 1.0 in "code length" which may produce strange results for volume
  quantities.


Enzo MHDCT data
^^^^^^^^^^^^^^^

The electric and magnetic fields for Enzo MHDCT simulations are defined on cell
faces, unlike other Enzo fields which are defined at cell centers. In yt, we
call face-centered fields like this "nodal".  We define a field to be nodal in
a given direction if the field data is defined at the "low" and "high" sides of
the cell in that direction, rather than at the cell center.  Instead of
returning one field value per cell selected, nodal fields return a number of
values, depending on their centering. This centering is marked by a ``nodal_flag``
that describes whether the fields is nodal in each dimension.  ``nodal_flag =
[0, 0, 0]`` means that the field is cell-centered, while ``nodal_flag = [0, 0,
1]`` means that the field is nodal in the z direction and cell centered in the
others, i.e. it is defined on the z faces of each cell.  ``nodal_flag = [1, 1,
0]`` would mean that the field is centered in the z direction, but nodal in the
other two, i.e. it lives on the four cell edges that are normal to the z
direction.

.. code-block:: python

    ds.index
    ad = ds.all_data()
    print(ds.field_info["enzo", "Ex"].nodal_flag)
    print(ad["enzo", "Ex"].shape)
    print(ds.field_info["enzo", "BxF"].nodal_flag)
    print(ad["enzo", "Bx"].shape)
    print(ds.field_info["enzo", "Bx"].nodal_flag)
    print(ad["enzo", "Bx"].shape)

Here, the field ``('enzo', 'Ex')`` is nodal in two directions, so four values
per cell are returned, corresponding to the four edges in each cell on which the
variable is defined. ``('enzo', 'BxF')`` is nodal in one direction, so two
values are returned per cell. The standard, non-nodal field ``('enzo', 'Bx')``
is also available.

Currently, slices and data selection are implemented for nodal
fields. Projections, volume rendering, and many of the analysis modules will not
work.

.. _loading-enzoe-data:

Enzo-E Data
-----------

Enzo-E outputs have three types of files.

.. code-block:: none

   hello-0200/
   hello-0200/hello-0200.block_list
   hello-0200/hello-0200.file_list
   hello-0200/hello-0200.hello-c0020-p0000.h5

To load Enzo-E data into yt, provide the block list file:

.. code-block:: python

   import yt

   ds = yt.load("hello-0200/hello-0200.block_list")

Mesh and particle fields are fully supported for 1, 2, and 3D datasets.  Enzo-E
supports arbitrary particle types defined by the user.  The available particle
types will be known as soon as the dataset index is created.

.. code-block:: python

   ds = yt.load("ENZOP_DD0140/ENZOP_DD0140.block_list")
   ds.index
   print(ds.particle_types)
   print(ds.particle_type_counts)
   print(ds.r["dark", "particle_position"])

.. _loading-exodusii-data:

Exodus II Data
--------------

.. note::

   To load Exodus II data, you need to have the `netcdf4 <http://unidata.github.io/
   netcdf4-python/>`_ python interface installed.

Exodus II is a file format for Finite Element datasets that is used by the MOOSE
framework for file IO. Support for this format (and for unstructured mesh data in
general) is a new feature as of yt 3.3, so while we aim to fully support it, we
also expect there to be some buggy features at present. Currently, yt can visualize
quads, hexes, triangles, and tetrahedral element types at first order. Additionally,
there is experimental support for the high-order visualization of 20-node hex elements.
Development of more high-order visualization capability is a work in progress.

To load an Exodus II dataset, you can use the ``yt.load`` command on the Exodus II
file:

.. code-block:: python

   import yt

   ds = yt.load("MOOSE_sample_data/out.e-s010", step=0)

Because Exodus II datasets can have multiple steps (which can correspond to time steps,
Picard iterations, non-linear solve iterations, etc...), you can also specify a step
argument when you load an Exodus II data that defines the index at which to look when
you read data from the file. Omitting this argument is the same as passing in 0, and
setting ``step=-1`` selects the last time output in the file.

You can access the connectivity information directly by doing:

.. code-block:: python

   import yt

   ds = yt.load("MOOSE_sample_data/out.e-s010", step=-1)
   print(ds.index.meshes[0].connectivity_coords)
   print(ds.index.meshes[0].connectivity_indices)
   print(ds.index.meshes[1].connectivity_coords)
   print(ds.index.meshes[1].connectivity_indices)

This particular dataset has two meshes in it, both of which are made of 8-node hexes.
yt uses a field name convention to access these different meshes in plots and data
objects. To see all the fields found in a particular dataset, you can do:

.. code-block:: python

   import yt

   ds = yt.load("MOOSE_sample_data/out.e-s010")
   print(ds.field_list)

This will give you a list of field names like ``('connect1', 'diffused')`` and
``('connect2', 'convected')``. Here, fields labelled with ``'connect1'`` correspond to the
first mesh, and those with ``'connect2'`` to the second, and so on. To grab the value
of the ``'convected'`` variable at all the nodes in the first mesh, for example, you
would do:

.. code-block:: python

   import yt

   ds = yt.load("MOOSE_sample_data/out.e-s010")
   ad = ds.all_data()  # geometric selection, this just grabs everything
   print(ad["connect1", "convected"])

In this dataset, ``('connect1', 'convected')`` is nodal field, meaning that the field values
are defined at the vertices of the elements. If we examine the shape of the returned array:

.. code-block:: python

   import yt

   ds = yt.load("MOOSE_sample_data/out.e-s010")
   ad = ds.all_data()
   print(ad["connect1", "convected"].shape)

we see that this mesh has 12480 8-node hexahedral elements, and that we get 8 field values
for each element. To get the vertex positions at which these field values are defined, we
can do, for instance:

.. code-block:: python

   import yt

   ds = yt.load("MOOSE_sample_data/out.e-s010")
   ad = ds.all_data()
   print(ad["connect1", "vertex_x"])

If we instead look at an element-centered field, like ``('connect1', 'conv_indicator')``,
we get:

.. code-block:: python

   import yt

   ds = yt.load("MOOSE_sample_data/out.e-s010")
   ad = ds.all_data()
   print(ad["connect1", "conv_indicator"].shape)

we instead get only one field value per element.

For information about visualizing unstructured mesh data, including Exodus II datasets,
please see :ref:`unstructured-mesh-slices` and :ref:`unstructured_mesh_rendering`.

Displacement Fields
^^^^^^^^^^^^^^^^^^^

Finite element codes often solve for the displacement of each vertex from its
original position as a node variable, rather than updating the actual vertex
positions with time. For analysis and visualization, it is often useful to turn
these displacements on or off, and to be able to scale them arbitrarily to
emphasize certain features of the solution. To allow this, if ``yt`` detects
displacement fields in an Exodus II dataset (using the convention that they will
be named ``disp_x``, ``disp_y``, etc...), it will optionally add these to
the mesh vertex positions for the purposes of visualization. Displacement fields
can be controlled when a dataset is loaded by passing in an optional dictionary
to the ``yt.load`` command. This feature is turned off by default, meaning that
a dataset loaded as

.. code-block:: python

   import yt

   ds = yt.load("MOOSE_sample_data/mps_out.e")

will not include the displacements in the vertex positions. The displacements can
be turned on separately for each mesh in the file by passing in a tuple of
(scale, offset) pairs for the meshes you want to enable displacements for.
For example, the following code snippet turns displacements on for the second
mesh, but not the first:

.. code-block:: python

    import yt

    ds = yt.load(
        "MOOSE_sample_data/mps_out.e",
        step=10,
        displacements={"connect2": (1.0, [0.0, 0.0, 0.0])},
    )

The displacements can also be scaled by an arbitrary factor before they are
added in to the vertex positions. The following code turns on displacements
for both ``connect1`` and ``connect2``, scaling the former by a factor of 5.0
and the later by a factor of 10.0:

.. code-block:: python

    import yt

    ds = yt.load(
        "MOOSE_sample_data/mps_out.e",
        step=10,
        displacements={
            "connect1": (5.0, [0.0, 0.0, 0.0]),
            "connect2": (10.0, [0.0, 0.0, 0.0]),
        },
    )

Finally, we can also apply an arbitrary offset to the mesh vertices after
the scale factor is applied. For example, the following code scales all
displacements in the second mesh by a factor of 5.0, and then shifts
each vertex in the mesh by 1.0 unit in the z-direction:

.. code-block:: python

    import yt

    ds = yt.load(
        "MOOSE_sample_data/mps_out.e",
        step=10,
        displacements={"connect2": (5.0, [0.0, 0.0, 1.0])},
    )

.. _loading-fits-data:

FITS Data
---------

FITS data is *mostly* supported and cared for by John ZuHone. In order to
read FITS data, `AstroPy <https://www.astropy.org>`_ must be installed. FITS
data cubes can be loaded in the same way by yt as other datasets. yt
can read FITS image files that have the following (case-insensitive) suffixes:

* fits
* fts
* fits.gz
* fts.gz

yt can currently read two kinds of FITS files: FITS image files and FITS
binary table files containing positions, times, and energies of X-ray
events. These are described in more detail below.

Types of FITS Datasets Supported by yt
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

yt FITS Data Standard
"""""""""""""""""""""

yt has facilities for creating 2 and 3-dimensional FITS images from derived,
fixed-resolution data products from other datasets. These include images
produced from slices, projections, and 3D covering grids. The resulting
FITS images are fully-describing in that unit, parameter, and coordinate
information is passed from the original dataset. These can be created via the
:class:`~yt.visualization.fits_image.FITSImageData` class and its subclasses.
For information about how to use these special classes, see
:doc:`../visualizing/FITSImageData`.

Once you have produced a FITS file in this fashion, you can load it using
yt and it will be detected as a ``YTFITSDataset`` object, and it can be analyzed
in the same way as any other dataset in yt.

Astronomical Image Data
"""""""""""""""""""""""

These files are one of three types:

* Generic two-dimensional FITS images in sky coordinates
* Three or four-dimensional "spectral cubes"
* *Chandra* event files

These FITS images typically are in celestial or galactic coordinates, and
for 3D spectral cubes the third axis is typically in velocity, wavelength,
or frequency units. For these datasets, since yt does not yet recognize
non-spatial axes, the coordinates are in units of the image pixels. The
coordinates of these pixels in the WCS coordinate systems will be available
in separate fields.

Often, the aspect ratio of 3D spectral cubes can be far from unity. Because yt
sets the pixel scale as the ``code_length``, certain visualizations (such as
volume renderings) may look extended or distended in ways that are
undesirable. To adjust the width in ``code_length`` of the spectral axis, set
``spectral_factor`` equal to a constant which gives the desired scaling, or set
it to ``"auto"`` to make the width the same as the largest axis in the sky
plane:

.. code-block:: python

   ds = yt.load("m33_hi.fits.gz", spectral_factor=0.1)

For 4D spectral cubes, the fourth axis is assumed to be composed of different
fields altogether (e.g., Stokes parameters for radio data).

*Chandra* X-ray event data, which is in tabular form, will be loaded as
particle fields in yt, but a grid will be constructed from the WCS
information in the FITS header. There is a helper function,
``setup_counts_fields``, which may be used to make deposited image fields
from the event data for different energy bands (for an example see
:doc:`../cookbook/fits_xray_images`).

Generic FITS Images
"""""""""""""""""""

If the FITS file contains images but does not have adequate header information
to fall into one of the above categories, yt will still load the data, but
the resulting field and/or coordinate information will necessarily be
incomplete. Field names may not be descriptive, and units may be incorrect. To
get the full use out of yt for FITS files, make sure that the file is sufficiently
self-descripting to fall into one of the above categories.

Making the Most of yt for FITS Data
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

yt will load data without WCS information and/or some missing header keywords,
but the resulting field and/or coordinate information will necessarily be
incomplete. For example, field names may not be descriptive, and units will not
be correct. To get the full use out of yt for FITS files, make sure that for
each image HDU the following standard header keywords have sensible values:

* ``CDELTx``: The pixel width in along axis ``x``
* ``CRVALx``: The coordinate value at the reference position along axis ``x``
* ``CRPIXx``: The reference pixel along axis ``x``
* ``CTYPEx``: The projection type of axis ``x``
* ``CUNITx``: The units of the coordinate along axis ``x``
* ``BTYPE``: The type of the image, this will be used as the field name
* ``BUNIT``: The units of the image

FITS header keywords can easily be updated using AstroPy. For example,
to set the ``BTYPE`` and ``BUNIT`` keywords:

.. code-block:: python

   from astropy.io import fits

   f = fits.open("xray_flux_image.fits", mode="update")
   f[0].header["BUNIT"] = "cts/s/pixel"
   f[0].header["BTYPE"] = "flux"
   f.flush()
   f.close()


FITS Data Decomposition
^^^^^^^^^^^^^^^^^^^^^^^

Though a FITS image is composed of a single array in the FITS file,
upon being loaded into yt it is automatically decomposed into grids:

.. code-block:: python

   import yt

   ds = yt.load("m33_hi.fits")
   ds.print_stats()

.. parsed-literal::

   level  # grids         # cells     # cells^3
   ----------------------------------------------
     0       512          981940800       994
   ----------------------------------------------
             512          981940800

For 3D spectral-cube data, the decomposition into grids will be done along the
spectral axis since this will speed up many common operations for this
particular type of dataset.

yt will generate its own domain decomposition, but the number of grids can be
set manually by passing the ``nprocs`` parameter to the ``load`` call:

.. code-block:: python

   ds = yt.load("m33_hi.fits", nprocs=64)

Fields in FITS Datasets
^^^^^^^^^^^^^^^^^^^^^^^

Multiple fields can be included in a FITS dataset in several different ways.
The first way, and the simplest, is if more than one image HDU is
contained within the same file. The field names will be determined by the
value of ``BTYPE`` in the header, and the field units will be determined by
the value of ``BUNIT``. The second way is if a dataset has a fourth axis,
with each slice along this axis corresponding to a different field. In this
case, the field names will be determined by the value of the ``CTYPE4`` keyword
and the index of the slice. So, for example, if ``BTYPE`` = ``"intensity"`` and
``CTYPE4`` = ``"stokes"``, then the fields will be named
``"intensity_stokes_1"``, ``"intensity_stokes_2"``, and so on.

The third way is if auxiliary files are included along with the main file, like so:

.. code-block:: python

   ds = yt.load("flux.fits", auxiliary_files=["temp.fits", "metal.fits"])

The image blocks in each of these files will be loaded as a separate field,
provided they have the same dimensions as the image blocks in the main file.

Additionally, fields corresponding to the WCS coordinates will be generated
based on the corresponding ``CTYPEx`` keywords. When queried, these fields
will be generated from the pixel coordinates in the file using the WCS
transformations provided by AstroPy.

.. note::

  Each FITS image from a single dataset, whether from one file or from one of
  multiple files, must have the same dimensions and WCS information as the
  first image in the primary file. If this is not the case,
  yt will raise a warning and will not load this field.

.. _additional_fits_options:

Additional Options
^^^^^^^^^^^^^^^^^^

The following are additional options that may be passed to the ``load`` command
when analyzing FITS data:

``nan_mask``
""""""""""""

FITS image data may include ``NaNs``. If you wish to mask this data out,
you may supply a ``nan_mask`` parameter, which may either be a
single floating-point number (applies to all fields) or a Python dictionary
containing different mask values for different fields:

.. code-block:: python

   # passing a single float for all images
   ds = yt.load("m33_hi.fits", nan_mask=0.0)

   # passing a dict
   ds = yt.load("m33_hi.fits", nan_mask={"intensity": -1.0, "temperature": 0.0})

``suppress_astropy_warnings``
"""""""""""""""""""""""""""""

Generally, AstroPy may generate a lot of warnings about individual FITS
files, many of which you may want to ignore. If you want to see these
warnings, set ``suppress_astropy_warnings = False``.

Miscellaneous Tools for Use with FITS Data
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

A number of tools have been prepared for use with FITS data that enhance yt's
visualization and analysis capabilities for this particular type of data. These
are included in the ``yt.frontends.fits.misc`` module, and can be imported like
so:

.. code-block:: python

  from yt.frontends.fits.misc import PlotWindowWCS, ds9_region, setup_counts_fields

``setup_counts_fields``
"""""""""""""""""""""""

This function can be used to create image fields from X-ray counts data in
different energy bands:

.. code-block:: python

  ebounds = [(0.1, 2.0), (2.0, 5.0)]  # Energies are in keV
  setup_counts_fields(ds, ebounds)

which would make two fields, ``"counts_0.1-2.0"`` and ``"counts_2.0-5.0"``,
and add them to the field registry for the dataset ``ds``.

``ds9_region``
""""""""""""""

This function takes a `ds9 <http://ds9.si.edu/site/Home.html>`_ region and
creates a "cut region" data container from it, that can be used to select
the cells in the FITS dataset that fall within the region. To use this
functionality, the `regions <https://github.com/astropy/regions/>`_
package must be installed.

.. code-block:: python

  ds = yt.load("m33_hi.fits")
  circle_region = ds9_region(ds, "circle.reg")
  print(circle_region.quantities.extrema("flux"))


``PlotWindowWCS``
"""""""""""""""""

This class takes a on-axis ``SlicePlot`` or ``ProjectionPlot`` of FITS
data and adds celestial coordinates to the plot axes. To use it, a
version of AstroPy >= 1.3 must be installed.

.. code-block:: python

  wcs_slc = PlotWindowWCS(slc)
  wcs_slc.show()  # for Jupyter notebooks
  wcs_slc.save()

``WCSAxes`` is still in an experimental state, but as its functionality
improves it will be utilized more here.

``create_spectral_slabs``
"""""""""""""""""""""""""

.. note::

  The following functionality requires the
  `spectral-cube <https://spectral-cube.readthedocs.io/en/latest/>`_ library to be
  installed.

If you have a spectral intensity dataset of some sort, and would like to
extract emission in particular slabs along the spectral axis of a certain
width, ``create_spectral_slabs`` can be used to generate a dataset with
these slabs as different fields. In this example, we use it to extract
individual lines from an intensity cube:

.. code-block:: python

  slab_centers = {
      "13CN": (218.03117, "GHz"),
      "CH3CH2CHO": (218.284256, "GHz"),
      "CH3NH2": (218.40956, "GHz"),
  }
  slab_width = (0.05, "GHz")
  ds = create_spectral_slabs(
      "intensity_cube.fits", slab_centers, slab_width, nan_mask=0.0
  )

All keyword arguments to ``create_spectral_slabs`` are passed on to ``load`` when
creating the dataset (see :ref:`additional_fits_options` above). In the
returned dataset, the different slabs will be different fields, with the field
names taken from the keys in ``slab_centers``. The WCS coordinates on the
spectral axis are reset so that the center of the domain along this axis is
zero, and the left and right edges of the domain along this axis are
:math:`\pm` ``0.5*slab_width``.

Examples of Using FITS Data
^^^^^^^^^^^^^^^^^^^^^^^^^^^

The following Jupyter notebooks show examples of working with FITS data in yt,
which we recommend you look at in the following order:

* :doc:`../cookbook/fits_radio_cubes`
* :doc:`../cookbook/fits_xray_images`
* :doc:`../visualizing/FITSImageData`

.. _loading-flash-data:

FLASH Data
----------

FLASH HDF5 data is *mostly* supported and cared for by John ZuHone.  To load a
FLASH dataset, you can use the ``yt.load`` command and provide it the file name of
a plot file, checkpoint file, or particle file. Particle files require special handling
depending on the situation, the main issue being that they typically lack grid information.
The first case is when you have a plotfile and a particle file that you would like to
load together. In the simplest case, this occurs automatically. For instance, if you
were in a directory with the following files:

.. code-block:: none

   radio_halo_1kpc_hdf5_plt_cnt_0100 # plotfile
   radio_halo_1kpc_hdf5_part_0100 # particle file

where the plotfile and the particle file were created at the same time (therefore having
particle data consistent with the grid structure of the former). Notice also that the
prefix ``"radio_halo_1kpc_"`` and the file number ``100`` are the same. In this special case,
the particle file will be loaded automatically when ``yt.load`` is called on the plotfile.
This also works when loading a number of files in a time series.

If the two files do not have the same prefix and number, but they nevertheless have the same
grid structure and are at the same simulation time, the particle data may be loaded with the
``particle_filename`` optional argument to ``yt.load``:

.. code-block:: python

    import yt

    ds = yt.load(
        "radio_halo_1kpc_hdf5_plt_cnt_0100",
        particle_filename="radio_halo_1kpc_hdf5_part_0100",
    )

However, if you don't have a corresponding plotfile for a particle file, but would still
like to load the particle data, you can still call ``yt.load`` on the file. However, the
grid information will not be available, and the particle data will be loaded in a fashion
similar to other particle-based datasets in yt.

Mean Molecular Weight and Number Density Fields
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

The way the mean molecular weight and number density fields are defined depends on
what type of simulation you are running. If you are running a simulation without
species and a :math:`\gamma`-law equation of state, then the mean molecular weight
is defined using the ``eos_singleSpeciesA`` parameter in the FLASH dataset. If you
have multiple species and your dataset contains the FLASH field ``"abar"``, then
this is used as the mean molecular weight. In either case, the number density field
is calculated using this weight.

If you are running a FLASH simulation where the fields ``"sumy"`` and ``"ye"`` are
present, Then the mean molecular weight is the inverse of ``"sumy"``, and the fields
``"El_number_density"``, ``"ion_number_density"``, and ``"number_density"`` are
defined using the following mathematical definitions:

* ``"El_number_density"`` :math:`n_e = N_AY_e\rho`
* ``"ion_number_density"`` :math:`n_i = N_A\rho/\bar{A}`
* ``"number_density"`` :math:`n = n_e + n_i`

where :math:`n_e` and :math:`n_i` are the electron and ion number densities,
:math:`\rho` is the mass density, :math:`Y_e` is the electron number per baryon,
:math:`\bar{A}` is the mean molecular weight, and :math:`N_A` is Avogadro's number.

.. rubric:: Caveats

* Please be careful that the units are correctly utilized; yt assumes cgs by default, but conversion to
  other unit systems is also possible.

.. _loading-gadget-data:

Gadget Data
-----------

.. note::

   For more information about how yt indexes and reads particle data, set the
   section :ref:`demeshening`.

yt has support for reading Gadget data in both raw binary and HDF5 formats.  It
is able to access the particles as it would any other particle dataset, and it
can apply smoothing kernels to the data to produce both quantitative analysis
and visualization. See :ref:`loading-sph-data` for more details and
:doc:`../cookbook/yt_gadget_analysis` for a detailed example
of loading, analyzing, and visualizing a Gadget dataset.  An example which
makes use of a Gadget snapshot from the OWLS project can be found in
:doc:`../cookbook/yt_gadget_owls_analysis`.

.. note::

   If you are loading a multi-file dataset with Gadget, you can either supply the *zeroth*
   file to the ``load`` command or the directory containing all of the files.
   For instance, to load the *zeroth* file: ``yt.load("snapshot_061.0.hdf5")`` . To
   give just the directory, if you have all of your ``snapshot_000.*`` files in a directory
   called ``snapshot_000``, do: ``yt.load("/path/to/snapshot_000")``.

Gadget data in HDF5 format can be loaded with the ``load`` command:

.. code-block:: python

   import yt

   ds = yt.load("snapshot_061.hdf5")

Gadget data in raw binary format can also be loaded with the ``load`` command.
This is supported for snapshots created with the ``SnapFormat`` parameter
set to 1 or 2.

.. code-block:: python

   import yt

   ds = yt.load("snapshot_061")

.. _particle-bbox:

Units and Bounding Boxes
^^^^^^^^^^^^^^^^^^^^^^^^

There are two additional pieces of information that may be needed.  If your
simulation is cosmological, yt can often guess the bounding box and the units of
the simulation.  However, for isolated simulations and for cosmological
simulations with non-standard units, these must be supplied by the user.  For
example, if a length unit of 1.0 corresponds to a kiloparsec, you can supply
this in the constructor.  yt can accept units such as ``Mpc``, ``kpc``, ``cm``,
``Mpccm/h`` and so on.  In particular, note that ``Mpc/h`` and ``Mpccm/h``
(``cm`` for comoving here) are usable unit definitions.

yt will attempt to use units for ``mass``, ``length``, ``time``, and
``magnetic`` as supplied in the argument ``unit_base``.  The ``bounding_box``
argument is a list of two-item tuples or lists that describe the left and right
extents of the particles. In this example we load a dataset with a custom bounding
box and units.

.. code-block:: python

   bbox = [[-600.0, 600.0], [-600.0, 600.0], [-600.0, 600.0]]
   unit_base = {
       "length": (1.0, "kpc"),
       "velocity": (1.0, "km/s"),
       "mass": (1.0, "Msun"),
   }

   ds = yt.load("snap_004", unit_base=unit_base, bounding_box=bbox)

.. warning::

    If a ``bounding_box`` argument is supplied and the original dataset
    has periodic boundaries, it will no longer have periodic boundaries
    after the bounding box is applied.

In addition, you can use ``UnitLength_in_cm``, ``UnitVelocity_in_cm_per_s``,
``UnitMass_in_g``, and ``UnitMagneticField_in_gauss`` as keys for the
``unit_base`` dictionary. These name come from the names used in the Gadget
runtime parameter file. This example will initialize a dataset with the same
units as the example above:

.. code-block:: python

  unit_base = {
      "UnitLength_in_cm": 3.09e21,
      "UnitVelocity_in_cm_per_s": 1e5,
      "UnitMass_in_g": 1.989e33,
  }

  ds = yt.load("snap_004", unit_base=unit_base, bounding_box=bbox)

.. _gadget-field-spec:

Field Specifications
^^^^^^^^^^^^^^^^^^^^

Binary Gadget outputs often have additional fields or particle types that are
non-standard from the default Gadget distribution format.  These can be
specified in the call to ``GadgetDataset`` by either supplying one of the
sets of field specifications as a string or by supplying a field specification
itself.  As an example, yt has built-in definitions for ``default`` (the
default), ``agora_unlv``, ``group0000``, and ``magneticum_box2_hr``. They can
be used like this:

.. code-block:: python

   ds = yt.load("snap_100", field_spec="group0000")

Field specifications must be tuples, and must be of this format:

.. code-block:: python

   default = (
       "Coordinates",
       "Velocities",
       "ParticleIDs",
       "Mass",
       ("InternalEnergy", "Gas"),
       ("Density", "Gas"),
       ("SmoothingLength", "Gas"),
   )

This is the default specification used by the Gadget frontend.  It means that
the fields are, in order, Coordinates, Velocities, ParticleIDs, Mass, and the
fields InternalEnergy, Density and SmoothingLength *only* for Gas particles.
So for example, if you have defined a Metallicity field for the particle type
Halo, which comes right after ParticleIDs in the file, you could define it like
this:

.. code-block:: python

   import yt

   my_field_def = (
       "Coordinates",
       "Velocities",
       "ParticleIDs",
       ("Metallicity", "Halo"),
       "Mass",
       ("InternalEnergy", "Gas"),
       ("Density", "Gas"),
       ("SmoothingLength", "Gas"),
   )

   ds = yt.load("snap_100", field_spec=my_field_def)

To save time, you can utilize the plugins file for yt and use it to add items
to the dictionary where these definitions are stored.  You could do this like
so:

.. code-block:: python

   import yt
   from yt.frontends.gadget.definitions import gadget_field_specs

   gadget_field_specs["my_field_def"] = my_field_def

   ds = yt.load("snap_100", field_spec="my_field_def")

Please also feel free to issue a pull request with any new field
specifications, as we're happy to include them in the main distribution!

Magneticum halos downloaded using the SIMCUT method from the
`Cosmological Web Portal <https://c2papcosmosim.uc.lrz.de/>`_ can be loaded
using the ``"magneticum_box2_hr"`` value for the ``field_spec`` argumemt.
However, this is strictly only true for halos downloaded after May 14, 2021,
since before then the halos had the following signature (with the ``"StellarAge"``
field for the ``"Bndry"`` particles missing):

.. code-block:: python

    magneticum_box2_hr = (
        "Coordinates",
        "Velocities",
        "ParticleIDs",
        "Mass",
        ("InternalEnergy", "Gas"),
        ("Density", "Gas"),
        ("SmoothingLength", "Gas"),
        ("ColdFraction", "Gas"),
        ("Temperature", "Gas"),
        ("StellarAge", "Stars"),
        "Potential",
        ("InitialMass", "Stars"),
        ("ElevenMetalMasses", ("Gas", "Stars")),
        ("StarFormationRate", "Gas"),
        ("TrueMass", "Bndry"),
        ("AccretionRate", "Bndry"),
    )

and before November 20, 2020, the field specification had the ``"ParticleIDs"`` and ``"Mass"``
fields swapped:

.. code-block:: python

    magneticum_box2_hr = (
        "Coordinates",
        "Velocities",
        "Mass",
        "ParticleIDs",
        ("InternalEnergy", "Gas"),
        ("Density", "Gas"),
        ("SmoothingLength", "Gas"),
        ("ColdFraction", "Gas"),
        ("Temperature", "Gas"),
        ("StellarAge", "Stars"),
        "Potential",
        ("InitialMass", "Stars"),
        ("ElevenMetalMasses", ("Gas", "Stars")),
        ("StarFormationRate", "Gas"),
        ("TrueMass", "Bndry"),
        ("AccretionRate", "Bndry"),
    )

In general, to determine what fields are in your Gadget binary file, it may
be useful to inspect them with the `g3read <https://github.com/aragagnin/g3read>`_
code first.

.. _gadget-species-fields:

Gadget Species Fields
^^^^^^^^^^^^^^^^^^^^^

Gas and star particles in Gadget binary and HDF5 files can have fields
corresponding to different species fractions or masses. The following field
definitions are supported, in the sense that they are automatically detected
and will be used to construct species fractions, densities, and number densities
after the manner specified in :ref:`species-fields`. For Gadget binary files, the
following fields (as specified in the ``field_spec`` argument) are supported:

* ``"ElevenMetalMasses"``: 11 mass fields: He, C, Ca, O, N, Ne, Mg, S, Si, Fe, Ej
* ``"FourMetalFractions"``: 4 fraction fields: C, O, Si, Fe

For Gadget HDF5 files, the fields ``"MetalMasses"`` or ``"Mass Of Metals"`` are
supported, with the number of species determined by the size of the dataset's
second dimension in the file. Four different numbers of species in these fields
are supported, corresponding to the following species:

* 7, corresponding to C, N, O, Mg, Si, Fe, Ej
* 8, corresponding to He, C, O, Mg, S, Si, Fe, Ej
* 11, corresponding to He, C, Ca, O, N, Ne, Mg, S, Si, Fe, Ej
* 15, corresponding to He, C, Ca, O, N, Ne, Mg, S, Si, Fe, Na, Al, Ar, Ni, Ej

Two points should be noted about the above: the "Ej" species corresponds to the
remaining mass of elements heavier than hydrogen and not enumerated, and in the
case of 8, 11, and 15 species, hydrogen is assumed to be the remaining mass
fraction.

Finally, for Gadget HDF5 files, element fields which are of the form
``"X_fraction"`` are also suppoted, and correspond to the mass fraction of element
X.

.. _gadget-long-ids:

Long Particle IDs
^^^^^^^^^^^^^^^^^

Some Gadget binary files use 64-bit integers for particle IDs. To use these,
simply set ``long_ids=True`` when loading the dataset:

.. code-block:: python

    import yt

    ds = yt.load("snap_100", long_ids=True)

This is needed, for example, for Magneticum halos downloaded using the SIMCUT
method from the `Cosmological Web Portal <https://c2papcosmosim.uc.lrz.de/>`_

.. _gadget-ptype-spec:

Particle Type Definitions
^^^^^^^^^^^^^^^^^^^^^^^^^

In some cases, research groups add new particle types or re-order them.  You
can supply alternate particle types by using the keyword ``ptype_spec`` to the
``GadgetDataset`` call.  The default for Gadget binary data is:

.. code-block:: python

   ("Gas", "Halo", "Disk", "Bulge", "Stars", "Bndry")

You can specify alternate names, but note that this may cause problems with the
field specification if none of the names match old names.

.. _gadget-header-spec:

Header Specification
^^^^^^^^^^^^^^^^^^^^

If you have modified the header in your Gadget binary file, you can specify an
alternate header specification with the keyword ``header_spec``.  This can
either be a list of strings corresponding to individual header types known to
yt, or it can be a combination of strings and header specifications.  The
default header specification (found in ``yt/frontends/sph/definitions.py``) is:

.. code-block:: python

   default = (
       ("Npart", 6, "i"),
       ("Massarr", 6, "d"),
       ("Time", 1, "d"),
       ("Redshift", 1, "d"),
       ("FlagSfr", 1, "i"),
       ("FlagFeedback", 1, "i"),
       ("Nall", 6, "i"),
       ("FlagCooling", 1, "i"),
       ("NumFiles", 1, "i"),
       ("BoxSize", 1, "d"),
       ("Omega0", 1, "d"),
       ("OmegaLambda", 1, "d"),
       ("HubbleParam", 1, "d"),
       ("FlagAge", 1, "i"),
       ("FlagMEtals", 1, "i"),
       ("NallHW", 6, "i"),
       ("unused", 16, "i"),
   )

These items will all be accessible inside the object ``ds.parameters``, which
is a dictionary.  You can add combinations of new items, specified in the same
way, or alternately other types of headers.  The other string keys defined are
``pad32``, ``pad64``, ``pad128``, and ``pad256`` each of which corresponds to
an empty padding in bytes.  For example, if you have an additional 256 bytes of
padding at the end, you can specify this with:

.. code-block:: python

   header_spec = "default+pad256"

Note that a single string like this means a single header block.  To specify
multiple header blocks, use a list of strings instead:

.. code-block:: python

  header_spec = ["default", "pad256"]

This can then be supplied to the constructor.  Note that you can also define
header items manually, for instance with:

.. code-block:: python

   from yt.frontends.gadget.definitions import gadget_header_specs

   gadget_header_specs["custom"] = (("some_value", 8, "d"), ("another_value", 1, "i"))
   header_spec = "default+custom"

The letters correspond to data types from the Python struct module.  Please
feel free to submit alternate header types to the main yt repository.

.. _specifying-gadget-units:

Specifying Units
^^^^^^^^^^^^^^^^

If you are running a cosmology simulation, yt will be able to guess the units
with some reliability.  However, if you are not and you do not specify a
dataset, yt will not be able to and will use the defaults of length
being 1.0 Mpc/h (comoving), velocity being in cm/s, and mass being in 10^10
Msun/h.  You can specify alternate units by supplying the ``unit_base`` keyword
argument of this form:

.. code-block:: python

   unit_base = {"length": (1.0, "cm"), "mass": (1.0, "g"), "time": (1.0, "s")}

yt will utilize length, mass and time to set up all other units.

.. _loading-swift-data:

SWIFT Data
----------

.. note::

   For more information about how yt indexes and reads particle data, set the
   section :ref:`demeshening`.

yt has support for reading in SWIFT data from the HDF5 file format. It is able
to access all particles and fields which are stored on-disk and it is also able
to generate derived fields, i.e, linear momentum from on-disk fields.

It is also possible to smooth the data onto a grid or an octree. This
interpolation can be done using an SPH kernel using either the scatter or gather
approach. The SWIFT frontend is supported and cared for by Ashley Kelly.

SWIFT data in HDF5 format can be loaded with the ``load`` command:

.. code-block:: python

   import yt

   ds = yt.load("EAGLE_6/eagle_0005.hdf5")

.. _arepo-data:

Arepo Data
----------

.. note::

   For more information about how yt indexes and reads discrete data, set the
   section :ref:`demeshening`.

Arepo data is currently treated as SPH data. The gas cells have smoothing lengths
assigned using the following prescription for a given gas cell :math:`i`:

.. math::

    h_{\rm sml} = \alpha\left(\frac{3}{4\pi}\frac{m_i}{\rho_i}\right)^{1/3}

where :math:`\alpha` is a constant factor. By default, :math:`\alpha = 2`. In
practice, smoothing lengths are only used for creating slices and projections,
and this value of :math:`\alpha` works well for this purpose. However, this
value can be changed when loading an Arepo dataset by setting the
``smoothing_factor`` parameter:

.. code-block:: python

   import yt

   ds = yt.load("snapshot_100.hdf5", smoothing_factor=1.5)

Currently, only Arepo HDF5 snapshots are supported.

If the "GFM" metal fields are present in your dataset, they will be loaded in
and aliased to the appropriate species fields in the ``"GFM_Metals"`` field
on-disk. For more information, see the
`Illustris TNG documentation <http://www.tng-project.org/data/docs/specifications/#sec1b>`_.

If passive scalar fields are present in your dataset, they will be loaded in
and aliased to fields with the naming convention ``"PassiveScalars_XX"`` where
``XX`` is the number of the passive scalar array, e.g. ``"00"``, ``"01"``, etc.

HDF5 snapshots will be detected as Arepo data if they have the ``"GFM_Metals"``
field present, or if they have a ``"Config"`` group in the header. If neither of
these are the case, and your snapshot *is* Arepo data, you can fix this with the
following:

.. code-block:: python

    import h5py

    with h5py.File(saved_filename, "r+") as f:
        f.create_group("Config")
        f["/Config"].attrs["VORONOI"] = 1

.. _loading-gamer-data:

GAMER Data
----------

GAMER HDF5 data is supported and cared for by Hsi-Yu Schive and John ZuHone.
Datasets using hydrodynamics, particles, magnetohydrodynamics, wave dark matter,
and special relativistic hydrodynamics are supported. You can load the data like
this:

.. code-block:: python

   import yt

   ds = yt.load("InteractingJets/jet_000002")

For simulations without units (i.e., ``OPT__UNIT = 0``), you can supply conversions
for length, time, and mass to ``load`` using the ``units_override``
functionality:

.. code-block:: python

   import yt

   code_units = {
       "length_unit": (1.0, "kpc"),
       "time_unit": (3.08567758096e13, "s"),
       "mass_unit": (1.4690033e36, "g"),
   }
   ds = yt.load("InteractingJets/jet_000002", units_override=code_units)

Particle data are supported and are always stored in the same file as the grid
data.

For special relativistic simulations, both the gamma-law and Taub-Mathews EOSes
are supported, and the following fields are defined:

* ``("gas", "density")``: Comoving rest-mass density :math:`\rho`
* ``("gas", "frame_density")``: Coordinate-frame density :math:`D = \gamma\rho`
* ``("gas", "gamma")``: Ratio of specific heats :math:`\Gamma`
* ``("gas", "four_velocity_[txyz]")``: Four-velocity fields :math:`U_t, U_x, U_y, U_z`
* ``("gas", "lorentz_factor")``: Lorentz factor :math:`\gamma = \sqrt{1+U_iU^i/c^2}`
  (where :math:`i` runs over the spatial indices)
* ``("gas", "specific_reduced_enthalpy")``: Specific reduced enthalpy :math:`\tilde{h} = \epsilon + p/\rho`
* ``("gas", "specific_enthalpy")``: Specific enthalpy :math:`h = c^2 + \epsilon + p/\rho`

These, and other fields following them (3-velocity, energy densities, etc.) are
computed in the same manner as in the
`GAMER-SR paper <https://ui.adsabs.harvard.edu/abs/2021MNRAS.504.3298T/abstract>`_
to avoid catastrophic cancellations.

All of the special relativistic fields will only be available if the ``Temp`` and
``Enth`` fields are present in the dataset, which can be ensured if the runtime
options ``OPT__OUTPUT_TEMP = 1`` and ``OPT__OUTPUT_ENTHALPY  = 1`` are set in the
``Input__Parameter`` file when running the simulation. This greatly speeds up
calculations of the above derived fields in yt.

.. rubric:: Caveats

* GAMER data in raw binary format (i.e., ``OPT__OUTPUT_TOTAL = "C-binary"``) is not
  supported.

.. _loading-amr-data:

Generic AMR Data
----------------

See :doc:`Loading_Generic_Array_Data` and
:func:`~yt.frontends.stream.data_structures.load_amr_grids` for more detail.

.. note::

   It is now possible to load data using *only functions*, rather than using the
   fully-in-memory method presented here.  For more information and examples,
   see :doc:`Loading_Data_via_Functions`.

It is possible to create native yt dataset from Python's dictionary
that describes set of rectangular patches of data of possibly varying
resolution.

.. code-block:: python

   import yt

   grid_data = [
       dict(
           left_edge=[0.0, 0.0, 0.0],
           right_edge=[1.0, 1.0, 1.0],
           level=0,
           dimensions=[32, 32, 32],
       ),
       dict(
           left_edge=[0.25, 0.25, 0.25],
           right_edge=[0.75, 0.75, 0.75],
           level=1,
           dimensions=[32, 32, 32],
       ),
   ]

   for g in grid_data:
       g["density"] = np.random.random(g["dimensions"]) * 2 ** g["level"]

   ds = yt.load_amr_grids(grid_data, [32, 32, 32], 1.0)

.. note::

   yt only supports a block structure where the grid edges on the ``n``-th
   refinement level are aligned with the cell edges on the ``n-1``-th level.

Particle fields are supported by adding 1-dimensional arrays to each
``grid``'s dict:

.. code-block:: python

   for g in grid_data:
       g["particle_position_x"] = np.random.random(size=100000)

.. rubric:: Caveats

* Some functions may behave oddly, and parallelism will be disappointing or
  non-existent in most cases.
* No consistency checks are performed on the index
* Data must already reside in memory.
* Consistency between particle positions and grids is not checked;
  ``load_amr_grids`` assumes that particle positions associated with one grid are
  not bounded within another grid at a higher level, so this must be
  ensured by the user prior to loading the grid data.

Generic Array Data
------------------

See :doc:`Loading_Generic_Array_Data` and
:func:`~yt.frontends.stream.data_structures.load_uniform_grid` for more detail.

Even if your data is not strictly related to fields commonly used in
astrophysical codes or your code is not supported yet, you can still feed it to
yt to use its advanced visualization and analysis facilities. The only
requirement is that your data can be represented as one or more uniform, three
dimensional numpy arrays. Assuming that you have your data in ``arr``,
the following code:

.. code-block:: python

   import yt

   data = dict(Density=arr)
   bbox = np.array([[-1.5, 1.5], [-1.5, 1.5], [1.5, 1.5]])
   ds = yt.load_uniform_grid(data, arr.shape, 3.08e24, bbox=bbox, nprocs=12)

will create yt-native dataset ``ds`` that will treat your array as
density field in cubic domain of 3 Mpc edge size (3 * 3.08e24 cm) and
simultaneously divide the domain into 12 chunks, so that you can take advantage
of the underlying parallelism.

Particle fields are added as one-dimensional arrays in a similar manner as the
three-dimensional grid fields:

.. code-block:: python

   import yt

   data = dict(
       Density=dens,
       particle_position_x=posx_arr,
       particle_position_y=posy_arr,
       particle_position_z=posz_arr,
   )
   bbox = np.array([[-1.5, 1.5], [-1.5, 1.5], [1.5, 1.5]])
   ds = yt.load_uniform_grid(data, arr.shape, 3.08e24, bbox=bbox, nprocs=12)

where in this example the particle position fields have been assigned. If no
particle fields are supplied, then the number of particles is assumed to be
zero.

.. rubric:: Caveats

* Particles may be difficult to integrate.
* Data must already reside in memory.

.. _loading-semi-structured-mesh-data:

Semi-Structured Grid Data
-------------------------

.. note::

   With the release of yt-4.1, functionality has been added to allow loading
   "stretched" grids that are operated on in a more efficient way.  This is done
   via the :func:`~yt.frontends.stream.data_structures.load_uniform_grid`
   operation, supplying the ``cell_widths`` argument.  Using the hexahedral mesh
   is no longer suggested for situations where the mesh can be adequately
   described with three arrays of cell widths.

   See :ref:`loading-stretched-grids` for more information.

See :doc:`Loading_Generic_Array_Data`,
:func:`~yt.frontends.stream.data_structures.hexahedral_connectivity`,
:func:`~yt.frontends.stream.data_structures.load_hexahedral_mesh` for
more detail.

In addition to uniform grids as described above, you can load in data
with non-uniform spacing between datapoints. To load this type of
data, you must first specify a hexahedral mesh, a mesh of six-sided
cells, on which it will live. You define this by specifying the x,y,
and z locations of the corners of the hexahedral cells. The following
code:

.. code-block:: python

   import numpy

   import yt

   xgrid = numpy.array([-1, -0.65, 0, 0.65, 1])
   ygrid = numpy.array([-1, 0, 1])
   zgrid = numpy.array([-1, -0.447, 0.447, 1])

   coordinates, connectivity = yt.hexahedral_connectivity(xgrid, ygrid, zgrid)

will define the (x,y,z) coordinates of the hexahedral cells and
information about that cell's neighbors such that the cell corners
will be a grid of points constructed as the Cartesian product of
xgrid, ygrid, and zgrid.

Then, to load your data, which should be defined on the interiors of
the hexahedral cells, and thus should have the shape,
``(len(xgrid)-1, len(ygrid)-1, len(zgrid)-1)``, you can use the following code:

.. code-block:: python

   bbox = numpy.array(
       [
           [numpy.min(xgrid), numpy.max(xgrid)],
           [numpy.min(ygrid), numpy.max(ygrid)],
           [numpy.min(zgrid), numpy.max(zgrid)],
       ]
   )
   data = {"density": arr}
   ds = yt.load_hexahedral_mesh(data, conn, coords, 1.0, bbox=bbox)

to load your data into the dataset ``ds`` as described above, where we
have assumed your data is stored in the three-dimensional array
``arr``.

.. rubric:: Caveats

* Integration is not implemented.
* Some functions may behave oddly or not work at all.
* Data must already reside in memory.

.. _loading-stretched-grids:

Stretched Grid Data
-------------------

.. warning::

   API consistency for loading stretched grids is not guaranteed until at least
   yt 4.2!  There may be changes in between then and now, as this is a
   preliminary feature.

With version 4.1, yt has the ability to specify cell widths for grids.  This
allows situations where a grid has a functional form for cell widths, or where
widths are provided in advance.

.. note::

   At present, stretched grids are restricted to a single level of refinement.
   Future versions of yt will have more complete and flexible support!

To load a stretched grid, you use the standard (and now rather-poorly named)
``load_uniform_grid`` function, but supplying a ``cell_widths`` argument.  This
argument should be a list of three arrays, corresponding to the first, second
and third index-direction cell widths.  (For instance, in a "standard"
cartesian dataset, this would be x, y, z.)

This script,
demonstrates loading a simple "random" dataset with a random set of cell-widths.

.. code:: python

   import yt
   import numpy as np

   N = 8

   data = {"density": np.random.random((N, N, N))}

   cell_widths = []
   for i in range(3):
       widths = np.random.random(N)
       widths /= widths.sum()  # Normalize to span 0 .. 1.
       cell_widths.append(widths)

   ds = yt.load_uniform_grid(
       data,
       [N, N, N],
       bbox=np.array([[0.0, 1.0], [0.0, 1.0], [0.0, 1.0]]),
       cell_widths=cell_widths,
   )


This can be modified to load data from a file, as well as to use more (or
fewer) cells. Like with a standard uniform grid, providing ``nprocs>1`` will
decompose the domain into multiple grids (without refinement).

Unstructured Grid Data
----------------------

See :doc:`Loading_Generic_Array_Data`,
:func:`~yt.frontends.stream.data_structures.load_unstructured_mesh` for
more detail.

In addition to the above grid types, you can also load data stored on
unstructured meshes. This type of mesh is used, for example, in many
finite element calculations. Currently, hexahedral and tetrahedral
mesh elements are supported.

To load an unstructured mesh, you need to specify the following. First,
you need to have a coordinates array, which should be an (L, 3) array
that stores the (x, y, z) positions of all of the vertices in the mesh.
Second, you need to specify a connectivity array, which describes how
those vertices are connected into mesh elements. The connectivity array
should be (N, M), where N is the number of elements and M is the
connectivity length, i.e. the number of vertices per element. Finally,
you must also specify a data dictionary, where the keys should be
the names of the fields and the values should be numpy arrays that
contain the field data. These arrays can either supply the cell-averaged
data for each element, in which case they would be (N, 1), or they
can have node-centered data, in which case they would also be (N, M).

Here is an example of how to load an in-memory, unstructured mesh dataset:

.. code-block:: python

   import numpy as np

   import yt

   coords = np.array([[0.0, 0.0], [1.0, 0.0], [1.0, 1.0], [0.0, 1.0]], dtype=np.float64)

   connect = np.array([[0, 1, 3], [1, 2, 3]], dtype=np.int64)

   data = {}
   data["connect1", "test"] = np.array(
       [[0.0, 1.0, 3.0], [1.0, 2.0, 3.0]], dtype=np.float64
   )

Here, we have made up a simple, 2D unstructured mesh dataset consisting of two
triangles and one node-centered data field. This data can be loaded as an in-memory
dataset as follows:

.. code-block:: python

    ds = yt.load_unstructured_mesh(connect, coords, data)

The in-memory dataset can then be visualized as usual, e.g.:

.. code-block:: python

    sl = yt.SlicePlot(ds, "z", ("connect1", "test"))
    sl.annotate_mesh_lines()

Note that load_unstructured_mesh can take either a single mesh or a list of meshes.
To load multiple meshes, you can do:

.. code-block:: python

   import numpy as np

   import yt

   coordsMulti = np.array(
       [[0.0, 0.0], [1.0, 0.0], [1.0, 1.0], [0.0, 1.0]], dtype=np.float64
   )

   connect1 = np.array(
       [
           [0, 1, 3],
       ],
       dtype=np.int64,
   )
   connect2 = np.array(
       [
           [1, 2, 3],
       ],
       dtype=np.int64,
   )

   data1 = {}
   data2 = {}
   data1["connect1", "test"] = np.array(
       [
           [0.0, 1.0, 3.0],
       ],
       dtype=np.float64,
   )
   data2["connect2", "test"] = np.array(
       [
           [1.0, 2.0, 3.0],
       ],
       dtype=np.float64,
   )

   connectList = [connect1, connect2]
   dataList = [data1, data2]

   ds = yt.load_unstructured_mesh(connectList, coordsMulti, dataList)

   # only plot the first mesh
   sl = yt.SlicePlot(ds, "z", ("connect1", "test"))

   # only plot the second
   sl = yt.SlicePlot(ds, "z", ("connect2", "test"))

   # plot both
   sl = yt.SlicePlot(ds, "z", ("all", "test"))

Note that you must respect the field naming convention that fields on the first
mesh will have the type ``connect1``, fields on the second will have ``connect2``, etc...

.. rubric:: Caveats

* Integration is not implemented.
* Some functions may behave oddly or not work at all.
* Data must already reside in memory.

Generic Particle Data
---------------------

.. note::

   For more information about how yt indexes and reads particle data, set the
   section :ref:`demeshening`.

See :doc:`Loading_Generic_Particle_Data` and
:func:`~yt.frontends.stream.data_structures.load_particles` for more detail.

You can also load generic particle data using the same ``stream`` functionality
discussed above to load in-memory grid data.  For example, if your particle
positions and masses are stored in ``positions`` and ``masses``, a
vertically-stacked array of particle x,y, and z positions, and a 1D array of
particle masses respectively, you would load them like this:

.. code-block:: python

    import yt

    data = dict(particle_position=positions, particle_mass=masses)
    ds = yt.load_particles(data)

You can also load data using 1D x, y, and z position arrays:

.. code-block:: python

    import yt

    data = dict(
        particle_position_x=posx,
        particle_position_y=posy,
        particle_position_z=posz,
        particle_mass=masses,
    )
    ds = yt.load_particles(data)

The ``load_particles`` function also accepts the following keyword parameters:

``length_unit``
      The units used for particle positions.

``mass_unit``
       The units of the particle masses.

``time_unit``
       The units used to represent times. This is optional and is only used if
       your data contains a ``creation_time`` field or a ``particle_velocity`` field.

``velocity_unit``
       The units used to represent velocities.  This is optional and is only used
       if you supply a velocity field.  If this is not supplied, it is inferred from
       the length and time units.

``bbox``
       The bounding box for the particle positions.

.. _smooth-non-sph:

Adding Smoothing Lengths for Non-SPH Particles
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

A novel use of the ``load_particles`` function is to facilitate SPH
visualization of non-SPH particles. See the example below:

.. code-block:: python

    import yt

    # Load dataset and center on the dense region
    ds = yt.load("FIRE_M12i_ref11/snapshot_600.hdf5")
    _, center = ds.find_max(("PartType0", "density"))

    # Reload DM particles into a stream dataset
    ad = ds.all_data()
    pt = "PartType1"
    fields = ["particle_mass"] + [f"particle_position_{ax}" for ax in "xyz"]
    data = {field: ad[pt, field] for field in fields}
    ds_dm = yt.load_particles(data, data_source=ad)

    # Generate the missing SPH fields
    ds_dm.add_sph_fields()

    # Make the SPH projection plot
    p = yt.ProjectionPlot(ds_dm, "z", ("io", "density"), center=center, width=(1, "Mpc"))
    p.set_unit(("io", "density"), "Msun/kpc**2")
    p.show()

Here we see two new things. First, ``load_particles`` accepts a ``data_source``
argument to infer parameters like code units, which could be tedious to provide
otherwise. Second, the returned
:class:`~yt.frontends.stream.data_structures.StreamParticleDataset` has an
:meth:`~yt.frontends.stream.data_structures.StreamParticleDataset.add_sph_fields`
method, to create the ``smoothing_length`` and ``density`` fields required for
SPH visualization to work.

.. _loading-gizmo-data:

Gizmo Data
----------

.. note::

   For more information about how yt indexes and reads particle data, set the
   section :ref:`demeshening`.

Gizmo datasets, including FIRE outputs, can be loaded into yt in the usual
manner.  Like other SPH data formats, yt loads Gizmo data as particle fields
and then uses smoothing kernels to deposit those fields to an underlying
grid structure as spatial fields as described in :ref:`loading-gadget-data`.
To load Gizmo datasets using the standard HDF5 output format::

   import yt
   ds = yt.load("snapshot_600.hdf5")

Because the Gizmo output format is similar to the Gadget format, yt
may load Gizmo datasets as Gadget depending on the circumstances, but this
should not pose a problem in most situations.  FIRE outputs will be loaded
accordingly due to the number of metallicity fields found (11 or 17).

If ``("PartType0", "MagneticField")`` is present in the output, it would be
loaded and aliased to ``("PartType0", "particle_magnetic_field")``. The
corresponding component field like ``("PartType0", "particle_magnetic_field_x")``
would be added automatically.

Note that ``("PartType4", "StellarFormationTime")`` field has different
meanings depending on whether it is a cosmological simulation. For cosmological
runs this is the scale factor at the redshift when the star particle formed.
For non-cosmological runs it is the time when the star particle formed. (See the
`GIZMO User Guide <http://www.tapir.caltech.edu/~phopkins/Site/GIZMO_files/gizmo_documentation.html>`_)
For this reason, ``("PartType4", "StellarFormationTime")`` is loaded as a
dimensionless field. We defined two related fields
``("PartType4", "creation_time")``, and ``("PartType4", "age")`` with physical
units for your convenience.

For Gizmo outputs written as raw binary outputs, you may have to specify
a bounding box, field specification, and units as are done for standard
Gadget outputs.  See :ref:`loading-gadget-data` for more information.

.. _halo-catalog-data:

Halo Catalog Data
-----------------

.. note::

   For more information about how yt indexes and reads particle data, set the
   section :ref:`demeshening`.

yt has support for reading halo catalogs produced by the AdaptaHOP, Amiga Halo
Finder (AHF), Rockstar and the inline FOF/SUBFIND halo finders of Gadget and
OWLS.  The halo catalogs are treated as particle datasets where each particle
represents a single halo.  For example, this means that the ``"particle_mass"``
field refers to the mass of the halos.  For Gadget FOF/SUBFIND catalogs, the
member particles for a given halo can be accessed by creating ``halo`` data
containers.  See :ref:`halo_containers` for more information.

If you have access to both the halo catalog and the simulation snapshot from
the same redshift, additional analysis can be performed for each halo using
:ref:`halo-analysis`.  The resulting product can be reloaded in a similar manner
to the other halo catalogs shown here.

AdataHOP
^^^^^^^^

`AdaptaHOP <https://ascl.net/1305.004>`_ halo catalogs are loaded by providing
the path to the ``tree_bricksXXX`` file. As the halo catalog does not contain
all the information about the simulation (for example the cosmological
parameters), you also need to pass the parent dataset for it to load correctly.
Some fields of note available from AdaptaHOP are:

+---------------------+---------------------------+
| Rockstar field      | yt field name             |
+=====================+===========================+
| halo id             | particle_identifier       |
+---------------------+---------------------------+
| halo mass           | particle_mass             |
+---------------------+---------------------------+
| virial mass         | virial_mass               |
+---------------------+---------------------------+
| virial radius       | virial_radius             |
+---------------------+---------------------------+
| virial temperature  | virial_temperature        |
+---------------------+---------------------------+
| halo position       | particle_position_(x,y,z) |
+---------------------+---------------------------+
| halo velocity       | particle_velocity_(x,y,z) |
+---------------------+---------------------------+

Numerous other AdataHOP fields exist.  To see them, check the field list by
typing ``ds.field_list`` for a dataset loaded as ``ds``.  Like all other datasets,
fields must be accessed through :ref:`Data-objects`.

.. code-block:: python

   import yt

   parent_ds = yt.load("output_00080/info_00080.txt")
   ds = yt.load("output_00080_halos/tree_bricks080", parent_ds=parent_ds)
   ad = ds.all_data()
   # halo masses
   print(ad["halos", "particle_mass"])
   # halo radii
   print(ad["halos", "virial_radius"])

Halo Data Containers
""""""""""""""""""""

Halo member particles are accessed by creating halo data containers with the
the halo id and the type of the particles.  Scalar values for halos
can be accessed in the same way.  Halos also have mass, position, velocity, and
member ids attributes.

.. code-block:: python

   halo = ds.halo(1, ptype="io")
   # member particles for this halo
   print(halo.member_ids)
   # masses of the halo particles
   print(halo["io", "particle_mass"])
   # halo mass
   print(halo.mass)

In addition, the halo container contains a sphere container. This is the smallest
sphere that contains all the halos' particles

.. code-block:: python

  halo = ds.halo(1, ptype="io")
  sp = halo.sphere
  # Density in halo
  sp["gas", "density"]
  # Entropy in halo
  sp["gas", "entropy"]


.. _ahf:

Amiga Halo Finder
^^^^^^^^^^^^^^^^^

Amiga Halo Finder (AHF) halo catalogs are loaded by providing the path to the
.parameter files.  The corresponding .log and .AHF_halos files must exist for
data loading to succeed. The field type for all fields is "halos". Some fields
of note available from AHF are:

+----------------+---------------------------+
| AHF field      | yt field name             |
+================+===========================+
| ID             | particle_identifier       |
+----------------+---------------------------+
| Mvir           | particle_mass             |
+----------------+---------------------------+
| Rvir           | virial_radius             |
+----------------+---------------------------+
| (X,Y,Z)c       | particle_position_(x,y,z) |
+----------------+---------------------------+
| V(X,Y,Z)c      | particle_velocity_(x,y,z) |
+----------------+---------------------------+

Numerous other AHF fields exist.  To see them, check the field list by typing
``ds.field_list`` for a dataset loaded as ``ds``.  Like all other datasets, fields
must be accessed through :ref:`Data-objects`.

.. code-block:: python

   import yt

   ds = yt.load("ahf_halos/snap_N64L16_135.parameter", hubble_constant=0.7)
   ad = ds.all_data()
   # halo masses
   print(ad["halos", "particle_mass"])
   # halo radii
   print(ad["halos", "virial_radius"])

.. note::

  Currently the dimensionless Hubble parameter that yt needs is not provided in
  AHF outputs. So users need to provide the ``hubble_constant`` (default to 1.0)
  while loading datasets, as shown above.

.. _rockstar:

Rockstar
^^^^^^^^

Rockstar halo catalogs are loaded by providing the path to one of the .bin files.
In the case where multiple files were produced, one need only provide the path
to a single one of them.  The field type for all fields is "halos".  Some fields
of note available from Rockstar are:

+----------------+---------------------------+
| Rockstar field | yt field name             |
+================+===========================+
| halo id        | particle_identifier       |
+----------------+---------------------------+
| virial mass    | particle_mass             |
+----------------+---------------------------+
| virial radius  | virial_radius             |
+----------------+---------------------------+
| halo position  | particle_position_(x,y,z) |
+----------------+---------------------------+
| halo velocity  | particle_velocity_(x,y,z) |
+----------------+---------------------------+

Numerous other Rockstar fields exist.  To see them, check the field list by
typing ``ds.field_list`` for a dataset loaded as ``ds``.  Like all other datasets,
fields must be accessed through :ref:`Data-objects`.

.. code-block:: python

   import yt

   ds = yt.load("rockstar_halos/halos_0.0.bin")
   ad = ds.all_data()
   # halo masses
   print(ad["halos", "particle_mass"])
   # halo radii
   print(ad["halos", "virial_radius"])

.. _gadget_fof:

Gadget FOF/SUBFIND
^^^^^^^^^^^^^^^^^^

Gadget FOF/SUBFIND halo catalogs work in the same way as those created by
:ref:`rockstar`, except there are two field types: ``FOF`` for friend-of-friends
groups and ``Subhalo`` for halos found with the SUBFIND substructure finder.
Also like Rockstar, there are a number of fields specific to these halo
catalogs.

+-------------------+---------------------------+
| FOF/SUBFIND field | yt field name             |
+===================+===========================+
| halo id           | particle_identifier       |
+-------------------+---------------------------+
| halo mass         | particle_mass             |
+-------------------+---------------------------+
| halo position     | particle_position_(x,y,z) |
+-------------------+---------------------------+
| halo velocity     | particle_velocity_(x,y,z) |
+-------------------+---------------------------+
| num. of particles | particle_number           |
+-------------------+---------------------------+
| num. of subhalos  | subhalo_number (FOF only) |
+-------------------+---------------------------+

Many other fields exist, especially for SUBFIND subhalos.  Check the field
list by typing ``ds.field_list`` for a dataset loaded as ``ds``.  Like all
other datasets, fields must be accessed through :ref:`Data-objects`.

.. code-block:: python

   import yt

   ds = yt.load("gadget_fof_halos/groups_042/fof_subhalo_tab_042.0.hdf5")
   ad = ds.all_data()
   # The halo mass
   print(ad["Group", "particle_mass"])
   print(ad["Subhalo", "particle_mass"])
   # Halo ID
   print(ad["Group", "particle_identifier"])
   print(ad["Subhalo", "particle_identifier"])
   # positions
   print(ad["Group", "particle_position_x"])
   # velocities
   print(ad["Group", "particle_velocity_x"])

Multidimensional fields can be accessed through the field name followed by an
underscore and the index.

.. code-block:: python

   # x component of the spin
   print(ad["Subhalo", "SubhaloSpin_0"])

.. _halo_containers:

Halo Data Containers
""""""""""""""""""""

Halo member particles are accessed by creating halo data containers with the
type of halo ("Group" or "Subhalo") and the halo id.  Scalar values for halos
can be accessed in the same way.  Halos also have mass, position, and velocity
attributes.

.. code-block:: python

   halo = ds.halo("Group", 0)
   # member particles for this halo
   print(halo["member_ids"])
   # halo virial radius
   print(halo["Group_R_Crit200"])
   # halo mass
   print(halo.mass)

Subhalos containers can be created using either their absolute ids or their
subhalo ids.

.. code-block:: python

   # first subhalo of the first halo
   subhalo = ds.halo("Subhalo", (0, 0))
   # this subhalo's absolute id
   print(subhalo.group_identifier)
   # member particles
   print(subhalo["member_ids"])

OWLS FOF/SUBFIND
^^^^^^^^^^^^^^^^

OWLS halo catalogs have a very similar structure to regular Gadget halo catalogs.
The two field types are ``FOF`` and ``SUBFIND``.  See :ref:`gadget_fof` for more
information.  At this time, halo member particles cannot be loaded.

.. code-block:: python

   import yt

   ds = yt.load("owls_fof_halos/groups_008/group_008.0.hdf5")
   ad = ds.all_data()
   # The halo mass
   print(ad["FOF", "particle_mass"])

.. _halocatalog:

YTHaloCatalog
^^^^^^^^^^^^^

These are catalogs produced by the analysis discussed in :ref:`halo-analysis`.
In the case where multiple files were produced, one need only provide the path
to a single one of them.  The field type for all fields is "halos".  The fields
available here are similar to other catalogs.  Any addition
:ref:`halo_catalog_quantities` will also be accessible as fields.

+-------------------+---------------------------+
| HaloCatalog field | yt field name             |
+===================+===========================+
| halo id           | particle_identifier       |
+-------------------+---------------------------+
| virial mass       | particle_mass             |
+-------------------+---------------------------+
| virial radius     | virial_radius             |
+-------------------+---------------------------+
| halo position     | particle_position_(x,y,z) |
+-------------------+---------------------------+
| halo velocity     | particle_velocity_(x,y,z) |
+-------------------+---------------------------+

.. code-block:: python

   import yt

   ds = yt.load("tiny_fof_halos/DD0046/DD0046.0.h5")
   ad = ds.all_data()
   # The halo mass
   print(ad["halos", "particle_mass"])

Halo Data Containers
""""""""""""""""""""

Halo particles can be accessed by creating halo data containers with the
type of halo ("halos") and the halo id and then querying the "member_ids"
field. Halo containers have mass, radius, position, and velocity
attributes. Additional fields for which there will be one value per halo
can be accessed in the same manner as conventional data containers.

.. code-block:: python

   halo = ds.halo("halos", 0)
   # particles for this halo
   print(halo["member_ids"])
   # halo properties
   print(halo.mass, halo.radius, halo.position, halo.velocity)

.. _loading-openpmd-data:

openPMD Data
------------

`openPMD <https://www.openpmd.org>`_ is an open source meta-standard and naming
scheme for mesh based data and particle data. It does not actually define a file
format.

HDF5-containers respecting the minimal set of meta information from
versions 1.0.0 and 1.0.1 of the standard are compatible.
Support for the ED-PIC extension is not available. Mesh data in cartesian coordinates
and particle data can be read by this frontend.

To load the first in-file iteration of a openPMD datasets using the standard HDF5
output format:

.. code-block:: python

   import yt

   ds = yt.load("example-3d/hdf5/data00000100.h5")

If you operate on large files, you may want to modify the virtual chunking behaviour through
``open_pmd_virtual_gridsize``. The supplied value is an estimate of the size of a single read request
for each particle attribute/mesh (in Byte).

.. code-block:: python

  import yt

  ds = yt.load("example-3d/hdf5/data00000100.h5", open_pmd_virtual_gridsize=10e4)
  sp = yt.SlicePlot(ds, "x", ("openPMD", "rho"))
  sp.show()

Particle data is fully supported:

.. code-block:: python

  import yt

  ds = yt.load("example-3d/hdf5/data00000100.h5")
  ad = f.all_data()
  ppp = yt.ParticlePhasePlot(
      ad,
      ("all", "particle_position_y"),
      ("all", "particle_momentum_y"),
      ("all", "particle_weighting"),
  )
  ppp.show()

.. rubric:: Caveats

* 1D, 2D and 3D data is compatible, but lower dimensional data might yield
  strange results since it gets padded and treated as 3D. Extraneous dimensions are
  set to be of length 1.0m and have a width of one cell.
* The frontend has hardcoded logic for renaming the openPMD ``position``
  of particles to ``positionCoarse``

.. _loading-pyne-data:

PyNE Data
---------

`PyNE <http://pyne.io/>`_ is an open source nuclear engineering toolkit
maintained by the PyNE development team (pyne-dev@googlegroups.com).
PyNE meshes utilize the Mesh-Oriented datABase
`(MOAB) <https://press3.mcs.anl.gov/sigma/moab-library/>`_ and can be
Cartesian or tetrahedral. In addition to field data, pyne meshes store pyne
Material objects which provide a rich set of capabilities for nuclear
engineering tasks. PyNE Cartesian (Hex8) meshes are supported by yt.

To create a pyne mesh:

.. code-block:: python

  from pyne.mesh import Mesh

  num_divisions = 50
  coords = linspace(-1, 1, num_divisions)
  m = Mesh(structured=True, structured_coords=[coords, coords, coords])

Field data can then be added:

.. code-block:: python

  from pyne.mesh import iMeshTag

  m.neutron_flux = IMeshTag()
  # neutron_flux_data is a list or numpy array of size num_divisions^3
  m.neutron_flux[:] = neutron_flux_data

Any field data or material data on the mesh can then be viewed just like any other yt dataset!

.. code-block:: python

  import yt

  pf = yt.frontends.moab.data_structures.PyneMoabHex8Dataset(m)
  s = yt.SlicePlot(pf, "z", "neutron_flux")
  s.display()

.. _loading-ramses-data:

RAMSES Data
-----------

In yt-4.x, RAMSES data is fully supported.  If you are interested in taking a
development or stewardship role, please contact the yt-dev mailing list.  To
load a RAMSES dataset, you can use the ``yt.load`` command and provide it
the ``info*.txt`` filename.  For instance, if you were in a
directory with the following files:

.. code-block:: none

   output_00007
   output_00007/amr_00007.out00001
   output_00007/grav_00007.out00001
   output_00007/hydro_00007.out00001
   output_00007/info_00007.txt
   output_00007/part_00007.out00001

You would feed it the filename ``output_00007/info_00007.txt``:

.. code-block:: python

   import yt

   ds = yt.load("output_00007/info_00007.txt")

yt will attempt to guess the fields in the file. For more control over the hydro fields or the particle fields, see :ref:`loading-ramses-data-args`.

yt also support the new way particles are handled introduced after
version ``stable_17_09`` (the version introduced after the 2017 Ramses
User Meeting). In this case, the file ``part_file_descriptor.txt``
containing the different fields in the particle files will be read. If
you use a custom version of RAMSES, make sure this file is up-to-date
and reflects the true layout of the particles.

yt supports outputs made by the mainline ``RAMSES`` code as well as the
``RAMSES-RT`` fork. Files produces by ``RAMSES-RT`` are recognized as such
based on the presence of a ``info_rt_*.txt`` file in the output directory.

.. note::
   for backward compatibility, particles from the
   ``part_XXXXX.outYYYYY`` files have the particle type ``io`` by
   default (including dark matter, stars, tracer particles, ...). Sink
   particles have the particle type ``sink``.

.. _loading-ramses-data-args:

Arguments passed to the load function
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
It is possible to provide extra arguments to the load function when loading RAMSES datasets. Here is a list of the ones specific to RAMSES:

``fields``
    A list of fields to read from the hydro files. For example, in a pure
    hydro simulation with an extra custom field named ``my-awesome-field``, one
    would specify the fields argument following this example:

      .. code-block:: python

          import yt

          fields = [
              "Density",
              "x-velocity",
              "y-velocity",
              "z-velocity",
              "Pressure",
              "my-awesome-field",
          ]
          ds = yt.load("output_00123/info_00123.txt", fields=fields)
          "my-awesome-field" in ds.field_list  # is True


``extra_particle_fields``
      A list of tuples describing extra particles fields to read in. By
      default, yt will try to detect as many fields as possible,
      assuming the extra ones to be double precision floats. This
      argument is useful if you have extra fields besides the particle mass,
      position, and velocity fields that yt cannot detect automatically. For
      example, for a dataset containing two extra particle integer fields named
      ``family`` and ``info``, one would do:

      .. code-block:: python

          import yt

          extra_fields = [("family", "I"), ("info", "I")]
          ds = yt.load("output_00001/info_00001.txt", extra_particle_fields=extra_fields)
          # ('all', 'family') and ('all', 'info') now in ds.field_list

      The format of the ``extra_particle_fields`` argument is as follows:
      ``[('field_name_1', 'type_1'), ..., ('field_name_n', 'type_n')]`` where
      the second element of the tuple follows the `python struct format
      convention
      <https://docs.python.org/3.5/library/struct.html#format-characters>`_.
      Note that if ``extra_particle_fields`` is defined, yt will not assume
      that the ``particle_birth_time`` and ``particle_metallicity`` fields
      are present in the dataset. If these fields are present, they must be
      explicitly enumerated in the ``extra_particle_fields`` argument.

``cosmological``
      Force yt to consider a simulation to be cosmological or
      not. This may be useful for some specific simulations e.g. that
      run down to negative redshifts.

``bbox``
      The subbox to load. yt will only read CPUs intersecting with the
      subbox. This is especially useful for large simulations or
      zoom-in simulations, where you don't want to have access to data
      outside of a small region of interest. This argument will prevent
      yt from loading AMR files outside the subbox and will hence
      spare memory and time.
      For example, one could use

      .. code-block:: python

          import yt

          # Only load a small cube of size (0.1)**3
          bbox = [[0.0, 0.0, 0.0], [0.1, 0.1, 0.1]]
          ds = yt.load("output_00001/info_00001.txt", bbox=bbox)

          # See the note below for the following examples
          ds.right_edge == [1, 1, 1]  # is True

          ad = ds.all_data()
          ad["all", "particle_position_x"].max() > 0.1  # _may_ be True

          bb = ds.box(left_edge=bbox[0], right_edge=bbox[1])
          bb["all", "particle_position_x"].max() < 0.1  # is True

      .. note::
         When using the bbox argument, yt will read all the CPUs
         intersecting with the subbox. However it may also read some
         data *outside* the selected region. This is due to the fact
         that domains have a complicated shape when using Hilbert
         ordering. Internally, yt will hence assume the loaded dataset
         covers the entire simulation. If you only want the data from
         the selected region, you may want to use ``ds.box(...)``.

      .. note::
         The ``bbox`` feature is only available for datasets using
         Hilbert ordering.

``max_level, max_level_convention``
      This will set the deepest level to be read from file. Both arguments
      have to be set, where the convention can be either "ramses" or "yt".

      In the "ramses" convention, levels go from 1 (the root grid)
      to levelmax, such that the finest cells have a size of ``boxsize/2**levelmax``.
      In the "yt" convention, levels are numbered from 0 (the coarsest
      uniform grid at RAMSES' ``levelmin``) to ``max_level``, such that
      the finest cells are ``2**max_level`` smaller than the coarsest.


      .. code-block:: python

          import yt

          # Assuming RAMSES' levelmin=6, i.e. the structure is full
          # down to levelmin=6
          ds_all = yt.load("output_00080/info_00080.txt")
          ds_yt = yt.load("output_00080/info_00080.txt", max_level=2, max_level_convention="yt")
          ds_ramses = yt.load(
              "output_00080/info_00080.txt",
              max_level=8,
              max_level_convention="ramses",
          )

          any(ds_all.r["index", "grid_level"] > 2)  # True
          all(ds_yt.r["index", "grid_level"] <= 2)  # True
          all(ds_ramses.r["index", "grid_level"] <= 2)  # True



Adding custom particle fields
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

There are three way to make yt detect all the particle fields. For example, if you wish to make yt detect the birth time and metallicity of your particles, use one of these methods

1. ``yt.load`` method. Whenever loading a dataset, add the extra particle fields as a keyword argument to the ``yt.load`` call.

   .. code-block:: python

      import yt

      epf = [("particle_birth_time", "d"), ("particle_metallicity", "d")]
      ds = yt.load("dataset", extra_particle_fields=epf)

      ("io", "particle_birth_time") in ds.derived_field_list  # is True
      ("io", "particle_metallicity") in ds.derived_field_list  # is True

2. yt config method. If you don't want to pass the arguments for each call of ``yt.load``, you can add in your configuration

   .. code-block:: none

      [ramses-particles]
      fields = """
         particle_position_x, d
         particle_position_y, d
         particle_position_z, d
         particle_velocity_x, d
         particle_velocity_y, d
         particle_velocity_z, d
         particle_mass, d
         particle_identifier, i
         particle_refinement_level, I
         particle_birth_time, d
         particle_metallicity, d
      """

   Each line should contain the name of the field and its data type (``d`` for double precision, ``f`` for single precision, ``i`` for integer and ``l`` for long integer). You can also configure the auto detected fields for fluid types by adding a section ``ramses-hydro``, ``ramses-grav`` or ``ramses-rt`` in the config file. For example, if you customized your gravity files so that they contain the potential, the potential in the previous timestep and the x, y and z accelerations, you can use :

   .. code-block:: none

      [ramses-grav]
      fields = [ "Potential", "Potential-old", "x-acceleration", "y-acceleration", "z-acceleration" ]

3. New RAMSES way. Recent versions of RAMSES automatically write in their output an ``hydro_file_descriptor.txt`` file that gives information about which field is where. If you wish, you can simply create such a file in the folder containing the ``info_xxxxx.txt`` file

   .. code-block:: none

      # version:  1
      # ivar, variable_name, variable_type
       1, position_x, d
       2, position_y, d
       3, position_z, d
       4, velocity_x, d
       5, velocity_y, d
       6, velocity_z, d
       7, mass, d
       8, identity, i
       9, levelp, i
      10, birth_time, d
      11, metallicity, d

   It is important to note that this file should not end with an empty line (but in this case with ``11, metallicity, d``).

.. note::

   The kind (``i``, ``d``, ``I``, ...) of the field follow the `python convention <https://docs.python.org/3.5/library/struct.html#format-characters>`_.



Customizing the particle type association
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

In versions of RAMSES more recent than December 2017, particles carry
along a ``family`` array. The value of this array gives the kind of
the particle, e.g. 1 for dark matter. It is possible to customize the
association between particle type and family by customizing the yt
config (see :ref:`configuration-file`), adding

.. code-block:: none

   [ramses-families]
   gas_tracer = 100
   star_tracer = 101
   dm = 0
   star = 1



Particle ages and formation times
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

For non-cosmological simulations, particle ages are stored in physical units on
disk. To access the birth time for the particles, use the
``particle_birth_time`` field. The time recorded in this field is relative to
the beginning of the simulation. Particles that were present in the initial
conditions will have negative values for ``particle_birth_time``.

For cosmological simulations that include star particles, RAMSES stores particle
formation times as conformal times. To access the formation time field data in
conformal units use the ``conformal_birth_time`` field. This will return the
formation times of particles in the simulation in conformal units as a
dimensionless array. To access the formation time in physical units, use the
``particle_birth_time`` field. Finally, to access the ages of star particles in
your simulation, use the ``star_age`` field. Note that this field is defined for
all particle types but will only make sense for star particles.

For simulations conducted in Newtownian coordinates, with no cosmology or
comoving expansion, the time is equal to zero at the beginning of the
simulation. That means that particles present in the initial conditions may have
negative birth times. This can happen, for example, in idealized isolated galaxy
simulations, where star particles are included in the initial conditions. For
simulations conducted in cosmological comoving units, the time is equal to zero
at the big bang, and all particles should have positive values for the
``particle_birth_time`` field.

To help clarify the above discussion, the following table describes the meaning
of the various particle formation time and age fields:

+------------------+--------------------------+--------------------------------+
| Simulation type  | Field name               | Description                    |
+==================+==========================+================================+
| cosmological     | ``conformal_birth_time`` | Formation time in conformal    |
|                  |                          | units (dimensionless)          |
+------------------+--------------------------+--------------------------------+
| any              | ``particle_birth_time``  | The time relative to the       |
|                  |                          | beginning of the simulation    |
|                  |                          | when the particle was formed.  |
|                  |                          | For non-cosmological           |
|                  |                          | simulations, this field will   |
|                  |                          | have positive values for       |
|                  |                          | particles formed during the    |
|                  |                          | simulation and negative for    |
|                  |                          | particles of finite age in the |
|                  |                          | initial conditions. For        |
|                  |                          | cosmological simulations this  |
|                  |                          | is the time the particle       |
|                  |                          | formed relative to the big     |
|                  |                          | bang, therefore the value of   |
|                  |                          | this field should be between   |
|                  |                          | 0 and 13.7 Gyr.                |
+------------------+--------------------------+--------------------------------+
| any              | ``star_age``             | Age of the particle.           |
|                  |                          | Only physically meaningful for |
|                  |                          | stars and particles that       |
|                  |                          | formed dynamically during the  |
|                  |                          | simulation.                    |
+------------------+--------------------------+--------------------------------+

RAMSES datasets produced by a version of the code newer than November 2017
contain the metadata necessary for yt to automatically distinguish between star
particles and other particle types. If you are working with a dataset produced
by a version of RAMSES older than November 2017, yt will only automatically
recognize a single particle ``io``. It may be convenient to define a particle
filter in your scripts to distinguish between particles present in the initial
conditions and particles that formed dynamically during the simulation by
filtering particles with ``"conformal_birth_time"`` values equal to zero and not
equal to zero.  An example particle filter definition for dynamically formed
stars might look like this:

.. code-block:: python

    @yt.particle_filter(requires=["conformal_birth_time"], filtered_type="io")
    def stars(pfilter, data):
        filter = data[pfilter.filtered_type, "conformal_birth_time"] != 0
        return filter

For a cosmological simulation, this filter will distinguish between stars and
dark matter particles.

.. _loading-sph-data:

SPH Particle Data
-----------------

.. note::

   For more information about how yt indexes and reads particle data, set the
   section :ref:`demeshening`.

For all of the SPH frontends, yt uses cython-based SPH smoothing onto an
in-memory octree to create deposited mesh fields from individual SPH particle
fields.

This uses a standard M4 smoothing kernel and the ``smoothing_length``
field to calculate SPH sums, filling in the mesh fields.  This gives you the
ability to both track individual particles (useful for tasks like following
contiguous clouds of gas that would be require a clump finder in grid data) as
well as doing standard grid-based analysis (i.e. slices, projections, and profiles).

The ``smoothing_length`` variable is also useful for determining which particles
can interact with each other, since particles more distant than twice the
smoothing length do not typically see each other in SPH simulations.  By
changing the value of the ``smoothing_length`` and then re-depositing particles
onto the grid, you can also effectively mimic what your data would look like at
lower resolution.

.. _loading-tipsy-data:

Tipsy Data
----------

.. note::

   For more information about how yt indexes and reads particle data, set the
   section :ref:`demeshening`.

See :doc:`../cookbook/tipsy_and_yt` and :ref:`loading-sph-data` for more details.

yt also supports loading Tipsy data.  Many of its characteristics are similar
to how Gadget data is loaded.

.. code-block:: python

   ds = load("./halo1e11_run1.00400")

.. _specifying-cosmology-tipsy:

Specifying Tipsy Cosmological Parameters and Setting Default Units
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Cosmological parameters can be specified to Tipsy to enable computation of
default units.  For example do the following, to load a Tipsy dataset whose
path is stored in the variable ``my_filename`` with specified cosmology
parameters:

.. code-block:: python

   cosmology_parameters = {
       "current_redshift": 0.0,
       "omega_lambda": 0.728,
       "omega_matter": 0.272,
       "hubble_constant": 0.702,
   }

   ds = yt.load(my_filename, cosmology_parameters=cosmology_parameters)

If you wish to set the unit system directly, you can do so by using the
``unit_base`` keyword in the load statement.

.. code-block:: python

   import yt

   ds = yt.load(filename, unit_base={"length", (1.0, "Mpc")})

See the documentation for the
:class:`~yt.frontends.tipsy.data_structures.TipsyDataset` class for more
information.

Loading Cosmological Simulations
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

If you are not using a parameter file (i.e. non-Gasoline users), then you must
use keyword ``cosmology_parameters`` when loading your data set to indicate to
yt that it is a cosmological data set. If you do not wish to set any
non-default cosmological parameters, you may pass an empty dictionary.

.. code-block:: python

   import yt

   ds = yt.load(filename, cosmology_parameters={})

.. _loading-cfradial-data:

CfRadial Data
-------------

Cf/Radial is a CF compliant netCDF convention for radial data from radar and
lidar platforms that supports both airborne and ground-based sensors. Because
of its CF-compliance, CfRadial will allow researchers familiar with CF to read
the data into a wide variety of analysis tools, models etc. For more see:
[CfRadialDoc.v1.4.20160801.pdf](https://github.com/NCAR/CfRadial/blob/d4562a995d0589cea41f4f6a4165728077c9fc9b/docs/CfRadialDoc.v1.4.20160801.pdf)

yt provides support for loading cartesian-gridded CfRadial netcdf-4 files as
well as polar coordinate Cfradial netcdf-4 files. When loading a standard
CfRadial dataset in polar coordinates, yt will first build a sample on a
cartesian grid (see :ref:`cfradial_gridding`). To load a CfRadial data file:

.. code-block:: python

   import yt

   ds = yt.load("CfRadialGrid/grid1.nc")

.. _cfradial_gridding:

Gridding Behavior
^^^^^^^^^^^^^^^^^

When you load a CfRadial dataset in polar coordinates (elevation, azimuth and
range), yt will first build a sample by mapping the data onto a cartesian grid
using the Python-ARM Radar Toolkit (`pyart <https://github.com/ARM-DOE/pyart>`_).
Grid points are found by interpolation of all data points within a specified radius of influence.
This data, now in x, y, z coordinate domain is then saved as a new dataset and subsequent
loads of the original native CfRadial dataset will use the gridded file.
Mapping the data from spherical to Cartesian coordinates is useful for 3D volume
rendering the data using yt.

See the documentation for the
:class:`~yt.frontends.cf_radial.data_structures.CFRadialDataset` class for a
description of how to adjust the gridding parameters and storage of the gridded
file.