mesowx / MesoPy

A Python wrapper for the MesoWest environmental data API
MIT License
59 stars 23 forks source link

add funcs for units conversion and saving to csv #5

Open ghost opened 9 years ago

ghost commented 9 years ago

Considering adding these two functions as a little extra utility for the user. Units can be changed in the API call and some endpoints allow output as csv. However, I think it would be beneficial to provide some accessible functions if the user wanted to change the units or write to csv any subset of data from the api request instead of making multiple requests, constantly changing the request, or writing their own code. Any thoughts are appreciated.

lesserwhirls commented 9 years ago

Hey @jclark754 - these are good ideas. For me, they bring up two bigger picture questions:

  1. Do all API calls support changing units? If not, do you just want to support what the API provides in terms of unit changes, or do you think it would be better to deal with all units inside MesoPy using something like the package pint (we use that it MetPy)?
  2. Is the csv file the API returns well documented (i.e. lots of metadata in the header?). As above, do you think it would be better to do the output to csv inside MesoPy so that it's enabled everywhere (and you get to control the content of the csv header)?
ghost commented 9 years ago

@lesserwhirls, I think the module is so simple I'll stick with just supporting the units provided in the API. That's simple enough and practical for right now. I'm just hesitant to add another dependency I think.

Could you elaborate on 2? The API usually returns a json dict unless you set the output variable to 'csv' but this is only for a select few endpoints (climatology and timeseries I think). It would be neat to provide a simple function that writes a csv file to the user's working directory after any data has been retrieved. .

lesserwhirls commented 9 years ago

So with the second point, I was just wondering if the requested csv file from the server contains a header in the first few lines of the file that contains useful information.

If you want to get csv from all endpoints, then I would simply always request a json return and write a function to convert the json dict to a csv file. It's possible code for that already exists somewhere.