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

JP-2037 and JP-1926: Fixing ramp fitting multiprocessing to work with new STCAL interface. #30

Merged
merged 5 commits into from
Jul 28, 2021

Conversation

kmacdonald-stsci
Copy link
Collaborator

@kmacdonald-stsci kmacdonald-stsci commented Jun 15, 2021

Ramp fitting multiprocessing is now working as it did in JWST 1.1.0 with the optional results bug detailed in JP-1926. For JP-1926, the optional results product varies in size depending on the maximum number of segments. When sliced results from each process was being reassembled into the final optional results product returned from ramp fitting, the maximum sizes per slice may be different, so this needed to be accounted for.

All unit tests pass on JWST.

Copy link
Contributor

@dmggh dmggh left a comment

Choose a reason for hiding this comment

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

In addition to these, I may have a few other comments.

new_model.err : ndarray
The output total variance for each pixel, 2-D float32
rows_per_slice: list
The number of rows in each row.
Copy link
Contributor

Choose a reason for hiding this comment

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

Should that be "The number of rows in each slice" ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes. Thank you for catching that.

new_model.var_rnoise : ndarray
The variance in each pixel due to read noise, 2-D float32
pool_results: list
The list of return values from ols_ramp_fit_single for each slice.
Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps state what these values are in the list.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I expanded this docstring.

group_time=ramp_data.group_time,
groupgap=ramp_data.groupgap,
nframes=ramp_data.nframes,
drop_frames1=ramp_data.drop_frames1)
Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't this meta data for same for each slice ? If so perhaps it can be moved outside the loop this function is within.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This meta data is needed by each process in multiprocessing, therefore each RampData class needs this information.

return out_model, int_model, opt_model


def create_output_models(input_model, number_of_integrations, save_opt,
Copy link
Contributor

Choose a reason for hiding this comment

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

Has create_output_models( ) been replaced by another function ?

Copy link
Collaborator Author

@kmacdonald-stsci kmacdonald-stsci Jun 16, 2021

Choose a reason for hiding this comment

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

No. There are no models being returned from ramp fitting anymore. Ramp fitting returns tuples of arrays that the step code in each pipeline will now use to create the desired data model specific to that pipeline.

For multiprocessing, however, output arrays need to be created that are assembled from the sliced return values. The function create_output_info does this in assemble_pool_results.

if save_opt:
get_opt_slice(opt_info, opt_slice, current_row_start, nrows)
current_row_start = current_row_start + nrows

Copy link
Contributor

Choose a reason for hiding this comment

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

Does get_integ_slice( ) assemble the output info from the slices whose output info was assembled from each image by get_image_slice( ) ? Maybe add a bit more documentation to clarify what these functions do.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

No. The sliced (by row) return values are returned from starmap where each sliced input is used as parameters for ols_ramp_fit_single. These sliced return values are used by the get_xxxx_slice() functions to assemble each slice into a single xxxx product to be returned from ramp fitting.

jdavies-st
jdavies-st previously approved these changes Jun 17, 2021
Copy link
Collaborator

@jdavies-st jdavies-st left a comment

Choose a reason for hiding this comment

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

This looks good!

Comment on lines +324 to +331
slope[:, :oslope.shape[1], srow:erow, :] = oslope
sigslope[:, :osigslope.shape[1], srow:erow, :] = osigslope
var_poisson[:, :ovar_poisson.shape[1], srow:erow, :] = ovar_poisson
var_rnoise[:, :ovar_rnoise.shape[1], srow:erow, :] = ovar_rnoise
yint[:, :oyint.shape[1], srow:erow, :] = oyint
sigyint[:, :osigyint.shape[1], srow:erow, :] = osigyint
weights[:, :oweights.shape[1], srow:erow, :] = oweights
crmag[:, :ocrmag.shape[1], srow:erow, :] = ocrmag
Copy link
Collaborator

Choose a reason for hiding this comment

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

I really like the use of mnemonics here. Much easier to read code. What's the significance of shape[1]? Is that number of integrations?

Copy link
Collaborator Author

@kmacdonald-stsci kmacdonald-stsci Jun 17, 2021

Choose a reason for hiding this comment

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

The significance of shape[1] is that it is of variable size. All but the crmag depend on the maximum number of segments in each ramp. The crmag size depends on the maximum number of cosmic rays. Since it's possible for each slice to have different maximum sizes, the full optional results arrays will be set to the maximum across all slices. Since it's possible for the different slices to be of different sizes simple assignment can throw an error trying to assign arrays of different sizes.

For example, it is not possible to do

crmag[:, :, srow:erow, :] = ocrmag

if crmag[:, :, srow:erow, :].shape is (1, 5, 256, 2048), while ocrmag.shape is (1, 2, 256, 2048).

The shapes must have the same dimensions. By construction the first, third, and fourth dimensions will be the same. The second dimension of crmag will always be at least as large as the second dimension of ocrmag, but it may be larger. To ensure that this dimension is the same, it needs to be explicitly applied during assignment.

…=nd.float32, but should be dtype=np.uint32. Changed to allocate an array with the correct dtype.
@codecov
Copy link

codecov bot commented Jul 9, 2021

Codecov Report

❗ No coverage uploaded for pull request base (main@686a1bb). Click here to learn what that means.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##             main      #30   +/-   ##
=======================================
  Coverage        ?   10.30%           
=======================================
  Files           ?       13           
  Lines           ?     1563           
  Branches        ?        0           
=======================================
  Hits            ?      161           
  Misses          ?     1402           
  Partials        ?        0           

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 686a1bb...3604a44. Read the comment docs.

hbushouse
hbushouse previously approved these changes Jul 27, 2021
@nden
Copy link
Collaborator

nden commented Jul 28, 2021

@kmacdonald-stsci This needs a change log entry and it's ready to be merged.

@nden nden merged commit 8cf81e0 into spacetelescope:main Jul 28, 2021
@dmggh
Copy link
Contributor

dmggh commented Jul 29, 2021

I realize this PR has already been merged; nevertheless LGTM.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants