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

Map Creation Error when norm_kwargs dictionary is sparse. #84

Open
TheSkyentist opened this issue Nov 24, 2023 · 5 comments
Open

Map Creation Error when norm_kwargs dictionary is sparse. #84

TheSkyentist opened this issue Nov 24, 2023 · 5 comments
Assignees
Labels
bug Something isn't working

Comments

@TheSkyentist
Copy link
Contributor

There is some unpredictable behavior with a per-file norm_kwargs dictionary.

I have a directory with the following structure:

 fitsmap/
├─ F200W.fits
├─ F200W-307.0.fits
├─ RGB.png
├─ Segmentation.png
/

The following code snippet results in the following error:

# Normalization kwargs
norm_kwargs = {
    'F200W.fits':dict(stretch='log',min_percent=30, max_percent=99.9),
    'Segmentation.png':dict(stretch='log',min_percent=10, max_percent=99.9)
}

# Make Map
files = ['RGB.png','F200W.fits','F200W-307.0.fits','Segmentation.png']
convert.files_to_map(
    files,out_dir='test',
    norm_kwargs=norm_kwargs
    )
  File "████/fitsmap/fitsmap/convert.py", line 1196, in files_to_map
    any(map(f, tasks))
  File "████/fitsmap/fitsmap/convert.py", line 1194, in f
    func_args[0](**func_args[1])
  File "████/fitsmap/fitsmap/convert.py", line 461, in tile_img
    mpl_norm, mpl_cmap = build_mpl_objects(array.array, image_norm)
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "████/fitsmap/fitsmap/convert.py", line 408, in build_mpl_objects
    mpl_norm = simple_norm(array, **norm_kwargs)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: simple_norm() got an unexpected keyword argument 'F200W.fits'

The error occurs after converting the F200W.fits file and the index.html file is not created.
Behaviour is a little unpredictable, depending on which files are called as input, their order, and how many are used in the norm_kwargs file.

@ryanhausen ryanhausen self-assigned this Nov 27, 2023
@ryanhausen
Copy link
Owner

Thanks for reporting. I will look into this.

@ryanhausen ryanhausen added the bug Something isn't working label Nov 27, 2023
@ryanhausen
Copy link
Owner

@TheSkyentist

It looks the norm_kwargs are trying to map to the png image:

# Normalization kwargs
norm_kwargs = {
    'F200W.fits':dict(stretch='log',min_percent=30, max_percent=99.9),
    'Segmentation.png':dict(stretch='log',min_percent=10, max_percent=99.9) # this image shouldn't have any norm kwargs 
}

Do you get the same error if you give a norm kwargs map for just the fits files?

The code doesn't currently validate the norm_kwargs and because you don't provide any norm_kwargs for one of your fits files the whole dict is being passed in.

I will add some norm_kwargs validation. In the mean time, you need to provide either:

  1. a single norm_kwargs dict for all the fits files

or

  1. a dictionary with a norm_kwargs with an entry for each of the fits files.

@TheSkyentist
Copy link
Contributor Author

TheSkyentist commented Nov 29, 2023

It does not give me an error when I only include the FITS files. However, it also does not give me an error when I include some of the PNGs and FITS files, only certain combinations cause errors. For example:

norm_kwargs={
        'RGB.png':dict(stretch="log",min_percent=30,max_percent=99.9),
        'F200W.fits':dict(stretch="log",min_percent=30,max_percent=99.9),
        'F200W-307.0.fits':dict(stretch="log",min_percent=30,max_percent=99.9),
        'Segmentation.png':dict(stretch="log",min_percent=30,max_percent=99.9)
    }

causes no errors.

@ryanhausen
Copy link
Owner

@TheSkyentist

Thanks for checking. It will only give the error when there is a FITS file that doesn't contain an entry in the dictionary. The offending code is here:

    image_engine = IMG_ENGINE_MPL if file_location.endswith(".fits") else IMG_ENGINE_PIL
    if image_engine == IMG_ENGINE_MPL:
        image_norm = norm_kwargs.get(os.path.basename(file_location), norm_kwargs)
        mpl_norm, mpl_cmap = build_mpl_objects(array.array, image_norm)

If you put a PNG in there it won't ever get checked because the code only uses the norm_kwargs for FITS image files.

I need to add some code to validate the norm_kwargs, but for now doing the above will avoid errors.

Thanks again for reporting!

@TheSkyentist
Copy link
Contributor Author

Ah okay I understand now, thanks for checking!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants