diff --git a/examples/symba_mars_disk/testnetcdf.ipynb b/examples/symba_mars_disk/testnetcdf.ipynb index d98408178..88e68d95f 100644 --- a/examples/symba_mars_disk/testnetcdf.ipynb +++ b/examples/symba_mars_disk/testnetcdf.ipynb @@ -25,7 +25,7 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": 2, "metadata": {}, "outputs": [ { @@ -36,8 +36,6 @@ "\n", "Creating Dataset\n", "Successfully converted 11 output frames.\n", - "\n", - "Adding particle info to Dataset\n", "Swiftest simulation data stored as xarray DataSet .ds\n" ] } @@ -49,1096 +47,7 @@ }, { "cell_type": "code", - "execution_count": 13, - "metadata": {}, - "outputs": [ - { - "data": { - "text/html": [ - "
\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "
<xarray.Dataset>\n",
-       "Dimensions:      (id: 1521, time: 11)\n",
-       "Coordinates:\n",
-       "  * id           (id) int64 1 2 3 4 5 6 7 ... 1515 1516 1517 1518 1519 1520 1521\n",
-       "  * time         (time) float64 0.0 600.0 1.2e+03 ... 4.8e+03 5.4e+03 6e+03\n",
-       "Data variables: (12/46)\n",
-       "    npl          (time) int32 1500 1500 1500 1500 1500 ... 1518 1518 1518 1518\n",
-       "    ntp          (time) int32 0 0 0 0 0 0 0 0 0 0 0\n",
-       "    xhx          (id, time) float64 0.0 0.0 0.0 ... 1.587e+06 2.838e+06\n",
-       "    xhy          (id, time) float64 0.0 0.0 0.0 ... -9.103e+06 -8.791e+06\n",
-       "    xhz          (id, time) float64 0.0 0.0 0.0 ... -3.433e+04 -3.905e+04\n",
-       "    vhx          (id, time) float64 0.0 0.0 0.0 ... 2.118e+03 2.045e+03\n",
-       "    ...           ...\n",
-       "    py_origin    (id) float64 0.0 -4.373e+06 ... -8.094e+06 -8.123e+06\n",
-       "    pz_origin    (id) float64 0.0 -9.627e+03 2.41e+04 ... 2.923e+03 -3.139e+03\n",
-       "    vhx_origin   (id) float64 0.0 988.0 1.016e+03 ... 1.881e+03 1.887e+03\n",
-       "    vhy_origin   (id) float64 0.0 -1.888e+03 ... -1.004e+03 -1.027e+03\n",
-       "    vhz_origin   (id) float64 0.0 10.69 -2.604 -1.465 ... 18.95 -9.448 -12.51\n",
-       "    origin_type  (id) <U32 'Central body' ... 'Supercatastrophic'
" - ], - "text/plain": [ - "\n", - "Dimensions: (id: 1521, time: 11)\n", - "Coordinates:\n", - " * id (id) int64 1 2 3 4 5 6 7 ... 1515 1516 1517 1518 1519 1520 1521\n", - " * time (time) float64 0.0 600.0 1.2e+03 ... 4.8e+03 5.4e+03 6e+03\n", - "Data variables: (12/46)\n", - " npl (time) int32 ...\n", - " ntp (time) int32 ...\n", - " xhx (id, time) float64 ...\n", - " xhy (id, time) float64 ...\n", - " xhz (id, time) float64 ...\n", - " vhx (id, time) float64 ...\n", - " ... ...\n", - " py_origin (id) float64 0.0 -4.373e+06 ... -8.094e+06 -8.123e+06\n", - " pz_origin (id) float64 0.0 -9.627e+03 2.41e+04 ... 2.923e+03 -3.139e+03\n", - " vhx_origin (id) float64 0.0 988.0 1.016e+03 ... 1.881e+03 1.887e+03\n", - " vhy_origin (id) float64 0.0 -1.888e+03 ... -1.004e+03 -1.027e+03\n", - " vhz_origin (id) float64 0.0 10.69 -2.604 -1.465 ... 18.95 -9.448 -12.51\n", - " origin_type (id) \n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "
<xarray.Dataset>\n",
-       "Dimensions:      (id: 1521)\n",
-       "Coordinates:\n",
-       "  * id           (id) int32 1 1130 216 1326 20 27 ... 1517 1518 1519 1520 1521\n",
-       "Data variables:\n",
-       "    time_origin  (id) float64 0.0 0.0 0.0 0.0 ... 2.4e+03 2.4e+03 2.4e+03\n",
-       "    xhx_origin   (id) float64 0.0 1.047e+07 -1.034e+07 ... -4.435e+06 -4.426e+06\n",
-       "    py_origin    (id) float64 0.0 3.395e+06 2.852e+05 ... -8.094e+06 -8.123e+06\n",
-       "    pz_origin    (id) float64 0.0 2.709e+04 -3.221e+04 ... 2.923e+03 -3.139e+03\n",
-       "    vhx_origin   (id) float64 0.0 -597.1 -50.0 ... 1.885e+03 1.881e+03 1.887e+03\n",
-       "    vhy_origin   (id) float64 0.0 1.881e+03 -2.018e+03 ... -1.004e+03 -1.027e+03\n",
-       "    vhz_origin   (id) float64 0.0 -6.96 11.61 3.592 ... 18.95 -9.448 -12.51\n",
-       "    origin_type  (id) <U32 'Central body' ... 'Supercatastrophic'
" - ], - "text/plain": [ - "\n", - "Dimensions: (id: 1521)\n", - "Coordinates:\n", - " * id (id) int32 1 1130 216 1326 20 27 ... 1517 1518 1519 1520 1521\n", - "Data variables:\n", - " time_origin (id) float64 0.0 0.0 0.0 0.0 ... 2.4e+03 2.4e+03 2.4e+03\n", - " xhx_origin (id) float64 0.0 1.047e+07 -1.034e+07 ... -4.435e+06 -4.426e+06\n", - " py_origin (id) float64 0.0 3.395e+06 2.852e+05 ... -8.094e+06 -8.123e+06\n", - " pz_origin (id) float64 0.0 2.709e+04 -3.221e+04 ... 2.923e+03 -3.139e+03\n", - " vhx_origin (id) float64 0.0 -597.1 -50.0 ... 1.885e+03 1.881e+03 1.887e+03\n", - " vhy_origin (id) float64 0.0 1.881e+03 -2.018e+03 ... -1.004e+03 -1.027e+03\n", - " vhz_origin (id) float64 0.0 -6.96 11.61 3.592 ... 18.95 -9.448 -12.51\n", - " origin_type (id) 0, drop=True)" - ] - }, - { - "cell_type": "code", - "execution_count": 11, - "metadata": {}, - "outputs": [ - { - "ename": "KeyError", - "evalue": "216", - "output_type": "error", - "traceback": [ - "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[0;31mKeyError\u001b[0m Traceback (most recent call last)", - "\u001b[0;32m~/.conda/envs/cent7/2020.02-py37/swiftestOOF/lib/python3.7/site-packages/pandas/core/indexes/base.py\u001b[0m in \u001b[0;36mget_loc\u001b[0;34m(self, key, method, tolerance)\u001b[0m\n\u001b[1;32m 3079\u001b[0m \u001b[0;32mtry\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 3080\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_engine\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mget_loc\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mcasted_key\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 3081\u001b[0m \u001b[0;32mexcept\u001b[0m \u001b[0mKeyError\u001b[0m \u001b[0;32mas\u001b[0m \u001b[0merr\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;32mpandas/_libs/index.pyx\u001b[0m in \u001b[0;36mpandas._libs.index.IndexEngine.get_loc\u001b[0;34m()\u001b[0m\n", - "\u001b[0;32mpandas/_libs/index.pyx\u001b[0m in \u001b[0;36mpandas._libs.index.IndexEngine.get_loc\u001b[0;34m()\u001b[0m\n", - "\u001b[0;32mpandas/_libs/hashtable_class_helper.pxi\u001b[0m in \u001b[0;36mpandas._libs.hashtable.Int64HashTable.get_item\u001b[0;34m()\u001b[0m\n", - "\u001b[0;32mpandas/_libs/hashtable_class_helper.pxi\u001b[0m in \u001b[0;36mpandas._libs.hashtable.Int64HashTable.get_item\u001b[0;34m()\u001b[0m\n", - "\u001b[0;31mKeyError\u001b[0m: 216", - "\nThe above exception was the direct cause of the following exception:\n", - "\u001b[0;31mKeyError\u001b[0m Traceback (most recent call last)", - "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mnewp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0msel\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mid\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;36m216\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", - "\u001b[0;32m~/.conda/envs/cent7/2020.02-py37/swiftestOOF/lib/python3.7/site-packages/xarray/core/dataset.py\u001b[0m in \u001b[0;36msel\u001b[0;34m(self, indexers, method, tolerance, drop, **indexers_kwargs)\u001b[0m\n\u001b[1;32m 2347\u001b[0m \u001b[0mindexers\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0meither_dict_or_kwargs\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mindexers\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mindexers_kwargs\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m\"sel\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 2348\u001b[0m pos_indexers, new_indexes = remap_label_indexers(\n\u001b[0;32m-> 2349\u001b[0;31m \u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mindexers\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mindexers\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mmethod\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mmethod\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mtolerance\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mtolerance\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 2350\u001b[0m )\n\u001b[1;32m 2351\u001b[0m \u001b[0mresult\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0misel\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mindexers\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mpos_indexers\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mdrop\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mdrop\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;32m~/.conda/envs/cent7/2020.02-py37/swiftestOOF/lib/python3.7/site-packages/xarray/core/coordinates.py\u001b[0m in \u001b[0;36mremap_label_indexers\u001b[0;34m(obj, indexers, method, tolerance, **indexers_kwargs)\u001b[0m\n\u001b[1;32m 418\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 419\u001b[0m pos_indexers, new_indexes = indexing.remap_label_indexers(\n\u001b[0;32m--> 420\u001b[0;31m \u001b[0mobj\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mv_indexers\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mmethod\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mmethod\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mtolerance\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mtolerance\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 421\u001b[0m )\n\u001b[1;32m 422\u001b[0m \u001b[0;31m# attach indexer's coordinate to pos_indexers\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;32m~/.conda/envs/cent7/2020.02-py37/swiftestOOF/lib/python3.7/site-packages/xarray/core/indexing.py\u001b[0m in \u001b[0;36mremap_label_indexers\u001b[0;34m(data_obj, indexers, method, tolerance)\u001b[0m\n\u001b[1;32m 276\u001b[0m \u001b[0mcoords_dtype\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mdata_obj\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mcoords\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mdim\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mdtype\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 277\u001b[0m \u001b[0mlabel\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mmaybe_cast_to_coords_dtype\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mlabel\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mcoords_dtype\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 278\u001b[0;31m \u001b[0midxr\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mnew_idx\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mconvert_label_indexer\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mindex\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mlabel\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mdim\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mmethod\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mtolerance\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 279\u001b[0m \u001b[0mpos_indexers\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mdim\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0midxr\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 280\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mnew_idx\u001b[0m \u001b[0;32mis\u001b[0m \u001b[0;32mnot\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;32m~/.conda/envs/cent7/2020.02-py37/swiftestOOF/lib/python3.7/site-packages/xarray/core/indexing.py\u001b[0m in \u001b[0;36mconvert_label_indexer\u001b[0;34m(index, label, index_name, method, tolerance)\u001b[0m\n\u001b[1;32m 197\u001b[0m \u001b[0mindexer\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mindex\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mget_loc\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mlabel_value\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 198\u001b[0m \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 199\u001b[0;31m \u001b[0mindexer\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mindex\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mget_loc\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mlabel_value\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mmethod\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mmethod\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mtolerance\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mtolerance\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 200\u001b[0m \u001b[0;32melif\u001b[0m \u001b[0mlabel\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mdtype\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mkind\u001b[0m \u001b[0;34m==\u001b[0m \u001b[0;34m\"b\"\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 201\u001b[0m \u001b[0mindexer\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mlabel\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;32m~/.conda/envs/cent7/2020.02-py37/swiftestOOF/lib/python3.7/site-packages/pandas/core/indexes/base.py\u001b[0m in \u001b[0;36mget_loc\u001b[0;34m(self, key, method, tolerance)\u001b[0m\n\u001b[1;32m 3080\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_engine\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mget_loc\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mcasted_key\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 3081\u001b[0m \u001b[0;32mexcept\u001b[0m \u001b[0mKeyError\u001b[0m \u001b[0;32mas\u001b[0m \u001b[0merr\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 3082\u001b[0;31m \u001b[0;32mraise\u001b[0m \u001b[0mKeyError\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mkey\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32mfrom\u001b[0m \u001b[0merr\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 3083\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 3084\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mtolerance\u001b[0m \u001b[0;32mis\u001b[0m \u001b[0;32mnot\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;31mKeyError\u001b[0m: 216" - ] - } - ], - "source": [] - }, - { - "cell_type": "code", - "execution_count": 7, + "execution_count": 5, "metadata": {}, "outputs": [ { @@ -1495,43 +404,28 @@ " stroke: currentColor;\n", " fill: currentColor;\n", "}\n", - "
<xarray.Dataset>\n",
-       "Dimensions:      ()\n",
+       "
<xarray.DataArray 'particle_type' (id: 1521)>\n",
+       "array([b'Central Body', b'Massive Body', b'Massive Body', ..., b'Massive Body',\n",
+       "       b'Massive Body', b'Massive Body'], dtype='|S32')\n",
        "Coordinates:\n",
-       "    id           int32 216\n",
-       "Data variables:\n",
-       "    time_origin  float64 0.0\n",
-       "    xhx_origin   float64 -1.034e+07\n",
-       "    py_origin    float64 2.852e+05\n",
-       "    pz_origin    float64 -3.221e+04\n",
-       "    vhx_origin   float64 -50.0\n",
-       "    vhy_origin   float64 -2.018e+03\n",
-       "    vhz_origin   float64 11.61\n",
-       "    origin_type  <U32 'Initial conditions'
" + " * id (id) int32 0 1 2 3 4 5 6 7 ... 1514 1515 1516 1517 1518 1519 1520
" ], "text/plain": [ - "\n", - "Dimensions: ()\n", + "\n", + "array([b'Central Body', b'Massive Body', b'Massive Body', ..., b'Massive Body',\n", + " b'Massive Body', b'Massive Body'], dtype='|S32')\n", "Coordinates:\n", - " id int32 216\n", - "Data variables:\n", - " time_origin float64 0.0\n", - " xhx_origin float64 -1.034e+07\n", - " py_origin float64 2.852e+05\n", - " pz_origin float64 -3.221e+04\n", - " vhx_origin float64 -50.0\n", - " vhy_origin float64 -2.018e+03\n", - " vhz_origin float64 11.61\n", - " origin_type
<xarray.DataArray 'name' (str: 32)>\n",
-       "array([b'M', b'e', b'r', b'c', b'u', b'r', b'y', b'', b'', b'', b'', b'', b'',\n",
-       "       b'', b'', b'', b'', b'', b'', b'', b'', b'', b'', b'', b'', b'', b'',\n",
-       "       b'', b'', b'', b'', b''], dtype='|S1')\n",
+       "
<xarray.DataArray 'name' (id: 9)>\n",
+       "array(['Sun', 'Mercury', 'Venus', 'Earth', 'Mars', 'Jupiter', 'Saturn',\n",
+       "       'Uranus', 'Neptune'], dtype='<U7')\n",
        "Coordinates:\n",
-       "    id       int32 1\n",
-       "Dimensions without coordinates: str
" + " * id (id) int32 0 1 2 3 4 5 6 7 8
" ], "text/plain": [ - "\n", - "array([b'M', b'e', b'r', b'c', b'u', b'r', b'y', b'', b'', b'', b'', b'', b'',\n", - " b'', b'', b'', b'', b'', b'', b'', b'', b'', b'', b'', b'', b'', b'',\n", - " b'', b'', b'', b'', b''], dtype='|S1')\n", + "\n", + "array(['Sun', 'Mercury', 'Venus', 'Earth', 'Mars', 'Jupiter', 'Saturn',\n", + " 'Uranus', 'Neptune'], dtype=', line 2)", - "output_type": "error", - "traceback": [ - "\u001b[0;36m File \u001b[0;32m\"\"\u001b[0;36m, line \u001b[0;32m2\u001b[0m\n\u001b[0;31m ds['name'].sel(id=i) = 'test'\u001b[0m\n\u001b[0m ^\u001b[0m\n\u001b[0;31mSyntaxError\u001b[0m\u001b[0;31m:\u001b[0m can't assign to function call\n" - ] - } - ], - "source": [ - "for i in ds.id:\n", - " ds['name'].sel(id=i) = 'test'" + "ds['name']" ] }, { "cell_type": "code", - "execution_count": 11, + "execution_count": 6, "metadata": {}, "outputs": [ { "data": { + "text/html": [ + "
\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "
<xarray.Dataset>\n",
+       "Dimensions:        (id: 9, time: 3)\n",
+       "Coordinates:\n",
+       "  * time           (time) float64 0.0 0.0006845 0.001369\n",
+       "  * id             (id) int32 0 1 2 3 4 5 6 7 8\n",
+       "Data variables: (12/19)\n",
+       "    npl            (time) int32 8 8 8\n",
+       "    ntp            (time) int32 0 0 0\n",
+       "    name           (id) <U7 'Sun' 'Mercury' 'Venus' ... 'Uranus' 'Neptune'\n",
+       "    particle_type  (id) <U12 'Central Body' 'Massive Body' ... 'Massive Body'\n",
+       "    xhx            (time, id) float64 0.0 -0.2951 -0.211 ... 6.48 14.74 29.58\n",
+       "    xhy            (time, id) float64 0.0 -0.3435 -0.6945 ... 13.13 -4.487\n",
+       "    ...             ...\n",
+       "    capom          (time, id) float64 0.0 0.8431 1.337 ... 1.983 1.293 2.299\n",
+       "    omega          (time, id) float64 0.0 0.5094 0.9619 ... 5.859 1.673 4.29\n",
+       "    capm           (time, id) float64 0.0 2.426 2.107 ... 3.935 4.116 5.838\n",
+       "    Gmass          (time, id) float64 39.48 6.554e-06 ... 0.001724 0.002034\n",
+       "    rhill          (time, id) float64 0.0 0.001475 0.006759 ... 0.4697 0.7814\n",
+       "    radius         (time, id) float64 0.00465 1.631e-05 ... 0.0001695 0.0001646
" + ], "text/plain": [ - "array('SMVEMJSUNueeaauarenrnrrptap\\x00cutsiunt\\x00ush\\x00truu\\x00r\\x00\\x00\\x00ensn\\x00y\\x00\\x00\\x00r\\x00\\x00e',\n", - " dtype='\n", + "Dimensions: (id: 9, time: 3)\n", + "Coordinates:\n", + " * time (time) float64 0.0 0.0006845 0.001369\n", + " * id (id) int32 0 1 2 3 4 5 6 7 8\n", + "Data variables: (12/19)\n", + " npl (time) int32 ...\n", + " ntp (time) int32 ...\n", + " name (id) of fragments produced in collisional events. type :: swiftest_particle_info character(len=NAMELEN) :: name !! Non-unique name - character(len=NAMELEN) :: particle_type !! String containing a description of the particle type (e.g. CentralBody, MassiveBody, TestParticle) + character(len=NAMELEN) :: particle_type !! String containing a description of the particle type (e.g. Central Body, Massive Body, Test Particle) contains procedure :: dump => io_dump_particle_info !! Dumps contents of particle information to file procedure :: read_in => io_read_in_particle_info !! Read in a particle information object from an open file diff --git a/src/modules/swiftest_globals.f90 b/src/modules/swiftest_globals.f90 index dd6752b8f..b84e7f2f9 100644 --- a/src/modules/swiftest_globals.f90 +++ b/src/modules/swiftest_globals.f90 @@ -55,9 +55,9 @@ module swiftest_globals character(*), parameter :: XV = 'XV' !! Symbolic name for binary output file contents for cartesian position and velocity vectors character(*), parameter :: XVEL = 'XVEL' !! Symbolic name for binary output file contents for both cartesian position and velocity and orbital elements - character(*), parameter :: CB_TYPE_NAME = "CentralBody" - character(*), parameter :: PL_TYPE_NAME = "MassiveBody" - character(*), parameter :: TP_TYPE_NAME = "TestParticle" + character(*), parameter :: CB_TYPE_NAME = "Central Body" + character(*), parameter :: PL_TYPE_NAME = "Massive Body" + character(*), parameter :: TP_TYPE_NAME = "Test Particle" ! OpenMP Parameters integer(I4B) :: nthreads = 1 !! Number of OpenMP threads @@ -139,6 +139,7 @@ module swiftest_globals character(*), parameter :: TIME_DIMNAME = "time" !! NetCDF name of the time dimension character(*), parameter :: ID_DIMNAME = "id" !! NetCDF name of the particle id dimension character(*), parameter :: STR_DIMNAME = "str" !! NetCDF name of the particle id dimension + character(*), parameter :: PTYPE_VARNAME = "particle_type" ! NetCDF name of the particle type variable character(*), parameter :: NAME_VARNAME = "name" !! NetCDF name of the particle name variable character(*), parameter :: NPL_VARNAME = "npl" !! NetCDF name of the number of active massive bodies variable character(*), parameter :: NTP_VARNAME = "ntp" !! NetCDF name of the number of active test particles variable diff --git a/src/modules/symba_classes.f90 b/src/modules/symba_classes.f90 index 5294efa64..18cb8fe96 100644 --- a/src/modules/symba_classes.f90 +++ b/src/modules/symba_classes.f90 @@ -4,7 +4,7 @@ module symba_classes !! Definition of classes and methods specific to the Democratic SyMBAcentric Method !! Adapted from David E. Kaufmann's Swifter routine: helio.f90 use swiftest_globals - use swiftest_classes, only : swiftest_parameters, swiftest_base, swiftest_encounter, swiftest_particle_info + use swiftest_classes, only : swiftest_parameters, swiftest_base, swiftest_encounter, swiftest_particle_info, netcdf_parameters use helio_classes, only : helio_cb, helio_pl, helio_tp, helio_nbody_system use rmvs_classes, only : rmvs_chk_ind implicit none @@ -14,6 +14,28 @@ module symba_classes integer(I4B), private, parameter :: NTENC = 3 real(DP), private, parameter :: RHSCALE = 6.5_DP real(DP), private, parameter :: RSHELL = 0.48075_DP + character(*), parameter :: ORIGIN_TYPE_VARNAME = "origin_type" + character(*), parameter :: ORIGIN_TIME_VARNAME = "origin_time" + character(*), parameter :: ORIGIN_XHX_VARNAME = "origin_xhx" + character(*), parameter :: ORIGIN_XHY_VARNAME = "origin_xhy" + character(*), parameter :: ORIGIN_XHZ_VARNAME = "origin_xhz" + character(*), parameter :: ORIGIN_VHX_VARNAME = "origin_vhx" + character(*), parameter :: ORIGIN_VHY_VARNAME = "origin_vhy" + character(*), parameter :: ORIGIN_VHZ_VARNAME = "origin_vhz" + + type, extends(netcdf_parameters) :: symba_netcdf_parameters + integer(I4B) :: origin_type_varid !! NetCDF ID for the origin type + integer(I4B) :: origin_time_varid !! NetCDF ID for the origin type + integer(I4B) :: origin_xhx_varid !! NetCDF ID for the origin xh x component + integer(I4B) :: origin_xhy_varid !! NetCDF ID for the origin xh y component + integer(I4B) :: origin_xhz_varid !! NetCDF ID for the origin xh z component + integer(I4B) :: origin_vhx_varid !! NetCDF ID for the origin xh x component + integer(I4B) :: origin_vhy_varid !! NetCDF ID for the origin xh y component + integer(I4B) :: origin_vhz_varid !! NetCDF ID for the origin xh z component + contains + procedure :: initialize => symba_netcdf_initialize_output !! Initialize a set of parameters used to identify a NetCDF output objec + procedure :: open => symba_netcdf_open !! Opens a NetCDF file + end type symba_netcdf_parameters type, extends(swiftest_parameters) :: symba_parameters real(DP) :: GMTINY = -1.0_DP !! Smallest G*mass that is fully gravitating @@ -96,6 +118,8 @@ module symba_classes procedure :: sort => symba_util_sort_pl !! Sorts body arrays by a sortable componen procedure :: rearrange => symba_util_sort_rearrange_pl !! Rearranges the order of array elements of body based on an input index array. Used in sorting methods procedure :: spill => symba_util_spill_pl !! "Spills" bodies from one object to another depending on the results of a mask (uses the PACK intrinsic) + procedure :: write_frame_netcdf => symba_netcdf_write_frame_pl !! I/O routine for writing out a single frame of time-series data for all bodies in the system in NetCDF format + generic :: write_frame => write_frame_netcdf end type symba_pl type, extends(symba_pl) :: symba_merger @@ -433,6 +457,28 @@ module subroutine symba_kick_encounter(self, system, dt, irec, sgn) integer(I4B), intent(in) :: irec !! Current recursion level integer(I4B), intent(in) :: sgn !! sign to be applied to acceleration end subroutine symba_kick_encounter + + module subroutine symba_netcdf_initialize_output(self, param) + use swiftest_classes, only : swiftest_parameters + implicit none + class(symba_netcdf_parameters), intent(inout) :: self !! Parameters used to identify a particular NetCDF dataset + class(swiftest_parameters), intent(in) :: param !! Current run configuration parameters + end subroutine symba_netcdf_initialize_output + + module subroutine symba_netcdf_open(self, param) + use swiftest_classes, only : swiftest_parameters + implicit none + class(symba_netcdf_parameters), intent(inout) :: self !! Parameters used to identify a particular NetCDF dataset + class(swiftest_parameters), intent(in) :: param !! Current run configuration parameters + end subroutine symba_netcdf_open + + module subroutine symba_netcdf_write_frame_pl(self, iu, param) + use swiftest_classes, only : swiftest_parameters, netcdf_parameters + implicit none + class(symba_pl), intent(in) :: self !! Swiftest particle object + class(netcdf_parameters), intent(inout) :: iu !! Parameters used to identify a particular NetCDF dataset + class(swiftest_parameters), intent(in) :: param !! Current run configuration parameters + end subroutine symba_netcdf_write_frame_pl module subroutine symba_setup_initialize_particle_info_system(self, param) use swiftest_classes, only : swiftest_parameters diff --git a/src/netcdf/netcdf.f90 b/src/netcdf/netcdf.f90 index 785e10a92..8925b05ac 100644 --- a/src/netcdf/netcdf.f90 +++ b/src/netcdf/netcdf.f90 @@ -47,7 +47,7 @@ module subroutine netcdf_initialize_output(self, param) integer(I4B) :: old_mode !! Create the new output file, deleting any previously existing output file of the same name - call check( nf90_create(param%outfile, NF90_HDF5, self%ncid) ) + call check( nf90_create(param%outfile, NF90_NETCDF4, self%ncid) ) call check( nf90_set_fill(self%ncid, nf90_nofill, old_mode) ) ! Define the NetCDF dimensions with particle name as the record dimension @@ -68,6 +68,7 @@ module subroutine netcdf_initialize_output(self, param) call check( nf90_def_var(self%ncid, NPL_VARNAME, NF90_INT, self%time_dimid, self%npl_varid) ) call check( nf90_def_var(self%ncid, NTP_VARNAME, NF90_INT, self%time_dimid, self%ntp_varid) ) call check( nf90_def_var(self%ncid, NAME_VARNAME, NF90_CHAR, [self%str_dimid, self%id_dimid], self%name_varid) ) + call check( nf90_def_var(self%ncid, PTYPE_VARNAME, NF90_CHAR, [self%str_dimid, self%id_dimid], self%ptype_varid) ) if ((param%out_form == XV) .or. (param%out_form == XVEL)) then call check( nf90_def_var(self%ncid, XHX_VARNAME, self%out_type, [self%id_dimid, self%time_dimid], self%xhx_varid) ) call check( nf90_def_var(self%ncid, XHY_VARNAME, self%out_type, [self%id_dimid, self%time_dimid], self%xhy_varid) ) @@ -119,8 +120,6 @@ module subroutine netcdf_initialize_output(self, param) call check( nf90_def_var(self%ncid, GMESCAPE_VARNAME, self%out_type, self%time_dimid, self%GMescape_varid) ) end if - call check( nf90_enddef(self%ncid) ) - return end subroutine netcdf_initialize_output @@ -144,6 +143,7 @@ module subroutine netcdf_open(self, param) call check( nf90_inq_varid(self%ncid, NPL_VARNAME, self%npl_varid)) call check( nf90_inq_varid(self%ncid, NTP_VARNAME, self%ntp_varid)) call check( nf90_inq_varid(self%ncid, NAME_VARNAME, self%name_varid)) + call check( nf90_inq_varid(self%ncid, PTYPE_VARNAME, self%ptype_varid)) if ((param%out_form == XV) .or. (param%out_form == XVEL)) then call check( nf90_inq_varid(self%ncid, XHX_VARNAME, self%xhx_varid)) @@ -214,9 +214,7 @@ module subroutine netcdf_write_frame_base(self, iu, param) ! Internals integer(I4B) :: i, j, tslot, strlen, idslot integer(I4B), dimension(:), allocatable :: ind - character(len=:), allocatable :: name - - !! Open the netCDF file + character(len=:), allocatable :: charstring tslot = int(param%ioutput, kind=I4B) + 1 @@ -231,9 +229,14 @@ module subroutine netcdf_write_frame_base(self, iu, param) j = ind(i) idslot = self%id(j) + 1 call check( nf90_put_var(iu%ncid, iu%id_varid, self%id(j), start=[idslot]) ) - name = trim(adjustl(self%info(j)%name)) - strlen = len(name) - call check( nf90_put_var(iu%ncid, iu%name_varid, name, start=[1, idslot], count=[strlen, 1]) ) + charstring = trim(adjustl(self%info(j)%name)) + strlen = len(charstring) + call check( nf90_put_var(iu%ncid, iu%name_varid, charstring, start=[1, idslot], count=[strlen, 1]) ) + + charstring = trim(adjustl(self%info(j)%particle_type)) + strlen = len(charstring) + call check( nf90_put_var(iu%ncid, iu%ptype_varid, charstring, start=[1, idslot], count=[strlen, 1]) ) + if ((param%out_form == XV) .or. (param%out_form == XVEL)) then call check( nf90_put_var(iu%ncid, iu%xhx_varid, self%xh(1, j), start=[idslot, tslot]) ) call check( nf90_put_var(iu%ncid, iu%xhy_varid, self%xh(2, j), start=[idslot, tslot]) ) @@ -277,9 +280,15 @@ module subroutine netcdf_write_frame_base(self, iu, param) class is (swiftest_cb) idslot = self%id + 1 call check( nf90_put_var(iu%ncid, iu%id_varid, self%id, start=[idslot]) ) - name = trim(adjustl(self%info%name)) - strlen = len(name) - call check( nf90_put_var(iu%ncid, iu%name_varid, name, start=[1, idslot], count=[strlen, 1]) ) + + charstring = trim(adjustl(self%info%name)) + strlen = len(charstring) + call check( nf90_put_var(iu%ncid, iu%name_varid, charstring, start=[1, idslot], count=[strlen, 1]) ) + + charstring = trim(adjustl(self%info%particle_type)) + strlen = len(charstring) + call check( nf90_put_var(iu%ncid, iu%ptype_varid, charstring, start=[1, idslot], count=[strlen, 1]) ) + call check( nf90_put_var(iu%ncid, iu%Gmass_varid, self%Gmass, start=[idslot, tslot]) ) call check( nf90_put_var(iu%ncid, iu%radius_varid, self%radius, start=[idslot, tslot]) ) if (param%lrotation) then diff --git a/src/symba/symba_netcdf.f90 b/src/symba/symba_netcdf.f90 new file mode 100644 index 000000000..e4e715f35 --- /dev/null +++ b/src/symba/symba_netcdf.f90 @@ -0,0 +1,115 @@ +submodule (symba_classes) s_symba_netcdf + use swiftest + use netcdf +contains + + subroutine check(status) + !! author: Carlisle A. Wishard, Dana Singh, and David A. Minton + !! + !! Checks the status of all NetCDF operations to catch errors + implicit none + ! Arguments + integer, intent (in) :: status + + if(status /= nf90_noerr) then + write(*,*) trim(nf90_strerror(status)) + call util_exit(FAILURE) + end if + + return + end subroutine check + + module subroutine symba_netcdf_initialize_output(self, param) + !! author: Carlisle A. Wishard, Dana Singh, and David A. Minton + !! + !! Initialize a NetCDF file system and defines all variables. + implicit none + ! Arguments + class(symba_netcdf_parameters), intent(inout) :: self !! Parameters used to identify a particular NetCDF dataset + class(swiftest_parameters), intent(in) :: param !! Current run configuration parameters + + + call netcdf_initialize_output(self, param) + + ! Define the variables + call check( nf90_def_var(self%ncid, ORIGIN_TYPE_VARNAME, NF90_CHAR, [self%str_dimid, self%id_dimid], self%origin_type_varid) ) + call check( nf90_def_var(self%ncid, ORIGIN_TIME_VARNAME, self%out_type, self%id_dimid, self%origin_time_varid) ) + call check( nf90_def_var(self%ncid, ORIGIN_XHX_VARNAME, self%out_type, self%id_dimid, self%origin_xhx_varid) ) + call check( nf90_def_var(self%ncid, ORIGIN_XHY_VARNAME, self%out_type, self%id_dimid, self%origin_xhy_varid) ) + call check( nf90_def_var(self%ncid, ORIGIN_XHZ_VARNAME, self%out_type, self%id_dimid, self%origin_xhz_varid) ) + call check( nf90_def_var(self%ncid, ORIGIN_VHX_VARNAME, self%out_type, self%id_dimid, self%origin_vhx_varid) ) + call check( nf90_def_var(self%ncid, ORIGIN_VHY_VARNAME, self%out_type, self%id_dimid, self%origin_vhy_varid) ) + call check( nf90_def_var(self%ncid, ORIGIN_VHZ_VARNAME, self%out_type, self%id_dimid, self%origin_vhz_varid) ) + + return + + end subroutine symba_netcdf_initialize_output + + + module subroutine symba_netcdf_open(self, param) + !! author: Carlisle A. Wishard, Dana Singh, and David A. Minton + !! + !! Opens a NetCDF file and does the variable inquiries to activate variable ids + implicit none + ! Arguments + class(symba_netcdf_parameters), intent(inout) :: self !! Parameters used to identify a particular NetCDF dataset + class(swiftest_parameters), intent(in) :: param !! Current run configuration parameters + ! Internals + integer(I4B) :: old_mode + + call netcdf_open(self, param) + + call check( nf90_inq_varid(self%ncid, ORIGIN_TYPE_VARNAME, self%origin_type_varid)) + call check( nf90_inq_varid(self%ncid, ORIGIN_TIME_VARNAME, self%origin_type_varid)) + call check( nf90_inq_varid(self%ncid, ORIGIN_XHX_VARNAME, self%origin_xhx_varid)) + call check( nf90_inq_varid(self%ncid, ORIGIN_XHY_VARNAME, self%origin_xhy_varid)) + call check( nf90_inq_varid(self%ncid, ORIGIN_XHZ_VARNAME, self%origin_xhz_varid)) + call check( nf90_inq_varid(self%ncid, ORIGIN_VHX_VARNAME, self%origin_vhx_varid)) + call check( nf90_inq_varid(self%ncid, ORIGIN_VHY_VARNAME, self%origin_vhy_varid)) + call check( nf90_inq_varid(self%ncid, ORIGIN_VHZ_VARNAME, self%origin_vhz_varid)) + + return + end subroutine symba_netcdf_open + + + module subroutine symba_netcdf_write_frame_pl(self, iu, param) + !! author: Carlisle A. Wishard, Dana Singh, and David A. Minton + !! + !! Write a frame of output of a SyMBA massive body data to the binary output file + !! Note: If outputting to orbital elements, but sure that the conversion is done prior to calling this method + implicit none + ! Arguments + class(symba_pl), intent(in) :: self !! SyMBA massive body object + class(netcdf_parameters), intent(inout) :: iu !! Parameters used to identify a particular NetCDF dataset + class(swiftest_parameters), intent(in) :: param !! Current run configuration parameters + ! Internals + integer(I4B) :: i, j, tslot, strlen, idslot + integer(I4B), dimension(:), allocatable :: ind + character(len=:), allocatable :: charstring + + call netcdf_write_frame_base(self, iu, param) + tslot = int(param%ioutput, kind=I4B) + 1 + select type(iu) + class is (symba_netcdf_parameters) + associate(npl => self%nbody) + if (npl == 0) return + allocate(ind(npl)) + call util_sort(self%id(1:npl), ind(1:npl)) + select type(info => self%info) + class is (symba_particle_info) + do i = 1, npl + j = ind(i) + idslot = self%id(j) + 1 + + charstring = trim(adjustl(info(j)%origin_type)) + strlen = len(charstring) + call check( nf90_put_var(iu%ncid, iu%origin_type_varid, charstring, start=[1, idslot], count=[strlen, 1]) ) + end do + end select + end associate + + end select + + return + end subroutine symba_netcdf_write_frame_pl +end submodule s_symba_netcdf \ No newline at end of file