Ejemplo n.º 1
0
 def test_collapse2(self):
     # parent with same ancestor
     sids = numpy.array([
         0x300a30000000000a, 0x300a30800000000a, 0x300a31000000000a,
         0x300a31800000000a
     ])
     ivs = pystare.to_compressed_range(sids.flatten())
     #indices = numpy.zeros([srange.get_size_as_values()], dtype=numpy.int64)
     #srange.copy_values(indices)
     with self.subTest():
         self.assertEqual(ivs.size, 1)
     with self.subTest():
         self.assertEqual(hex(ivs[0]), '0x300a300000000009')
Ejemplo n.º 2
0
    def test_tocompressedrange(self):

        # indices = numpy.array([4151504989081014892, 4161865161846704588, 3643626718498217164])
        # expected = numpy.array([3643626718498217164, 4151504989081014892, 4161865161846704588])

        indices  = numpy.array([0x399d1bcabd6f926c,0x39c1ea506ef249cc,0x3290c3321a355ccc])
        expected = numpy.array([0x3290c3300000000c,0x399d1bc80000000c,0x39c1ea500000000c])
        
        compressed = pystare.to_compressed_range(indices)

        # print('')
        # print('indices','compressed','expected')
        # for i in [0,1,2]:
        #     print(i,hex(indices[i]),hex(compressed[i]),hex(expected[i]))
        # print('\nindices')
        # for i in [0,1,2]:
        #     print(hex(indices[i]))
        # print('\ncompressed')
        # for i in [0,1,2]:
        #     print(hex(compressed[i]))
        
        numpy.testing.assert_array_equal(compressed, expected)
def compress_sids(sids):
    """ Dissolve STARE index values.
    Combine/dissolve sibiling sids into the parent sids. That is:
    1. Any 4 siblings with the same parent in the collection get replaced by the parent. And
    2. Any child whose parents is in the collection will be removed

    Parameters
    ------------
    sids: array-like
        A collection of SIDs to dissolve

    Returns
    ---------
    dissolved: numpy.array
        Dissolved SIDs

    See Also
    ----------
    merge_stare

    Examples
    ---------
    >>> import starepandas
    >>> # The two latter SIDs are contained in the first SID
    >>> sids = [4035225266123964416, 4254212798004854789, 4255901647865118724]
    >>> starepandas.compress_sids(sids)
    array([4035225266123964416])

    Notes
    --------
    .. image:: ../../../_static/dissolve.png

    """
    sids = numpy.unique(sids)
    s_range = pystare.to_compressed_range(sids)
    expanded = pystare.expand_intervals(s_range, -1, multi_resolution=True)
    return expanded
Ejemplo n.º 4
0
def dissolve(sids):
    s_range = pystare.to_compressed_range(sids)
    expanded = pystare.expand_intervals(s_range, -1, multi_resolution=True)
    return expanded
