Skip to content

Latis#5

Open
sbird wants to merge 7 commits into
sbird:heliumreionfrom
qezlou:LATIS
Open

Latis#5
sbird wants to merge 7 commits into
sbird:heliumreionfrom
qezlou:LATIS

Conversation

@sbird
Copy link
Copy Markdown
Owner

@sbird sbird commented Feb 24, 2020

Creating a PR for the LATIS work so I can see differences more easily.

Comment thread lyaemu/coarse_grid.py
di = self.get_outdir(pp, strz=2)
single_flux_pdf = myspec.get_snapshot_list(base=di)
return single_flux_pdf

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is probably easier to just rename the variables in _get_fv to something generic. The functions are the same and if they are reused it means that fixes to one propagate to the others.

Comment thread lyaemu/coarse_grid.py

def save_pdf_vectors(self, aparams, deltaF_bins, pdf_vectors, savefile="emulator_pdf_vectors.hdf5"):
""" Save the pdf vecotrs to a file, which is the only thing read on reload """
save_Dir = "/work/06536/qezlou/stampede2/Spectra"
Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't hard-code absolute paths!

Comment thread lyaemu/coarse_grid.py
#Same in all boxes
self.save_pdf_vectors(aparams, deltaF_bins, deltaF_vectors, mfc=mfc)
assert np.shape(deltaF_vectors)[0] == np.shape(aparams)[0]
return aparams, deltaF_bins, deltaF_vectors
Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this just the same as the flux_vector function? In which case a better thing to do is to reuse that function with maybe slight changes to the default arguments.

Comment thread lyaemu/flux_power.py
"""Modules to generate the flux power spectrum from a simulation box."""
from __future__ import print_function
import sys
sys.path.remove('/opt/apps/intel18/impi18_0/python2/2.7.15/lib/python2.7/site-packages')
Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's up with this line? The emulator code is python3 only anyway.

Comment thread lyaemu/deltaF_pdf.py
from fake_spectra import abstractsnapshot as absn
import spectra_mocking as sm

def rebin_power_to_kms(kfkms, kfmpc, flux_powers, zbins, omega_m, omega_l = None):
Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can just import this function from flux_power.py

Comment thread lyaemu/deltaF_pdf.py
flux_rebinned = [rebinned[ii](okmsbins[ii]*velfac(zz)) for ii, zz in enumerate(zbins)]
return okmsbins, flux_rebinned

class FluxPdf(object):
Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why don't you subclass the FluxPower object and re-use the common functions? As in:

class FluxPdf(FluxPower):

and then only get_deltaF_pdf needs to change.

Comment thread lyaemu/deltaF_pdf.py
for ss in self.spectrae:
ss.tau[('H',1,1215)] = np.array([0])

class MySpectra(object):
Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can just import this from flux_power.py

Comment thread lyaemu/flux_pdf.py
@@ -0,0 +1,201 @@
"""Modules to generate the flux power spectrum from a simulation box."""
Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you have three copies of this code?

Comment thread lyaemu/flux_power.py
kfkms = np.array([ self.kf / (ss.velfac * 3.085678e24/ss.units.UnitLength_in_cm) for ss in self.spectrae])
return kfkms
for (i, ss) in enumerate(self.spectrae):
mbins, hist = sm.get_pdf_Wiener_filtered()
Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not the same as the FluxPdf class above: which one do you mean to use?

Comment thread lyaemu/flux_power.py
#I have checked that for k < 0.1 the corrected version
#is identical to the unsmoothed version (without mean flux rescaling).
self.spec_res = 0.
self.spec_res = 127
Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please note the comment: "hence does not commute with mean flux rescaling": it doesn't make sense to correct for spectral resolution at the same time as doing mean flux rescaling, unfortunately, because they are both non-linear operations. So you have to do the spectral resolution correction on the observations but not the simulations.

Comment thread lyaemu/flux_power.py
flux_dist = FluxPDF()
for snap in range(9,13):
## Added a new adress for my directory because I have no write permission on Simeon's Directory
my_spectra_dir = '/work/06536/qezlou/stampede2/Spectra/'
Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't hard-code it: you can pass it as an argument.

Comment thread lyaemu/flux_power.py
#We use a much smaller pixel resolution so that the window functions
#are small for mean flux rescaling, and also so that HCDs are confined.
self.pix_res = 10.
self.pix_res = 123.4
Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The pix_res has to be smaller than the spec_res: spec_res is a Gaussian smoothing, pix_res is the size of a pixel. Smoothing over a window size < 1 pixel doesn't make sense.

Comment thread lyaemu/flux_power.py
if not self._check_redshift(ss.red):
return None
except OSError:
except (OSError, AttributeError):
Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Under what circumstances does it throw AttributeError?

Comment thread lyaemu/spectra_mocking.py
import os
import subprocess

def plot_pdf_Wiener_filtered(map_file=['60_512', '60_1024', '120_1024'],bins=np.arange(-1.0, 1.0, 0.02)):
Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Docstring please. What is this function supposed to be doing? I can see what it does, but the docstring explains whether that is what you meant it to do.

Comment thread lyaemu/spectra_mocking.py

mbin = np.array([(bins[i]+bins[i+1])/2. for i in range(0,np.size(bins)-1)])
m = np.fromfile(map_file)
hist = np.histogram(m, bins=bins, density=True)[0]
Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm confused by this: this is a histogram, not a Wiener filter. Did you intend to Wiener filter initially and then change your mind after seeing the results?

@sbird
Copy link
Copy Markdown
Owner Author

sbird commented Feb 24, 2020

I took a look through and I had a few comments. Some of them are cleanups but these are important too - I often find real bugs when I'm doing a cleanup, because bugs can hide in duplicated code.

sbird added a commit that referenced this pull request Sep 13, 2023
Switch over to MCMC sampling with Cobaya
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants