How to store a novel variable? #1222
Replies: 2 comments 1 reply
-
Hi. My boss/advisor Chris Edwards helped me figure this out! I was on the right track adding 'NO3' to the 'required_variables' dictionary in my model, but Opendrift needs a reader to read data for the variables specified there! So, I copied and modified 'reader_ROMS_native.py' and added: 'NO3': 'NO3' to the 'self.ROMS_variable_mapping' dictionary. That's all it took. And then used my custom reader in place of the ROMS native reader in my Opendrift model, and I now have nitrate values along my particle trajectories. Hope this helps someone! |
Beta Was this translation helpful? Give feedback.
-
Hi, good that you found a solution. However, strictly the mapping is from As long as your implementation works for you, it is fine. But to be generally applicable (and included in the main repository), CF standard names should be used instead of ad hoc variable names. |
Beta Was this translation helpful? Give feedback.
-
Hi. The ROMS output files I have include biology-related variables like 'NO3', and I want to store their values along particle trajectories.
Naively, I tried the following:
reader_nitrate = reader_ROMS_native.Reader(his_file)
o.add_reader(reader_nitrate, variables=['NO3'])
And got what might be a predictable error, if I knew how things worked:
ValueError: Reader roms native does not provide variables: ['NO3']
I then tried to use a different kind of reader, a-la:
reader_nitrate = reader_netCDF_CF_generic.Reader(his_file)
o.add_reader(reader_nitrate, variables=['NO3'])
But this seemed to hang forever after printing:
17:21:40 INFO opendrift.readers.reader_netCDF_CF_generic:99: Opening files with MFDataset
What might the reason for that be?
I've found a routine called "get_variables_along_trajectory", but I don't know enough about the I/O to feel confident trying to implement this, and it might not be what I need in the first place. I'm hoping that there's a more natural way to make something like 'NO3' an environment variable, so that it's stored by default (as I was able to do with 'sea_water_temperature'). To that end, I have added 'NO3' to the 'required_variables' dictionary in my model class, but, without a reader to go along with it, I'm not getting any output for it. I even tried to "hack" things by adding it as follows:
'NO3': {'fallback': 0, 'default': 'environment'}
Where 'default': 'environment' is copied from configuration specification (and thus probably doesn't belong in the 'required_variables' definition).
Any guidance is appreciated, whether it's examples or explanation/documentation that can help me learn and understand!
Thank you!
Bruce
Beta Was this translation helpful? Give feedback.
All reactions