Skip to content

Commit

Permalink
Add discrete maps of the Scientific colour maps
Browse files Browse the repository at this point in the history
Update colormap_class.f90 and scientific_colour_maps.f90.
Add gpl_to_lut.f90 to convert gpl files to lut files.
Update the scripts.
Update README.md.
  • Loading branch information
gha3mi committed Nov 2, 2023
1 parent 73f84ed commit 0e59c94
Show file tree
Hide file tree
Showing 7 changed files with 6,176 additions and 374 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ forcolormap = {git = "https://github.com/vmagnin/forcolormap.git" }
* [ ] Improve the documentation.
* [ ] Include a few images in the README.md file.
* [ ] A table with the characteristics of the colormaps: which are colorblind friendly, perceptually uniform, B&W print safe, etc.
* [ ] In the *Scientific colour maps,* the discrete colormaps were not imported for the time being because there is no `.lut` file. F. Crameri could add them in a future version.
* [ ] Colormaps could have an option for logscale.
* [ ] A `get_colorbar()` function could return an `array(:,:,1:3)` containing the RGB image of the colorbar. The arguments could be the width and height, the direction (horizontal/vertical), etc.
* [ ] A `save()` method could save a colormap as RGB values separated by spaces in a `.lut` text file.
Expand Down
448 changes: 384 additions & 64 deletions scripts/copy-paste_code.f90

Large diffs are not rendered by default.

237 changes: 223 additions & 14 deletions scripts/generate_scmap.f90
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,228 @@ program generate_scientific_colour_maps
! List of the Scientific coulour maps:
character(*), dimension(*), parameter :: scientific_colour_maps_list = &
[character(colormap_name_length) :: &
"acton", "actonS", "bamako", "bamakoS", "bam", &
"bamO", "batlowK", "batlowKS", "batlow", "batlowS",&
"batlowW", "batlowWS", "berlin", "bilbao", "bilbaoS",&
"broc", "brocO", "buda", "budaS", "bukavu",&
"cork", "corkO", "davos", "davosS", "devon",&
"devonS", "fes", "glasgow", "glasgowS", "grayC",&
"grayCS", "hawaii", "hawaiiS", "imola", "imolaS",&
"lajolla", "lajollaS", "lapaz", "lapazS", "lipari",&
"lipariS", "lisbon", "managua", "navia", "naviaS", &
"naviaW", "naviaWS", "nuuk", "nuukS", "oleron",&
"oslo", "osloS", "roma", "romaO", "tofino", &
"tokyo", "tokyoS", "turku", "turkuS", "vanimo", &
"vik", "vikO" ]
"acton",&
"acton10",&
"acton100",&
"acton25",&
"acton50",&
"actonS",&
"bam",&
"bam10",&
"bam100",&
"bam25",&
"bam50",&
"bamako",&
"bamako10",&
"bamako100",&
"bamako25",&
"bamako50",&
"bamakoS",&
"bamO",&
"bamO10",&
"bamO100",&
"bamO25",&
"bamO50",&
"batlow",&
"batlow10",&
"batlow100",&
"batlow25",&
"batlow50",&
"batlowK",&
"batlowK10",&
"batlowK100",&
"batlowK25",&
"batlowK50",&
"batlowKS",&
"batlowS",&
"batlowW",&
"batlowW10",&
"batlowW100",&
"batlowW25",&
"batlowW50",&
"batlowWS",&
"berlin",&
"berlin10",&
"berlin100",&
"berlin25",&
"berlin50",&
"bilbao",&
"bilbao10",&
"bilbao100",&
"bilbao25",&
"bilbao50",&
"bilbaoS",&
"broc",&
"broc10",&
"broc100",&
"broc25",&
"broc50",&
"brocO",&
"brocO10",&
"brocO100",&
"brocO25",&
"brocO50",&
"buda",&
"buda10",&
"buda100",&
"buda25",&
"buda50",&
"budaS",&
"bukavu",&
"bukavu10",&
"bukavu100",&
"bukavu25",&
"bukavu50",&
"cork",&
"cork10",&
"cork100",&
"cork25",&
"cork50",&
"corkO",&
"corkO10",&
"corkO100",&
"corkO25",&
"corkO50",&
"davos",&
"davos10",&
"davos100",&
"davos25",&
"davos50",&
"davosS",&
"devon",&
"devon10",&
"devon100",&
"devon25",&
"devon50",&
"devonS",&
"fes",&
"fes10",&
"fes100",&
"fes25",&
"fes50",&
"glasgow",&
"glasgow10",&
"glasgow100",&
"glasgow25",&
"glasgow50",&
"glasgowS",&
"grayC",&
"grayC10",&
"grayC100",&
"grayC25",&
"grayC50",&
"grayCS",&
"hawaii",&
"hawaii10",&
"hawaii100",&
"hawaii25",&
"hawaii50",&
"hawaiiS",&
"imola",&
"imola10",&
"imola100",&
"imola25",&
"imola50",&
"imolaS",&
"lajolla",&
"lajolla10",&
"lajolla100",&
"lajolla25",&
"lajolla50",&
"lajollaS",&
"lapaz",&
"lapaz10",&
"lapaz100",&
"lapaz25",&
"lapaz50",&
"lapazS",&
"lipari",&
"lipari10",&
"lipari100",&
"lipari25",&
"lipari50",&
"lipariS",&
"lisbon",&
"lisbon10",&
"lisbon100",&
"lisbon25",&
"lisbon50",&
"managua",&
"managua10",&
"managua100",&
"managua25",&
"managua50",&
"navia",&
"navia10",&
"navia100",&
"navia25",&
"navia50",&
"naviaS",&
"naviaW",&
"naviaW10",&
"naviaW100",&
"naviaW25",&
"naviaW50",&
"naviaWS",&
"nuuk",&
"nuuk10",&
"nuuk100",&
"nuuk25",&
"nuuk50",&
"nuukS",&
"oleron",&
"oleron10",&
"oleron100",&
"oleron25",&
"oleron50",&
"oslo",&
"oslo10",&
"oslo100",&
"oslo25",&
"oslo50",&
"osloS",&
"roma",&
"roma10",&
"roma100",&
"roma25",&
"roma50",&
"romaO",&
"romaO10",&
"romaO100",&
"romaO25",&
"romaO50",&
"tofino",&
"tofino10",&
"tofino100",&
"tofino25",&
"tofino50",&
"tokyo",&
"tokyo10",&
"tokyo100",&
"tokyo25",&
"tokyo50",&
"tokyoS",&
"turku",&
"turku10",&
"turku100",&
"turku25",&
"turku50",&
"turkuS",&
"vanimo",&
"vanimo10",&
"vanimo100",&
"vanimo25",&
"vanimo50",&
"vik",&
"vik10",&
"vik100",&
"vik25",&
"vik50",&
"vikO",&
"vikO10",&
"vikO100",&
"vikO25",&
"vikO50"]
character(colormap_name_length) :: cmap_name
character(colormap_name_length+4) :: filename
integer :: i, k, n
Expand Down Expand Up @@ -111,7 +320,7 @@ program generate_scientific_colour_maps

