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

Keyerror Raised #38

Closed
jjobel opened this issue Sep 19, 2020 · 2 comments
Closed

Keyerror Raised #38

jjobel opened this issue Sep 19, 2020 · 2 comments
Assignees

Comments

@jjobel
Copy link
Collaborator

jjobel commented Sep 19, 2020

It seems that the the key value x_label is not found in the config file when running the following code,

def get_data(self, config, catalog):
        xlabel = fits_label(config['x_label'])
        ylabel = fits_label(config['y_label'])

From my understanding, the xlabel references the fits_label function while taking in as input config['x_label'] as the axis name but I end up with the following error,

KeyError: 'x_label'

Which I found to mean that I'm trying to access a key that is not in the dictionary. I've also tried using the following,

def get_data(self, config, catalog):
        xlabel = fits_label(Config.__getitem__(x_label))
        ylabel = fits_label(Config.__getitem__(y_label))

I now get the following error,

NameError: name 'x_label' is not defined

Essentially, I'm trying to figure out how to obtain x and y for the Data class.

@jjobel
Copy link
Collaborator Author

jjobel commented Sep 20, 2020

This is a follow up.

It seems that I can define def get_data(self, config, catalog): as the following,

def get_data(self, config, catalog):
        args = parser.parse_args()
        x_label = args.x
        y_label = args.y
        xlabel = fits_label(config.__getitem__(x_label))
        ylabel = fits_label(config.__getitem__(y_label))
        x = catalog[xlabel]
        y = catalog[ylabel]

This way I'm able to retrieve x_label = r2500_band_lumin value. Unfortunately, I still get a KeyError message but I'm working that out.
I used the user input arguments for the x and y values and define them as x_label and y_label. This is an alternative to def get_data(options): from the master branch.

@sweverett
Copy link
Owner

I wrote the __getitem__() function of the Config class so that you can access it like a normal dictionary, so you don't need to do config.__getitem__(x_label).

The key error just means that there is no entry for x_label in the config. In the master branch that is because it is passed as a command line argument rather than through the config. Personally I think that is probably the better way, so you can quickly explore different x,y fits on a catalog with the same config settings. But we could move it to the config if you'd like.

Here's the short version of what I'd suggest:

# in main():
args = parser.parse_args()
config = Config(args)

...

# in Config():

def __init__(args):
        self.config_filename = args.config_file
        self.x = args.x
        self.y = args.y

        with open(self.config_filename, 'r') as stream:
            self._config = yaml.safe_load(stream)

        return

This way now constructs a Config purely from the command line arguments. It still grabs the config_file from args, but also grabs other useful things like the x and y names that are passed to fits_label() in the master branch.

sweverett added a commit that referenced this issue Sep 25, 2020
…st flag & NaN checking. Now runs successfully (at least on linux). #39, closes #31, #35, #36, #38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants