-
-
Notifications
You must be signed in to change notification settings - Fork 400
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Porting the line ID tool from tardisanalysis #1890
base: master
Are you sure you want to change the base?
Conversation
Before a pull request is accepted, it must meet the following criteria:
|
I moved this tool and the opacities.py tool to a folder titled 'analysis_tools' - that's why 2 new files are appearing instead of 1 |
Codecov Report
@@ Coverage Diff @@
## master #1890 +/- ##
=======================================
Coverage 62.55% 62.55%
=======================================
Files 68 68
Lines 7127 7127
=======================================
Hits 4458 4458
Misses 2669 2669 Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you so much @jamesgillanders - this looks like a nice addition. I've few comments - let me know if you need help with any of it.
Besides, could you please create a notebook (or rst file) to demonstrate the use of this tool so that it shows up on docs. Having unit-tests will also be nice but I think we might wanna save them for another PR.
f = open(output_filename, "w") | ||
f.write( | ||
f"# Line Transitions in Wavelength Range " | ||
f"{self.lam_min.value:.1f} - {self.lam_max.value:.1f}" | ||
f" Angstroms\n" | ||
) | ||
dataframe.to_csv(f, sep="\t", index=False) | ||
f.close() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
f = open(output_filename, "w") | |
f.write( | |
f"# Line Transitions in Wavelength Range " | |
f"{self.lam_min.value:.1f} - {self.lam_max.value:.1f}" | |
f" Angstroms\n" | |
) | |
dataframe.to_csv(f, sep="\t", index=False) | |
f.close() | |
with open(output_filename, "w") as f: | |
f.write( | |
f"# Line Transitions in Wavelength Range " | |
f"{self.lam_min.value:.1f} - {self.lam_max.value:.1f}" | |
f" Angstroms\n" | |
) | |
dataframe.to_csv(f, sep="\t", index=False) |
It's cleaner to do file operations this way. It ensures auto-closing.
dataframe_collapsed = dataframe.groupby(["Species"]).sum() | ||
dataframe_collapsed = dataframe_collapsed.sort_values( | ||
by=["Total no. of transitions"], ascending=False | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this reuses dataframe
that we have calculated already in previous if
block, let's put it in above block after L245.
f = open( | ||
f"{output_filename[:-4]}_collapsed{output_filename[-4:]}", "w" | ||
) | ||
f.write( | ||
f"# Line Transitions in Wavelength Range " | ||
f"{self.lam_min.value:.1f} - {self.lam_max.value:.1f}" | ||
f" Angstroms\n" | ||
) | ||
dataframe_collapsed.to_csv(f, sep="\t", index=True) | ||
f.close() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will move above as well. While doing so, can you please change it to with
syntax like I suggested in earlier comment?
self.lam_max = lam_max | ||
|
||
def plot_summary( | ||
self, nlines=None, lam_min=None, lam_max=None, output_filename=None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO we should separate out line contributions file writing from plot_summary()
by creating another method like save_summary()
. It's not clear to me why it has to be done in plotting function - let me know if I'm missing something
self._lines_ids = None | ||
self._lines_ids_unique = None | ||
|
||
@property |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please add docstring to this non-private property (an others below it) so that docstring coverage pipeline passes?
def plot_summary( | ||
self, nlines=None, lam_min=None, lam_max=None, output_filename=None | ||
): | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A docstring should be added here as well, not only because of pipeline but because it's most important function of this class.
from tardis.visualization.tools.sdec_plot import SDECData | ||
|
||
|
||
class line_identifier: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
class line_identifier: | |
class LineIdentifier(object): |
blatant PEP 8 violation 🤣
logger = logging.getLogger(__name__) | ||
|
||
|
||
class opacity_calculator(object): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
class opacity_calculator(object): | |
class OpacityCalculator: |
I will revisit this soon and try to get it to a merge-able state |
@jamesgillanders can this still be fixed up to merge? |
This PR moves the tardis_line_id tool across from tardisanalysis to the main TARDIS repository. The TARDIS line ID tool was originally written by @unoebauer.
Description
Code has been updated to work with the newest version of TARDIS, but behaves as before.
The tool can be used to extract a list of the N most prominent transitions (default has N = 20) within a user-specified wavelength range (default is the entire wavelength range of the simulation). This can be particularly helpful for diagnosing the species with the largest contribution within a wavelength range, which perhaps has a blend of different absorption features.
Motivation and context
This PR simply relocates the old tool, and makes it compatible with the new version of TARDIS.
How has this been tested?
Examples
Here is the output plot from the old tool:
test_line_ID_K2.pdf
And here is the new version:
test_output.pdf
Type of change
Checklist