예제 #1
0
    def test_replace_data_in_file(self):
        " Test replacing data in NASA Ames file"

        f = einput.NasaAmes(self.filename)
        f.write_attribute_value("ONAME", "Jane Doe; email: [email protected]")
        f.write_variable(self.new_data, varname="Time2")
        f.save_na_file(self.filename, float_format='%.4f')
        f.close()
        g = einput.NasaAmes(self.filename)
        self.assertEqual(self.new_originator, g.file_metadata['Originator'],
                         'Originator values do not match')
        var1_intcall = g.read_variable("Time2")
        self.assertEqual(self.new_data[2],
                         var1_intcall.value.tolist()[2], 'Var do not match')
        g.close()
예제 #2
0
 def setUp(self):
     self.na_filename = tempfile.mktemp('.na')
     self.nc_filename = tempfile.mktemp('.nc')
     f = einput.NasaAmes()
     f.save_na_file(self.na_filename, NA_DICT, float_format='%.4f')
     f.close()
     self.authors = 'John Doe; email: [email protected]'
     self.special_com = 'This is a test file for verifying the status of the EGADS NASA Ames functionality.'
     self.time = egads.EgadsData(
         value=[51143.42, 51144.42, 51145.42, 51146.42, 51147.42],
         units='seconds after midnight',
         _FillValue=-9900.,
         scale_factor=1.,
         standard_name='Time_np')
예제 #3
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')
예제 #4
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()
예제 #5
0
 def setUp(self):
     self.filename = tempfile.mktemp('.na')
     f = einput.NasaAmes()
     f.save_na_file(self.filename, NA_DICT, float_format='%.4f')
     f.close()
     self.originator = 'John Doe; email: [email protected]'
     self.new_originator = 'Jane Doe; email: [email protected]'
     self.org = 'ORGANIS'
     self.scom = [
         'This is a test file for verifying the status of the EGADS NASA Ames functionality.'
     ]
     self.var_names = [
         'GPS LAT', 'GPS LON', 'Height above sea level', 'Time2'
     ]
     self.units = ['degrees', 'degrees', 'm', 'seconds after midnight']
     self.miss_vals = [-9900.0, -9900.0, -9900.0, -9900.0]
     self.time_max = 51147.42
     self.time_min = 51143.42
     self.GPS_LON_max = 11.2778
     self.GPS_LON_min = 11.2809
     self.new_data = [61143.42, 61144.42, 61145.42, 61146.42, 61147.42]
예제 #6
0
    def test_read_file(self):
        " Test reading data from NASA Ames file"

        f = einput.NasaAmes(self.filename)
        self.assertEqual(self.org, f.file_metadata['Organisation'],
                         'Organisation values do not match')
        self.assertEqual(self.originator, f.file_metadata['Originator'],
                         'Originator values do not match')
        self.assertEqual(self.scom, f.file_metadata['SpecialComments'],
                         'Special comments do not match')
        var_names = f.get_variable_list()
        self.assertEqual(self.var_names, var_names,
                         'Variable names do not match')
        var1_intcall = f.read_variable(1)
        self.assertEqual(
            self.units[1], var1_intcall.metadata['units'],
            'Var 1 units do not match; {0} expected, {1} returned'.format(
                self.units[1], var1_intcall.metadata['units']))
        self.assertEqual(self.miss_vals[1],
                         var1_intcall.metadata['_FillValue'],
                         'Var 1 missing values do not match')
        self.assertEqual(self.GPS_LON_max, var1_intcall.value[-1],
                         'Var 1 max values do not match')
        self.assertEqual(self.GPS_LON_min, var1_intcall.value[0],
                         'Var 1 min values do not match')
        var1_namecall = f.read_variable(var_names[1])
        self.assertEqual(self.units[1], var1_namecall.metadata['units'],
                         'Var 1 units do not match')
        self.assertEqual(self.miss_vals[1],
                         var1_namecall.metadata['_FillValue'],
                         'Var 1 missing values do not match')
        self.assertEqual(self.GPS_LON_max, var1_namecall.value[-1],
                         'Var 1 max values do not match')
        self.assertEqual(self.GPS_LON_min, var1_namecall.value[0],
                         'Var 1 min values do not match')
        f.close()
예제 #7
0
def nasaames_reading(self):
    logging.debug(
        'gui - reading_functions.py - nasaames_reading : open_file_name ' +
        str(self.open_file_name))
    clear_gui(self)
    self.opened_file = input.NasaAmes(self.open_file_name, 'r')
    list_of_variables = sorted(
        self.opened_file.get_variable_list(vartype='independant') +
        self.opened_file.get_variable_list(vartype='main'))
    list_of_attributes = self.opened_file.get_attribute_list()
    self.list_of_global_attributes = {}
    for attribute in list_of_attributes:
        if attribute != 'V' and attribute != 'X':
            self.list_of_global_attributes[
                attribute] = self.opened_file.get_attribute_value(attribute)
    self.list_of_dimensions = self.opened_file.get_dimension_list(
        vartype='independant')
    list_of_var_dimensions = self.opened_file.get_dimension_list(
        vartype='main')
    add_global_attributes_to_buttons(self)
    for var in list_of_variables:
        dimensions = self.list_of_dimensions
        try:
            list_of_attributes = self.opened_file.get_attribute_list(
                str(var), vartype='main')
        except ValueError:
            list_of_attributes = self.opened_file.get_attribute_list(
                str(var), vartype='independant')
        list_of_var_attributes = {}
        for attribute in list_of_attributes:
            try:
                list_of_var_attributes[
                    attribute] = self.opened_file.get_attribute_value(
                        attribute, var, 'main')
            except ValueError:
                list_of_var_attributes[
                    attribute] = self.opened_file.get_attribute_value(
                        attribute, var, 'independant')
        list_of_var_attributes['var_name'] = str(var)
        list_of_var_attributes = add_correct_units(self,
                                                   list_of_var_attributes)
        egads_instance = self.opened_file.read_variable(var)
        self.list_of_variables_and_attributes[var] = [
            var, list_of_var_attributes, dimensions, egads_instance
        ]
    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, 'NASA Ames')
    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() != 'gm_button_7' and widget.objectName() != '':
            widget.clicked.connect(lambda: modify_attribute_gui(self, 'left'))
            widget.rightClick.connect(
                lambda: modify_attribute_gui(self, 'right'))
    logging.debug(
        'gui - reading_functions.py - nasaames_reading : nasa ames file loaded'
    )