Exemplo n.º 1
0
def navigate_dnb(h5f):

    scans = h5f.get_node("/All_Data/NumberOfScans").read()[0]
    geo_dset = h5f.get_node("/All_Data/VIIRS-DNB-GEO_All")
    all_c_align = geo_dset.AlignmentCoefficient.read()[np.newaxis,
                                                       np.newaxis, :,
                                                       np.newaxis]
    all_c_exp = geo_dset.ExpansionCoefficient.read()[np.newaxis, np.newaxis, :,
                                                     np.newaxis]
    all_lon = geo_dset.Longitude.read()
    all_lat = geo_dset.Latitude.read()

    res = []

    # FIXME: this supposes there is only one tiepoint zone in the
    # track direction
    scan_size = h5f.get_node_attr("/All_Data/VIIRS-DNB-SDR_All",
                                  "TiePointZoneSizeTrack")[0]
    track_offset = h5f.get_node_attr("/All_Data/VIIRS-DNB-SDR_All",
                                     "PixelOffsetTrack")[0]
    scan_offset = h5f.get_node_attr("/All_Data/VIIRS-DNB-SDR_All",
                                    "PixelOffsetScan")[0]

    try:
        group_locations = geo_dset.TiePointZoneGroupLocationScanCompact.read()
    except KeyError:
        group_locations = [0]
    param_start = 0
    for tpz_size, nb_tpz, start in \
        zip(h5f.get_node_attr("/All_Data/VIIRS-DNB-SDR_All",
                              "TiePointZoneSizeScan"),
            geo_dset.NumberOfTiePointZonesScan.read(),
            group_locations):
        lon = all_lon[:, start:start + nb_tpz + 1]
        lat = all_lat[:, start:start + nb_tpz + 1]
        c_align = all_c_align[:, :, param_start:param_start + nb_tpz, :]
        c_exp = all_c_exp[:, :, param_start:param_start + nb_tpz, :]
        param_start += nb_tpz
        nties = nb_tpz
        if (np.max(lon) - np.min(lon) > 90) or (np.max(abs(lat)) > 60):
            x, y, z = lonlat2xyz(lon, lat)
            x, y, z = (expand_array(x, scans, c_align, c_exp, scan_size,
                                    tpz_size, nties, track_offset,
                                    scan_offset),
                       expand_array(y, scans, c_align, c_exp, scan_size,
                                    tpz_size, nties, track_offset,
                                    scan_offset),
                       expand_array(z, scans, c_align, c_exp, scan_size,
                                    tpz_size, nties, track_offset,
                                    scan_offset))
            res.append(xyz2lonlat(x, y, z))
        else:
            res.append(
                (expand_array(lon, scans, c_align, c_exp, scan_size, tpz_size,
                              nties, track_offset, scan_offset),
                 expand_array(lat, scans, c_align, c_exp, scan_size, tpz_size,
                              nties, track_offset, scan_offset)))
    lons, lats = zip(*res)
    return da.hstack(lons), da.hstack(lats)
Exemplo n.º 2
0
def navigate_dnb(h5f):

    scans = h5f.get_node("/All_Data/NumberOfScans").read()[0]
    geo_dset = h5f.get_node("/All_Data/VIIRS-DNB-GEO_All")
    all_c_align = geo_dset.AlignmentCoefficient.read()[
        np.newaxis, np.newaxis, :, np.newaxis]
    all_c_exp = geo_dset.ExpansionCoefficient.read()[np.newaxis, np.newaxis, :,
                                                     np.newaxis]
    all_lon = geo_dset.Longitude.read()
    all_lat = geo_dset.Latitude.read()

    res = []

    # FIXME: this supposes there is only one tiepoint zone in the
    # track direction
    scan_size = h5f.get_node_attr("/All_Data/VIIRS-DNB-SDR_All",
                                  "TiePointZoneSizeTrack")[0]
    track_offset = h5f.get_node_attr("/All_Data/VIIRS-DNB-SDR_All",
                                     "PixelOffsetTrack")[0]
    scan_offset = h5f.get_node_attr("/All_Data/VIIRS-DNB-SDR_All",
                                    "PixelOffsetScan")[0]

    try:
        group_locations = geo_dset.TiePointZoneGroupLocationScanCompact.read()
    except KeyError:
        group_locations = [0]
    param_start = 0
    for tpz_size, nb_tpz, start in \
        zip(h5f.get_node_attr("/All_Data/VIIRS-DNB-SDR_All",
                              "TiePointZoneSizeScan"),
            geo_dset.NumberOfTiePointZonesScan.read(),
            group_locations):
        lon = all_lon[:, start:start + nb_tpz + 1]
        lat = all_lat[:, start:start + nb_tpz + 1]
        c_align = all_c_align[:, :, param_start:param_start + nb_tpz, :]
        c_exp = all_c_exp[:, :, param_start:param_start + nb_tpz, :]
        param_start += nb_tpz
        nties = nb_tpz
        if (np.max(lon) - np.min(lon) > 90) or (np.max(abs(lat)) > 60):
            x, y, z = lonlat2xyz(lon, lat)
            x, y, z = (
                expand_array(x, scans, c_align, c_exp, scan_size, tpz_size,
                             nties, track_offset, scan_offset),
                expand_array(y, scans, c_align, c_exp, scan_size, tpz_size,
                             nties, track_offset, scan_offset), expand_array(
                                 z, scans, c_align, c_exp, scan_size, tpz_size,
                                 nties, track_offset, scan_offset))
            res.append(xyz2lonlat(x, y, z))
        else:
            res.append(
                (expand_array(lon, scans, c_align, c_exp, scan_size, tpz_size,
                              nties, track_offset, scan_offset),
                 expand_array(lat, scans, c_align, c_exp, scan_size, tpz_size,
                              nties, track_offset, scan_offset)))
    lons, lats = zip(*res)
    return da.hstack(lons), da.hstack(lats)
Exemplo n.º 3
0
    def navigate(self):
        """Generate the navigation datasets."""
        chunks = self._get_geographical_chunks()
        lon = da.from_array(self.geography["Longitude"], chunks=chunks)
        lat = da.from_array(self.geography["Latitude"], chunks=chunks)
        if self.switch_to_cart:
            arrays = lonlat2xyz(lon, lat)
        else:
            arrays = (lon, lat)

        expanded = self.expand_angle_and_nav(arrays)
        if self.switch_to_cart:
            return xyz2lonlat(*expanded)

        return expanded
Exemplo n.º 4
0
    def navigate(self):
        """Generate the navigation datasets."""
        shape = self.geostuff['Longitude'].shape
        hchunks = (self.nb_tpzs + 1).compute()
        chunks = (shape[0], tuple(hchunks))
        lon = da.from_array(self.geostuff["Longitude"], chunks=chunks)
        lat = da.from_array(self.geostuff["Latitude"], chunks=chunks)
        if self.switch_to_cart:
            arrays = lonlat2xyz(lon, lat)
        else:
            arrays = (lon, lat)

        expanded = self.expand_angle_and_nav(arrays)
        if self.switch_to_cart:
            return xyz2lonlat(*expanded)

        return expanded
Exemplo n.º 5
0
    def test_lonlat2xyz(self):
        """Test the lonlat2xyz function."""
        x__, y__, z__ = lonlat2xyz(0, 0)
        self.assertAlmostEqual(x__, 1)
        self.assertAlmostEqual(y__, 0)
        self.assertAlmostEqual(z__, 0)

        x__, y__, z__ = lonlat2xyz(90, 0)
        self.assertAlmostEqual(x__, 0)
        self.assertAlmostEqual(y__, 1)
        self.assertAlmostEqual(z__, 0)

        x__, y__, z__ = lonlat2xyz(0, 90)
        self.assertAlmostEqual(x__, 0)
        self.assertAlmostEqual(y__, 0)
        self.assertAlmostEqual(z__, 1)

        x__, y__, z__ = lonlat2xyz(180, 0)
        self.assertAlmostEqual(x__, -1)
        self.assertAlmostEqual(y__, 0)
        self.assertAlmostEqual(z__, 0)

        x__, y__, z__ = lonlat2xyz(-90, 0)
        self.assertAlmostEqual(x__, 0)
        self.assertAlmostEqual(y__, -1)
        self.assertAlmostEqual(z__, 0)

        x__, y__, z__ = lonlat2xyz(0, -90)
        self.assertAlmostEqual(x__, 0)
        self.assertAlmostEqual(y__, 0)
        self.assertAlmostEqual(z__, -1)

        x__, y__, z__ = lonlat2xyz(0, 45)
        self.assertAlmostEqual(x__, np.sqrt(2) / 2)
        self.assertAlmostEqual(y__, 0)
        self.assertAlmostEqual(z__, np.sqrt(2) / 2)

        x__, y__, z__ = lonlat2xyz(0, 60)
        self.assertAlmostEqual(x__, np.sqrt(1) / 2)
        self.assertAlmostEqual(y__, 0)
        self.assertAlmostEqual(z__, np.sqrt(3) / 2)
