Exemplo n.º 1
0
def generate_ismn_nonref_validation():
    """Generate a validation where ISMN is used as non-reference"""
    run = ValidationRun()
    run.start_time = datetime.now(tzlocal())
    run.save()

    ref_c = DatasetConfiguration()
    ref_c.validation = run
    ref_c.dataset = Dataset.objects.get(short_name='C3S')
    ref_c.version = DatasetVersion.objects.get(short_name='C3S_V202012')
    ref_c.variable = DataVariable.objects.get(short_name='C3S_sm')
    ref_c.save()

    data_c = DatasetConfiguration()
    data_c.validation = run
    data_c.dataset = Dataset.objects.get(short_name='ISMN')
    data_c.version = DatasetVersion.objects.get(short_name='ISMN_V20180712_MINI')
    data_c.variable = DataVariable.objects.get(short_name='ISMN_soil_moisture')
    data_c.save()

    run.reference_configuration = ref_c
    run.scaling_ref = ref_c
    run.save()

    return run
Exemplo n.º 2
0
    def test_val_finished(self):
        test_datasets = [Dataset.objects.get(short_name=globals.C3S),
                         Dataset.objects.get(short_name=globals.ASCAT),
                         Dataset.objects.get(short_name=globals.SMAP),]

        run = ValidationRun()
        run.start_time = datetime.now(tzlocal())
        run.end_time = datetime.now(tzlocal())
        run.user = self.testuser
        run.save()

        for ds in test_datasets:
            data_c = DatasetConfiguration()
            data_c.validation = run
            data_c.dataset = ds
            data_c.version = ds.versions.first()
            data_c.variable = ds.variables.first()
            data_c.save()

        ref_c = DatasetConfiguration()
        ref_c.validation = run
        ref_c.dataset = Dataset.objects.get(short_name='ISMN')
        ref_c.version = DatasetVersion.objects.get(short_name='ISMN_V20180712_MINI')
        ref_c.variable = DataVariable.objects.get(short_name='ISMN_soil_moisture')
        ref_c.save()

        run.reference_configuration = ref_c
        run.scaling_ref = ref_c
        run.save()

        val_mail.send_val_done_notification(run)
        self.check_outbox()
Exemplo n.º 3
0
def generate_default_validation_triple_coll():
    run = ValidationRun()
    run.start_time = datetime.now(tzlocal())
    run.save()

    data_c = DatasetConfiguration()
    data_c.validation = run
    data_c.dataset = Dataset.objects.get(short_name='C3S')
    data_c.version = DatasetVersion.objects.get(short_name='C3S_V201912')
    data_c.variable = DataVariable.objects.get(short_name='C3S_sm')
    data_c.save()

    other_data_c = DatasetConfiguration()
    other_data_c.validation = run
    other_data_c.dataset = Dataset.objects.get(short_name='SMOS')
    other_data_c.version = DatasetVersion.objects.get(short_name='SMOS_105_ASC')
    other_data_c.variable = DataVariable.objects.get(short_name='SMOS_sm')
    other_data_c.save()

    ref_c = DatasetConfiguration()
    ref_c.validation = run
    ref_c.dataset = Dataset.objects.get(short_name='ISMN')
    ref_c.version = DatasetVersion.objects.get(short_name='ISMN_V20180712_MINI')
    ref_c.variable = DataVariable.objects.get(short_name='ISMN_soil_moisture')
    ref_c.save()

    run.reference_configuration = ref_c
    run.scaling_ref = ref_c
    run.tcol = True
    run.bootstrap_tcol_cis = True
    run.save()

    return run
Exemplo n.º 4
0
    def test_validation_c3s_ismn(self):
        run = ValidationRun()
        run.start_time = datetime.now(tzlocal())
        run.user = self.testuser
        # set validation period
        run.interval_from = datetime(1978, 1, 1, tzinfo=UTC)
        run.interval_to = datetime(2018, 12, 31, tzinfo=UTC)
        run.save()

        data_c = DatasetConfiguration()
        data_c.validation = run
        data_c.dataset = Dataset.objects.get(short_name='C3S')
        data_c.version = DatasetVersion.objects.get(short_name='C3S_V201812')
        data_c.variable = DataVariable.objects.get(short_name='C3S_sm')
        data_c.save() # object needs to be saved before m2m relationship can be used

        data_c.filters.add(DataFilter.objects.get(name='FIL_C3S_FLAG_0'))
        data_c.filters.add(DataFilter.objects.get(name='FIL_ALL_VALID_RANGE'))
        data_c.save()

        ref_c = DatasetConfiguration()
        ref_c.validation = run
        ref_c.dataset = Dataset.objects.get(short_name='ISMN')
        ref_c.version = DatasetVersion.objects.get(short_name='ISMN_V20180712_MINI')
        ref_c.variable = DataVariable.objects.get(short_name='ISMN_soil_moisture')
        ref_c.save()

        ref_c.filters.add(DataFilter.objects.get(name='FIL_ISMN_GOOD'))
        ref_c.save()

        run.reference_configuration = ref_c
        run.scaling_ref = ref_c
        run.save()

        run_id = run.id

        ## run the validation
        val.run_validation(run_id)

        ## wait until it's over (if necessary)
        finished_run = ValidationRun.objects.get(pk=run_id)
        timeout = 300 # seconds
        wait_time = 5 # seconds
        runtime = 0
        while(finished_run.end_time is None):
            assert runtime <= timeout, 'Validations are taking too long.'
            sleep(wait_time)
            runtime += wait_time

        ## TODO: check the results here

        self.generic_result_check(finished_run)
        self.delete_run(finished_run)
