Skip to content

Commit a6c489c

Browse files
authored
Merge pull request #29 from ACCESS-NRI/fixes-and-formatting
Fixes and formatting
2 parents 1d077e0 + fb860eb commit a6c489c

File tree

1 file changed

+42
-51
lines changed

1 file changed

+42
-51
lines changed

src/accessvis/earth.py

+42-51
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class Settings:
5151
if envdir:
5252
DATA_PATH = Path(envdir)
5353
else:
54-
# Check if running on 'gadi.nci.org.au'
54+
# Check if running on "gadi.nci.org.au"
5555
if gadi:
5656
# Use public shared data cache on gadi
5757
DATA_PATH = Path("/g/data/xp65/public/apps/access-vis-data")
@@ -94,6 +94,11 @@ def get_viewer(*args, **kwargs):
9494
# headless not required because always in headless mode
9595
metadata.metadata("lavavu")
9696
# Requires moderngl for EGL headless context
97+
import moderngl
98+
99+
print(
100+
moderngl.__file__
101+
) # If we don't use it the pre-commit will delete above
97102
except (ImportError, metadata.PackageNotFoundError):
98103
settings.HEADLESS = False
99104

@@ -216,7 +221,7 @@ def paste_image(fn, xpos, ypos, out):
216221
# print(fn, col.shape)
217222
xoff = xpos * col.shape[0]
218223
yoff = ypos * col.shape[1]
219-
# print(f'{yoff}:{yoff+col.shape[1]}, {xoff}:{xoff+col.shape[0]}')
224+
# print(f"{yoff}:{yoff+col.shape[1]}, {xoff}:{xoff+col.shape[0]}")
220225
out[yoff : yoff + col.shape[1], xoff : xoff + col.shape[0]] = col
221226

222227