Ejemplo n.º 5
0
def main():
    print('MODIS Sketching')

    data_sourcedir = '/home/mrilee/data/MODIS/'

    # Geolocation files
    mod03_catalog = gd.data_catalog({
        'directory': data_sourcedir,
        'patterns': ['MOD03*']
    })

    # Data files
    mod05_catalog = gd.data_catalog({
        'directory': data_sourcedir,
        'patterns': ['MOD05*']
    })

    print('mod03 catalog\n', mod03_catalog.get_files())
    print('mod03 catalog\n', mod03_catalog.get_tid_centered_index())
    print('mod05 catalog\n', mod05_catalog.get_tid_centered_index())

    modis_sets = SortedDict()
    tKeys = list(mod05_catalog.tid_centered_index.keys())
    for tid in tKeys:
        # for tid in tKeys[0:1]:
        # for tid in mod05_catalog.tid_centered_index: # replace with temporal comparison
        if (len(mod05_catalog.tid_centered_index[tid]) > 1
                or len(mod03_catalog.tid_centered_index[tid]) > 1):
            raise NotImplementedError(
                'sketchH only written for preselected pairs of MODIS files')
        modis_sets[tid] = modis05_set(mod05_catalog.tid_centered_index[tid][0],
                                      mod03_catalog.tid_centered_index[tid][0],
                                      data_sourcedir=data_sourcedir)
        modis_sets[tid].load_wv_nir().load_geo().make_sare()
        # print(hex(tid),modis_sets[tid].data,modis_sets[tid].location)
        # print(modis_sets[tid].info())

    ###########################################################################
    proj = ccrs.PlateCarree()
    transf = ccrs.Geodetic()

    def init_figure(proj):
        plt.figure()
        ax = plt.axes(projection=proj)
        # ax.set_global()
        # ax.coastlines()
        return ax

    vmin = np.amin(np.array([a.vmin() for a in modis_sets.values()]))
    vmax = np.amax(np.array([a.vmax() for a in modis_sets.values()]))
    tKeys = list(modis_sets.keys())
    tKeys = [tKeys[1]]
    # tid   = tKeys[0]
    # tKeys = tKeys[1:]
    # tKeys = tKeys[-2:-1]
    # for tid in mod05_catalog.tid_centered_index: # replace with temporal comparison
    # if True:
    for tid in tKeys:
        if False:
            plt.scatter(modis_sets[tid].geo_lon,
                        modis_sets[tid].geo_lat,
                        s=1,
                        c=modis_sets[tid].data_wv_nir,
                        transform=transf,
                        vmin=vmin,
                        vmax=vmax)

        tmp_data_src_name = mod05_catalog.tid_centered_index[tid][0][0:-4]
        # print('tmp_data_src_name: ',tmp_data_src_name)
        # clons,clats,cintmat = ps.triangulate_indices(modis_sets[tid].cover)
        tmp_cover = ps.to_compressed_range(modis_sets[tid].cover)
        # tmp_cover = ps.expand_intervals(tmp_cover,2)
        tmp_cover = ps.expand_intervals(tmp_cover, 4)
        # tmp_cover = ps.expand_intervals(tmp_cover,6,result_size_limit=1600)
        if False:
            clons, clats, cintmat = ps.triangulate_indices(tmp_cover)
            ctriang = tri.Triangulation(clons, clats, cintmat)
        spart_nmax = -1
        # tmp_cover = tmp_cover[0:10]
        idx_all = {}
        for sid in tmp_cover:
            # print(sid,' sid, indexing cover sid: 0x%016x'%sid)
            idx_all[sid] = np.where(
                ps.cmp_spatial(np.array([sid], dtype=np.int64),
                               modis_sets[tid].sare) != 0)
            spart_nmax = max(spart_nmax,
                             len(modis_sets[tid].sare[idx_all[sid]]))
        # print('max spart items to write per file: ',spart_nmax)
        spart_nmax = None  # Variable lengths

        spart_names = []
        for sid in tmp_cover:
            idx = idx_all[sid][0]
            # print(sid,' sid,cover sid: 0x%016x'%sid,' len(idx)=%i'%(len(idx)))
            # print('idx:      ',idx)
            # print('idx type: ',type(idx))
            spart_h5_namebase = 't%016x.%s' % (tid,
                                               tmp_data_src_name + '.sketchJ0')

            # MAKE
            spart_h5 = sare_partition(sid,
                                      spart_h5_namebase,
                                      src_name=tmp_data_src_name,
                                      var_nmax=spart_nmax)

            # CHECK
            # print(' data_wv_nir mn,mx: ',np.amin(modis_sets[tid].data_wv_nir),np.amax(modis_sets[tid].data_wv_nir))

            # WRITE
            if True:
                spart_h5.write1(
                    shape=[modis_sets[tid].nAcross, modis_sets[tid].nAlong],
                    dataset_name='wv_nir',
                    vars={
                        'sare':
                        modis_sets[tid].sare[idx],
                        'src_coord':
                        np.arange(len(modis_sets[tid].sare))[idx],
                        'Water_Vapor_Near_Infrared':
                        modis_sets[tid].data_wv_nir.flatten()[idx]
                    })
                # print('')

            spart_names.append(spart_h5.fname)
            if False:
                ax = init_figure(proj)
                ax.triplot(ctriang,
                           'b-',
                           transform=transf,
                           lw=1.0,
                           markersize=3,
                           alpha=0.5)
                plt.scatter(modis_sets[tid].geo_lon.flatten()[idx],
                            modis_sets[tid].geo_lat.flatten()[idx],
                            s=1,
                            c=modis_sets[tid].data_wv_nir.flatten()[idx],
                            transform=transf,
                            vmin=vmin,
                            vmax=vmax)
                plt.show()

            # READ
            spart_h5_1 = sare_partition(sid, spart_h5_namebase)
            (s5_shape, s5_name, s5_vars, s5_vars_dtype,
             s5_metadata_dtype) = spart_h5_1.read1()
            # print('found and loaded %s of type %s.'%(s5_name,s5_vars_dtype))

            idx = s5_vars['src_coord']
            if False:
                ax = init_figure(proj)
                ax.triplot(ctriang,
                           'g-',
                           transform=transf,
                           lw=1.0,
                           markersize=3,
                           alpha=0.5)
                plt.scatter(modis_sets[tid].geo_lon.flatten()[idx],
                            modis_sets[tid].geo_lat.flatten()[idx],
                            s=1,
                            c=modis_sets[tid].data_wv_nir.flatten()[idx],
                            transform=transf,
                            vmin=vmin,
                            vmax=vmax)
                plt.show()
            if False:
                ax = init_figure(proj)
                ax.triplot(ctriang,
                           'r-',
                           transform=transf,
                           lw=1.0,
                           markersize=3,
                           alpha=0.5)
                lat, lon = ps.to_latlon(s5_vars['sare'])
                plt.scatter(lon,
                            lat,
                            s=1,
                            c=s5_vars['Water_Vapor_Near_Infrared'],
                            transform=transf,
                            vmin=vmin,
                            vmax=vmax)
                plt.show()

        ####

        ## # Define the layout of the virtual data set.
        ## var_ns      = [len(idx_all[i][0]) for i in idx_all]
        ## var_n_cumul = [0]
        ## for i in range(len(idx_all)):
        ##     var_n_cumul.append(var_n_cumul[-1]+var_ns[i])
        ## # var_n_total = sum([len(i) for i in idx_all])
        ## var_n_total = var_n_cumul[-1]
        ##
        ## print('')
        ## print('var_ns:      ',var_ns)
        ## print('var_n_cumul: ',var_n_cumul)
        ## print('var_n_total: ',var_n_total)
        ##
        ## layout    = h5.VirtualLayout(shape=(var_n_total,),dtype=s5_vars_dtype)
        ## print('layout:      ',layout)
        ##
        ## layout_md = h5.VirtualLayout(shape=(len(spart_names),),dtype=s5_metadata_dtype)
        ## print('layout_md:   ',layout_md)
        ## print('')
        ##
        ## layout_idx = np.arange(var_n_total)
        ##
        ## for i in range(len(spart_names)):
        ##     print(i,' part: ',var_n_cumul[i],var_n_cumul[i+1],', ',var_ns[i])
        ## print('')
        ##
        ## # print('s5_metadata_dtype: ',s5_metadata_dtype)
        ## ds_name = 'wv_nir'
        ## for i in range(len(spart_names)):
        ##     # Just concatenate
        ##     #++ layout[var_n_cumul[i]:var_n_cumul[i+1]] = h5.VirtualSource(spart_names[i],ds_name,shape=(var_ns[i],))
        ##     # What I would like to do...
        ##     if var_ns[i] != 0:
        ##         with h5.File(spart_names[i]) as h:
        ##             vs = h5.VirtualSource(spart_names[i],ds_name,shape=(var_ns[i],))
        ##             for j in range(h[ds_name]['src_coord'].shape[0]): # Should be var_ns[i]
        ##                 layout[h[ds_name]['src_coord'][j]] = vs[j] # next step, try [j,k] for a virtual image....
        ##     # else: # zero-case
        ##     #    layout[var_n_cumul[i]:var_n_cumul[i+1]] = h5.VirtualSource(spart_names[i],ds_name,shape=(var_ns[i],))
        ##
        ## for i in range(len(spart_names)):
        ##     layout_md[i] = h5.VirtualSource(spart_names[i],'metadata',shape=(1,))
        ##
        ## vds_fname = '.'.join([tmp_data_src_name,ds_name,'sketchJ0.vds.h5'])
        ## print('writing ',vds_fname)
        ## with h5.File(vds_fname,'w',libver='latest') as f:
        ##     f.create_virtual_dataset('wv_nir',layout)      # fillvalue?
        ##     f.create_virtual_dataset('metadata',layout_md) # fillvalue?
        ##     # f.create_dataset(['image_lookup']...)

    print('MODIS Sketching Done')
    return
Ejemplo n.º 6
0
def main():
    print('MODIS Sketching')

    data_sourcedir = '/home/mrilee/data/MODIS/'

    # Geolocation files
    mod03_catalog = gd.data_catalog({
        'directory': data_sourcedir,
        'patterns': ['MOD03*']
    })

    # Data files
    mod05_catalog = gd.data_catalog({
        'directory': data_sourcedir,
        'patterns': ['MOD05*']
    })

    print('mod03 catalog\n', mod03_catalog.get_files())
    print('mod03 catalog\n', mod03_catalog.get_tid_centered_index())
    print('mod05 catalog\n', mod05_catalog.get_tid_centered_index())

    modis_sets = SortedDict()
    tKeys = list(mod05_catalog.tid_centered_index.keys())
    for tid in tKeys:
        # for tid in tKeys[0:1]:
        # for tid in mod05_catalog.tid_centered_index: # replace with temporal comparison
        if (len(mod05_catalog.tid_centered_index[tid]) > 1
                or len(mod03_catalog.tid_centered_index[tid]) > 1):
            raise NotImplementedError(
                'sketchH only written for preselected pairs of MODIS files')
        modis_sets[tid] = modis05_set(mod05_catalog.tid_centered_index[tid][0],
                                      mod03_catalog.tid_centered_index[tid][0],
                                      data_sourcedir=data_sourcedir)
        modis_sets[tid].load_wv_nir().load_geo().make_sare()
        # print(hex(tid),modis_sets[tid].data,modis_sets[tid].location)
        # print(modis_sets[tid].info())

    ###########################################################################
    proj = ccrs.PlateCarree()
    transf = ccrs.Geodetic()

    def init_figure(proj):
        plt.figure()
        ax = plt.axes(projection=proj)
        # ax.set_global()
        # ax.coastlines()
        return ax

    vmin = np.amin(np.array([a.vmin() for a in modis_sets.values()]))
    vmax = np.amax(np.array([a.vmax() for a in modis_sets.values()]))
    tKeys = list(modis_sets.keys())
    tid = tKeys[0]
    # tKeys = tKeys[1:]
    # tKeys = tKeys[-2:-1]
    # for tid in mod05_catalog.tid_centered_index: # replace with temporal comparison
    # if True:
    for tid in tKeys:
        if False:
            plt.scatter(modis_sets[tid].geo_lon,
                        modis_sets[tid].geo_lat,
                        s=1,
                        c=modis_sets[tid].data_wv_nir,
                        transform=transf,
                        vmin=vmin,
                        vmax=vmax)
        tmp_data_src_name = mod05_catalog.tid_centered_index[tid][0][0:-4]
        # print('tmp_data_src_name: ',tmp_data_src_name)
        # clons,clats,cintmat = ps.triangulate_indices(modis_sets[tid].cover)
        tmp_cover = ps.to_compressed_range(modis_sets[tid].cover)
        # tmp_cover = ps.expand_intervals(tmp_cover,2)
        tmp_cover = ps.expand_intervals(tmp_cover, 5)
        clons, clats, cintmat = ps.triangulate_indices(tmp_cover)
        ctriang = tri.Triangulation(clons, clats, cintmat)
        spart_nmax = -1
        # tmp_cover = tmp_cover[0:10]
        idx_all = {}
        for sid in tmp_cover:
            # print(sid,' sid, indexing cover sid: 0x%016x'%sid)
            idx_all[sid] = np.where(
                ps.cmp_spatial(np.array([sid], dtype=np.int64),
                               modis_sets[tid].sare) != 0)
            spart_nmax = max(spart_nmax,
                             len(modis_sets[tid].sare[idx_all[sid]]))
        # print('max spart items to write per file: ',spart_nmax)

        spart_names = []
        for sid in tmp_cover:
            idx = idx_all[sid][0]
            # print(sid,' sid,cover sid: 0x%016x'%sid,' len(idx)=%i'%(len(idx)))
            # print('idx:      ',idx)
            # print('idx type: ',type(idx))
            spart_h5_namebase = 't%016x.%s' % (tid,
                                               tmp_data_src_name + '.sketchH')
            spart_h5 = sare_partition(sid,
                                      spart_h5_namebase,
                                      src_name=tmp_data_src_name,
                                      var_nmax=spart_nmax)
            spart_h5.write1(
                shape=[modis_sets[tid].nAcross, modis_sets[tid].nAlong],
                dataset_name='wv_nir',
                vars={
                    'sare':
                    modis_sets[tid].sare[idx],
                    'src_coord':
                    np.arange(len(modis_sets[tid].sare))[idx],
                    'Water_Vapor_Near_Infrared':
                    modis_sets[tid].data_wv_nir.flatten()[idx]
                })
            spart_names.append(spart_h5.fname)
            if False:
                ax = init_figure(proj)
                ax.triplot(ctriang,
                           'b-',
                           transform=transf,
                           lw=1.0,
                           markersize=3,
                           alpha=0.5)
                plt.scatter(modis_sets[tid].geo_lon.flatten()[idx],
                            modis_sets[tid].geo_lat.flatten()[idx],
                            s=1,
                            c=modis_sets[tid].data_wv_nir.flatten()[idx],
                            transform=transf,
                            vmin=vmin,
                            vmax=vmax)
                plt.show()
            spart_h5_1 = sare_partition(sid, spart_h5_namebase)
            (s5_shape, s5_name, s5_vars, s5_vars_dtype,
             s5_metadata_dtype) = spart_h5_1.read1()
            # print('found and loaded %s of type %s.'%(s5_name,s5_vars_dtype))

            idx = s5_vars['src_coord']
            if False:
                ax = init_figure(proj)
                ax.triplot(ctriang,
                           'g-',
                           transform=transf,
                           lw=1.0,
                           markersize=3,
                           alpha=0.5)
                plt.scatter(modis_sets[tid].geo_lon.flatten()[idx],
                            modis_sets[tid].geo_lat.flatten()[idx],
                            s=1,
                            c=modis_sets[tid].data_wv_nir.flatten()[idx],
                            transform=transf,
                            vmin=vmin,
                            vmax=vmax)
                plt.show()
            if False:
                ax = init_figure(proj)
                ax.triplot(ctriang,
                           'r-',
                           transform=transf,
                           lw=1.0,
                           markersize=3,
                           alpha=0.5)
                lat, lon = ps.to_latlon(s5_vars['sare'])
                plt.scatter(lon,
                            lat,
                            s=1,
                            c=s5_vars['Water_Vapor_Near_Infrared'],
                            transform=transf,
                            vmin=vmin,
                            vmax=vmax)
                plt.show()

        ####

        layout = h5.VirtualLayout(shape=(len(spart_names), spart_nmax),
                                  dtype=s5_vars_dtype)
        layout_md = h5.VirtualLayout(shape=(len(spart_names), 1),
                                     dtype=s5_metadata_dtype)
        # print('s5_metadata_dtype: ',s5_metadata_dtype)
        ds_name = 'wv_nir'
        for i in range(len(spart_names)):
            layout[i] = h5.VirtualSource(spart_names[i],
                                         ds_name,
                                         shape=(spart_nmax, ))
            layout_md[i] = h5.VirtualSource(spart_names[i],
                                            'metadata',
                                            shape=(1, ))
        vds_fname = '.'.join([tmp_data_src_name, ds_name, 'vds.h5'])
        print('writing ', vds_fname)
        with h5.File(vds_fname, 'w', libver='latest') as f:
            f.create_virtual_dataset('wv_nir', layout)  # fillvalue?
            f.create_virtual_dataset('metadata', layout_md)  # fillvalue?

    print('MODIS Sketching Done')
    return
Ejemplo n.º 7
0
def dominica1(proj, transf):
    "Example and analysis for pystare bug#27."

    sids = numpy.array([
        2521898143583305738, 2521997099629805578, 2521989952804225034,
        2521991052315852810, 2521893745536794634, 2521897044071677962,
        2521897593827491850, 2521898693339119626, 2521899792850747402,
        2521991602071666698, 2521889347490283530, 2521899243094933514,
        2521900892362375178, 2521901442118189066, 2521901991874002954,
        2521903091385630730, 2521887698222841866, 2521886048955400202,
        2521992701583294474, 2521902541629816842, 2521906389920514058,
        2521890447001911306, 2521993251339108362, 2521886598711214090,
        2521908588943769610, 2521892646025166858, 2521894295292608522,
        2521989403048411146
    ])

    sids = numpy.array([
        2521902129312956427, 2521902404190863371, 2521899930289700875,
        2521900067728654347, 2521900205167607819, 2521991876949573643,
        2521992701583294475, 2521992839022247947, 2521992976461201419,
        2521997099629805579, 2521889484929237003, 2521991739510620171,
        2521902679068770315, 2521908726382723083, 2521894432731561995,
        2521901579557142539, 2521989952804225035, 2521990365121085451,
        2521991327193759755, 2521997237068759051, 2521997511946665995,
        2521898418461212683, 2521898555900166155, 2521898693339119627,
        2521889759807143947, 2521903091385630731, 2521901716996096011,
        2521897456388538379, 2521902266751909899, 2521897868705398795,
        2521898968217026571, 2521990227682131979, 2521889622368190475,
        2521901167240282123, 2521887973100748811, 2521902816507723787,
        2521892920903073803, 2521894020414701579, 2521890721879818251,
        2521993526217015307, 2521901304679235595, 2521901854435049483,
        2521902953946677259, 2521898006144352267, 2521890859318771723,
        2521886461272260619, 2521888110539702283, 2521898830778073099,
        2521903228824584203, 2521897044071677963, 2521903366263537675,
        2521899105655980043, 2521903503702491147, 2521886048955400203,
        2521991602071666699, 2521899380533886987, 2521890584440864779,
        2521992014388527115, 2521886873589121035, 2521887011028074507,
        2521889347490283531, 2521890447001911307, 2521886736150167563,
        2521893745536794635, 2521893882975748107, 2521894157853655051,
        2521897181510631435, 2521897731266445323, 2521899792850747403,
        2521887698222841867, 2521900892362375179, 2521901442118189067,
        2521906389920514059, 2521908588943769611, 2521901991874002955,
        2521902541629816843, 2521909001260630027, 2521989540487364619,
        2521897318949584907, 2521898143583305739, 2521898281022259211,
        2521897593827491851, 2521993113900154891, 2521993251339108363,
        2521993388778061835, 2521993663655968779, 2521886598711214091,
        2521886186394353675
    ])

    expanded_stare_test = numpy.array([
        0x22ff8a000000000b, 0x22ff8a200000000b, 0x22ff8a600000000b,
        0x22ff8a800000000b, 0x22ff8aa00000000b, 0x22ff8ac00000000b,
        0x22ff8ae00000000b, 0x22ff8b800000000b, 0x22ff8bc00000000b,
        0x22ff8be00000000b, 0x22ff8d000000000a, 0x22ff8e000000000a,
        0x22ff90400000000b, 0x22ff91000000000a, 0x22ff91a00000000b,
        0x22ff940000000009, 0x22ff96200000000b, 0x22ff96800000000a,
        0x22ff97800000000b, 0x22ff97c00000000b, 0x22ff97e00000000b,
        0x22ff980000000009, 0x22ff9c800000000b, 0x22ff9e800000000b,
        0x22ff9ea00000000b, 0x22ff9ee00000000b, 0x22ffe8200000000b,
        0x22ffe8800000000b, 0x22ffe8c00000000b, 0x22ffe8e00000000b,
        0x22ffe9c00000000b, 0x22ffea000000000a, 0x22ffeb000000000a,
        0x22ffeb800000000a, 0x22ffef000000000b, 0x22ffef200000000b,
        0x22ffef600000000b
    ])

    expanded_stare_test = numpy.array([
        0x22ff8a000000000b, 0x22ff8a200000000b, 0x22ff8a600000000b,
        0x22ff8a800000000a, 0x22ff8b000000000a, 0x22ff8b800000000a,
        0x22ff8b800000000b, 0x22ff8bc00000000b, 0x22ff8be00000000b,
        0x22ff8c0000000009, 0x22ff8d000000000a, 0x22ff8e0000000009,
        0x22ff8e000000000a, 0x22ff900000000008, 0x22ff90400000000b,
        0x22ff91000000000a, 0x22ff91a00000000b, 0x22ff940000000009,
        0x22ff96200000000b, 0x22ff96800000000a, 0x22ff97800000000b,
        0x22ff97c00000000b, 0x22ff97e00000000b, 0x22ff980000000008,
        0x22ff980000000009, 0x22ff9c800000000b, 0x22ff9e800000000b,
        0x22ff9ea00000000b, 0x22ff9ee00000000b, 0x22ffa00000000007,
        0x22ffc00000000007, 0x22ffe00000000007, 0x22ffe8200000000b,
        0x22ffe8800000000b, 0x22ffe8c00000000b, 0x22ffe8e00000000b,
        0x22ffe9c00000000b, 0x22ffea000000000a, 0x22ffeb000000000a,
        0x22ffeb800000000a, 0x22ffef000000000b, 0x22ffef200000000b,
        0x22ffef600000000b
    ])

    print('compressed = pystare.to_compressed_range(sids)')
    k = 0
    for i in sids:
        print(k, hex(i))
        k += 1
    print('')

    compressed = pystare.to_compressed_range(sids)
    # compressed = compressed[0:6] # Broken
    # compressed = compressed[0:5] # Broken
    # compressed = compressed[0:4] # Broken # fixed
    # compressed = compressed[0:3] # Okay
    print('compressed = pystare.to_compressed_range(sids)')
    k = 0
    for i in compressed:
        print(k, hex(i))
        k += 1
    print('')

    expanded = pystare.expand_intervals(compressed, -1, False)
    print('expanded = pystare.expand_intervals(compressed,-1,False)')
    k = 0
    for i in expanded:
        print(k, hex(i))
        k += 1
    print('')

    expanded_mr = pystare.expand_intervals(compressed, -1, True)
    print('expanded = pystare.expand_intervals(compressed,-1,True)')
    k = 0
    for i in expanded_mr:
        print(k, hex(i))
        k += 1
    print('')

    ncols = 4  # 5
    fig, axs = plt.subplots(nrows=1,
                            ncols=ncols,
                            subplot_kw={
                                'projection': proj,
                                'transform': transf
                            })
    # plt.figure()
    # plt.subplot(projection=proj,transform=transf)

    iax = 0

    ax = axs[iax]
    # ax.set_global()
    ax.coastlines()
    ax.title.set_text('1. Original\n(res=0xA)')
    ax.annotate(
        '1. sids\n2. compressed = pystare.to_compressed_range(sids) # Intervals. Terminators expressed as dots.\n3. expanded = pystare.expand_intervals(compressed,-1,False) # Intervals expanded according to embedded resolution.\n4. expanded_multires = pystare.expand_intervals(compressed,-1,True) # Intervals expanded into coarsest common ancestors.',
        xy=(50, 50),
        xycoords='figure pixels')
    plot2(sids, c0='r', c1='b', transf=transf, ax=ax)
    iax += 1

    ax = axs[iax]
    # ax.set_global()
    ax.coastlines()
    ax.title.set_text('2. Compressed\n(Incorrect usage)')
    plot2(compressed, c0='r', c1='b', transf=transf, ax=ax)
    iax += 1

    ax = axs[iax]
    # ax.set_global()
    ax.coastlines()
    ax.title.set_text('3. Expand Compressed\n(mono-res)')
    plot2(expanded, c0='r', c1='b', transf=transf, ax=ax)
    iax += 1

    ax = axs[iax]
    # ax.set_global()
    ax.coastlines()
    ax.title.set_text('4. Expand Compressed\n(multi-res)')
    plot2(expanded_mr, c0='r', c1='b', transf=transf, ax=ax)
    iax += 1

    #    ax=axs[iax]
    #    # ax.set_global()
    #    ax.coastlines()
    #    ax.title.set_text('5. Expand Compressed\n(multi-res)\nfrom STARE lib tests')
    #    plot2(expanded_stare_test,c0='r',c1='b',transf=transf,ax=ax)
    #    iax += 1

    plt.show()

    #    compressed = pystare.to_compressed_range(flat_list)
    #    compressed.size
    #    22
    #    we get
    #
    #    array([2521886048955400202, 2521887148467027967, 2521887698222841866,
    #        2521889347490283530, 2521890447001911306, 2521892646025166858,
    #    2521893745536794634, 2521894845048422399, 2521897044071677961,
    #    2521899243094933514, 2521900342606561279, 2521900892362375178,
    #    2521903641141444607, 2521906389920514058, 2521908588943769610,
    #    2521989403048411146, 2521990502560038911, 2521991052315852810,
    #    2521992151827480575, 2521992701583294474, 2521993801094922239,
    #               2521997099629805578])

    return