Beispiel #1
0
    def process_asc_files(self):
        '''
        Loop through all .asc files and write each one out as a netCDF file trajectory format

        Processed c*.asc files look like:

      TimeJ       PrDM      DepSM      C0S/m      C1S/m      T090C      T190C        Bat      Xmiss         V1    Sbeox0V         V2  FlECO-AFL         V3     Upoly0         V4        Par         V5       AltM         V6      Sal00      Sal11 Potemp090C Potemp190C  Sigma-###  Sigma-###   Sbeox0PS Sbeox0ML/LSbeox0Mm/Kg       Nbin       Flag
 255.146576    201.000    199.418   3.624490   3.624558     8.9554     8.9567     0.5549    87.0474     4.3840     0.9861     0.9866     0.3602     0.0344  0.0002000     0.0000 1.0000e-12     0.1295     100.00     5.0000    34.0047    34.0043     8.9339     8.9352    26.3492    26.3487   25.01885    1.62677     70.846         45 0.0000e+00
 255.146622    200.000    198.436   3.624405   3.624416     8.9551     8.9556     0.5529    87.0908     4.3862 -9.990e-29     0.9866     0.3557     0.0342  0.0002000     0.0000 1.0000e-12     0.1294     100.00     5.0000    34.0046    34.0042     8.9337     8.9343    26.3492    26.3488 -9.990e-29 -9.990e-29 -9.990e-29         27 0.0000e+00
 255.146622    199.000    197.437   3.624085   3.624098     8.9518     8.9525     0.5547    87.0507     4.3842 -9.990e-29     0.9866     0.3700     0.0348  0.0002000     0.0000 1.0000e-12     0.1294     100.00     5.0000    34.0048    34.0044     8.9306     8.9312    26.3499    26.3494 -9.990e-29 -9.990e-29 -9.990e-29         22 0.0000e+00
        '''

        # Fill up the object's member data item lists from all the files - read only the processed *.asc files that match pattern, 
        fileList = glob(os.path.join(self.args.inDir, self.args.pattern))
        fileList.sort()
        for file in fileList:
            if not file.endswith('.asc'):
                continue
            print "file = %s" % file
            if file == './pctd/c0912c01.asc':
                # Special fix for first cast on September 2012 CANON cruise
                print "Converting %s up to down" % file
                file = convert_up_to_down(file)

            try:
                year, lat, lon = get_year_lat_lon(file)
            except HdrFileNotFound as e:
                print e
                print "Please make sure that the archive is consistent with naming of .asc, .btl, and .hdr files"
                continue
            except PositionNotFound as e:
                print e
                continue

            # Initialize member lists for each file processed
            self.esec_list = []
            self.lat_list = []
            self.lon_list = []
            self.pr_list = [] 
            self.t_list = []
            self.sal_list = []
            self.xmiss_list = []
            self.ecofl_list = []
            self.wetstar_list = []
            self.oxygen_list = []
            if self.args.analog:
                self.an_chan, self.an_var, self.an_units = self.args.analog.split(':')
                self.analog_list = []

            for r in csv.DictReader(open(file), delimiter=' ', skipinitialspace=True):
                ##print r
                if not r['TimeJ']:
                    continue
                if r['TimeJ'] == '-9.990e-29':
                    continue
                # A TimeJ value of 1.0 is 0000 hours 1 January, so subtract 1 day
                dt = datetime(year, 1, 1, 0, 0, 0) + timedelta(days=float(r['TimeJ'])) - timedelta(days=1)

                ##print dt
                esDiff = dt - datetime(1970, 1, 1, 0, 0, 0)
                es = 86400 * esDiff.days + esDiff.seconds
                ##print datetime.fromtimestamp(es)
                
                self.esec_list.append(es)
                try:
                    self.lat_list.append(float(r['Latitude']))  # For tow-yo processed data
                except KeyError:
                    self.lat_list.append(lat)

                try:
                    self.lon_list.append(float(r['Longitude'])) # For tow-yo processed data
                except KeyError:
                    self.lon_list.append(lon)

                try:
                    self.pr_list.append(float(r['PrDM']))
                except KeyError:
                    self.pr_list.append(float(r['PrdM']))       # Sub compact rosette
       
                try: 
                    self.t_list.append(r['T190C'])
                except KeyError:
                    pass
                try:
                    self.t_list.append(r['Tv290C'])
                except KeyError:
                    pass

                self.sal_list.append(r['Sal00'])

                try:
                    self.xmiss_list.append(float(r['Xmiss']))
                except ValueError:
                    self.xmiss_list.append(self.missing_value)

                try:
                    self.ecofl_list.append(r['FlECO-AFL'])
                except KeyError:
                    pass
                try:
                    self.wetstar_list.append(r['WetStar'])
                except KeyError:
                    pass
                try:
                    self.oxygen_list.append(r['Sbeox0ML/L'])
                except KeyError:
                    pass

                if self.args.analog:
                    try:
                        self.analog_list.append(r[self.an_chan])
                    except KeyError:
                        pass

            self.write_pctd(file)