Exemplo n.º 5
0
    def test_validation_configuration(self):
        run = ValidationRun()
        run.start_time = now()
        run.save()

        dc = DatasetConfiguration()
        dc.validation = run
        dc.dataset = Dataset.objects.get(pk=1)
        dc.version = DatasetVersion.objects.get(pk=1)
        dc.variable = DataVariable.objects.get(pk=1)

        dc.save()

        run.reference_configuration = dc
        run.scaling_ref = dc

        run.save()

        assert len(run.dataset_configurations.all()) == 1
        assert run.reference_configuration
        assert run.scaling_ref
Exemplo n.º 6
0
    def test_ds_config_order(self):
        dataset_range = range(1, 6)
        run = ValidationRun()
        run.start_time = now()
        run.save()

        # create dataset configs in order of dataset ids
        for i in dataset_range:
            dc = DatasetConfiguration()
            dc.validation = run
            dc.dataset = Dataset.objects.get(pk=i)
            dc.version = dc.dataset.versions.first()
            dc.variable = dc.dataset.variables.first()
            dc.save()

        run.reference_configuration = dc
        run.scaling_ref = dc
        run.save()

        # check that we can get the order of dataset configs from the validation run
        orderorder = run.get_datasetconfiguration_order()
        self.__logger.debug('Orig order {}'.format(orderorder))
        assert orderorder

        # check that they have the same order when using all()
        for i, dsc in enumerate(run.dataset_configurations.all(), 1):
            assert dsc.dataset.id == i
            assert dsc.id == orderorder[i-1]

        # randomly change the order
        newworldorder = np.random.permutation(orderorder)
        self.__logger.debug('New order {}'.format(newworldorder))
        run.set_datasetconfiguration_order(newworldorder)

        # make sure the new order is used
        for i, dsc in enumerate(run.dataset_configurations.all(), 1):
            self.__logger.debug('current id {}'.format(dsc.id))
            assert dsc.id == newworldorder[i-1]
Exemplo n.º 7
0
    def test_doi(self):
        infile = 'testdata/output_data/c3s_era5land.nc'

        ## generate test validation
        val = ValidationRun()
        val.start_time = timezone.now() - timedelta(days=1)
        val.end_time = timezone.now()
        val.user = self.testuser
        val.save()

        data_c = DatasetConfiguration()
        data_c.validation = val
        data_c.dataset = Dataset.objects.get(short_name='C3S')
        data_c.version = DatasetVersion.objects.get(short_name='C3S_V201812')
        data_c.variable = DataVariable.objects.get(short_name='C3S_sm')
        data_c.save()

        ref_c = DatasetConfiguration()
        ref_c.validation = val
        ref_c.dataset = Dataset.objects.get(short_name='ISMN')
        ref_c.version = DatasetVersion.objects.get(short_name='ISMN_V20191211')
        ref_c.variable = DataVariable.objects.get(
            short_name='ISMN_soil_moisture')
        ref_c.save()

        val.reference_configuration = ref_c
        val.scaling_ref = ref_c
        val.save()

        ## set valid output file for validation
        run_dir = path.join(OUTPUT_FOLDER, str(val.id))
        mkdir_if_not_exists(run_dir)
        shutil.copy(infile, path.join(run_dir, 'results.nc'))
        set_outfile(val, run_dir)
        val.save()

        ## test the publishing form

        # no name given
        val.user.first_name = None
        val.user.last_name = None
        form = PublishingForm(validation=val)
        assert form

        # only first name given
        val.user.first_name = self.user_data['first_name']
        form = PublishingForm(validation=val)
        assert form
        val.user.first_name = None

        # only last name given
        val.user.last_name = self.user_data['last_name']
        form = PublishingForm(validation=val)
        assert form

        # first and last name given but not a real orcid id
        val.user.first_name = self.user_data['first_name']
        val.user.orcid = 'not a real orcid'
        form = PublishingForm(validation=val)

        caught_orcid_error = False
        try:
            assert form.pub_metadata
        except:
            caught_orcid_error = True

        assert caught_orcid_error

        # fix orcid
        val.user.orcid = self.user_data['orcid']

        ## finally everything should be ok and we can use the form to generate the necessary metadata
        form = PublishingForm(validation=val)
        metadata = form.pub_metadata

        ## create a test doi on zenodo's sandbox service
        get_doi_for_validation(val, metadata)

        val = ValidationRun.objects.get(pk=val.id)
        self.__logger.debug(val.doi)
        assert val.doi
        firstdoi = val.doi

        ## check that the DOI was correctly stored in the netcdf file
        with netCDF4.Dataset(val.output_file.path, mode='r') as ds:
            assert val.doi in ds.doi

        form = PublishingForm(validation=val)
        metadata = form.pub_metadata

        ## try to upload the same data with the same title again - it should work but yield a different doi
        get_doi_for_validation(val, metadata)

        val = ValidationRun.objects.get(pk=val.id)
        self.__logger.debug(val.doi)
        assert val.doi
        assert val.doi != firstdoi

        ## check that the DOI was correctly stored in the netcdf file
        with netCDF4.Dataset(val.output_file.path, mode='r') as ds:
            assert val.doi in ds.doi