This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
__author__ = "[José M. Beltrán](<[email protected]>)" | |
__credits__ = ["José M. Beltrán"] | |
__license__ = "GPL-3.0" | |
def date_to_week_number(date_string): | |
""" | |
:param date_string: input a date_string with format YYYYmmdd | |
:return: the week number for the given date_string |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
__author__ = "[José M. Beltrán](<[email protected]>)" | |
__credits__ = ["José M. Beltrán"] | |
__license__ = "GPL-3.0" | |
""" | |
The json file has the following scheme: | |
{"20020614":{"KEY1":{"KEY1.1":"path_to_file_01", ...}, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def create_pin_files(data_frame, outdir = '/outdir/path/only/' ): | |
""" | |
Batch process the creation of BEAM-VISAT (http://www.brockmann-consult.de/cms/web/beam/) pin files. | |
Outputs a "pin_sampling_date_batched.placemark" file. | |
Uses pandas data_frame as input. | |
Expected column names in the input data frame are: | |
["IS_DATE"] YYYYMMDD format | |
["SITE"] Name of the Placemark, ie. station, sampling site or Cast ID | |
["Latitude"] Latitude of Placemark in decimal degrees using WGS84 datum | |
["Longitude"] Longitude of Placemark in decimal degrees using WGS84 datum |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
""" | |
Modified from: http://stackoverflow.com/questions/14114610/finding-centre-of-a-polygon-using-limited-data | |
See also: http://en.wikipedia.org/wiki/Centroid#Centroid_of_polygon | |
NOTE: All the following geolocations calculations assumed that | |
the distance from each position is short, i.e. that can be considered to over a flat surface. | |
Otherwise, converting to spherical coordinates needs to be implemented. | |
""" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import colorsys | |
def get_N_HexCol(N=5): | |
HSV_tuples = [(x*1.0/N, 1, 1) for x in xrange(N)] | |
hex_out = [] | |
for rgb in HSV_tuples: | |
rgb = map(lambda x: int(x*255),colorsys.hsv_to_rgb(*rgb)) | |
hex_out.append("".join(map(lambda x: chr(x).encode('hex'),rgb))) | |
return ["#"+c_value for c_value in hex_out] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import matplotlib.pyplot as plt | |
from matplotlib import rc | |
rc('mathtext', default='regular') | |
%matplotlib inline | |
# | |
fig = plt.figure() | |
ax = fig.add_subplot(111) | |
# or |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ... | |
# The nutrients dictionary holds a panda data frame with columns week, and "PO4_mgP_m3" or "DIN_mgN_m3". | |
# for simplicity I rename the columns holding the values as value. | |
for station in nutrients.keys(): | |
for year in nutrients[station].keys(): | |
nutrients[station][year]["PO4"].rename(columns={"PO4_mgP_m3":'value'}, inplace=True) | |
nutrients[station][year]["DIN"].rename(columns={"DIN_mgN_m3":'value'}, inplace=True) | |
# Example of use |