Skip to content

Commit

Permalink
remove cartopy as an explicit dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
robertjwilson committed Jun 17, 2022
1 parent 7838be2 commit 6cdf04f
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 18 deletions.
66 changes: 51 additions & 15 deletions ncplot/plot.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
import sys
import warnings
from threading import Thread

from cartopy import crs
import time
import holoviews as hv
import panel as pn
import cartopy.crs as ccrs
try:
from cartopy import crs
import cartopy.crs as ccrs
projection = ccrs.PlateCarree()
except:
warnings.warn("Unable to import cartopy. For better plots install cartopy!")
projection = None

import pandas as pd
import hvplot.pandas
import hvplot.xarray
import hvplot
from bokeh.plotting import show
import xarray as xr
import warnings
import copy
import numpy as np

Expand Down Expand Up @@ -64,10 +69,6 @@ def change_coords(dx):
lat_df.columns = ["value", "number"]

if lat_df.number[0] / lat_df.number[1] < 10:
# switch_coords = True

## if there are repeated zeros
# if len([x for x in ds[lat_name].values[0] if x == 0]) <= 1:
return ds

if sum(ds[lon_name].values[0] == ds[lon_name].values[1]) == len(ds[lon_name][0]):
Expand Down Expand Up @@ -173,11 +174,13 @@ def view(x, vars=None, autoscale=True,out = None, **kwargs):
else:
xr_file = False

nc_vars = None
if xr_file is False:
try:
try:
import nctoolkit as nc
ds = nc.open_data(x)
nc_vars = ds.variables
ds = ds.to_xarray()
except:
ds = xr.open_dataset(x)
Expand Down Expand Up @@ -422,7 +425,13 @@ def view(x, vars=None, autoscale=True,out = None, **kwargs):

if len([x for x in coord_df.length if x > 1]) == 1 and spatial_map is False:

df = ds.to_dataframe().reset_index()
df = ds.to_dataframe()
if nc_vars is not None:
cols = [x for x in list(df.columns) if x in nc_vars]
df = df.loc[:,cols]

df = df.reset_index().drop_duplicates().reset_index()

if type(vars) is str:
vars = [vars]

Expand Down Expand Up @@ -745,7 +754,12 @@ def view(x, vars=None, autoscale=True,out = None, **kwargs):

if coastline:
coastline = get_coastline(ds, lon_name, lat_name)
projection = ccrs.PlateCarree()
try:
projection = ccrs.PlateCarree()
except:
projection = None
coastline = False

else:
projection = None

Expand All @@ -765,7 +779,11 @@ def view(x, vars=None, autoscale=True,out = None, **kwargs):

if coastline:
coastline = get_coastline(ds, lon_name, lat_name)
projection = ccrs.PlateCarree()
try:
projection = ccrs.PlateCarree()
except:
projection = None
coastline = False
else:
projection = None

Expand Down Expand Up @@ -814,7 +832,11 @@ def view(x, vars=None, autoscale=True,out = None, **kwargs):
if quadmesh:
if coastline:
coastline = get_coastline(ds, lon_name, lat_name)
projection = ccrs.PlateCarree()
try:
projection = ccrs.PlateCarree()
except:
projection = None
coastline = False
else:
projection = None

Expand Down Expand Up @@ -844,11 +866,14 @@ def view(x, vars=None, autoscale=True,out = None, **kwargs):
responsive=(in_notebook() is False),
**kwargs
)
# intplot = pn.Row(pn.WidgetBox(w1), intplot)
else:
if coastline:
coastline = get_coastline(ds, lon_name, lat_name)
projection = ccrs.PlateCarree()
try:
projection = ccrs.PlateCarree()
except:
projection = None
coastline = False
else:
projection = None

Expand Down Expand Up @@ -897,9 +922,15 @@ def view(x, vars=None, autoscale=True,out = None, **kwargs):
if quadmesh:
if coastline:
coastline = get_coastline(ds, lon_name, lat_name)
projection = ccrs.PlateCarree()
try:
projection = ccrs.PlateCarree()
except:
projection = None
coastline = False
else:
projection = None


if autoscale:
intplot = ds.hvplot.quadmesh(
lon_name,
Expand Down Expand Up @@ -931,9 +962,14 @@ def view(x, vars=None, autoscale=True,out = None, **kwargs):

if coastline:
coastline = get_coastline(ds, lon_name, lat_name)
projection = ccrs.PlateCarree()
try:
projection = ccrs.PlateCarree()
except:
projection = None
coastline = False
else:
projection = None
projection = None

if autoscale:
intplot = ds.hvplot.image(
Expand Down
3 changes: 0 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,5 @@ bokeh
panel
pandas
metpy
geoviews
pyproj
cartopy
datashader

0 comments on commit 6cdf04f

Please sign in to comment.