Skip to content
This repository has been archived by the owner on Dec 22, 2021. It is now read-only.

save_surfer function #413

Open
jgmenzer opened this issue Nov 17, 2017 · 3 comments
Open

save_surfer function #413

jgmenzer opened this issue Nov 17, 2017 · 3 comments

Comments

@jgmenzer
Copy link

jgmenzer commented Nov 17, 2017

Hey All,
I have started working on a save(or export) as surfer ascii grid file function. I am fairly new to python and fatiando, so any suggestions are greatly appreciated. Jeremy

import numpy
def save_surfer(fname,data):
#set header variables, note all variables are switched to x horizontal and y vertical to fit with surfer terminology
#also z values are set to a max of 5 decimal places to save on space in ascii format
#this was chosen because this is just slightly above most field equipment's level of precision
#required inputs are a file name (fname) which should end in ".asc" and the data (data) to be exported 
#also need data shape and area which should already be created from fatiando
    ncols = int(shape[1])
    nrows = int(shape[0])
    xmin = area[2]
    xmax = area[3]
    ymin = area[0]
    ymax = area[1]
    datamin = round(numpy.amin(data), 5)
    datamax = round(numpy.amax(data), 5)
    header = ('DSAA'+'\n'+' '+str(ncols)+' '+str(nrows)+'\n'+' '+str(xmin)+' '+str(xmax)
              +'\n'+' '+str(ymin)+' '+str(ymax)+'\n'+' '+str(datamin)+' '+str(datamax))
#make 2d array
    tmp = numpy.array(tf).reshape(ncols,nrows)
    numpy.savetxt(fname,tmp, fmt='%.5f', delimiter=' ', header=(header), comments = '')
@leouieda
Copy link
Member

Hi Jeremy, thanks for writing this!

I added some markup to your issue text to format the code properly. Github has a Markdown guide if you want to see what is possible.

Have you ever used git? This is what we use to manage code contributions and collaborate on Fatiando.

A contribution here is called a Pull Request. We have services in place that automatically test the code and check if everything is well. We can also review the code and make suggestions. See this recent one by @santis19 for an example: #411

If you want to give it a try, checkout these great guides:

It's a very useful skill to have and I guarantee that it will not be time wasted.
I use this for everything, including writing papers: https://github.com/pinga-lab

Of course, we're very happy to help with whatever you need.

If you don't want (or have time) to get into git, we can always comment here and we'll add the code ourselves.

@jgmenzer
Copy link
Author

Hi Leo,

This is my first time using git, I am interested in learning more about it and how to properly contribute as there are some other things I will need to develop for some of my research which are probably well suited to add to fatiando. However, I may be a little slow getting to this at least until the semester is over, but if there is no rush I would be happy to go through the steps to add the save_surfer function.

Thanks,
Jeremy

@leouieda
Copy link
Member

@jgmenzer there is no rush. Take your time and please ask as much as you need. Either here on this issue, on the mailing list, or on our Gitter chatroom. I'm really bad at keeping up to date with all the notifications and emails (there a few sitting in my inbox needing a reply), so no pressure.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants