Ejemplo n.º 1
0
    def create_two_driving_datasets(self):
        """
        Creates two driving datasets with datasets, parameter values etc set up
        :return: nothing
        """

        with session_scope(Session) as session:
            self.create_driving_dataset(session)

            model_run_service = ModelRunService()

            driving2 = DrivingDataset()
            driving2.name = "driving2"
            driving2.description = "driving 2 description"
            driving2.geographic_region = 'Global'
            driving2.spatial_resolution = 'Half degree'
            driving2.temporal_resolution = '3 Hours'
            driving2.boundary_lat_north = 85
            driving2.boundary_lat_south = -90
            driving2.boundary_lon_west = -180
            driving2.boundary_lon_east = 180
            driving2.time_start = datetime.datetime(1901, 1, 1, 0, 0, 0)
            driving2.time_end = datetime.datetime(2001, 1, 1, 0, 0, 0)
            driving2.view_order_index = 200
            driving2.usage_order_index = 2
            driving2.is_restricted_to_admins = False

            location3 = DrivingDatasetLocation()
            location3.base_url = "base_url3"
            location3.driving_dataset = driving2

            val = f90_helper.python_to_f90_str(8 * ["i"])
            pv1 = DrivingDatasetParameterValue(model_run_service, driving2,
                                               constants.JULES_PARAM_DRIVE_INTERP, val)
            val = f90_helper.python_to_f90_str(3600)
            pv2 = DrivingDatasetParameterValue(model_run_service, driving2,
                                               constants.JULES_PARAM_DRIVE_DATA_PERIOD, val)
            val = f90_helper.python_to_f90_str("data/driving2/frac.nc")
            pv3 = DrivingDatasetParameterValue(model_run_service, driving2,
                                               constants.JULES_PARAM_FRAC_FILE, val)
            val = f90_helper.python_to_f90_str("frac2")
            pv4 = DrivingDatasetParameterValue(model_run_service, driving2,
                                               constants.JULES_PARAM_FRAC_NAME, val)
            val = f90_helper.python_to_f90_str(['b', 'sathh', 'satcon', 'sm_sat', 'sm_crit',
                                                'sm_wilt', 'hcap', 'hcon', 'albsoil'])
            pv5 = DrivingDatasetParameterValue(model_run_service, driving2,
                                               constants.JULES_PARAM_SOIL_PROPS_VAR, val)
            val = f90_helper.python_to_f90_str(['bexp', 'sathh', 'satcon', 'vsat', 'vcrit',
                                                'vwilt', 'hcap', 'hcon', 'albsoil'])
            pv6 = DrivingDatasetParameterValue(model_run_service, driving2,
                                               constants.JULES_PARAM_SOIL_PROPS_VAR_NAME, val)
            val = f90_helper.python_to_f90_str(9)
            pv7 = DrivingDatasetParameterValue(model_run_service, driving2,
                                               constants.JULES_PARAM_SOIL_PROPS_NVARS, val)
            val = f90_helper.python_to_f90_str("data/WATCH_2D/ancils/soil_igbp_bc_watch_0p5deg_capUM6.6_2D.nc")
            pv7 = DrivingDatasetParameterValue(model_run_service, driving2,
                                               constants.JULES_PARAM_SOIL_PROPS_FILE, val)
            session.add(driving2)
            session.commit()
Ejemplo n.º 2
0
 def set_value_from_python(self, value):
     """
     Set the Parameter value, converting a Python type to a Fortran namelist string
     :param value: Value to set (Python type)
     :return:
     """
     self.value = f90_helper.python_to_f90_str(value)
 def _create_parameter_values_for_namelist(self, namelist, namelist_dict, group_id):
     """
     Create parameter values for a namelist
     :param namelist: the name list
     :param namelist_dict: the namelist from the file
     :param group_id: group id
     :return: parameter values
     """
     log.info("    Namelist: %s" % namelist.name)
     parameter_values = []
     for parameter_dict_name, parameter_dict_value in namelist_dict.iteritems():
         pv = self._create_parameter_value_for_parameter(
             namelist.parameters,
             parameter_dict_name,
             python_to_f90_str(parameter_dict_value),
             group_id)
         parameter_values.append(pv)
         log.info("      {}: {} ({})".format(pv.parameter.name, pv.value, pv.group_id))
     return parameter_values
    def add_to_driving_dataset(self, model_run_service, driving_dataset, session):
        """
        Create driving data set parameters for non-none parameters set and add them to the driving dataset
        :param model_run_service: model run service to use
        :param driving_dataset: the driving dataset to add the parameters to
        :param session: database session to use
        :return:nothing
        """

        for key, value in self.values.iteritems():
            if value is not None and value != []:
                val = f90_helper.python_to_f90_str(value)
                DrivingDatasetParameterValue(
                    model_run_service,
                    driving_dataset,
                    self._names_constant_dict[key],
                    val,
                    session)

        for parameter_id, value in self._extra_parameters.iteritems():
            if value is not None and value != []:
                DrivingDatasetParameterValue(model_run_service, driving_dataset, parameter_id, value, session)
Ejemplo n.º 5
0
 def test_GIVEN_float32_WHEN_convert_THEN_float_returned(self):
     input = numpy.float32(3600.0)
     output = f90_helper.python_to_f90_str(input)
     expected_output = '3600.0'
     assert_that(output, is_(expected_output))
Ejemplo n.º 6
0
 def test_GIVEN_list_of_strings_WHEN_convert_to_list_THEN_list_of_strings_returned(self):
     input = ["str1", "str2", "str3"]
     output = f90_helper.python_to_f90_str(input)
     expected_output = "'str1'    'str2'    'str3'"
     assert_that(output, is_(expected_output))
Ejemplo n.º 7
0
 def test_GIVEN_list_of_ints_WHEN_convert_to_list_THEN_list_of_ints_returned(self):
     input = [2, 4, 6, 8, 10]
     output = f90_helper.python_to_f90_str(input)
     expected_output = '2    4    6    8    10'
     assert_that(output, is_(expected_output))
Ejemplo n.º 8
0
 def test_GIVEN_int_WHEN_convert_THEN_int_returned(self):
     input = 3600
     output = f90_helper.python_to_f90_str(input)
     expected_output = '3600'
     assert_that(output, is_(expected_output))
Ejemplo n.º 9
0
 def test_GIVEN_false_WHEN_convert_THEN_false_returned(self):
     input = False
     output = f90_helper.python_to_f90_str(input)
     expected_output = '.false.'
     assert_that(output, is_(expected_output))
Ejemplo n.º 10
0
 def test_GIVEN_date_WHEN_convert_THEN_date_returned(self):
     input = datetime.datetime(2012, 1, 1, 0, 0, 0)
     output = f90_helper.python_to_f90_str(input)
     expected_output = "'" + input.strftime("%Y-%m-%d %X") + "'"
     assert_that(output, is_(expected_output))
Ejemplo n.º 11
0
 def test_GIVEN_string_WHEN_convert_THEN_string_returned(self):
     input = 'text string here'
     output = f90_helper.python_to_f90_str(input)
     expected_output = "'text string here'"
     assert_that(output, is_(expected_output))
Ejemplo n.º 12
0
    def create_driving_dataset(
            self,
            session,
            jules_params=DrivingDatasetJulesParams(dataperiod=3600, var_interps=8 * ["i"]),
            is_restricted_to_admins=False,
            data_range_from = 10,
            data_range_to = 5):
        """
        Create a driving dataset
        :param session: session to use
        :param jules_params: set of jules parameters
        :return: dataset
        """
        model_run_service = ModelRunService()

        driving1 = DrivingDataset()
        driving1.name = "driving1"
        driving1.description = "driving 1 description"
        driving1.geographic_region = 'European'
        driving1.spatial_resolution = '1km'
        driving1.temporal_resolution = '24 hours'
        driving1.boundary_lat_north = 50
        driving1.boundary_lat_south = -10
        driving1.boundary_lon_west = -15
        driving1.boundary_lon_east = 30
        driving1.time_start = datetime.datetime(1979, 1, 1, 0, 0, 0)
        driving1.time_end = datetime.datetime(2010, 1, 1, 0, 0, 0)
        driving1.view_order_index = 100
        driving1.is_restricted_to_admins = is_restricted_to_admins
        location1 = DrivingDatasetLocation()
        location1.base_url = "base_url"
        location1.dataset_type_id = 1
        location1.driving_dataset = driving1
        location2 = DrivingDatasetLocation()
        location2.base_url = "base_url2"
        location2.driving_dataset = driving1
        location2.dataset_type_id = 1
        jules_params.add_to_driving_dataset(model_run_service, driving1, session)

        val = f90_helper.python_to_f90_str(8 * ["i"])
        pv1 = DrivingDatasetParameterValue(model_run_service, driving1,
                                           constants.JULES_PARAM_DRIVE_INTERP, val)
        val = f90_helper.python_to_f90_str(3600)
        pv2 = DrivingDatasetParameterValue(model_run_service, driving1,
                                           constants.JULES_PARAM_DRIVE_DATA_PERIOD, val)
        val = f90_helper.python_to_f90_str("data/driving1/frac.nc")
        pv3 = DrivingDatasetParameterValue(model_run_service, driving1,
                                           constants.JULES_PARAM_FRAC_FILE, val)
        val = f90_helper.python_to_f90_str("frac")
        pv4 = DrivingDatasetParameterValue(model_run_service, driving1,
                                           constants.JULES_PARAM_FRAC_NAME, val)

        session.add(driving1)
        session.commit()

        driving_data_filename_param_val = DrivingDatasetParameterValue(
            model_run_service,
            driving1,
            constants.JULES_PARAM_DRIVE_FILE,
            "'testFileName'")
        session.add(driving_data_filename_param_val)
        session.commit()

        return driving1