Skip to content

Commit f6aede9

Browse files
committed
methods
1 parent ff79761 commit f6aede9

1 file changed

Lines changed: 27 additions & 28 deletions

File tree

python/alborexdata.py

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -179,27 +179,27 @@ def get_from_netcdf(self, datafile):
179179
"""
180180
Read the coordinates and the temperature from existing data file
181181
"""
182-
if os.path.exists(datafile):
183-
with netCDF4.Dataset(datafile, 'r') as nc:
184-
self.lon = nc.get_variables_by_attributes(standard_name='longitude')[0][:]
185-
self.lat = nc.get_variables_by_attributes(standard_name='latitude')[0][:]
186-
self.time = nc.get_variables_by_attributes(standard_name='time')[0][:]
187-
self.timeunits = nc.get_variables_by_attributes(standard_name='time')[0].units
188-
self.dates = netCDF4.num2date(self.time, self.timeunits)
189182

190-
try:
191-
self.qclat = nc.get_variables_by_attributes(standard_name='latitude status_flag')[0][:]
192-
except IndexError:
193-
self.qclat = None
183+
with netCDF4.Dataset(datafile, 'r') as nc:
184+
self.lon = nc.get_variables_by_attributes(standard_name='longitude')[0][:]
185+
self.lat = nc.get_variables_by_attributes(standard_name='latitude')[0][:]
186+
self.time = nc.get_variables_by_attributes(standard_name='time')[0][:]
187+
self.timeunits = nc.get_variables_by_attributes(standard_name='time')[0].units
188+
self.dates = netCDF4.num2date(self.time, self.timeunits)
194189

195-
try:
196-
self.qclon = nc.get_variables_by_attributes(standard_name='longitude status_flag')[0][:]
197-
except IndexError:
198-
self.qclon = None
199-
try:
200-
self.temperature = nc.get_variables_by_attributes(standard_name='sea_water_temperature')[0][:]
201-
except IndexError:
202-
self.temperature = None
190+
try:
191+
self.qclat = nc.get_variables_by_attributes(standard_name='latitude status_flag')[0][:]
192+
except IndexError:
193+
self.qclat = None
194+
195+
try:
196+
self.qclon = nc.get_variables_by_attributes(standard_name='longitude status_flag')[0][:]
197+
except IndexError:
198+
self.qclon = None
199+
try:
200+
self.temperature = nc.get_variables_by_attributes(standard_name='sea_water_temperature')[0][:]
201+
except IndexError:
202+
self.temperature = None
203203

204204
def apply_qc_latlon(self, QC=[1]):
205205
"""
@@ -304,15 +304,14 @@ def get_from_netcdf(self, datafile):
304304
"""
305305
Read the coordinates and the field values from a netCDF file
306306
"""
307-
if os.path.exists(datafile):
308-
with netCDF4.Dataset(datafile, 'r') as nc:
309-
self.lon = nc.get_variables_by_attributes(standard_name='longitude')[0][:]
310-
self.lat = nc.get_variables_by_attributes(standard_name='latitude')[0][:]
311-
self.time = nc.get_variables_by_attributes(standard_name='time')[0][:]
312-
timeunits = nc.get_variables_by_attributes(standard_name='time')[0].units
313-
self.dates = netCDF4.num2date(self.time, timeunits)
314-
self.salinity = nc.get_variables_by_attributes(standard_name='sea_water_salinity')[0][:]
315-
self.temperature = nc.get_variables_by_attributes(standard_name='sea_water_temperature')[0][:]
307+
with netCDF4.Dataset(datafile, 'r') as nc:
308+
self.lon = nc.get_variables_by_attributes(standard_name='longitude')[0][:]
309+
self.lat = nc.get_variables_by_attributes(standard_name='latitude')[0][:]
310+
self.time = nc.get_variables_by_attributes(standard_name='time')[0][:]
311+
timeunits = nc.get_variables_by_attributes(standard_name='time')[0].units
312+
self.dates = netCDF4.num2date(self.time, timeunits)
313+
self.salinity = nc.get_variables_by_attributes(standard_name='sea_water_salinity')[0][:]
314+
self.temperature = nc.get_variables_by_attributes(standard_name='sea_water_temperature')[0][:]
316315

317316
class CTD():
318317

0 commit comments

Comments
 (0)