@@ -473,12 +478,12 @@ def cubemap_sphere_vertices(
473478
and save the data for next time
474479
hemisphere: str
475480
Crop the data to show a single hemisphere
476-
'N' = North polar
477-
'S' = South polar
478-
'EW' = Antimeridian at centre (Oceania/Pacific)
479-
'WE' = Prime meridian at centre (Africa/Europe)
480-
'E' = Eastern hemisphere - prime meridian to antimeridian (Indian ocean)
481-
'W' = Western hemisphere - antimeridian to prime meridian (Americas)
481+
"N" = North polar
482+
"S" = South polar
483+
"EW" = Antimeridian at centre (Oceania/Pacific)
484+
"WE" = Prime meridian at centre (Africa/Europe)
485+
"E" = Eastern hemisphere - prime meridian to antimeridian (Indian ocean)
486+
"W" = Western hemisphere - antimeridian to prime meridian (Americas)
482487
"""
483488
if resolution is None:
484489
resolution = settings.GRIDRES
@@ -592,12 +597,12 @@ def load_topography_cubemap(
592597
Radius of the sphere, defaults to 6.371 Earth's approx radius in Mm
593598
hemisphere: str
594599
Crop the data to show a single hemisphere
595-
'N' = North polar
596-
'S' = South polar
597-
'EW' = Antimeridian at centre (Oceania/Pacific)
598-
'WE' = Prime meridian at centre (Africa/Europe)
599-
'E' = Eastern hemisphere - prime meridian to antimeridian (Indian ocean)
600-
'W' = Western hemisphere - antimeridian to prime meridian (Americas)
600+
"N" = North polar
601+
"S" = South polar
602+
"EW" = Antimeridian at centre (Oceania/Pacific)
603+
"WE" = Prime meridian at centre (Africa/Europe)
604+
"E" = Eastern hemisphere - prime meridian to antimeridian (Indian ocean)
605+
"W" = Western hemisphere - antimeridian to prime meridian (Americas)
601606
"""
602607
# Load detailed topo data
603608
if resolution is None:
@@ -717,7 +722,7 @@ def plot_region(
717722
uniforms["waves"] = True
718723
719724
if shaders is None:
720-
shaders = [f'{settings.INSTALL_PATH}/data/earth_shader.vert', f'{settings.INSTALL_PATH}/data/earth_shader.frag']
725+
shaders = [f"{settings.INSTALL_PATH}/data/earth_shader.vert", f"{settings.INSTALL_PATH}/data/earth_shader.frag"]
721726
"""
722727

723728
# Split kwargs into global props, object props and uniform values
@@ -750,9 +755,9 @@ def plot_region(
750755
# TODO: support cropping tiled high res blue marble textures
751756
# Also download relief textures if not found or call process_bluemarble
752757
# TODO2: write a process_relief function for splitting/downloading relief from Earth_Model.ipynb
753-
# colour_tex = f'{settings.DATA_PATH}/relief/4_no_ice_clouds_mts_16k.jpg'
758+
# colour_tex = f"{settings.DATA_PATH}/relief/4_no_ice_clouds_mts_16k.jpg"
754759
colour_tex = f"{settings.DATA_PATH}/bluemarble/source_full/world.200412.3x21600x10800.jpg"
755-
# colour_tex = f'{settings.DATA_PATH}/landmask/world.oceanmask.21600x10800.png'
760+
# colour_tex = f"{settings.DATA_PATH}/landmask/world.oceanmask.21600x10800.png"
756761
uniforms["bluemarble"] = True
757762
elif texture == "relief":
758763
colour_tex = f"{settings.DATA_PATH}/relief/4_no_ice_clouds_mts_16k.jpg"
@@ -801,15 +806,15 @@ def plot_earth(
801806
----------
802807
texture: str
803808
Path to textures, face label and texres will be applied with .format(), eg:
804-
texture='path/{face}_mytexture_{texres}.png'
805-
with: texture.format(face='F', texres=settings.TEXRES)
806-
to:'path/F_mytexture_1024.png'
809+
texture="path/{face}_mytexture_{texres}.png"
810+
with: texture.format(face="F", texres=settings.TEXRES)
811+
to:"path/F_mytexture_1024.png"
807812
radius: float
808813
Radius of the sphere, defaults to 6.371 Earth's approx radius in Mm
809814
vertical_exaggeration: number
810815
Multiplier to topography/bathymetry height
811816
texture: str
812-
Texture set to use, 'bluemarble' for the 2004 NASA satellite data, 'relief' for a basic relief map
817+
Texture set to use, "bluemarble" for the 2004 NASA satellite data, "relief" for a basic relief map
813818
or provide a custom set of textures using a filename template with the following variables, only face is required
814819
{face} (F/R/B/L/U/D) {month} (name of month, capitialised) {texres} (2048/4096/8192/16384)
815820
lighting: bool
@@ -818,9 +823,9 @@ def plot_earth(
818823
Provide a datetime object to set the month for texture sets that vary over the year and time for
819824
position of sun and rotation of earth when calculating sun light position
820825
hour: int
821-
If not providing 'when' datetime, provide just the hour and minute
826+
If not providing "when" datetime, provide just the hour and minute
822827
minute: int
823-
If not providing 'when' datetime, provide just the hour and minute
828+
If not providing "when" datetime, provide just the hour and minute
824829
waves: bool
825830
When plotting ocean as surface, set this to true to render waves
826831
sunlight: bool
@@ -834,17 +839,17 @@ def plot_earth(
834839
uniforms: dict
835840
Provide a set of uniform variables, these can be used to pass data to a custom shader
836841
shaders: list
837-
Provide a list of two custom shader file paths eg: ['vertex_shader.glsl', 'fragment_shader.glsl']
842+
Provide a list of two custom shader file paths eg: ["vertex_shader.glsl", "fragment_shader.glsl"]
838843
background: str
839844
Provide a background colour string, X11 colour name or hex RGB
840845
hemisphere: str
841846
Crop the data to show a single hemisphere
842-
'N' = North polar
843-
'S' = South polar
844-
'EW' = Antimeridian at centre (Oceania/Pacific)
845-
'WE' = Prime meridian at centre (Africa/Europe)
846-
'E' = Eastern hemisphere - prime meridian to antimeridian (Indian ocean)
847-
'W' = Western hemisphere - antimeridian to prime meridian (Americas)
847+
"N" = North polar
848+
"S" = South polar
849+
"EW" = Antimeridian at centre (Oceania/Pacific)
850+
"WE" = Prime meridian at centre (Africa/Europe)
851+
"E" = Eastern hemisphere - prime meridian to antimeridian (Indian ocean)
852+
"W" = Western hemisphere - antimeridian to prime meridian (Americas)
848853
"""
849854
if lv is None:
850855
lv = get_viewer(
@@ -1027,7 +1032,7 @@ def update_earth_datetime(
10271032
obj = lv.objects[o]
10281033
uniforms = obj["uniforms"]
10291034

1030-
# if not 'blendTex' in uniforms or uniforms['blendTex'] != texfn2:
1035+
# if not "blendTex" in uniforms or uniforms["blendTex"] != texfn2:
10311036
if obj["texture"] != texfn:
10321037
obj["texture"] = texfn # Not needed, but set so can be checked above
10331038
obj.texture(texfn, flip=False)
@@ -1090,8 +1095,6 @@ def update_earth_values(lv, name="", flip=False, *args, **kwargs):
10901095

10911096
lv.render() # Required to render a frame which fixes texture glitch
10921097

1093-
# Load the texture arrays
1094-
10951098

10961099
def vec_rotate(v, theta, axis):
10971100
"""
@@ -1110,7 +1113,6 @@ def vec_rotate(v, theta, axis):
11101113
-------
11111114
numpy.ndarray: rotated 3d vector
11121115
"""
1113-
np.array([0.0] + v)
11141116
rot_axis = np.array([0.0] + axis)
11151117
axis_angle = (theta * 0.5) * rot_axis / np.linalg.norm(rot_axis)
11161118

@@ -1497,27 +1499,20 @@ def load_mask(res_y=None, masktype="watermask", cropbox=None):
14971499
https://neo.gsfc.nasa.gov/archive/bluemarble/bmng/landmask_new/
14981500
https://neo.gsfc.nasa.gov/archive/bluemarble/bmng/landmask/world.watermask.21600x21600.A1.png
14991501
1500-
masktype = 'oceanmask' / 'watermask'
1502+
masktype = "oceanmask" / "watermask"
15011503
"""
15021504
if res_y is None:
15031505
res_y = settings.FULL_RES_Y
15041506
# Get the tiled high res images
15051507
os.makedirs(settings.DATA_PATH / "landmask/source_tiled", exist_ok=True)
1506-
if (
1507-
len(
1508-
glob.glob(
1509-
f"{settings.DATA_PATH}/landmask/source_tiled/world.{masktype}.21600x21600.*.tif.gz"
1510-
)
1511-
)
1512-
< 8
1513-
):
1508+
filespec = f"{settings.DATA_PATH}/landmask/source_tiled/world.{masktype}.21600x21600.*.tif.gz"
1509+
if len(glob.glob(filespec)) < 8:
15141510
# Download tiles
15151511
for t in bm_tiles:
15161512
# https://eoimages.gsfc.nasa.gov/images/imagerecords/73000/73967/world.200402.3x21600x21600.A1.jpg
15171513
url = f"https://neo.gsfc.nasa.gov/archive/bluemarble/bmng/landmask_new/world.{masktype}.21600x21600.{t}.tif.gz"
15181514
# print(url)
15191515
download(url, f"{settings.DATA_PATH}/landmask/source_tiled")
1520-
# print(filename)
15211516

15221517
# Calculate full image res to use for specified TEXRES
15231518
ffn = f"{settings.DATA_PATH}/landmask/world.{masktype}.{2 * res_y}x{res_y}.png"
@@ -1529,12 +1524,8 @@ def load_mask(res_y=None, masktype="watermask", cropbox=None):
15291524
for t in bm_tiles:
15301525
x = ord(t[0]) - ord("A")
15311526
y = 1 if int(t[1]) == 2 else 0
1532-
paste_image(
1533-
f"{settings.DATA_PATH}/landmask/source_tiled/world.{masktype}.21600x21600.{t}.tif.gz",
1534-
x,
1535-
y,
1536-
mask,
1537-
)
1527+
filespec = f"{settings.DATA_PATH}/landmask/source_tiled/world.{masktype}.21600x21600.{t}.tif.gz"
1528+
paste_image(filespec, x, y, mask)
15381529

15391530
# Save full mask in various resolutions
15401531
for res in [(86400, 43200), (43200, 21600), (21600, 10800)]:
@@ -1782,7 +1773,7 @@ def process_gebco(overwrite=False, redownload=False):
17821773
#TODO2: move subsampling and export functions from GEBCO.ipynb to this module
17831774
url = f"https://github.com/ACCESS-NRI/visualisations/releases/download/v0.0.1/gebco_cubemap_{settings.GRIDRES}.npz"
17841775
raise(Exception("TODO: upload gebco cubemap data to github releases!"))
1785-
filename = utils.download(url, './data/gebco')
1776+
filename = utils.download(url, "./data/gebco")
17861777
"""
17871778

17881779
# Attempt to load full GEBCO

0 commit comments

Comments
 (0)