Beispiel #2
0
    def process_asc_files(self):
        '''
        Loop through all .asc files and write each one out as a netCDF file trajectory format

        Processed c*.asc files look like:

      TimeJ       PrDM      DepSM      C0S/m      C1S/m      T090C      T190C        Bat      Xmiss         V1    Sbeox0V         V2  FlECO-AFL         V3     Upoly0         V4        Par         V5       AltM         V6      Sal00      Sal11 Potemp090C Potemp190C  Sigma-###  Sigma-###   Sbeox0PS Sbeox0ML/LSbeox0Mm/Kg       Nbin       Flag
 255.146576    201.000    199.418   3.624490   3.624558     8.9554     8.9567     0.5549    87.0474     4.3840     0.9861     0.9866     0.3602     0.0344  0.0002000     0.0000 1.0000e-12     0.1295     100.00     5.0000    34.0047    34.0043     8.9339     8.9352    26.3492    26.3487   25.01885    1.62677     70.846         45 0.0000e+00
 255.146622    200.000    198.436   3.624405   3.624416     8.9551     8.9556     0.5529    87.0908     4.3862 -9.990e-29     0.9866     0.3557     0.0342  0.0002000     0.0000 1.0000e-12     0.1294     100.00     5.0000    34.0046    34.0042     8.9337     8.9343    26.3492    26.3488 -9.990e-29 -9.990e-29 -9.990e-29         27 0.0000e+00
 255.146622    199.000    197.437   3.624085   3.624098     8.9518     8.9525     0.5547    87.0507     4.3842 -9.990e-29     0.9866     0.3700     0.0348  0.0002000     0.0000 1.0000e-12     0.1294     100.00     5.0000    34.0048    34.0044     8.9306     8.9312    26.3499    26.3494 -9.990e-29 -9.990e-29 -9.990e-29         22 0.0000e+00
        '''

        # Fill up the object's member data item lists from all the files - read only the processed *.asc files that match pattern,
        fileList = glob(os.path.join(self.args.inDir, self.args.pattern))
        fileList.sort()
        for file in fileList:
            if not file.endswith('.asc'):
                continue
            print "file = %s" % file
            if file == './pctd/c0912c01.asc':
                # Special fix for first cast on September 2012 CANON cruise
                print "Converting %s up to down" % file
                file = convert_up_to_down(file)

            try:
                year, lat, lon = get_year_lat_lon(file)
            except HdrFileNotFound as e:
                print e
                print "Please make sure that the archive is consistent with naming of .asc, .btl, and .hdr files"
                continue
            except PositionNotFound as e:
                print e
                continue

            # Initialize member lists for each file processed
            self.esec_list = []
            self.lat_list = []
            self.lon_list = []
            self.pr_list = []
            self.t_list = []
            self.sal_list = []
            self.xmiss_list = []
            self.ecofl_list = []
            self.wetstar_list = []
            self.oxygen_list = []
            if self.args.analog:
                self.an_chan, self.an_var, self.an_units = self.args.analog.split(
                    ':')
                self.analog_list = []

            for r in csv.DictReader(open(file),
                                    delimiter=' ',
                                    skipinitialspace=True):
                ##print r
                if not r['TimeJ']:
                    continue
                if r['TimeJ'] == '-9.990e-29':
                    continue
                # A TimeJ value of 1.0 is 0000 hours 1 January, so subtract 1 day
                dt = datetime(year, 1, 1, 0, 0, 0) + timedelta(
                    days=float(r['TimeJ'])) - timedelta(days=1)

                ##print dt
                esDiff = dt - datetime(1970, 1, 1, 0, 0, 0)
                es = 86400 * esDiff.days + esDiff.seconds
                ##print datetime.fromtimestamp(es)

                self.esec_list.append(es)
                try:
                    self.lat_list.append(float(
                        r['Latitude']))  # For tow-yo processed data
                except KeyError:
                    self.lat_list.append(lat)

                try:
                    self.lon_list.append(float(
                        r['Longitude']))  # For tow-yo processed data
                except KeyError:
                    self.lon_list.append(lon)

                try:
                    self.pr_list.append(float(r['PrDM']))
                except KeyError:
                    self.pr_list.append(float(
                        r['PrdM']))  # Sub compact rosette

                try:
                    self.t_list.append(r['T190C'])
                except KeyError:
                    pass
                try:
                    self.t_list.append(r['Tv290C'])
                except KeyError:
                    pass

                self.sal_list.append(r['Sal00'])

                try:
                    self.xmiss_list.append(float(r['Xmiss']))
                except ValueError:
                    self.xmiss_list.append(self.missing_value)

                try:
                    self.ecofl_list.append(r['FlECO-AFL'])
                except KeyError:
                    pass
                try:
                    self.wetstar_list.append(r['WetStar'])
                except KeyError:
                    pass
                try:
                    self.oxygen_list.append(r['Sbeox0ML/L'])
                except KeyError:
                    pass

                if self.args.analog:
                    try:
                        self.analog_list.append(r[self.an_chan])
                    except KeyError:
                        pass

            self.write_pctd(file)