! That code must be copied/pasted in the colormap_class.f90 file:
write(out2, '( 8x, A, A, A)') 'case("', trim(cmap_name), '")'
write(out2, '(12x, 5A)') 'call self%create("', trim(cmap_name), '", &
write(out2, '(12x, 5A)') 'call self%create(self%name,&
& self%zmin, self%zmax, ', trim(cmap_name), ")"

! We use the .lut files (ImageJ format) from the Scientific coulour maps (https://www.fabiocrameri.ch/colourmaps/):
Expand Down
102 changes: 102 additions & 0 deletions scripts/gpl_to_lut.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
! This program converts .gpl files in the Scientific Colour Map directory and its subdirectories to .lut files.
! The .lut files are written to the same directory, and copies are made to the current directory.
! It also prints the list of all .lut files.
! Note: This program is intended for use on Linux/Unix systems.
!-------------------------------------------------------------------------------
! Contributed by gha3mi: 2023-11-02
! Last modification: gha3mi 2023-11-02
!-------------------------------------------------------------------------------
! Run with the command:
! gfortran gpl_to_lut.f90 && ./a.out

program gpl_to_lut
implicit none

character(*), parameter :: dir='./ScientificColourMaps8' ! path to Scientific Colour Map directory

call convert_all(dir)
call print_lut_files(dir)
call cp_lut_files(dir)

contains

subroutine convert_gpl_to_lut(file_name)
character(len=*), intent(in) :: file_name
integer :: nunit, i, iostat, num_rows
integer, dimension(:,:), allocatable :: colors
logical :: file_exists

inquire(file=file_name//'.gpl', exist=file_exists)
if (file_exists) then
open(newunit=nunit,file=trim(file_name)//'.gpl',status='old',action='read')
read(nunit,*)
read(nunit,*)
read(nunit,*)
read(nunit,*)
num_rows = 0
do
read(nunit, *, iostat=iostat)
if (iostat /= 0) exit
num_rows = num_rows + 1
end do
allocate(colors(num_rows,3))
rewind(nunit)
read(nunit,*)
read(nunit,*)
read(nunit,*)
read(nunit,*)
do i = 1, num_rows
read(nunit, *) colors(i,1:3)
end do
close(nunit)
open(newunit=nunit, file=file_name//'.lut', status='replace', action='write')
print'(a,a,a)', 'Writing '//file_name//'.lut'
do i = 1, size(colors,1)
write(nunit, '(*(I3,1x))') colors(i,:)
end do
close(nunit)
else
error stop 'File '//file_name//'.gpl does not exist'
end if
end subroutine convert_gpl_to_lut

subroutine convert_all(path)
character(*), intent(in) :: path
character(1024) :: file_name, gpl_file_list
integer :: nunit, iostat
logical :: file_exists

inquire(file=path, exist=file_exists)
if (file_exists) then
gpl_file_list = 'gpl_file_list.txt'
call execute_command_line("find "//trim(path)//" -type f -name '*.gpl' | sed 's/\.gpl$//' > "//trim(gpl_file_list))
inquire(file=trim(gpl_file_list), exist=file_exists)
if (file_exists) then
open(newunit=nunit, file=trim(gpl_file_list), status='old', action='read')
do
read(nunit, '(a)', iostat=iostat) file_name(:)
call convert_gpl_to_lut(trim(file_name))
if (iostat /= 0) exit
end do
close(nunit, status='delete')
else
error stop 'File '//trim(gpl_file_list)//' does not exist'
end if
else
error stop 'Directory '//path//' does not exist. Please provide the correct path to the Scientific Colour Map directory'
end if
end subroutine convert_all

subroutine print_lut_files(path)
character(*), intent(in) :: path
print'(a)','list of all .lut files:'
call execute_command_line("find "//trim(path)//" -type f -name '*.lut'")
call execute_command_line("find "//trim(path)//&
" -type f -name '*.lut' -execdir bash -c 'echo $(basename '{}' .lut)' \; | sort")
end subroutine print_lut_files

subroutine cp_lut_files(path)
character(*), intent(in) :: path
call execute_command_line("find "//trim(path)//" -type f -name '*.lut' -exec cp {} . \;")
end subroutine cp_lut_files
end program gpl_to_lut
Loading

0 comments on commit 0e59c94

Please sign in to comment.