Thanks to visit codestin.com
Credit goes to github.com

Skip to content

imod.visualize.read_legend could also return labels #332

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

Open
Manangka opened this issue Feb 17, 2023 · 5 comments
Open

imod.visualize.read_legend could also return labels #332

Manangka opened this issue Feb 17, 2023 · 5 comments
Milestone

Comments

@Manangka
Copy link
Collaborator

In GitLab by @Huite on Feb 17, 2023, 13:26

@Manangka
Copy link
Collaborator Author

In GitLab by @FransRoelofsen on Feb 22, 2023, 14:04

Huite, nice that you added this issue. Based on our discussion on the NewOrleans project where I needed the labels for my cross section. For that reason I create a new issue to upgrade imod.visualize.cross_section

My quick fix for now:

def read_imod_legend(path):    
   ...
   ...
   labels = list(legend["domain"])[::-1][1:]
return colors, levels, labels

@FransRoelofsen
Copy link

Hi @JoerivanEngelen , this is an easy fix and logical addition. And it works. Can you add it to the code?

@FransRoelofsen
Copy link

FransRoelofsen commented Jun 4, 2025

the update of the code is slightly more than suggested in an earlier post.
It should be

# From def read_imod_legend(path):
def _read(delim_whitespace):
    return pd.read_csv(
        path,
        header=1,
        delim_whitespace=delim_whitespace,
        index_col=False,
        usecols=[0, 1, 2, 3, 4, 5],
        names=["upper", "lower", "red", "green", "blue", "domain"],
    )

# Try both comma and whitespace separated
try:
    legend = _read(delim_whitespace=False)
except ValueError:
    legend = _read(delim_whitespace=True)

# The colors in iMOD are formatted in RGB. Format to hexadecimal.
red = legend["red"]
blue = legend["blue"]
green = legend["green"]
colors = [f"#{r:02x}{g:02x}{b:02x}" for r, g, b in zip(red, green, blue)][::-1]
levels = list(legend["lower"])[::-1][1:]
labels= list(legend["domain"])[::-1][1:]

return colors, levels, labels

@JoerivanEngelen
Copy link
Contributor

Hi @FransRoelofsen,

Thanks for reminding me and adding some code to showcase what you want, two questions:

  • Is this a requirement for the 1.0 release in your opinion? If so I'll add it to the milestone
  • Could you share some example files here which should work?

@FransRoelofsen
Copy link

  1. Please make it available in 1.0 while it is a simple improvement but most of all: it could be important for iMOD5 users to try iMOD Python.
  2. FYI: LEG files can not be uploaded so I changed it into LEG.TXT.
    Transmissivity.leg.txt

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

No branches or pull requests

3 participants