Skip to content

Comments

100 Lens Sample with Substructure#1

Open
lobrien6 wants to merge 33 commits intodrphilmarshall:mainfrom
lobrien6:main
Open

100 Lens Sample with Substructure#1
lobrien6 wants to merge 33 commits intodrphilmarshall:mainfrom
lobrien6:main

Conversation

@lobrien6
Copy link

I am creating a new notebook (Substructure.ipynb) to generate two samples of 100 gravitationally lensed quasars with one sample comprised of a smooth mass distribution of a single main deflector and the other sample including substructure to the main deflector. Metrics for the precision, accuracy, bias, and standard deviation will be calculated as well.

@smericks
Copy link

Two high level comments to start (scribing for @drphilmarshall):

  1. make each notebook self contained and self explanatory
  2. Every function and class needs a docstring.

Let us know when this is done, and we'll take another look!

…ts. Initial code for finding the fermat potential differences of the predicted image locations.
Copy link

@smericks smericks left a comment

Choose a reason for hiding this comment

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

Here's my first round of comments

"sample_num = 101\n",
"\n",
"#Define how many parameters each lens has\n",
"param_num = 10\n",

Choose a reason for hiding this comment

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

This doesn't match # of params listed right below, prob just remove? (It's not used in this cell)

"outputs": [],
"source": [
"# Add timing\n",
"import time\n",

Choose a reason for hiding this comment

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

Package imports should always be in the top cell of the notebook

"import time\n",
"tick = time.time()\n",
"\n",
"im_WoS, metadata = paltas_model.PaltasModelWoS(path,sample_num)\n",

Choose a reason for hiding this comment

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

I see that you're passing a folder rather than the full path to the config file. I think it would be more clear if you pass the whole path to the config file '.../Configs/substructure_WoS_config.py', so you can easily change the config file you're passing in. This will just require a minor change to the interface of PaltasModelWoS

Dictionary of corresponding sampled values.

"""
test_sample_i = ConfigHandler(path+'Configs/perturber_sample_wpl_config.py')

Choose a reason for hiding this comment

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

So this only returns one image, as opposed to PaltasModelWoS below, which returns a list of images. Why the difference? I think PaltasModelWoS makes sense, but I'm confused about what you would use this function for, especially since new_sample=False.


return im,metadata

def PaltasModelWoS(path,sample_num):

Choose a reason for hiding this comment

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

Linked to my previous comment in the notebook, if you change the argument to file_path here instead of path, and just have that be the full path to the config file, you should be able to use the same function to do both PaltasModelWoS and PaltasModelWS, right? Then you can avoid code duplication.

from paltas import generate

#define a function for a general case of n situations
def Predictions(sample_num, path, config_path, image_path):

Choose a reason for hiding this comment

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

Overall note: the two functions in this file could be condensed into one function (to avoid duplication). If you write one function that takes in the path to the data.tfrecord, and returns y_test, y_pred, ... for the lenses in that one data.tfrecord, you can just call that function one time for each test set to avoid code duplication.

cosmo=FlatLambdaCDM(H0=70.0, Om0=0.3)
)
lens_model = LensModel(['EPL', 'SHEAR'])
td_cosmo = TDCosmography(0.5, 2., kwargs_model, cosmo_fiducial=FlatLambdaCDM(H0=70.0, Om0=0.3))

Choose a reason for hiding this comment

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

This line is unused, you can remove this line and line 9 (the import)

from lenstronomy.LensModel.Solver.lens_equation_solver import LensEquationSolver

# Declaring arrays
kwargs_model = dict(

Choose a reason for hiding this comment

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

Note that the lens model components are hard-coded here. When switching to include substructure, this will need to be flexible.


##Msigma - Mean Standard Deviation
sum=0
for i in std_pred_WoS:

Choose a reason for hiding this comment

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

you should be able to call np.mean() here to do this concisely / with numpy built-ins which are the usually preferred

mean_metrics = [ME_WoS, ME_WS, Mstd_WoS, Mstd_WS]
#median_metrics = [Median_wop, Median_wpl, MDstd_wop, MDstd_wpl]

return mean_metrics No newline at end of file

Choose a reason for hiding this comment

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

If you return the metrics without labels like this (which is ok, you could also return a dict like {'mean_error_wos':ME_WoS, etc...} but you don't have to), make sure in the function docstring, you clearly spell out what you return and in what order.

… WS cases using correct truth values. Remove duplicate image generation code.
@smericks
Copy link

smericks commented Feb 4, 2025

When you compute ground truth fermat potentials with fermat_potentials.fermat.fermat_potential_at_image_positions(), this isn't capable of using the LensModel that has substructure components in it, so this cannot create the ground truth fermat potentials with substructure. This function always uses a LensModel with an EPL + SHEAR profile. You can see this by tracing back through the code. Note at line 186, this uses the LensModel hardcoded at line 20. We need a LensModel that, when a substructure is present, also contains a 'TNFW' profile.

I suggest we implement the computation of ground truth fermat potentials during image generation, since paltas already constructs this LensModel with 'TNFW' components for us. Then, we can just write that information to the metadata.csv during image generation.

@smericks
Copy link

smericks commented Feb 4, 2025

I'm also confused in Substructures.ipynb, in your "# Plotting histograms" cell, I don't see the two vertical lines you showed us in plots last Friday. Maybe this commit is missing that? Or should I be looking somewhere else?

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