diff --git a/cht_cyclones/tropical_cyclone.py b/cht_cyclones/tropical_cyclone.py index 79ccc87..ef82a01 100644 --- a/cht_cyclones/tropical_cyclone.py +++ b/cht_cyclones/tropical_cyclone.py @@ -106,8 +106,8 @@ def __init__(self, name=None): # Reading - def from_jmv30(self, filename): - self.read_track(filename, "jmv30") + def from_trk(self, filename): + self.read_track(filename, "trk") def from_ddb_cyc(self, filename): self.read_track(filename, "ddb_cyc") @@ -218,8 +218,188 @@ def read_track(self, filename, fmt): self.track = self.track.reset_index(drop=True) if self.debug == 1: print('Successfully read track - ddb_cyc') - elif fmt == 'jmv30': - print("to do: work on progress") + elif fmt == 'trk': + + # Initialize variables + lasttime = np.datetime64(datetime.strptime("2000010118", "%Y%m%d%H")) + newtime2 = lasttime.astype('O') + tc_time_string = newtime2.strftime('%Y%m%d %H%M%S') + it = 0 + point = Point(0,0) + gdf = gpd.GeoDataFrame({"datetime": [tc_time_string],"geometry": [point], "vmax": [-999], "pc": [-999], "RMW": [-999], + "R35_NE": [-999], "R35_SE": [-999], "R35_SW": [-999], "R35_NW": [-999], + "R50_NE": [-999], "R50_SE": [-999], "R50_SW": [-999], "R50_NW": [-999], + "R65_NE": [-999], "R65_SE": [-999], "R65_SW": [-999], "R65_NW": [-999], + "R100_NE": [-999], "R100_SE": [-999],"R100_SW": [-999], "R100_NW": [-999]}) + gdf.set_crs(epsg=self.EPSG, inplace=True) + self.track = gdf # Always start clean + + # Open the file + with open(filename, 'r') as fid: + # Read line by line + for s0 in fid: + s0 = s0.strip() + if not s0: + continue + + # Start + s = s0.split(',') + tc = {'name': 'not_known'} + tc['basin'] = s[0] + tc['storm_number'] = int(s[1]) + + # Read time + tstr = str(s[2]) + tstr = tstr.replace(" ", "") + time = datetime.strptime(tstr, "%Y%m%d%H") + newtime = np.datetime64(time) + + # Add forecasted time + hrs = float(s[5]) + newtime = newtime + np.timedelta64(int(hrs*3600), 's') + if newtime > lasttime + np.timedelta64(1, 's'): + + # Update all variables in gdf (when it is not the first one) + if it > 0: + gdf['geometry'] = [Point(x,y)] # Assign the new geometry + gdf.vmax = vmax + gdf.pc = pc + gdf.RMW = rmax + if R35_NE > 0: gdf.R35_NE = R35_NE + if R35_SE > 0: gdf.R35_SE = R35_SE + if R35_SW > 0: gdf.R35_SW = R35_SW + if R35_NW > 0: gdf.R35_NW = R35_NW + + if R50_NE > 0: gdf.R50_NE = R50_NE + if R50_SE > 0: gdf.R50_SE = R50_SE + if R50_SW > 0: gdf.R50_SW = R50_SW + if R50_NW > 0: gdf.R50_NW = R50_NW + + if R65_NE > 0: gdf.R65_NE = R65_NE + if R65_SE > 0: gdf.R65_SE = R65_SE + if R65_SW > 0: gdf.R65_SW = R65_SW + if R65_NW > 0: gdf.R65_NW = R65_NW + + if R100_NE > 0: gdf.R100_NE = R100_NE + if R100_SE > 0: gdf.R100_SE = R100_SE + if R100_SW > 0: gdf.R100_SW = R100_SW + if R100_NW > 0: gdf.R100_NW = R100_NW + + # New time point found + it += 1 + lasttime = newtime + + # Append self + self.track = pd.concat([self.track,gdf]) + + # Make TC string + newtime2 = newtime.astype('O') + tc_time_string = newtime2.strftime('%Y%m%d %H%M%S') + + # Start fresh + gdf = gpd.GeoDataFrame({"datetime": [tc_time_string],"geometry": [point], "vmax": [-999], "pc": [-999], "RMW": [-999], + "R35_NE": [-999], "R35_SE": [-999], "R35_SW": [-999], "R35_NW": [-999], + "R50_NE": [-999], "R50_SE": [-999], "R50_SW": [-999], "R50_NW": [-999], + "R65_NE": [-999], "R65_SE": [-999], "R65_SW": [-999], "R65_NW": [-999], + "R100_NE": [-999], "R100_SE": [-999],"R100_SW": [-999], "R100_NW": [-999]}) + gdf.set_crs(epsg=self.EPSG, inplace=True) + + # Reset all values + x = 0 + y = 0 + vmax = -999 + pc = -999 + RMW = -999 + R35_NE = -999 + R35_SE = -999 + R35_SW = -999 + R35_NW = -999 + + R50_NE = -999 + R50_SE = -999 + R50_SW = -999 + R50_NW = -999 + + R65_NE = -999 + R65_SE = -999 + R65_SW = -999 + R65_NW = -999 + + R100_NE = -999 + R100_SE = -999 + R100_SW = -999 + R100_NW = -999 + + # Latitude + if s[6][-1] == 'N': + y = 0.1 * float(s[6][:-1]) + else: + y = -0.1 * float(s[6][:-1]) + # Longitude + if s[7][-1] == 'E': + x = 0.1 * float(s[7][:-1]) + else: + x = -0.1 * float(s[7][:-1]) + + # vmax + if float(s[8]) > 0: + vmax = float(s[8]) + + # Pressure and raddi + if len(s) > 9: + + # Pressure + if float(s[9]) > 0: + pc = float(s[9]) + + # Radii + r = float(s[11]) + if r in [34, 35]: + R35_NE = float(s[13]) + R35_SE = float(s[14]) + R35_SW = float(s[15]) + R35_NW = float(s[16]) + elif r == 50: + R50_NE = float(s[13]) + R50_SE = float(s[14]) + R50_SW = float(s[15]) + R50_NW = float(s[16]) + elif r in [64, 65]: + R65_NE = float(s[13]) + R65_SE = float(s[14]) + R65_SW = float(s[15]) + R65_NW = float(s[16]) + elif r == 100: + R100_NE = float(s[13]) + R100_SE = float(s[14]) + R100_SW = float(s[15]) + R100_NW = float(s[16]) + + # Other things + if len(s) > 17: + if s[17]: + pressure_last_closed_isobar = float(s[17]) + if s[18]: + radius_last_closed_isobar = float(s[18]) + if s[19]: + try: + if float(s[19]) > 0: + rmax = float(s[19]) + except ValueError: + print("Error: Unable to convert to float for RMW") + rmax = -999 + if len(s) >= 28: + if s[27]: + name = s[27] + + # Done with this => rest so track looks good + self.track = self.track.reset_index(drop=True) + self.track = self.track.drop([0]) # remove the dummy + self.track = self.track.reset_index(drop=True) + self.track = self.track.drop([0]) # remove the dummy + self.track = self.track.reset_index(drop=True) + if self.debug == 1: print('Successfully read track - trk') + else: raise Exception('This file format is not supported as read track!') @@ -1291,6 +1471,11 @@ def write_spiderweb_netcdf(self, spiderweb, filename): root_grp = Dataset(filename, 'w', format='NETCDF4') root_grp.description = 'Tropical cyclone spiderweb by Coastal Hazards Toolkit' + # Define dimensions + root_grp.createDimension('time', ntime) + root_grp.createDimension('range', nrows) + root_grp.createDimension('azimuth', ncols) + # Define variables time_var = root_grp.createVariable('time', 'f8', ('time',)) range_var = root_grp.createVariable('range', 'f8', ('range',)) @@ -1429,6 +1614,9 @@ def __init__(self, name=None, TropicalCyclone=None): # Methods self.position_method = 0 + # We assume that we are in the imperial system, so convert if needed + TropicalCyclone.convert_units_metric_imperial() + # Define best-track self.best_track = TropicalCyclone self.tstart = datetime.strptime(self.best_track.track.datetime[0], dateformat_module) # starting time of the track @@ -1440,6 +1628,7 @@ def __init__(self, name=None, TropicalCyclone=None): # Compute ensemble member def compute_ensemble(self, number_of_realizations=None): + # First set time variables based on best track if self.debug == 1: print("Started with making ensembles") self.number_of_realizations = number_of_realizations @@ -1679,6 +1868,7 @@ def compute_ensemble(self, number_of_realizations=None): dy = dy / 110540 ensemble_lon[it,:] = best_track_lon2[it] + dx ensemble_lat[it,:] = best_track_lat2[it] + dy + elif self.position_method == 1: # Compute new position based on best track position and ate/cte lon0 = best_track_lon2[items0] diff --git a/tests/TRK_COAMPS_CTCX_3_2017092006_15L b/tests/TRK_COAMPS_CTCX_3_2017092006_15L new file mode 100644 index 0000000..4ac93af --- /dev/null +++ b/tests/TRK_COAMPS_CTCX_3_2017092006_15L @@ -0,0 +1,66 @@ +AL, 15, 2017092006, 03, CTCX, 000, 175N, 651W, 135, 914, XX, 34, NEQ, 0142, 0134, 0111, 0141, 0, 0, 018 +AL, 15, 2017092006, 03, CTCX, 000, 175N, 651W, 135, 914, XX, 50, NEQ, 0097, 0081, 0064, 0093, 0, 0, 018 +AL, 15, 2017092006, 03, CTCX, 000, 175N, 651W, 135, 914, XX, 64, NEQ, 0063, 0053, 0045, 0061, 0, 0, 018 +AL, 15, 2017092006, 03, CTCX, 006, 180N, 660W, 115, 935, XX, 34, NEQ, 0167, 0201, 0103, 0124, 0, 0, 022 +AL, 15, 2017092006, 03, CTCX, 006, 180N, 660W, 115, 935, XX, 50, NEQ, 0115, 0073, 0059, 0084, 0, 0, 022 +AL, 15, 2017092006, 03, CTCX, 006, 180N, 660W, 115, 935, XX, 64, NEQ, 0055, 0046, 0041, 0058, 0, 0, 022 +AL, 15, 2017092006, 03, CTCX, 012, 186N, 667W, 107, 949, XX, 34, NEQ, 0147, 0135, 0108, 0127, 0, 0, 025 +AL, 15, 2017092006, 03, CTCX, 012, 186N, 667W, 107, 949, XX, 50, NEQ, 0093, 0069, 0068, 0082, 0, 0, 025 +AL, 15, 2017092006, 03, CTCX, 012, 186N, 667W, 107, 949, XX, 64, NEQ, 0068, 0042, 0044, 0066, 0, 0, 025 +AL, 15, 2017092006, 03, CTCX, 018, 192N, 675W, 115, 951, XX, 34, NEQ, 0155, 0141, 0104, 0141, 0, 0, 023 +AL, 15, 2017092006, 03, CTCX, 018, 192N, 675W, 115, 951, XX, 50, NEQ, 0104, 0065, 0068, 0089, 0, 0, 023 +AL, 15, 2017092006, 03, CTCX, 018, 192N, 675W, 115, 951, XX, 64, NEQ, 0059, 0045, 0050, 0061, 0, 0, 023 +AL, 15, 2017092006, 03, CTCX, 024, 196N, 682W, 118, 951, XX, 34, NEQ, 0162, 0137, 0113, 0136, 0, 0, 020 +AL, 15, 2017092006, 03, CTCX, 024, 196N, 682W, 118, 951, XX, 50, NEQ, 0097, 0098, 0059, 0077, 0, 0, 020 +AL, 15, 2017092006, 03, CTCX, 024, 196N, 682W, 118, 951, XX, 64, NEQ, 0063, 0047, 0039, 0054, 0, 0, 020 +AL, 15, 2017092006, 03, CTCX, 030, 201N, 688W, 116, 951, XX, 34, NEQ, 0148, 0145, 0092, 0126, 0, 0, 019 +AL, 15, 2017092006, 03, CTCX, 030, 201N, 688W, 116, 951, XX, 50, NEQ, 0090, 0101, 0060, 0082, 0, 0, 019 +AL, 15, 2017092006, 03, CTCX, 030, 201N, 688W, 116, 951, XX, 64, NEQ, 0058, 0052, 0044, 0052, 0, 0, 019 +AL, 15, 2017092006, 03, CTCX, 036, 206N, 693W, 117, 949, XX, 34, NEQ, 0153, 0153, 0109, 0188, 0, 0, 025 +AL, 15, 2017092006, 03, CTCX, 036, 206N, 693W, 117, 949, XX, 50, NEQ, 0095, 0086, 0061, 0080, 0, 0, 025 +AL, 15, 2017092006, 03, CTCX, 036, 206N, 693W, 117, 949, XX, 64, NEQ, 0071, 0068, 0041, 0065, 0, 0, 025 +AL, 15, 2017092006, 03, CTCX, 042, 212N, 696W, 113, 951, XX, 34, NEQ, 0162, 0195, 0104, 0127, 0, 0, 026 +AL, 15, 2017092006, 03, CTCX, 042, 212N, 696W, 113, 951, XX, 50, NEQ, 0119, 0088, 0068, 0082, 0, 0, 026 +AL, 15, 2017092006, 03, CTCX, 042, 212N, 696W, 113, 951, XX, 64, NEQ, 0071, 0074, 0038, 0066, 0, 0, 026 +AL, 15, 2017092006, 03, CTCX, 048, 217N, 700W, 117, 953, XX, 34, NEQ, 0166, 0160, 0095, 0138, 0, 0, 018 +AL, 15, 2017092006, 03, CTCX, 048, 217N, 700W, 117, 953, XX, 50, NEQ, 0106, 0108, 0063, 0098, 0, 0, 018 +AL, 15, 2017092006, 03, CTCX, 048, 217N, 700W, 117, 953, XX, 64, NEQ, 0080, 0055, 0046, 0058, 0, 0, 018 +AL, 15, 2017092006, 03, CTCX, 054, 225N, 704W, 108, 954, XX, 34, NEQ, 0167, 0171, 0150, 0143, 0, 0, 018 +AL, 15, 2017092006, 03, CTCX, 054, 225N, 704W, 108, 954, XX, 50, NEQ, 0116, 0116, 0068, 0076, 0, 0, 018 +AL, 15, 2017092006, 03, CTCX, 054, 225N, 704W, 108, 954, XX, 64, NEQ, 0085, 0050, 0053, 0062, 0, 0, 018 +AL, 15, 2017092006, 03, CTCX, 060, 233N, 707W, 104, 957, XX, 34, NEQ, 0165, 0175, 0137, 0140, 0, 0, 023 +AL, 15, 2017092006, 03, CTCX, 060, 233N, 707W, 104, 957, XX, 50, NEQ, 0117, 0126, 0080, 0091, 0, 0, 023 +AL, 15, 2017092006, 03, CTCX, 060, 233N, 707W, 104, 957, XX, 64, NEQ, 0060, 0057, 0042, 0058, 0, 0, 023 +AL, 15, 2017092006, 03, CTCX, 066, 239N, 709W, 92, 958, XX, 34, NEQ, 0177, 0194, 0136, 0147, 0, 0, 025 +AL, 15, 2017092006, 03, CTCX, 066, 239N, 709W, 92, 958, XX, 50, NEQ, 0117, 0134, 0085, 0095, 0, 0, 025 +AL, 15, 2017092006, 03, CTCX, 066, 239N, 709W, 92, 958, XX, 64, NEQ, 0068, 0055, 0049, 0074, 0, 0, 025 +AL, 15, 2017092006, 03, CTCX, 072, 247N, 713W, 97, 960, XX, 34, NEQ, 0175, 0223, 0167, 0157, 0, 0, 030 +AL, 15, 2017092006, 03, CTCX, 072, 247N, 713W, 97, 960, XX, 50, NEQ, 0111, 0102, 0090, 0120, 0, 0, 030 +AL, 15, 2017092006, 03, CTCX, 072, 247N, 713W, 97, 960, XX, 64, NEQ, 0074, 0065, 0029, 0054, 0, 0, 030 +AL, 15, 2017092006, 03, CTCX, 078, 254N, 717W, 91, 961, XX, 34, NEQ, 0197, 0183, 0161, 0151, 0, 0, 028 +AL, 15, 2017092006, 03, CTCX, 078, 254N, 717W, 91, 961, XX, 50, NEQ, 0150, 0128, 0070, 0105, 0, 0, 028 +AL, 15, 2017092006, 03, CTCX, 078, 254N, 717W, 91, 961, XX, 64, NEQ, 0073, 0046, 0041, 0051, 0, 0, 028 +AL, 15, 2017092006, 03, CTCX, 084, 261N, 719W, 77, 960, XX, 34, NEQ, 0203, 0193, 0167, 0160, 0, 0, 021 +AL, 15, 2017092006, 03, CTCX, 084, 261N, 719W, 77, 960, XX, 50, NEQ, 0128, 0143, 0074, 0102, 0, 0, 021 +AL, 15, 2017092006, 03, CTCX, 084, 261N, 719W, 77, 960, XX, 64, NEQ, 0061, 0112, 0042, 0052, 0, 0, 021 +AL, 15, 2017092006, 03, CTCX, 090, 268N, 718W, 79, 959, XX, 34, NEQ, 0199, 0193, 0175, 0198, 0, 0, 032 +AL, 15, 2017092006, 03, CTCX, 090, 268N, 718W, 79, 959, XX, 50, NEQ, 0135, 0138, 0081, 0115, 0, 0, 032 +AL, 15, 2017092006, 03, CTCX, 090, 268N, 718W, 79, 959, XX, 64, NEQ, 0112, 0052, 0045, 0052, 0, 0, 032 +AL, 15, 2017092006, 03, CTCX, 096, 277N, 717W, 79, 961, XX, 34, NEQ, 0198, 0220, 0156, 0154, 0, 0, 021 +AL, 15, 2017092006, 03, CTCX, 096, 277N, 717W, 79, 961, XX, 50, NEQ, 0124, 0127, 0080, 0101, 0, 0, 021 +AL, 15, 2017092006, 03, CTCX, 096, 277N, 717W, 79, 961, XX, 64, NEQ, 0066, 0063, 0053, 0054, 0, 0, 021 +AL, 15, 2017092006, 03, CTCX, 102, 285N, 715W, 82, 963, XX, 34, NEQ, 0204, 0205, 0169, 0154, 0, 0, 022 +AL, 15, 2017092006, 03, CTCX, 102, 285N, 715W, 82, 963, XX, 50, NEQ, 0138, 0133, 0094, 0105, 0, 0, 022 +AL, 15, 2017092006, 03, CTCX, 102, 285N, 715W, 82, 963, XX, 64, NEQ, 0058, 0069, 0024, 0033, 0, 0, 022 +AL, 15, 2017092006, 03, CTCX, 108, 294N, 713W, 76, 963, XX, 34, NEQ, 0202, 0216, 0165, 0165, 0, 0, 026 +AL, 15, 2017092006, 03, CTCX, 108, 294N, 713W, 76, 963, XX, 50, NEQ, 0142, 0161, 0092, 0110, 0, 0, 026 +AL, 15, 2017092006, 03, CTCX, 108, 294N, 713W, 76, 963, XX, 64, NEQ, 0129, 0063, 0000, 0039, 0, 0, 026 +AL, 15, 2017092006, 03, CTCX, 114, 302N, 710W, 71, 966, XX, 34, NEQ, 0210, 0221, 0163, 0166, 0, 0, 042 +AL, 15, 2017092006, 03, CTCX, 114, 302N, 710W, 71, 966, XX, 50, NEQ, 0143, 0147, 0082, 0112, 0, 0, 042 +AL, 15, 2017092006, 03, CTCX, 114, 302N, 710W, 71, 966, XX, 64, NEQ, 0099, 0049, 0049, 0062, 0, 0, 042 +AL, 15, 2017092006, 03, CTCX, 120, 311N, 707W, 72, 967, XX, 34, NEQ, 0196, 0224, 0163, 0159, 0, 0, 032 +AL, 15, 2017092006, 03, CTCX, 120, 311N, 707W, 72, 967, XX, 50, NEQ, 0126, 0128, 0105, 0091, 0, 0, 032 +AL, 15, 2017092006, 03, CTCX, 120, 311N, 707W, 72, 967, XX, 64, NEQ, 0069, 0043, 0000, 0046, 0, 0, 032 +AL, 15, 2017092006, 03, CTCX, 126, 317N, 703W, 76, 969, XX, 34, NEQ, 0201, 0207, 0184, 0165, 0, 0, 030 +AL, 15, 2017092006, 03, CTCX, 126, 317N, 703W, 76, 969, XX, 50, NEQ, 0143, 0119, 0092, 0111, 0, 0, 030 +AL, 15, 2017092006, 03, CTCX, 126, 317N, 703W, 76, 969, XX, 64, NEQ, 0082, 0089, 0000, 0000, 0, 0, 030 diff --git a/tests/best_track_idai.cyc b/tests/best_track_idai.cyc deleted file mode 100644 index 82542d0..0000000 --- a/tests/best_track_idai.cyc +++ /dev/null @@ -1,62 +0,0 @@ -# Tropical Cyclone Toolbox - DelftDashBoard v2.03.17753 - 2022-08-04 13:59:54 -Name "IDAI" -WindProfile holland2010 -WindPressureRelation holland2008 -RMaxRelation nederhoff2019 -Backgroundpressure 1012 -PhiSpiral 20 -WindConversionFactor 0.93 -SpiderwebRadius 1000 -NrRadialBins 500 -NrDirectionalBins 36 -# -# Date Time Lat Lon Vmax (kts) Pc (hPa) Rmax (NM) R35(NE) R35(SE) R35(SW) R35(NW) R50(NE) R50(SE) R50(SW) R50(NW) R65(NE) R65(SE) R65(SW) R65(NW) R100(NE) R100(SE) R100(SW) R100(NE) -# -20190305 000000 -17.100 37.500 25.0 1004.0 40.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -20190305 060000 -17.000 37.400 25.0 1004.0 40.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -20190305 120000 -16.800 37.200 30.0 1002.0 40.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -20190305 180000 -16.400 37.000 30.0 1002.0 40.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -20190306 000000 -15.900 36.900 30.0 1003.0 40.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -20190306 060000 -15.500 36.800 30.0 1004.0 40.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -20190306 120000 -15.100 36.700 30.0 1004.0 40.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -20190306 180000 -14.900 36.600 25.0 1007.0 40.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -20190307 000000 -15.000 36.200 20.0 1008.0 40.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -20190307 060000 -15.000 35.800 25.0 1006.0 50.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -20190307 120000 -15.100 35.400 20.0 1006.0 50.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -20190307 180000 -15.100 35.000 20.0 1007.0 50.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -20190308 000000 -15.500 35.000 20.0 1007.0 50.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -20190308 060000 -15.700 35.800 20.0 1007.0 50.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -20190308 120000 -15.900 36.900 20.0 1007.0 50.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -20190308 180000 -16.200 38.000 25.0 1005.0 50.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -20190309 000000 -16.600 39.100 30.0 1004.0 50.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -20190309 060000 -17.000 40.200 30.0 1005.0 30.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -20190309 120000 -17.000 41.300 35.0 1004.0 35.0 70.0 70.0 55.0 55.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -20190309 180000 -17.000 41.900 40.0 1002.0 35.0 80.0 100.0 70.0 70.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -20190310 000000 -17.200 42.400 40.0 1002.0 40.0 95.0 75.0 45.0 65.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -20190310 060000 -17.200 42.600 50.0 996.0 20.0 90.0 80.0 70.0 90.0 20.0 25.0 30.0 30.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -20190310 120000 -17.200 43.000 60.0 990.0 20.0 90.0 80.0 70.0 90.0 20.0 25.0 30.0 30.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -20190310 180000 -17.200 43.200 75.0 980.0 5.0 80.0 75.0 80.0 80.0 40.0 45.0 40.0 35.0 20.0 20.0 20.0 25.0 -999.0 -999.0 -999.0 -999.0 -20190311 000000 -17.300 43.100 95.0 965.0 5.0 85.0 85.0 85.0 90.0 50.0 55.0 45.0 50.0 20.0 20.0 20.0 20.0 -999.0 -999.0 -999.0 -999.0 -20190311 030000 -17.300 43.000 115.0 947.0 5.0 85.0 85.0 85.0 90.0 50.0 55.0 45.0 50.0 20.0 20.0 20.0 20.0 -999.0 -999.0 -999.0 -999.0 -20190311 060000 -17.400 43.000 110.0 950.0 12.0 110.0 100.0 100.0 110.0 60.0 50.0 45.0 60.0 35.0 30.0 30.0 35.0 -999.0 -999.0 -999.0 -999.0 -20190311 120000 -17.500 42.800 110.0 951.0 12.0 115.0 105.0 110.0 125.0 55.0 50.0 50.0 55.0 30.0 30.0 30.0 30.0 -999.0 -999.0 -999.0 -999.0 -20190311 180000 -17.700 42.400 105.0 956.0 12.0 110.0 100.0 105.0 120.0 65.0 65.0 65.0 60.0 30.0 30.0 30.0 25.0 -999.0 -999.0 -999.0 -999.0 -20190312 000000 -18.000 42.100 100.0 959.0 12.0 115.0 110.0 115.0 115.0 60.0 65.0 60.0 55.0 30.0 35.0 30.0 30.0 -999.0 -999.0 -999.0 -999.0 -20190312 060000 -18.300 41.700 90.0 968.0 12.0 110.0 120.0 115.0 115.0 50.0 55.0 40.0 30.0 35.0 30.0 30.0 25.0 -999.0 -999.0 -999.0 -999.0 -20190312 120000 -18.700 41.300 90.0 968.0 12.0 115.0 125.0 120.0 120.0 55.0 60.0 60.0 50.0 30.0 30.0 30.0 25.0 -999.0 -999.0 -999.0 -999.0 -20190312 180000 -19.000 40.800 95.0 964.0 12.0 100.0 110.0 100.0 115.0 60.0 60.0 55.0 45.0 35.0 35.0 30.0 30.0 -999.0 -999.0 -999.0 -999.0 -20190313 000000 -19.200 40.100 95.0 966.0 15.0 105.0 110.0 105.0 120.0 65.0 55.0 55.0 55.0 35.0 35.0 25.0 35.0 -999.0 -999.0 -999.0 -999.0 -20190313 060000 -19.300 39.500 95.0 966.0 15.0 130.0 145.0 145.0 115.0 70.0 80.0 70.0 60.0 45.0 55.0 55.0 45.0 -999.0 -999.0 -999.0 -999.0 -20190313 120000 -19.400 39.000 105.0 960.0 15.0 85.0 100.0 85.0 80.0 40.0 50.0 50.0 35.0 30.0 35.0 35.0 30.0 -999.0 -999.0 -999.0 -999.0 -20190313 180000 -19.500 38.500 115.0 948.0 22.0 130.0 150.0 135.0 115.0 80.0 80.0 75.0 65.0 40.0 40.0 40.0 45.0 -999.0 -999.0 -999.0 -999.0 -20190314 000000 -19.700 37.900 110.0 953.0 20.0 115.0 125.0 135.0 115.0 60.0 65.0 75.0 60.0 30.0 35.0 40.0 30.0 -999.0 -999.0 -999.0 -999.0 -20190314 060000 -19.800 37.200 105.0 958.0 27.0 110.0 120.0 120.0 115.0 70.0 70.0 60.0 60.0 40.0 40.0 40.0 45.0 -999.0 -999.0 -999.0 -999.0 -20190314 120000 -19.900 36.400 95.0 967.0 27.0 125.0 145.0 135.0 115.0 65.0 80.0 75.0 60.0 35.0 40.0 40.0 30.0 -999.0 -999.0 -999.0 -999.0 -20190314 180000 -19.800 35.600 90.0 968.0 20.0 85.0 95.0 100.0 85.0 60.0 55.0 60.0 40.0 30.0 35.0 40.0 25.0 -999.0 -999.0 -999.0 -999.0 -20190314 210000 -19.800 35.200 100.0 964.0 20.0 85.0 95.0 100.0 85.0 60.0 55.0 60.0 40.0 30.0 35.0 40.0 25.0 -999.0 -999.0 -999.0 -999.0 -20190315 000000 -19.700 34.800 100.0 965.0 20.0 85.0 95.0 100.0 85.0 40.0 55.0 60.0 45.0 15.0 20.0 20.0 15.0 -999.0 -999.0 -999.0 -999.0 -20190315 060000 -19.500 34.100 85.0 977.0 20.0 80.0 90.0 85.0 70.0 40.0 50.0 45.0 30.0 10.0 10.0 10.0 10.0 -999.0 -999.0 -999.0 -999.0 -20190315 120000 -19.300 33.400 70.0 987.0 20.0 100.0 115.0 85.0 85.0 50.0 60.0 40.0 40.0 25.0 30.0 20.0 20.0 -999.0 -999.0 -999.0 -999.0 -20190315 180000 -19.100 32.900 55.0 995.0 20.0 40.0 75.0 55.0 55.0 -999.0 20.0 20.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -20190316 000000 -19.000 32.100 40.0 1000.0 30.0 40.0 40.0 45.0 40.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -20190316 060000 -18.700 31.500 30.0 1010.0 30.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 -999.0 diff --git a/tests/test_reading_TRK_forecasted.py b/tests/test_reading_TRK_forecasted.py new file mode 100644 index 0000000..57af006 --- /dev/null +++ b/tests/test_reading_TRK_forecasted.py @@ -0,0 +1,45 @@ +# Load modules +from cht_cyclones.tropical_cyclone import TropicalCyclone +from cht_cyclones.tropical_cyclone import TropicalCycloneEnsemble +import os + +# Define a track +tc = TropicalCyclone(name="Maria_forecast") + +# Read a track +current_directory = os.path.dirname(os.path.abspath(__file__)) +file_path = os.path.join(current_directory, 'TRK_COAMPS_CTCX_3_2017092006_15L') +tc.read_track(file_path,'trk') + +# Define settings +# Uses typical Wind Enhance Scheme (WES) formulations +tc.include_rainfall = True # using empirical formulation to compute rainfall (IPET default) +tc.rainfall_factor = 2.0 # factor to calibrate rainfall 2.0 means 2x as much as relationship + +# Write as cyc +tc.convert_units_metric_imperial() +file_path = os.path.join(current_directory, 'forecasted_track_Maria.cyc') +tc.write_track(file_path, 'ddb_cyc') + +# create (regular) ASCII spiderweb +file_path = os.path.join(current_directory, 'forecasted_track_Maria.spw') +tc.to_spiderweb(file_path) + +# create (netcdf) spiderweb +file_path = os.path.join(current_directory, 'forecasted_track_Maria.nc') +tc.to_spiderweb(file_path, format_type='netcdf') + +# Write out as shapefile +file_path = os.path.join(current_directory, 'forecasted_track_Maria.shp') +tc.track.to_file(file_path) + +# Write out as geojson +file_path = os.path.join(current_directory, 'forecasted_track_Maria.json') +tc.track.to_file(file_path, driver="GeoJSON") + +# TC-FF ensemble members +tc2 = TropicalCycloneEnsemble(name="Maria_forecast_ensembles", TropicalCyclone=tc) +tc2.dt = 3 # 3 hourly +tc2.include_best_track = 0 # not included best-track +tc2.compute_ensemble(100) +tc2.to_shapefile(current_directory) \ No newline at end of file