-
Notifications
You must be signed in to change notification settings - Fork 11
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
Further documentation on creating fields and writing fields to file #53
Comments
This would be a great help! Lets say I already have a compliant file, can I extract the schema in a sensible in order to populate a new file with similar but potentially different data. An example like this would be really helpful. Is there a way to create a "skeleton" of the file and then populate it with data? |
Hi @kurtsansom, thanks for registering that you would also find such further documentation useful. It helps us to know multiple people would benefit from some improvement, as in this case, so we can make it a higher priority. Your particular questions are interesting because (if I understand your requests correctly) both are indeed possible and also documented quite well, just not with the cfdm library directly, rather in cf-python, our data analysis library which extends cfdm in functionality and scope. So, if you are willing to use cf-python instead of cfdm standalone (see here for the installation guide), I can point you directly to documentation which covers in detail how to do what you wish to, programmatically:
Yes, this can be achieved by two different approaches in cf-python:
We do have detailed examples for each the three stages I list above in our documentation, but not all three stages at once to create an end-to-end example for what you specifically want to do. Now I have pointed out relevant sections, do you think it could still be helpful to have an end-to-end example, or do you think what we already have, as covered separately, is sufficient? I am asking because I personally think it could be "overkill" to have an additional section, but what is obvious to me about how to link various functionality together might not be obvious to others. In general, for documentation on using cf-python to write out new files modified in a CF-compliant way relative to existing ones, I suggest consulting the following sections which detail the two steps necessary:
If instead you want or need to use cfdm and not cf-python, note that in the near future we plan to port the so-called 'creation commands' which enable such constructions from cf-python into cfdm, such that they can be used in both libraries and therefore will be available directly in cfdm too. Of course we will update the documentation accordingly to cover the extended capability. I hope this helps. If it is not quite what you were asking for, or you have further questions, please let us know. |
The " creation commands" methods will be available in cfdm at the next release (1.8.7.0). They'll behave exactly the same as they do in cf-python (i.e. https://ncas-cms.github.io/cf-python/tutorial.html#command-modification) Thanks. |
@sadielbartholomew I think I was thinking along the lines of the metadata as well. pyart, uses something like a simple dictionary of dictionaries to define the attributes that map to the actual variables in the code. Or something like
|
Hi @kurtsansom, creating such a dictionary should be straightforward, using the In [8]: import cfdm
In [9]: f = cfdm.example_field(0)
In [10]: f.properties()
Out[10]:
{'Conventions': 'CF-1.8',
'project': 'research',
'standard_name': 'specific_humidity',
'units': '1'}
In [11]: for c in f.constructs.values():
...: try:
...: print(repr(c), c.properties())
...: except AttributeError:
...: pass
...:
<DimensionCoordinate: latitude(5) degrees_north> {'units': 'degrees_north', 'standard_name': 'latitude'}
<DimensionCoordinate: longitude(8) degrees_east> {'units': 'degrees_east', 'standard_name': 'longitude'}
<DimensionCoordinate: time(1) days since 2018-12-01 > {'units': 'days since 2018-12-01', 'standard_name': 'time'}
Does that help? Do let me know if I've missed anything. |
As stated in an email thread:
This is in response to a(n expert) user request:
The text was updated successfully, but these errors were encountered: