Skip to content
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

Add basic centroid file capability. #112

Merged
merged 7 commits into from
Jul 15, 2018
Merged

Add basic centroid file capability. #112

merged 7 commits into from
Jul 15, 2018

Conversation

cwwalter
Copy link
Member

@cwwalter cwwalter commented May 5, 2018

I am working on adding more pixel level truth to the simulation but thought it would be useful to first add basic 'centroid file' capability (requested in #32).

My work on adding information based on what each object looks like on the sensor is currently adding a lot of CPU run time and I need more work to optimize it. So, this initial PR uses only truth information about the objects in the centroid file. This makes it more difficult to use this to do imSim/PhoSim validation comparisons (because the PhoSim centroid values are average X and Y values on the sensor) but it is better for comparing catalog truth with the sensor since the true values are not affected by being near the edge of the sensor etc. Eventually we may want both.

This code will make centroid files corresponding to each fits file in the output directory. For example:

wasabi:fits % ls
centroid_197356_R22_S01_r.txt	lsst_e_197356_R22_S01_r.fits
centroid_197356_R22_S10_r.txt	lsst_e_197356_R22_S10_r.fits
centroid_197356_R22_S11_r.txt	lsst_e_197356_R22_S11_r.fits
centroid_197356_R22_S12_r.txt	lsst_e_197356_R22_S12_r.fits
centroid_197356_R22_S21_r.txt	lsst_e_197356_R22_S21_r.fits

With a small piece of code this can be converted into a ds9 region file for overlay. This pandas code example puts a circle at each true object position with the radius scaled by the log of the number of photons for one of the centroid files:

import math
import numpy as np
import pandas as pd

centroids = pd.read_csv('fits/centroid_197356_R22_S11_r.txt', delim_whitespace=True, comment="#")

with open('region_file.reg','w') as outfile:
    outfile.write('physical\n')
    centroids.query('Photons>0').to_string(outfile, columns=['xpos','ypos','Photons'], 
                                           header=False, index=False,
                                           formatters=['circle {:10.3f}'.format,
                                                       '{:10.3f}'.format,
                                                       lambda x: '{:10.3f}'.format(math.log(x))])

Loading this regions file after loading the fits file results in:

screen shot 2018-05-06 at 12 12 42 am

To my eye, there is a small shift between the circle centers and the objects. I'm not sure if this is a plotting issue, a misunderstanding on my part of the variables I used, or some small bug in the code.

The imSim code only sets the options to turn this on and sets the file prefix in the config file. The code to open, close and write to the files is in sims_GalSimInterface. I will open a separate PR there.

Currently, this code only is in the non-sensor version of the GalSimInterpreter class. I would like some feedback from @jchiang87, @rmjarvis and @danielsf before I add much more to make sure this approach seems reasonable to people.

I started by making this look like a PhoSim centroid file since I thought this might make things easier on the people running the pipeline but in principle we could also add more information into the file.

@danielsf
Copy link
Contributor

danielsf commented May 7, 2018

Regarding the offset between the green circles and the objects in the image above:

Was this with or without the sensor model, @cwwalter ? The pixel positions you are printing to the centroid files are calculated before the sensor model is applied. That might have something to do with it.

@cwwalter
Copy link
Member Author

cwwalter commented May 8, 2018

Was this with or without the sensor model, @cwwalter ? The pixel positions you are printing to the centroid files are calculated before the sensor model is applied. That might have something to do with it.

This was without the sensor model (Just calling the drawObject version in GalSimInterpreter). I also ran with the sensor model turned on which uses GalSimSiliconInterpeter. There I saw what looked to my eye like a smaller shift if it was still there in another direction.

@cwwalter
Copy link
Member Author

cwwalter commented Jul 4, 2018

This last change (along with a PR in the sims_GalSimInterface) moves the centroid information into a data structure in memory. This way it can be stored with checkpoints. The centroid files are now written out at the end of the simulation.

in the fits directory with filenames corresponding to the fits
files. The uiniqueID, the true flux and the true object position in
detector coordinates are written to each file.

The code to write obejct information into the filesis in
sims_GalSimInterface.
files at the end of the process.  This is so we can use this with the
checkpointing system.
@coveralls
Copy link

coveralls commented Jul 12, 2018

Coverage Status

Coverage decreased (-0.2%) to 70.534% when pulling 25b9aeb on centroid into e4b4bfc on master.

Copy link
Collaborator

@jchiang87 jchiang87 left a comment

Choose a reason for hiding this comment

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

Looks good...just a few minor change requests.

@@ -34,7 +34,7 @@ class ImageSimulator:
Class to manage the parallel simulation of sensors using the
multiprocessing module.
"""
def __init__(self, instcat, psf, numRows=None, config=None, seed=267,
def __init__(self, instcat, create_centroid_file, psf, numRows=None, config=None, seed=267,
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would prefer to make create_centroid_file a keyword argument with a default value of False rather than make it a required argument, so that existing scripts won't break. I would also add it towards the end of the argument list, say after apply_sensor_model.

@@ -125,6 +126,10 @@ def _make_gs_interpreters(self, seed, sensor_list, file_id):
self.phot_params,
self.obs_md)

if self.create_centroid_file is True:
self.gs_interpreters[det_name].centroid_base_name = self.outdir \
Copy link
Collaborator

Choose a reason for hiding this comment

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

It mostly doesn't matter, but it's probably better to use os.path.join for concatenating path components.

@@ -125,6 +126,10 @@ def _make_gs_interpreters(self, seed, sensor_list, file_id):
self.phot_params,
self.obs_md)

if self.create_centroid_file is True:
Copy link
Collaborator

Choose a reason for hiding this comment

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

if self.create_centroid_file is True: -> if self.create_centroid_file:

@cwwalter
Copy link
Member Author

Requested changes are done in this repo.

The code in close_centroid_files in sims_GalSimInterface was moved
into write_centroid_files.
@cwwalter cwwalter merged commit e311a5f into master Jul 15, 2018
@cwwalter cwwalter deleted the centroid branch July 15, 2018 15:39
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.

4 participants