metno / pyaerocom

Python tools for climate and air quality model evaluation
https://pyaerocom.readthedocs.io/
GNU General Public License v3.0
26 stars 15 forks source link

Presence of "-" character in metadata keys breaks UngriddedData.filter_by_meta() #122

Closed hansbrenna closed 2 years ago

hansbrenna commented 4 years ago

Any metadata variable key containing the character "-" is unusable for filtering on metadata using UngriddedData.filter_by_meta() because any metadata key has to be a valid python keyword and not an expression.

We should consider fixing this either by making sure characters like "-" are never used in metadata keys, or changing how filter_by_meta() workd.

Example code that fails:

import pyaerocom as pya
reader= pya.io.ReadUngridded()
eea=reader.read('GHOST.EEA.daily','concpm25',)
eea.filter_by_meta(NOAA-DMSP-OLS_v4_average_nighttime_stable_lights_25km=[1,28])
jgliss commented 4 years ago

Good point. One workaround in such cases could be to call the method differently, by parsing via dict directly (which you would possibly also do in similar functionality in other libraries, e.g. xarray):

import pyaerocom as pya
reader= pya.io.ReadUngridded()
eea=reader.read('GHOST.EEA.daily','concpm25',)
eea.filter_by_meta(**{'NOAA-DMSP-OLS_v4_average_nighttime_stable_lights_25km':[1,28]})

@hansbrenna Have you tested if this works when running it through the web-tools (i.e. specify as dict obs_filters)?

hansbrenna commented 4 years ago

Interesting that that works. I thought it would not work, but I was probably having problems with issue #118 and not this when I filtering Joly-Peuch did not work in the web processing.

I'll test it when I have time using "NOAA-DMSP-OLS_v4_average_nighttime_stable_lights_25km".

jgliss commented 4 years ago

Yeah, that is a python peculiarity / feature I guess. But you can always parse kwargs either via expressions (i.e. callable(bla='Blub', blub=42) or as dictionaries callable({'bla':'Blub', 'blub':42}). Let me know if it works through the highlevel routines!

jgliss commented 4 years ago

Under the hood, *kwargs are always* parsed as a dictionary and can be used as such within the function body.

jgriesfeller commented 2 years ago

closed due to age