Exemplo n.º 1
0
 def setUp(self):
     self.data1 = egads.EgadsData(value=[0.5, 2.3, 6.2, 8.1, 4.],
                                  units='mm',
                                  long_name='a common data',
                                  scale_factor=1.,
                                  _FillValue=-999)
     self.data2 = egads.EgadsData(value=[0., 1., 2., 3., 4.],
                                  units='days since 20170101 00:00:00Z',
                                  long_name='a common time vector',
                                  scale_factor=1.,
                                  _FillValue=-999)
     self.ncfilename = tempfile.mktemp('.nc')
     self.nafilename = tempfile.mktemp('.na')
     self.csvfilename = tempfile.mktemp('.csv')
     f = einput.EgadsNetCdf(self.ncfilename, 'w')
     f.add_attribute('Conventions', 'CF-1.0')
     f.add_attribute('history', 'the netcdf file has been created by EGADS')
     f.add_attribute('comments', 'no comments on the netcdf file')
     f.add_attribute('institution', 'EUFAR')
     f.add_attribute('source', 'computer')
     f.add_attribute('title', 'a test file')
     f.add_attribute('authors', 'John Doe ([email protected])')
     f.add_dim('time', len(self.data2))
     f.write_variable(self.data2, 'time', ('time', ), 'double')
     f.write_variable(self.data1, 'data', ('time', ), 'double')
     f.add_attribute('long_name', self.data1.metadata['long_name'], 'data')
     f.add_attribute('units', self.data1.metadata['units'], 'data')
     f.add_attribute('scale_factor', self.data1.metadata['scale_factor'],
                     'data')
     f.add_attribute('units', self.data2.metadata['units'], 'time')
     f.add_attribute('long_name', self.data2.metadata['long_name'], 'time')
     f.add_attribute('scale_factor', self.data2.metadata['scale_factor'],
                     'time')
     f.close()
Exemplo n.º 2
0
    def test_convert_na_to_nc(self):
        """ Test conversion of NASA Ames to NetCDF"""

        f = einput.NasaAmes(self.na_filename)
        f.convert_to_netcdf(self.nc_filename)
        g = einput.EgadsNetCdf(self.nc_filename, 'r')
        author = g.get_attribute_value('authors')
        special_com = g.get_attribute_value('special_comments')
        time = g.read_variable('Time_np')
        self.assertEqual(self.authors, author,
                         'Originator values do not match')
        self.assertEqual(self.special_com, special_com,
                         'Special comments do not match')
        self.assertListEqual(time.value.tolist(), time.value.tolist(),
                             'both time values do not match')
Exemplo n.º 3
0
    def test_convert_nc_to_na_egadsnetcdf(self):
        """ Test conversion of NetCDF to NASA Ames, using the EgadsNetCdf class """

        f = einput.EgadsNetCdf(self.ncfilename)
        f.convert_to_nasa_ames(self.nafilename)
        f.close()
        g = einput.NasaAmes(self.nafilename)
        self.assertEqual('John Doe ([email protected])',
                         g.file_metadata['Originator'],
                         'Originator values do not match')
        self.assertEqual('computer', g.file_metadata['Source'],
                         'Source values do not match')
        data = g.read_variable('data')
        self.assertListEqual(self.data1.value.tolist(), data.value.tolist(),
                             'data and data1 values do not match')
        g.close()
Exemplo n.º 4
0
    def test_read_n6sp_data(self):
        """ Test reading in data using N6SP formatted NetCDF """

        infile = einput.EgadsNetCdf(self.file)
        self.assertEqual(infile.file_metadata['title'], TITLE,
                         'NetCDF title attribute doesnt match')
        data = infile.read_variable(VAR_NAME)
        assert_array_equal(data.value, random_data)
        self.assertEqual(data.units, VAR_UNITS,
                         'EgadsData units attribute doesnt match')
        self.assertEqual(data.metadata['units'], VAR_UNITS,
                         'EgadsData units attribute doesnt match')
        self.assertEqual(data.metadata['long_name'], VAR_LONG_NAME,
                         'EgadsData long name attribute doesnt match')
        self.assertEqual(data.metadata['standard_name'], VAR_STD_NAME,
                         'EgadsData standard name attribute doesnt match')
        infile.close()
