def main():
    writer = FCDRWriter()

    # get a template for sensor name in FULL format, supply product height
    # The scan-width is set automatically
    # ---------------------------------------------------------------------
    dataset = writer.createTemplateFull("AVHRR", 128)

    # set some mandatory global attributes (CF standards). Writing will fail if not all of them are filled
    # automatically set: CF version and FIDUCEO license
    # ----------------------------------------------------------------------------------------------------
    dataset.attrs["institution"] = "Brockmann Consult GmbH"
    dataset.attrs["title"] = "FIDUCEO test dataset"
    dataset.attrs["source"] = "arbitray stuff"
    dataset.attrs["history"] = "none"
    dataset.attrs["references"] = "CDR_FCDR sensor reference documentation"
    dataset.attrs[
        "comment"] = "just to show how things are intended to be used"

    # write real data to the variables. All variables initially contain "_FillValue".
    # Not writing to the whole array is completely OK
    # -------------------------------------------------------------------------------
    Time = dataset.variables["Time"]
    Time.data[44] = 0.456
    Time.data[45] = 0.457

    raa = dataset.variables["relative_azimuth_angle"]
    raa.data[3, 0] = 0.567
    raa.data[3, 1] = 0.568

    # ensure not to generate over/underflows
    # --------------------------------------
    DataUtility.check_scaling_ranges(raa)

    # create a standardized file name
    # -------------------------------
    start = datetime.datetime(2006, 8, 23, 14, 24, 52)
    end = datetime.datetime(2006, 8, 23, 15, 25, 53)
    file_name = writer.create_file_name_FCDR_full("AVHRR", "NOAA12", start,
                                                  end, "01.2")

    # dump it to disk, netcdf4, medium compression
    # overwrite existing file
    # --------------------------------------------
    writer.write(dataset,
                 "D:\\Satellite\\DELETE\\" + file_name,
                 overwrite=True)
def main(file_in, fileout='None'):
    data = read_netcdf(file_in)

    writer = FCDRWriter()

    # get a template for sensor name in EASY format, supply product height
    # The scan-width is set automatically
    dataset = writer.createTemplateEasy("AVHRR", data.ny)

    # set some mandatory global attributes. Writing will fail if not all of them are filled
    dataset.attrs["institution"] = "University of Reading"
    dataset.attrs[
        "title"] = "pre-B version of AVHRR Fundamental Climate Data Records"
    dataset.attrs["source"] = "FIDUCEO"
    dataset.attrs["history"] = ""
    dataset.attrs["references"] = "CDF_FCDR_File Spec"
    dataset.attrs[
        "comment"] = "This version is a pre-B one and aims at showing the kind of uncertainties we are aiming to deliver within FIDUCEO. The values are not final ones and should not be used for science purposes."
    dataset.attrs['sensor'] = "AVHRR"
    dataset.attrs['platform'] = data.noaa_string
    dataset.attrs['software_version'] = data.version
    # write real data to the variables. All variables initially contain "_FillValue".
    # Not writing to the whole array is completely OK
    dataset.variables["latitude"].data = data.lat
    dataset.variables["longitude"].data = data.lon
    dataset.variables["Time"].data = data.time

    dataset.variables["satellite_zenith_angle"].data = data.satza
    dataset.variables["solar_zenith_angle"].data = data.solza
    dataset.variables["relative_azimuth_angle"].data = data.relaz

    dataset.variables["Ch1_Ref"].data = data.ch1
    dataset.variables["Ch2_Ref"].data = data.ch2
    if data.ch3a_there:
        dataset.variables["Ch3a_Ref"].data = data.ch3a
    dataset.variables["Ch3b_Bt"].data = data.ch3b
    dataset.variables["Ch4_Bt"].data = data.ch4
    if data.ch5_there:
        dataset.variables["Ch5_Bt"].data = data.ch5

    dataset.variables["u_random_Ch1"].data = data.u_random_ch1
    dataset.variables["u_random_Ch2"].data = data.u_random_ch2
    if data.ch3a_there:
        dataset.variables["u_random_Ch3a"].data = data.u_random_ch3a
    dataset.variables["u_random_Ch3b"].data = data.u_random_ch3b
    dataset.variables["u_random_Ch4"].data = data.u_random_ch4
    if data.ch5_there:
        dataset.variables["u_random_Ch5"].data = data.u_random_ch5

    dataset.variables["u_non_random_Ch1"].data = data.u_non_random_ch1
    dataset.variables["u_non_random_Ch2"].data = data.u_non_random_ch2
    if data.ch3a_there:
        dataset.variables["u_non_random_Ch3a"].data = data.u_non_random_ch3a
    dataset.variables["u_non_random_Ch3b"].data = data.u_non_random_ch3b
    dataset.variables["u_non_random_Ch4"].data = data.u_non_random_ch4
    if data.ch5_there:
        dataset.variables["u_non_random_Ch5"].data = data.u_non_random_ch5

    dataset.variables["quality_scanline_bitmask"].data = data.scan_qual
    dataset.variables["quality_channel_bitmask"].data = data.chan_qual

    #avhrr.AVHRR._create_channel_refl_variable(12835, "Channel 6 Reflectance")
    # dump it to disk, netcdf4, medium compression
    # writing will fail when the target file already exists
    if 'None' == fileout:
        file_out = writer.create_file_name_FCDR_easy('AVHRR',data.noaa_string,\
                                                         data.date_time[0],\
                                                         data.date_time[-1],\
                                                         data.version)
    else:
        file_out = fileout
    writer.write(dataset, file_out)
Exemple #3
0
    def setUp(self):
        self.fcdr_reader = FCDRReader()

        fcdr_writer = FCDRWriter()
        self.dataset = fcdr_writer.createTemplateFull("MVIRI", 5000)