Beispiel #3
0
    def process_asc_files(self):
        '''
        Loop through all .asc files and write each one out as a netCDF file trajectory format

        Processed c*.asc files look like:

      TimeJ       PrDM      DepSM      C0S/m      C1S/m      T090C      T190C        Bat      Xmiss         V1    Sbeox0V         V2  FlECO-AFL         V3     Upoly0         V4        Par         V5       AltM         V6      Sal00      Sal11 Potemp090C Potemp190C  Sigma-###  Sigma-###   Sbeox0PS Sbeox0ML/LSbeox0Mm/Kg       Nbin       Flag
 255.146576    201.000    199.418   3.624490   3.624558     8.9554     8.9567     0.5549    87.0474     4.3840     0.9861     0.9866     0.3602     0.0344  0.0002000     0.0000 1.0000e-12     0.1295     100.00     5.0000    34.0047    34.0043     8.9339     8.9352    26.3492    26.3487   25.01885    1.62677     70.846         45 0.0000e+00
 255.146622    200.000    198.436   3.624405   3.624416     8.9551     8.9556     0.5529    87.0908     4.3862 -9.990e-29     0.9866     0.3557     0.0342  0.0002000     0.0000 1.0000e-12     0.1294     100.00     5.0000    34.0046    34.0042     8.9337     8.9343    26.3492    26.3488 -9.990e-29 -9.990e-29 -9.990e-29         27 0.0000e+00
 255.146622    199.000    197.437   3.624085   3.624098     8.9518     8.9525     0.5547    87.0507     4.3842 -9.990e-29     0.9866     0.3700     0.0348  0.0002000     0.0000 1.0000e-12     0.1294     100.00     5.0000    34.0048    34.0044     8.9306     8.9312    26.3499    26.3494 -9.990e-29 -9.990e-29 -9.990e-29         22 0.0000e+00
        '''

        # Fill up the object's member data item lists from all the files - read only the processed c*.asc files, 
        # the realtime.asc data will be processed by the end of the cruise
        fileList = glob(os.path.join(self.inDir, self.beginFileString + '*.asc'))
        fileList.sort()
        for file in fileList:
            print "file = %s" % file
            if file == './pctd/c0912c01.asc':
                # Special fix for first cast on September 2012 CANON cruise
                print "Converting %s up to down" % file
                file = convert_up_to_down(file)

            year, lat, lon = get_year_lat_lon(file)

            # Initialize member lists for each file processed
            self.esec_list = []
            self.lat_list = []
            self.lon_list = []
            self.pr_list = [] 
            self.t_list = []
            self.sal_list = []
            self.xmiss_list = []
            self.ecofl_list = []
            self.wetstar_list = []
            self.oxygen_list = []
            self.oxyps_list = []

            for r in csv.DictReader(open(file), delimiter=' ', skipinitialspace=True):
                if not r['TimeJ']:
                    continue
                # A TimeJ value of 1.0 is 0000 hours 1 January, so subtract 1 day
                dt = datetime(year, 1, 1, 0, 0, 0) + timedelta(days=float(r['TimeJ'])) - timedelta(days=1)

                ##print dt
                esDiff = dt - datetime(1970, 1, 1, 0, 0, 0)
                es = 86400 * esDiff.days + esDiff.seconds
                ##print datetime.fromtimestamp(es)
                
                self.esec_list.append(es)
                self.lat_list.append(lat)
                self.lon_list.append(lon)
                try:
                    self.pr_list.append(float(r['PrDM']))
                except KeyError:
                    self.pr_list.append(float(r['PrdM']))       # Sub compact rosette
       
                try: 
                    self.t_list.append(r['T190C'])
                except KeyError:
                    pass
                try:
                    self.t_list.append(r['Tv290C'])
                except KeyError:
                    pass

                self.sal_list.append(r['Sal00'])
                self.xmiss_list.append(r['Xmiss'])
                try:
                    self.ecofl_list.append(r['FlECO-AFL'])
                except KeyError:
                    pass
                try:
                    self.wetstar_list.append(r['WetStar'])
                except KeyError:
                    pass
                try:
                    self.oxygen_list.append(r['Sbeox0ML/L'])
                except KeyError:
                    pass
                try:
                    self.oxyps_list.append(r['Sbeox0PS'])
                except KeyError:
                    pass

            self.write_pctd(file)