Exemplo n.º 6
0
    def test_lonlat2xyz(self):
        """Test the lonlat2xyz function."""
        x__, y__, z__ = lonlat2xyz(0, 0)
        self.assertAlmostEqual(x__, 1)
        self.assertAlmostEqual(y__, 0)
        self.assertAlmostEqual(z__, 0)

        x__, y__, z__ = lonlat2xyz(90, 0)
        self.assertAlmostEqual(x__, 0)
        self.assertAlmostEqual(y__, 1)
        self.assertAlmostEqual(z__, 0)

        x__, y__, z__ = lonlat2xyz(0, 90)
        self.assertAlmostEqual(x__, 0)
        self.assertAlmostEqual(y__, 0)
        self.assertAlmostEqual(z__, 1)

        x__, y__, z__ = lonlat2xyz(180, 0)
        self.assertAlmostEqual(x__, -1)
        self.assertAlmostEqual(y__, 0)
        self.assertAlmostEqual(z__, 0)

        x__, y__, z__ = lonlat2xyz(-90, 0)
        self.assertAlmostEqual(x__, 0)
        self.assertAlmostEqual(y__, -1)
        self.assertAlmostEqual(z__, 0)

        x__, y__, z__ = lonlat2xyz(0, -90)
        self.assertAlmostEqual(x__, 0)
        self.assertAlmostEqual(y__, 0)
        self.assertAlmostEqual(z__, -1)

        x__, y__, z__ = lonlat2xyz(0, 45)
        self.assertAlmostEqual(x__, sqrt(2) / 2)
        self.assertAlmostEqual(y__, 0)
        self.assertAlmostEqual(z__, sqrt(2) / 2)

        x__, y__, z__ = lonlat2xyz(0, 60)
        self.assertAlmostEqual(x__, sqrt(1) / 2)
        self.assertAlmostEqual(y__, 0)
        self.assertAlmostEqual(z__, sqrt(3) / 2)
Exemplo n.º 7
0
    def navigate(self):

        all_lon = self.geostuff["Longitude"].value
        all_lat = self.geostuff["Latitude"].value

        res = []
        param_start = 0
        for tpz_size, nb_tpz, start in zip(self.tpz_sizes, self.nb_tpzs,
                                           self.group_locations):

            lon = all_lon[:, start:start + nb_tpz + 1]
            lat = all_lat[:, start:start + nb_tpz + 1]

            c_align = self.c_align[:, :, param_start:param_start + nb_tpz, :]
            c_exp = self.c_exp[:, :, param_start:param_start + nb_tpz, :]

            param_start += nb_tpz

            expanded = []
            switch_to_cart = ((np.max(lon) - np.min(lon) > 90)
                              or (np.max(abs(lat)) > 60))

            if switch_to_cart:
                arrays = lonlat2xyz(lon, lat)
            else:
                arrays = (lon, lat)

            for data in arrays:
                expanded.append(
                    expand_array(data, self.scans, c_align, c_exp,
                                 self.scan_size, tpz_size, nb_tpz,
                                 self.track_offset, self.scan_offset))

            if switch_to_cart:
                res.append(xyz2lonlat(*expanded))
            else:
                res.append(expanded)
        lons, lats = zip(*res)
        return da.hstack(lons), da.hstack(lats)
Exemplo n.º 8
0
    def navigate(self):

        all_lon = self.geostuff["Longitude"].value
        all_lat = self.geostuff["Latitude"].value

        res = []
        param_start = 0
        for tpz_size, nb_tpz, start in zip(self.tpz_sizes, self.nb_tpzs,
                                           self.group_locations):

            lon = all_lon[:, start:start + nb_tpz + 1]
            lat = all_lat[:, start:start + nb_tpz + 1]

            c_align = self.c_align[:, :, param_start:param_start + nb_tpz, :]
            c_exp = self.c_exp[:, :, param_start:param_start + nb_tpz, :]

            param_start += nb_tpz

            expanded = []
            switch_to_cart = ((np.max(lon) - np.min(lon) > 90) or
                              (np.max(abs(lat)) > 60))

            if switch_to_cart:
                arrays = lonlat2xyz(lon, lat)
            else:
                arrays = (lon, lat)

            for data in arrays:
                expanded.append(expand_array(
                    data, self.scans, c_align, c_exp, self.scan_size,
                    tpz_size, nb_tpz, self.track_offset, self.scan_offset))

            if switch_to_cart:
                res.append(xyz2lonlat(*expanded))
            else:
                res.append(expanded)
        lons, lats = zip(*res)
        return da.hstack(lons), da.hstack(lats)
Exemplo n.º 9
0
    def navigate(self):
        """Generate lon and lat datasets."""
        all_lon = da.from_array(self.geostuff["Longitude"])
        all_lat = da.from_array(self.geostuff["Latitude"])

        res = []
        param_start = 0
        for tpz_size, nb_tpz, start in zip(self.tpz_sizes, self.nb_tpzs,
                                           self.group_locations):

            lon = all_lon[:, start:start + nb_tpz + 1]
            lat = all_lat[:, start:start + nb_tpz + 1]

            c_align = self.c_align[:, :, param_start:param_start + nb_tpz, :]
            c_exp = self.c_exp[:, :, param_start:param_start + nb_tpz, :]

            param_start += nb_tpz

            expanded = []

            if self.switch_to_cart:
                arrays = lonlat2xyz(lon, lat)
            else:
                arrays = (lon, lat)

            for data in arrays:
                expanded.append(
                    expand_array(data, self.scans, c_align, c_exp,
                                 self.scan_size, tpz_size, nb_tpz,
                                 self.track_offset, self.scan_offset))

            if self.switch_to_cart:
                res.append(xyz2lonlat(*expanded))
            else:
                res.append(expanded)
        lons, lats = zip(*res)
        return da.hstack(lons), da.hstack(lats)