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

Function to read ICGEM data files #10

Closed
leouieda opened this issue Oct 18, 2018 · 4 comments · Fixed by #11
Closed

Function to read ICGEM data files #10

leouieda opened this issue Oct 18, 2018 · 4 comments · Fixed by #11
Assignees
Labels
enhancement Idea or request for a new feature
Milestone

Comments

@leouieda
Copy link
Member

Description of the desired feature

The ICGEM Calculation Service is an amazing resource to get gravity data. Their grids are in an ASCII format that can be tricky to parse because some values are included in the header. It would be great to have a function that reads the ICGEM file and returns an xarray.Dataset.

This will really help with #9

@leouieda leouieda added the enhancement Idea or request for a new feature label Oct 18, 2018
@leouieda leouieda added this to the v0.1.0 milestone Oct 18, 2018
@leouieda
Copy link
Member Author

leouieda commented Oct 18, 2018

@santis19 would you mind porting fatiando/fatiando#421 to harmonica? There a few changes that will need to be done:

  • Replace the asserts with proper if ... raise checks
  • Use **kwargs to pass arguments to numpy.loadtxt instead of manually specifying usecols
  • Return an xarray.Dataset instead of a dict. You can pass the entire header string as metadata.
  • Probably no need to read in the latitude and longitude limits. But we do need to parse the grid shape from the header.

The function can go in a new harmonica/io.py module and then import it in harminca/__init__.py. This way we can use it as harmonica.load_icgem_gdf instead of having to load several modules.

@santisoler
Copy link
Member

santisoler commented Oct 18, 2018

@leouieda I've just started working on this.
As soon I have a respectable code I'll PR.

I have one two questions: what about tests functions for this function?
Are you intending to leave tests functions for the future or to only merge PRs with 100% test coverage?

@santisoler
Copy link
Member

We need xarray to be listed in environment.yml.
Do you want me to add it on the PR I'm currently working on?

@leouieda
Copy link
Member Author

Are you intending to leave tests functions for the future or to only merge PRs with 100% test coverage?

Yep, test coverage is a must for merging. Github automatically bars merging if coverage of the diff is less than 80%. Leaving it for later is a recipe for never doing it, as I learned from fatiando.

what about tests functions for this function?

The fatiando version has some tests that you can use, if I'm not mistaken. But try to see if you can get 100% coverage. It's worth the exercise as you learn a lot about designing good code. For example, it might be best to try to allow a file name or a file object as input. This way we can use StringIO for testing.

Do you want me to add it on the PR I'm currently working on?

Please include it in the environment.yml, requirements.txt, setup.py, and doc/install.rst.

leouieda pushed a commit that referenced this issue Oct 26, 2018
Port of the `load_icgem_gdf` function from `fatiando.datasets` to `harmonica`.
The new `load_icgem_gdf` loads gdf files that are downloaded from the
[ICGEM Calculation Service](https://icgem.gfz-potsdam.de/) with a few changes:

- Returns an `xarray.Dataset` instance instead of a dictionary.
- The `assert` lines have been replaced by proper `if...raise` checks.
- The `usecols` argument have been explicitly removed, but it still can be passed 
  through `**kwargs`.
- The gdf file header is passed as a dictionary to the `attr` argument of 
  `xarray.Dataset`.

Fixes #10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Idea or request for a new feature
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants