Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Task] Explore the correct way of creating COG. #276

Open
mahrsee1997 opened this issue Jan 5, 2023 · 0 comments
Open

[Task] Explore the correct way of creating COG. #276

mahrsee1997 opened this issue Jan 5, 2023 · 0 comments

Comments

@mahrsee1997
Copy link
Collaborator

As per rasterio/rasterio#2675 (comment) the way we are creating COG's is not right.

Check correctness & measure efficiency of the current & suggested approach -- make necessary changes if required.

Code snippet as per above comment:

                profile = {
                    'dtype': dtype,
                    'width': data[0].data.shape[1],
                    'height': data[0].data.shape[0],
                    'count': len(data),
                    'nodata': np.nan,
                    'crs': crs,
                    'transform': transform,
                    'compress': 'lzw'
                }
                with tempfile.NamedTemporaryFile() as temp:
                    with rasterio.MemoryFile() as memfile:
                        with memfile.open(driver='GTiff', **profile) as f:
                            for i, da in enumerate(data):
                                f.write(da, i + 1)    
                                # Making the channel name EE-safe.
                                f.set_band_description(i + 1,
                                                    get_ee_safe_name(channel_names[i]))
                                f.update_tags(i + 1, band_name=channel_names[i])
                                f.update_tags(i + 1, **da.attrs)

                            # Write attributes as tags in tiff.
                            f.update_tags(**attrs)
                            print("tags update : " + datetime.now().strftime("%H:%M:%S"))
                            
                            # Create COG
                            rasterio_copy(f, temp.name, driver="COG", compress="lzw", bigtiff="IF_NEEDED")
                            
                            # Copy the created COG to gcs.
                            target_path = os.path.join(self.asset_location, file_name)                
                            gcs_copy(temp.name, target_path)
         
                del f, memfile, data
@mahrsee1997 mahrsee1997 changed the title [Task] Explore correct way of creating COG. [Task] Explore the correct way of creating COG. Jan 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant