99from PIL import Image
1010from celery import current_task , shared_task
1111import cftime
12- from django .db import transaction
1312from django .contrib .gis .geos import Polygon
1413from django .contrib .gis .geos .error import GEOSException
1514from django .core .files .base import ContentFile
15+ from django .db import transaction
1616from matplotlib import cm
1717import numpy as np
1818import pandas as pd
@@ -175,7 +175,6 @@ def create_netcdf_data_layer(file_item, metadata):
175175 logger .warning (f'Variable Min/Max Exception { var_name } : { e } ' )
176176 logger .warning (f'Variable info { var_info } ' )
177177
178-
179178 description ['variables' ][var_name ] = var_info
180179 if metadata .get ('tags' , False ):
181180 description ['tags' ] = metadata .get ('tags' )
@@ -570,7 +569,9 @@ def create_netcdf_slices(
570569 and all (isinstance (x , int ) for x in slicer_range )
571570 )
572571
573- if is_range_of_integers and not (np .issubdtype (ds [sliding_variable ].dtype , np .datetime64 )):
572+ if is_range_of_integers and not (
573+ np .issubdtype (ds [sliding_variable ].dtype , np .datetime64 )
574+ ):
574575 # Check if range is within the number of layers
575576 num_layers = len (ds [sliding_variable ])
576577 if not (
@@ -780,14 +781,16 @@ def create_netcdf_slices(
780781 slice_data = data_var .isel (indexers ).values
781782
782783 # Normalize data to 0-1 for colormap application
783- # Uncomment for per-image normalization
784+ # Uncomment for per-image normalization
784785 # slice_min = np.nanmin(slice_data)
785786 # slice_max = np.nanmax(slice_data)
786787 normalized_data = (slice_data - slice_min ) / (slice_max - slice_min )
787788
788789 # Apply the colormap
789790 colored_data = colormap (normalized_data ) # Returns RGBA values
790- colored_data = (colored_data [:, :, :3 ] * 255 ).astype (np .uint8 ) # Drop alpha, scale to 0-255
791+ colored_data = (colored_data [:, :, :3 ] * 255 ).astype (
792+ np .uint8
793+ ) # Drop alpha, scale to 0-255
791794
792795 # Convert to an RGB image using PIL
793796 image = Image .fromarray (colored_data , mode = 'RGB' )
@@ -798,15 +801,17 @@ def create_netcdf_slices(
798801 image_content = ContentFile (image_buffer .getvalue (), name = image_name )
799802
800803 # Collect the NetCDFImage objects for bulk creation later
801- image_objects .append (NetCDFImage (
802- netcdf_layer = netcdf_layer ,
803- image = image_content , # Save the image to the S3 field
804- slider_index = i ,
805- bounds = bounds , # Reuse the bounds calculated earlier
806- ))
804+ image_objects .append (
805+ NetCDFImage (
806+ netcdf_layer = netcdf_layer ,
807+ image = image_content , # Save the image to the S3 field
808+ slider_index = i ,
809+ bounds = bounds , # Reuse the bounds calculated earlier
810+ )
811+ )
807812
808813 # Bulk create the NetCDFImage objects in a single database transaction
809- logger .info (f 'Creating Image Objects' )
814+ logger .info ('Creating Image Objects' )
810815 with transaction .atomic ():
811816 NetCDFImage .objects .bulk_create (image_objects )
812817 if processing_task :
0 commit comments