PK!>33oceandata/__init__.py__version__ = '0.2.0' __all__ = ["mapps", "gdp"] PK!p'zoceandata/gdp.py """GDP: The global drifter program Reference: https://www.aoml.noaa.gov/phod/gdp/ """ import os import glob import pathlib import ftplib from urllib.parse import urlsplit import numpy as np import pandas as pd import requests import click DATADIR = os.path.expanduser("~/.oceandata/") pathlib.Path(DATADIR).mkdir(parents=True, exist_ok=True) def read_dat(filename, sst=False, vel=False, var=False): df = pd.read_csv( filename, sep=" ", skipinitialspace=True, compression='gzip', names=["id", "month", "day", "year", "lat", "lon", "sst", "vel_east", "vel_north", "speed", "var_lat", "var_lon", "var_temp"]) df["hour"] = ((df.day - df["day"].astype(int)) * 24).astype(np.int32) df.set_index(pd.to_datetime(df[["year","month","day","hour"]]),inplace=True) del df["year"], df["month"], df["day"], df["hour"] if not sst: del df["sst"] if not vel: del df["vel_east"], df["vel_north"], df["speed"] if not var: del df["var_lat"], df["var_lon"], df["var_temp"] return df def load(v1=None, sst=False, vel=False, var=False): """Load gzipped dat file to a pandas dataframe""" if v1 is None: dflist = [] for v1 in [1, 5001, 10001, 15001]: dflist.append(load(v1, sst=sst, vel=vel, var=var)) return pd.concat(dflist) if v1 == 1: v2 = 5000 elif v1 == 5001: v2 = 10000 elif v1 == 10001: v2 = 15000 elif v1 == 15001: v2 = "oct18" filename = os.path.join(DATADIR, f"buoydata_{v1}_{v2}.dat.gz") h5filename = filename[:-7] + ".h5" if os.path.isfile(h5filename): return pd.read_hdf(h5filename) if not os.path.isfile(filename): print("Downloading file") download(v1=v1, v2=v2) df = read_dat(filename, sst=sst, vel=vel, var=var) df.to_hdf(h5filename, "df") #ftp://ftp.aoml.noaa.gov/phod/pub/buoydata/buoydata_1_5000.dat.gz #ftp://ftp.aoml.noaa.gov/phod/pub/buoydata/buoydata_5001_10000.dat.gz #ftp://ftp.aoml.noaa.gov/phod/pub/buoydata/buoydata_10001_15000.dat.gz #ftp://ftp.aoml.noaa.gov/phod/pub/buoydata/buoydata_15001_oct18.dat.gz def vprint(text): pass #print(text) def download(url="ftp://ftp.aoml.noaa.gov/phod/pub/buoydata/", v1="15001", v2="oct18"): """Download tsv file from NOOA's website using ftp""" lfn = filename = f"buoydata_{v1}_{v2}.dat.gz" spliturl = urlsplit(url) try: ftp = ftplib.FTP(spliturl.netloc) vprint(ftp.login("anonymous", "oceandata@bror.us")) ftpdir = spliturl.path vprint("Change dir to '%s'" % ftpdir) vprint(ftp.cwd(ftpdir)) except ftplib.error_perm as err: print (spliturl.netloc) print (os.path.split(spliturl.path)[0]) raise IOError(err) local_filename = os.path.join(DATADIR, filename) if not filename in ftp.nlst(): print(ftp.nlst()) raise ftplib.Error("'%s' is not the ftp server" % lfn) with open(local_filename, 'wb') as lfh: ftp.voidcmd('TYPE I') length = ftp.size(lfn) short_lfn = lfn if len(lfn)<18 else lfn[:9] + "..." + lfn[-9:] with click.progressbar(length=length, label=short_lfn) as bar: def file_write(data): lfh.write(data) bar.update(len(data)) try: ftp.retrbinary("RETR %s" % lfn, file_write) except ftplib.error_perm as err: os.unlink(local_filename) raise IOError(err) ftp.quit() def unzip(filename="SOCATv6.tsv.zip"): local_filename = os.path.join(DATADIR, filename) zip_ref = zipfile.ZipFile(local_filename, 'r') zip_ref.extractall(DATADIR) zip_ref.close() PK!pu))oceandata/mapps.py import os """MAPPS: photosynthesis-irradiance parameters for marine phytoplankton The MAPPS global database of photosynthesis-irradiance (P-E) parameters consists of over 5000 P-E experiments that provides information on the spatio-temporal variability in the two P-E parameters (the assimilation number, and the initial slope) that are fundamental inputs for models of marine primary production that use chlorophyll as the state variable. The experiments were carried out by an international group of research scientists to examine the basin-scale variability in the photophysiological response of marine phytoplankton over a range of oceanic regimes (from the oligotrophic gyres to productive shelf systems) and covers several decades. These data can be used to improve the assignment of P-E parameters in the estimation of marine primary production using satellite dat Data DOI: DOI:10.1594/PANGAEA.874087 References: DOI:10.5194/essd-10-251-2018 """ import glob import pathlib import numpy as np import pandas as pd import requests DATADIR = os.path.expanduser("~/.oceandata/") FILENAME = "Bouman_2017.tab.tsv" pathlib.Path(DATADIR).mkdir(parents=True, exist_ok=True) def load(filename=FILENAME): """Load tsv file and fix some columns""" df = pd.read_csv(os.path.join(DATADIR, FILENAME), sep="\t", skiprows=57) df["lat"] = df["Latitude"] df["lon"] = df["Longitude"] df["region"] = df["BG province"] df["depth"] = df["Depth water [m]"] df["chl"] = df["Chl a [µg/l]"] df["alpha"] = df["alpha [(mg C/mg Chl a/h)/(µE/m**2/s)]"] df["PBmax"] = df["PBmax [mg C/mg Chl a/h]"] df["Ek"] = df["Ek [µmol/m**2/s]"] del df["Latitude"], df["Longitude"], df["BG province"] del df["Depth water [m]"], df["Chl a [µg/l]"] del df["alpha [(mg C/mg Chl a/h)/(µE/m**2/s)]"] del df["PBmax [mg C/mg Chl a/h]"], df["Ek [µmol/m**2/s]"] df.set_index(pd.DatetimeIndex(df["Date/Time"]), inplace=True) del df["Date/Time"] return df def download(url="https://doi.pangaea.de/10.1594/PANGAEA.874087", params={"format":"textfile"}, filename=None): """Download tsv file from Pangaea server""" filename = FILENAME if filename is None else filename local_filename = os.path.join(DATADIR, filename) try: r = requests.get(url, params=params, stream=True, timeout=2) except requests.ReadTimeout: warnings.warn("Connection to server timed out.") return False if r.ok: if local_filename is None: return r.text else: with open(local_filename, 'wb') as f: for chunk in r.iter_content(chunk_size=1024): if chunk: f.write(chunk) f.flush() return None else: raise IOError("Could not download file from server") def download_pml(url="https://github.com/brorfred/oceandata/raw/master/data/", filename="GLOBAL_PE_W_LOV_2019.csv", params={}): """Download local PML version of MAPPS""" download(url=f"{url}/{filename}", filename=filename, params=params) def load_pml(filename="GLOBAL_PE_W_LOV_2019.csv"): fn = os.path.join(DATADIR, filename) df = pd.read_csv(fn, parse_dates=[[4,5,6]], index_col="YEAR_MONTH_DAY") df = df.rename(columns={"LAT":"lat", "LON":"lon", "DEPTH":"depth", "TEMP":"temp", "TCHL":"chl", "ALPHA":"alpha", 'NITRATE':"NO3",'SILICATE':"Si4",'PHOSPHATE':"PO4", "PMB":"PBmax", "EK":"Ek","PROVNUM":"region"}) return df PK!i~ oceandata/socat.py import os """SOCAT: photosynthesis-irradiance parameters for marine phytoplankton Data DOI: DOI:10.1594/PANGAEA.874087 References: DOI:10.5194/essd-10-251-2018 """ import glob import pathlib import zipfile import numpy as np import pandas as pd import requests import click DATADIR = os.path.expanduser("~/.oceandata/") pathlib.Path(DATADIR).mkdir(parents=True, exist_ok=True) def load(filename="SOCATv6.tsv.zip"): """Load tsv file and fix some columns""" df = pd.read_csv(os.path.join(DATADIR, FILENAME), sep="\t", skiprows=57) df["lat"] = df["Latitude"] df["lon"] = df["Longitude"] df["region"] = df["BG province"] df["depth"] = df["Depth water [m]"] df["chl"] = df["Chl a [µg/l]"] df["alpha"] = df["alpha [(mg C/mg Chl a/h)/(µE/m**2/s)]"] df["PBmax"] = df["PBmax [mg C/mg Chl a/h]"] df["Ek"] = df["Ek [µmol/m**2/s]"] del df["Latitude"], df["Longitude"], df["BG province"] del df["Depth water [m]"], df["Chl a [µg/l]"] del df["alpha [(mg C/mg Chl a/h)/(µE/m**2/s)]"] del df["PBmax [mg C/mg Chl a/h]"], df["Ek [µmol/m**2/s]"] df.set_index(pd.DatetimeIndex(df["Date/Time"]), inplace=True) del df["Date/Time"] return df def download(url="https://www.socat.info/socat_files/", version="v6", filename="SOCATv6.tsv.zip"): """Download tsv file from Pangaea server""" local_filename = os.path.join(DATADIR, filename) try: r = requests.get(url=f"{url}/{version}/{filename}", stream=True, timeout=20) except requests.ReadTimeout: warnings.warn("Connection to server timed out.") return False if r.ok: total_size = int(r.headers.get('Content-Length')) if local_filename is None: return r.text else: with open(local_filename, 'wb') as f: with click.progressbar(length=total_size, label='Downloading files') as bar: for chunk in r.iter_content(chunk_size=1024): if chunk: f.write(chunk) f.flush() bar.update(len(chunk)) return None else: raise IOError("Could not download file from server") def unzip(filename="SOCATv6.tsv.zip"): local_filename = os.path.join(DATADIR, filename) zip_ref = zipfile.ZipFile(local_filename, 'r') zip_ref.extractall(DATADIR) zip_ref.close() PK!xxoceandata/test.h5HDF  x` TREEHEAPXdfH TITLE (CLASSGROUP (VERSION1.0 8PYTABLES_FORMAT_VERSION2.1TREE HEAPX8haxis0axis1block0_valuesblock0_items SNOD(H8P TITLE (CLASSGROUP (VERSION1.0 0 pandas_typeframe 0pandas_version0.15.2 0 encodingUTF-8 (errorsstrict 0 ndim@ 0axis0_varietyregularHH \ (CLASSARRAY (VERSION2.4 TITLESNOD (abab (FLAVORnumpy 8 transposed (kindstring (nameN.hP 0axis1_varietyregular @J \ (CLASSARRAY (VERSION2.4 TITLE (FLAVORnumpy 8 transposed (kindinteger (nameN.HX 0 nblocks@ (@b 0\ (CLASSARRAY (VERSION2.4 TITLE (FLAVORnumpy 8 transposed(H 8block0_items_varietyregular  \ (CLASSARRAY (VERSION2.4 TITLE (FLAVORnumpy 8 transposed (kindstring (nameN.PK!j*=I--!oceandata-0.2.0.dist-info/LICENSEMIT License Copyright (c) 2019 Bror Jonsson Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. PK!HڽTUoceandata-0.2.0.dist-info/WHEEL A н#Z;/"d&F[xzw@Zpy3Fv]\fi4WZ^EgM_-]#0(q7PK!HA="oceandata-0.2.0.dist-info/METADATAMO0 9ZM l:D4II=΄]vc4L_FCJFS;%ŭ32\׫Z,uC6.y%S2;%z\HI0M Ͽ0įk=m+hۑ}[cy1FAɦ͇ӕJ%5Oq5fHxe@9|KL4*ޙ'8.X+ͭxgId9J'M&>ZIIľy @V8v-3-G%_#Ɖ 'iO(:HZx|ݮ4ZuoL)5@P}Y.3S.\n+O>@9TDx07uE9Ufp&҂|Qo6&oyE%=,᭵u3zç" $ 8 (~vbS"(n33oceandata/__init__.pyPK!p'zfoceandata/gdp.pyPK!pu))7oceandata/mapps.pyPK!i~ oceandata/socat.pyPK!xx'oceandata/test.h5PK!j*=I--!;Coceandata-0.2.0.dist-info/LICENSEPK!HڽTUGoceandata-0.2.0.dist-info/WHEELPK!HA="8Hoceandata-0.2.0.dist-info/METADATAPK!H1 tIoceandata-0.2.0.dist-info/RECORDPK z_K