Repository: sunpy/sunpy

Issue:
GOES LightCurve object appears to read in the same file all the time-range regardless of the time request
The GOES Lightcurve operates as follows.  Given a request and if there is no data in the download directory, the GOES LightCurve object will download the requested data.  But if given a request, and if there is a GOES file already in the download directory, the GOES Lightcurve object will read that file and return that data, regardless of what the user requested.

I think what is happening is this.  The object understands the time-range request, but the first thing it does is to check to see if that data is already downloaded.  The filename it looks for is xrs_2s.csv.  This filename is always the same regardless of the time-range of the request.  It finds that data in the download directory, and so instead of downloading new data, it loads xrs_2s.csv from file, which is highly unlikely to be the file that the user requested.

Saving GOES data with a unique filename based on the details of the request would solve this problem.  This solution relies on the implicit assumption made by the downloader that every request for data generates a unique file name that is uniquely identified with that request.



Discussion:
good catch. i'll look into this.

@ehsteve Would you like me to take a look at this seeing how you are busy with balloons.


Resolving patch:
diff --git a/sunpy/lightcurve/lightcurve.py b/sunpy/lightcurve/lightcurve.py
--- a/sunpy/lightcurve/lightcurve.py
+++ b/sunpy/lightcurve/lightcurve.py
@@ -166,10 +166,16 @@ def peek(self, **kwargs):
 
     @staticmethod
     def _download(uri, kwargs, 
-                  err='Unable to download data at specified URL'):
+                  err='Unable to download data at specified URL',
+                  filename = None):
         """Attempts to download data at the specified URI"""
-        _filename = os.path.basename(uri).split("?")[0]
-
+        
+        #Allow manual override of output filename (used for GOES)
+        if filename is not None:
+            _filename = filename
+        else:            
+            _filename = os.path.basename(uri).split("?")[0]
+        
         # user specifies a download directory
         if "directory" in kwargs:
             download_dir = os.path.expanduser(kwargs["directory"])
diff --git a/sunpy/lightcurve/sources/goes.py b/sunpy/lightcurve/sources/goes.py
--- a/sunpy/lightcurve/sources/goes.py
+++ b/sunpy/lightcurve/sources/goes.py
@@ -118,6 +118,32 @@ def _get_url_for_date_range(*args, **kwargs):
                                         end.strftime("%Y%m%d"))
 
         return url
+    
+    #Subclass download to enable a different filename
+    @staticmethod
+    def _download(uri, kwargs, err='Unable to download data at specified URL',
+                  filename = None):
+        #Create a better filename
+        query_str = uri.split('?')[1]
+        pars = {}
+        for s in query_str.split('&'):
+            kv = s.split('=')
+            pars.update({kv[0]:kv[1]})
+        
+        base_url = uri.split('?')[0]
+        fname = base_url.split('/')[-1][:-4]
+        pars.update({'data_type':fname})
+        snumber = base_url.split('/')[-2]
+        pars.update({'satellite_number':snumber})
+        
+        filename = '%s_%s_%s_%s.csv'%(pars['satellite_number'],
+                                  pars['data_type'],
+                                  pars['fromDate'],
+                                  pars['toDate'])
+        
+        filepath = LightCurve._download(uri,kwargs,filename=filename)
+        
+        return filepath
 
     @staticmethod
     def _parse_csv(filepath):


Test patch:
diff --git a/sunpy/tests/lightcurve/test_goes.py b/sunpy/tests/lightcurve/test_goes.py
new file mode 100644
--- /dev/null
+++ b/sunpy/tests/lightcurve/test_goes.py
@@ -0,0 +1,34 @@
+"""
+GOES LightCurve Tests
+"""
+from __future__ import absolute_import
+
+import unittest
+import sunpy.lightcurve
+
+class TestGOESLightCurve(unittest.TestCase):
+    
+    def test_goes_range(self):
+       lc1 = sunpy.lightcurve.GOESLightCurve.create('2012/06/01','2012/06/02')
+       
+       assert isinstance(lc1, sunpy.lightcurve.GOESLightCurve)
+    
+    def compare(self,lc1,lc2):
+        try:
+            (lc1.data == lc2.data)
+        except:
+            raise Exception
+    def test_filename(self):
+        lc1 = sunpy.lightcurve.GOESLightCurve.create('2012/06/01','2012/06/02')
+        lc2 = sunpy.lightcurve.GOESLightCurve.create('2012/06/03','2012/06/04')
+        #If the dataframes are non-idential it raises an error, if they are
+        #identical it returns True
+        self.assertRaises(Exception, self.compare, lc1, lc2)
+        
+        #This snippet is better but python 2.7 only, maybe sometime it will be 
+        #useful
+#        with self.assertRaises(Exception) as context:
+#            (lc1.data == lc2.data).all()
+#        
+#        self.assertEqual(context.exception.message,
+#                         'Can only compare identically-labeled DataFrame objects')
\ No newline at end of file