-
Notifications
You must be signed in to change notification settings - Fork 86
Conversation
This PR needs Approvals as follows.
Please choose reviewers and requet reviews! Click to see how to approve each reviewsYou can approve this PR by triggered comments as follows.
See all trigger commentsPlease replace [Target] to review target
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kalpitthakkar-lm Thanks. turbo colormap looks nice.
blueoil/common.py
Outdated
# For replacing the Matplotlib Jet colormap, we use the Turbo color map | ||
# https://ai.googleblog.com/2019/08/turbo-improved-rainbow-colormap-for.html | ||
# The colormap allows for a large number of quantization levels: | ||
# https://github.com/blue-oil/blueoil/tree/master/docs/_static/turbo_cmap.png |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing link. Do you have plan to add image to the documentation?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@iizukak Yes, I will add that image and upload to the commit.
@@ -0,0 +1,258 @@ | |||
TURBO_CMAP_DATA = [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we need to set symlink to here
https://github.com/blue-oil/blueoil/tree/master/output_template/python/blueoil
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I get it. That will make sure the tests will pass (the ones that have failed, because the symlinks are missing there).
Thank you!!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kalpitthakkar-lm
Sorry, Can you add license header to the new file?
like
Lines 1 to 15 in 5575a8a
# -*- coding: utf-8 -*- | |
# Copyright 2018 The Blueoil Authors. All Rights Reserved. | |
# | |
# Licensed under the Apache License, Version 2.0 (the "License"); | |
# you may not use this file except in compliance with the License. | |
# You may obtain a copy of the License at | |
# | |
# http://www.apache.org/licenses/LICENSE-2.0 | |
# | |
# Unless required by applicable law or agreed to in writing, software | |
# distributed under the License is distributed on an "AS IS" BASIS, | |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
# See the License for the specific language governing permissions and | |
# limitations under the License. | |
# ============================================================================= |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OA
@iizukak The tests failed after I updated the branch by pulling from master. What should we do? |
@kalpitthakkar-lm |
@kalpitthakkar-lm This PR should get Python Readability Approval |
blueoil/common.py
Outdated
# The colormap allows for a large number of quantization levels: | ||
# https://github.com/blue-oil/blueoil/tree/master/docs/_static/turbo_cmap.png | ||
# Implementation inspired from the following gist: | ||
# https://gist.github.com/mikhailov-work/ee72ba4191942acecc03fe6da94fc73f |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Original codes are Apache 2.0 licensed.
To use Apache 2.0 licensed codes, you need to do the followings:
(Please see http://www.apache.org/licenses/LICENSE-2.0 4. Redistribution for further information)
- You need to put a copy of the License somewhere
- You need to clarify what you changed from the original
- You need to leave the original copyright
- You need to leave NOTICE files if any
I think there are some rules (e.g. where you should put the License files) in Blueoil, so please ask BO team that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@iizukak Where should I put the license file / clarify what I have changed from the original?
# limitations under the License. | ||
# ============================================================================= | ||
|
||
TURBO_CMAP_DATA = [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above.
blueoil/common.py
Outdated
def interpolate(colormap, x): | ||
x = max(0.0, min(1.0, x)) | ||
a = int(x*255.0) | ||
b = min(255, a + 1) | ||
f = x*255.0 - a | ||
return [colormap[a][0] + (colormap[b][0] - colormap[a][0]) * f, | ||
colormap[a][1] + (colormap[b][1] - colormap[a][1]) * f, | ||
colormap[a][2] + (colormap[b][2] - colormap[a][2]) * f] | ||
|
||
|
||
def interpolate_or_clip(colormap, x): | ||
if x < 0.0: | ||
return [0.0, 0.0, 0.0] | ||
elif x > 1.0: | ||
return [1.0, 1.0, 1.0] | ||
else: | ||
return interpolate(colormap, x) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will you need these methods?
I think only color_map_apply
is sufficient.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed them.
blueoil/common.py
Outdated
image_colored[image < 0.0] = 0.0 | ||
image_colored[image > 1.0] = 1.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this won't happen since we clipped values before.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct, I fixed it.
blueoil/common.py
Outdated
# If image range is [0, 1], continue ahead. Else convert to that range. | ||
if image.max() > 1.0: | ||
image = (image - image.min()) / image.max() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is inconsistency between the comment and its code.
(The code does not check the min value)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't need to change the range of values.
I've updated the code.
blueoil/common.py
Outdated
if image.max() > 1.0: | ||
image = (image - image.min()) / image.max() | ||
|
||
x = image.clip(0.0, 1.0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the comment is true, then you don't need this code.
blueoil/common.py
Outdated
return interpolate(colormap, x) | ||
|
||
|
||
def color_map_apply(image): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think apply_color_map
is more straightforward.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Made the change.
blueoil/common.py
Outdated
x = image.clip(0.0, 1.0) | ||
a = (x * 255).astype(int) | ||
b = (a + 1).clip(max=255) | ||
f = x * 255.0 - a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
numpy.modf
will be helpful
https://numpy.org/doc/stable/reference/generated/numpy.modf.html
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't it be easier to understand this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Although it is not a major issue, it seems redundant to calculate x * 255.0
twice.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct, let me update it to np.modf (I will add a comment on how it works above it though..)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Commented
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please let me review after fixing license issues. Thank you!
Sorry, I'm now checking the status |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Please put a copy of the License somewhere
- Please clarify what you changed from the original
They have not provided their LICENSE copy, but only the License Identifier (SPDX line) and a copyright line. I have included both in the colormap table file. Apache-2.0 LICENSE terms are available everywhere.
I did not change anything in the colormap table. That's the only thing I have taken from the gist. The function |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They have not provided their LICENSE copy, but only the License Identifier (SPDX line) and a copyright line. I have included both in the colormap table file. Apache-2.0 LICENSE terms are available everywhere.
Got it.
@iizukak Could you confirm whether it is OK or not?
I did not change anything in the colormap table. That's the only thing I have taken from the gist. The function apply_color_map is written by myself.
It seems you changed its format and name.
blueoil/turbo_color_map.py
Outdated
@@ -0,0 +1,279 @@ | |||
# -*- coding: utf-8 -*- | |||
# Copyright 2018 The Blueoil Authors. All Rights Reserved. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# Copyright 2018 The Blueoil Authors. All Rights Reserved. | |
# Copyright 2020 The Blueoil Authors. All Rights Reserved. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for taking long time!
Ownership Approval
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
RA (reverse-shadowing)
/ready |
⏳Merge job is queued... |
😥This PR is not approved yet. |
@tsawada Can you have a look? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Readability wise, this PR is okay.
Is this going to allow us to drop matplotlib dependency? If not, simply switching to inferno
colormap would be easier.
# Colormap table taken from the following gist: | ||
# https://gist.github.com/mikhailov-work/ee72ba4191942acecc03fe6da94fc73f | ||
# Copyright 2019 Google LLC. | ||
# SPDX-License-Identifier: Apache-2.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so what's the license of this file? I feel it's weird having two license claims on this file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, I will remove the Blueoil LICENSE header, as the table in the file is from the gist so I'll put these four lines at the top.
blueoil/common.py
Outdated
# >>> print(i.shape, f.shape) | ||
# >>> (6,) (6,) | ||
# >>> print(i) | ||
# >>> [ 1. 2. 4. 20. 6. 8.] | ||
# >>> print(f) | ||
# >>> [0.2 0.3 0.5 0.45 0.75 0.88] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
some lines wouldn't have >>>
on the interpreter.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it. Will update that.
@tsawada Yes this will allow us to drop matplotlib dependency (it's used for Jet colormap used in heatmaps). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Readability Approval
@iizukak Please give the command to merge this PR once the status checks are completed. Thank you! |
/ready |
⏳Merge job is queued... |
What this patch does to fix the issue.
This PR contains replacement of the current
Jet
colormap of matplotlib by adding the Google proposed Turbo Colormap as highlighted in #485 by @tk26eng inblueoil/common.py
.This colormap is for replacing the
Jet
colormap in matplotlib that is used for coloring heatmaps. So I added a new function that takes the heatmap as input and then returns the colored heatmap. As the function uses numpy, it should be called usingtf.py_func
interface.The table for reference colors is a (256x3) matrix of sRGB colors and I saved it to a separate file
blueoil/turbo_color_map.py
.Link to any relevant issues or pull requests.
Relevant issue: #485