Exemplo n.º 5
0
    def test_egadsnetcdf_instance_creation(self):
        """ Test creation of a netcdf file via the EgadsNetCdf class """

        filename = tempfile.mktemp('.nc')
        g = einput.EgadsNetCdf(filename, 'w')
        g.add_dim('time', len(self.data2))
        g.write_variable(self.data2, 'time', ('time', ), 'double')
        g.write_variable(self.data1, 'data', ('time', ), 'double')
        g.close()
        f = netCDF4.Dataset(filename, 'r')  # @UndefinedVariable
        varin = f.variables['data']
        self.assertEqual(varin.shape[0], len(self.data2),
                         'Variable dimensions dont match')
        self.assertEqual(varin.scale_factor, 1.0,
                         'Variable scale factor dont match')
        self.assertEqual(varin.long_name, 'a common data',
                         'Variable long name dont match')
        f.close()
Exemplo n.º 6
0
def netcdf_reading(self):
    logging.debug(
        'gui - reading_functions.py - netcdf_reading: open_file_name ' +
        str(self.open_file_name))
    clear_gui(self)
    self.opened_file = input.EgadsNetCdf(self.open_file_name, 'a')
    list_of_variables = sorted(self.opened_file.get_variable_list())
    self.list_of_global_attributes = self.opened_file.get_attribute_list()
    self.list_of_dimensions = self.opened_file.get_dimension_list()
    add_global_attributes_to_buttons(self)
    for var in list_of_variables:
        dimensions = self.opened_file.get_dimension_list(str(var))
        list_of_var_attributes = self.opened_file.get_attribute_list(str(var))
        list_of_var_attributes['var_name'] = str(var)
        list_of_var_attributes = add_correct_units(self,
                                                   list_of_var_attributes)
        try:
            egads_instance = self.opened_file.read_variable(var)
            self.list_of_variables_and_attributes[var] = [
                var, list_of_var_attributes, dimensions, egads_instance
            ]
        except Exception:
            self.list_of_unread_variables.append(var)
            logging.exception(
                'gui - reading_functions.py - : an error occured during the re'
                + 'ading of a variable, variable ' + str(var))
    update_compatibility_label(self)
    out_file_base, out_file_ext = ntpath.splitext(
        ntpath.basename(self.open_file_name))
    read_set_attribute_gui(self, self.gm_filename_ln,
                           out_file_base + out_file_ext)
    update_global_attribute_gui(self, 'NetCDF')
    self.listWidget.addItems(list_of_variables)
    self.listWidget.itemClicked.connect(lambda: var_reading(self))
    self.tabWidget.currentChanged.connect(lambda: update_icons_state(self))
    all_buttons = self.tabWidget.findChildren(QtWidgets.QToolButton)
    for widget in all_buttons:
        if widget.objectName() != '' and widget.objectName() != 'gm_button_7':
            widget.clicked.connect(lambda: modify_attribute_gui(self, 'left'))
            widget.rightClick.connect(
                lambda: modify_attribute_gui(self, 'right'))
    logging.debug(
        'gui - reading_functions.py - netcdf_reading: netcdf file loaded')
Exemplo n.º 7
0
    def test_convert_nc_to_csv_egadsnetcdf(self):
        """ Test conversion of NetCDF to Nasa/Ames CSV, using the EgadsNetCdf class """

        f = einput.EgadsNetCdf(self.ncfilename)
        f.convert_to_csv(self.csvfilename)
        f.close()
        g = einput.EgadsCsv()
        g.open(self.csvfilename, 'r')
        lines = g.read()
        author = lines[1][0]
        computer = lines[3][0]
        raw = lines[-5:]
        time = []
        data = []
        for i in raw:
            time.append(float(i[0]))
            data.append(float(i[1]))
        self.assertEqual('John Doe ([email protected])', author,
                         'Originator values do not match')
        self.assertEqual('computer', computer, 'Source values do not match')
        self.assertListEqual(self.data1.value.tolist(), data,
                             'data and data1 values do not match')
        self.assertListEqual(self.data2.value.tolist(), time,
                             'time and data2 values do not match')