Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Emissivity compiling and loading. (#62)
* Created CSP archistecture and basic sfh class * Added variables to constants * implements utility functions & new test files * Implements event rate calculation over time * BPASS data_files for testing file_loading * Adds `at_time` function to the event rate class This method allows for the calculation of the event rate at a given lookback time. It uses the BPASS binning for this. This method is much faster, but suffers from a lack of accuracy. * Adds docstrings and extra tests * Implements calculate spectrum at_time and over_time functions Both functions are implemented for the BPASS spectra. However, the method is similar to the BPASS event rate calculation, which is sub optimal for the spectra calculation. It takes an extremely long time to do the calculation. A for loop of 100000 iterations is present, because each wavelength is seen as it's own "event type". It should be possible to remove this by implementing a function to take the separate wavelengths as a single unit. It would be interesting so see the influence of putting the for loop within a numba function, but thinking about restructuring the function is probably better. Including a "caching" of the BPASS spectra into a pickled DataFrame. Additional test files are required for this to run. * Add normalisation function for the BPASS spectrum * fixed hrd plot * adding csp folder * minor changes * Moved tests to CSP folder + fix in function name _type_check * added a hokitype error * Added some code review for Max and minor stylistic changes * Added some code review for Max and minor stylistic changes * Updated the tests * bla * Adjust tests and docstrings * Adjust eventrate functions to take lists of functions Instead of requiring a scipy interpolated spline as input. These functions now take a list of functions as input for the stellar formation and metallicity history. This adjustment has been made by using `numpy.interp` instead of scipy.interpolate. Furthermore, instead of scipy's spline integration `numpy.trapz` is now used to calculate the mass per bin. * Disabled spectra test * Added parametric star formation histories to SFH and refactored some variable names * fixing CI * Auto stash before merge of "csp" and "official_hoki/csp" * upload files for remote work * Improve testing and functions - Adds BPASS IMFS to the constants - Adds check to BPASS IMFS - Adds test for `data_compiler.SpectraData` - Reduces data usage for rate tests * Add SpectraCompiler test Uses `unittest.mock` to allow for a smaller DataFrame to be used. * Adds extensive tests for the CSP package * Update SpectraCompiler The compiler now outputs the BPASS spectra as a 3D `numpy.ndarray` this minimises storage and allows for faster and less memory hungry operations than the MultiIndex pandas DataFrame. The tests are updated accordingly and using unittest.mock a single spectra file is use. (This could be simulated too) * Documentation update + SFH input The documentation now shows the size and shape of each input and output variable. The `_over_time` and `_at_time` for `CSPSpectra` and `CSPEventRate` are now able to take the `SFH` object as an input. * Removed CSP from utils due to cyclical import The CSP class in `utils` was importing the SFH class, which was importing the `utils` module. Therefore, failing importing. Thus, the CSP class has been moved to a separate file * Updated setup.cfg to include csp_test_data subfolder * Removes leftover print statement + prints loading precompiled failed * Correct metallicity mid-points * Added the parametric star formation histories as public functions * at_time new default sample rate + load functions moved to hoki.load at_time now uses 1000 as the default sample rate. The BPASS bins can still be used is a negative number is given. The `load_spectra` and `load_rates` have been moved to `hoki.load` and renamed to `all_spectra` and `all_rates`, respectively. tests have been adjusted accordingly * Fixed typo * Removes cyclical import * Adjusted tests that use SpectraCompiler * Getting tox to work * private optimised mass_per_time_bin calculation Implements 2 new functions: - A custom numba trapezoidal function - A optimised mass_per_bin function for non-function-based data * Refactored Event Rate calculation from array data The original event rate calculation took functions as in input. This becomes cumbersome when you have data at specific time values. This calculation is done by taking a 2D matrix with time points on one axis and BPASS metallicities on the other. The values of the matrix describes the SFR at that moment in time. The calculate_rate_over_time function has been adjusted to use this new function. * Removed dependency and added more doc information * BUG: pass on kwarg to spectra compiler. * Fix SpectraCompiler * BUG: use np instead of pd in SpectraCompiler. * BUG: fix index and make test pass. * BUG: fix another regression bug. * Fix further regression bug. * Clean up loading module * Updates mass per bin calculation for vectorized funciton input mass_per_bin now takes a normal python callable and a vectorized function as input. The latter boosts performance significantly * Renames CSPEventRate functions and adds grid functions - CSPEventRate functions are now called: - calculate_rate_over_time -> over_time - calculate_rate_at_time -> at_time new functions: - grid_over_time: calculates the rates from a 2D SFH (per BPASS metallicity) from time_points to time bins - grid_at_time: calculate the event rate at a specific moment in lookback time from a 2D SFH grid * np.zeros to np.empty where possible * Fixed incorrect test of at_time and over_time * Set default sample rate for at_time Also includes some docstring updates * Adds `cache` parameter to over_time_spectrum * Adds grid functions for the spectra calculation CSPSpectra now has the following functions: Public: - at_time: at time with function input - over_time: over lb time with function input - grid_at_time: at time with SFH grid input - grid_over_time: over lb time with SFH grid input Private: - grid_rate_calculator_at_time - grid_rate_calculator_over_time The grid_rate_calculators_* are numba functions that have the grid_* around them as wrappers for the input and output * Adds return_time_edges to grid_over_time & bug fix sfh vectorisation * Emissivity compiling and loading. * Rename func, add existence of metallicity files, remove try/except Try/except has been replace by a if/else with a file check. * Finalise merge of `origin/dev1.6` into `data_loading` Co-authored-by: Max Briel <max.briel@auckland.ac.nz> Co-authored-by: heloises <heloisefw@gmail.com> Co-authored-by: Max Briel <max.briel@gmail.com> Co-authored-by: Heloise <HeloiseS@users.noreply.github.com> Co-authored-by: Max <14039563+maxbriel@users.noreply.github.com> Co-authored-by: Martin Glatzle <mglatzle@mpa-garching.mpg.de>
- Loading branch information