Skip to content

Commit

Permalink
Fixing small docs issues (#1893)
Browse files Browse the repository at this point in the history
* fixing underlines and small code mistake

* fixing issue with exporting files

* fixing docstring

* commenting out code and fixing links

* removing hdf

* fixing links

* fixing overwrite issue

* black fix
  • Loading branch information
isaacgsmith authored Feb 15, 2022
1 parent c705946 commit ea31f49
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 39 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ docs/resources/ZENODO.rst
docs/tutorials.rst
docs/io/configuration/components/models/converters/density_parse.csv
docs/io/configuration/components/models/converters/abund_parse.csv
docs/io/configuration/components/models/converters/rebinned_snapshot_converted_to_tardis.csvy
docs/io/configuration/components/models/converters/snapshot_converted_to_tardis.csvy

# Eclipse editor project files
.project
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"id": "e3b3a256",
"metadata": {},
"source": [
"This parser is intended for loading Arepo output files ('snapshots'), extracting the relevant (line-of-sight dependent) data and exporting it to `csvy` files, which can in turn be used in TARDIS models ([see CSVY model](../index.html#csvy-model))."
"This parser is intended for loading Arepo output files ('snapshots'), extracting the relevant (line-of-sight dependent) data and exporting it to `csvy` files, which can in turn be used in TARDIS models ([see CSVY model](../index.rst#csvy-model))."
]
},
{
Expand Down Expand Up @@ -89,7 +89,7 @@
")\n",
"pos, vel, rho, xnuc, time = snapshot.get_grids()\n",
"```\n",
"This will load the necessary from the snapshot. See the [API](../../../../../api/tardis.io.parsers.arepo.html) documentation for more options on how to load snapshots."
"This will load the necessary from the snapshot. See the [API](../../../../../api/tardis.io.parsers.arepo.rst) documentation for more options on how to load snapshots."
]
},
{
Expand Down Expand Up @@ -257,7 +257,7 @@
"id": "dd6310ec",
"metadata": {},
"source": [
"Once you have created a profile of the desired region, you can export the profile to a `csvy` file, which in turn can be used in a TARDIS model. Here you have to specify how many shells you want to export. The profiles are rebinned using [Scipys binned_statistic function](https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.binned_statistic.html), using the mean value of the data in each bin."
"Once you have created a profile of the desired region, you can export the profile to a `csvy` using the commented-out code below, which in turn can be used in a TARDIS model. Here you have to specify how many shells you want to export. The profiles are rebinned using [Scipys binned_statistic function](https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.binned_statistic.html), using the mean value of the data in each bin."
]
},
{
Expand All @@ -267,17 +267,7 @@
"metadata": {},
"outputs": [],
"source": [
"profile.export(20, \"snapshot_converted_to_tardis.csvy\")"
]
},
{
"cell_type": "markdown",
"id": "7c4e8922",
"metadata": {},
"source": [
"During the export, the `yaml` header is automatically written and includes the time of the screenshot as the time for both the nuclear data as well as the density profile. Per default, the positive axis will be exported. the negative axis can be exported with `direction=\"neg\"`.\n",
"\n",
"All abundences will normalised such that roughly sum to 1, but slight deviations are expected to occur."
"profile.export(20, \"snapshot_converted_to_tardis.csvy\", overwrite=True)"
]
},
{
Expand All @@ -289,17 +279,23 @@
"source": [
"<div class=\"alert alert-info\">\n",
"\n",
"\n",
"\n",
"Note\n",
"\n",
"\n",
"The export function will not overwrite existing files, but rather add an incrementing number to the filename.\n",
"\n",
"By default, the `export` method will not overwrite existing files with the same file name. Setting `overwrite=True` allows overwriting -- for example, if `overwrite=True`, if you make changes and rerun the export your exported file will be updated without creaing an additional file.\n",
"\n",
"</div>"
]
},
{
"cell_type": "markdown",
"id": "7c4e8922",
"metadata": {},
"source": [
"During the export, the `yaml` header is automatically written and includes the time of the screenshot as the time for both the nuclear data as well as the density profile. Per default, the positive axis will be exported. the negative axis can be exported with `direction=\"neg\"`.\n",
"\n",
"All abundences will normalised such that roughly sum to 1, but slight deviations are expected to occur."
]
},
{
"cell_type": "markdown",
"id": "5a5ec37b",
Expand All @@ -320,7 +316,7 @@
"profile.rebin(20)\n",
"profile.plot_profile()\n",
"plt.show()\n",
"profile.export(20, \"snapshot_converted_to_tardis.csvy\", statistic=None)"
"profile.export(20, \"rebinned_snapshot_converted_to_tardis.csvy\", overwrite=True)"
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion docs/io/configuration/components/spectrum.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pages below:
* virtual: :ref:`Virtual Packet Scheme <virtual_packets>`
* integrated: :ref:`Formal Integral Method <formal_integral>`

The three methods can be specified when plotting the spectrum (see the :doc:`quickstart guide <../../../quickstart/quickstart>` for an example of this).
The three methods can be specified when plotting the spectrum (see the :doc:`quickstart guide <../../../quickstart>` for an example of this).

The following example shows how to edit variables for the different methods.

Expand Down
46 changes: 28 additions & 18 deletions tardis/io/parsers/arepo.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ class Profile:
def __init__(self, pos, vel, rho, xnuc, time):
"""
Parameters
-----
----------
pos : list of float
Meshgrid of positions in center of mass frames in
Cartesian coordinates
Expand Down Expand Up @@ -321,15 +321,15 @@ def plot_profile(self, save=None, dpi=600, **kwargs):
Plots profile, both in the positive and negative direction.
Parameters
-----
----------
save : str
Path under which the figure is to be saved. Default: None
dpi : int
Dpi of the saved figure
**kwargs : keywords passable to matplotlib.pyplot.plot()
Returns
-----
-------
fig : matplotlib figure object
"""

Expand Down Expand Up @@ -413,14 +413,14 @@ def rebin(self, nshells, statistic="mean"):
by passing the statistics="std" keyword.
Parameters
-----
----------
nshells : int
Number of bins of new data.
statistic : str
Scipy keyword for scipy.stats.binned_statistic. Default: mean
Returns
-----
-------
self : Profile object
"""
Expand Down Expand Up @@ -474,15 +474,22 @@ def rebin(self, nshells, statistic="mean"):

return self

def export(self, nshells, filename, direction="pos", statistic="mean"):
def export(
self,
nshells,
filename,
direction="pos",
statistic="mean",
overwrite=False,
):
"""
Function to export a profile as csvy file. Either the
positive or negative direction can be exported. Does
not overwrite existing files, saves to *(<n>).csvy
positive or negative direction can be exported. By default
does not overwrite existing files, saves to <filename>_<number>.csvy
file instead.
Parameters
-----
----------
nshells : int
Number of shells to be exported.
filename : str
Expand All @@ -494,9 +501,12 @@ def export(self, nshells, filename, direction="pos", statistic="mean"):
statistic : str
Scipy keyword for scipy.stats.binned_statistic. If
statistic=None, data is not rebinned. Default: "mean"
overwrite: bool
If true, will overwrite if a file of the same name exists.
By default False.
Returns
-----
-------
filename : str
Name of the actual saved file
"""
Expand All @@ -505,7 +515,7 @@ def export(self, nshells, filename, direction="pos", statistic="mean"):
if filename.endswith(".csvy"):
filename = filename.replace(".csvy", "")

if os.path.exists("%s.csvy" % filename):
if os.path.exists("%s.csvy" % filename) and not overwrite:
i = 0
while os.path.exists("%s_%s.csvy" % (filename, i)):
i += 1
Expand Down Expand Up @@ -598,7 +608,7 @@ def export(self, nshells, filename, direction="pos", statistic="mean"):

return filename

def get_profiles():
def get_profiles(self):
"""Returns all profiles for manual post_processing etc."""
return (
self.pos_prof_p,
Expand Down Expand Up @@ -630,7 +640,7 @@ def create_profile(
Creates a profile along the x-axis
Parameters
-----
----------
inner_radius : float
Inner radius where the profiles will be cut off. Default: None
outer_radius : float
Expand All @@ -644,7 +654,7 @@ def create_profile(
Dpi of the saved plot. Default: 600
Returns
-----
-------
profile : LineProfile object
"""
Expand Down Expand Up @@ -771,7 +781,7 @@ def create_profile(
Creates a profile along the x-axis without any averaging
Parameters
-----
----------
opening_angle : float
Opening angle (in degrees) of the cone from which the
data is extracted. Refers to the total opening angle, not
Expand All @@ -789,7 +799,7 @@ def create_profile(
Dpi of the saved plot. Default: 600
Returns
-----
-------
profile : LineProfile object
"""
Expand Down Expand Up @@ -932,7 +942,7 @@ def create_profile(
direction are identical.
Parameters
-----
----------
inner_radius : float
Inner radius where the profiles will be cut off. Default: None
outer_radius : float
Expand All @@ -946,7 +956,7 @@ def create_profile(
Dpi of the saved plot. Default: 600
Returns
-----
-------
profile : LineProfile object
"""
Expand Down

0 comments on commit ea31f49

Please sign in to comment.