Пример #1
0
 def test_write_climate_point1_overwrite(self):
     """ Test case where there is a single data file the station, the entry is overwritten """
     station = ClimatePointStation()
     station.type = "GHCN"
     station.id = "US1MDBL0027"
     station.longitude = -76.716
     station.latitude = 39.317
     station.elevation = 128.0
     station.name = "My station name"
     station.data = "clim.txt"
     station.startDate = datetime.strptime("201007", "%Y%m")
     station.endDate = datetime.strptime("201110", "%Y%m")
     station.variables = [ClimatePointStation.VAR_PRECIP, \
                          ClimatePointStation.VAR_SNOW]
     station.writeToMetadata(self.context)
     
     climatePointStation = GenericMetadata.readClimatePointStations(self.context)[0]  
     self.assertTrue(station.type.lower() == climatePointStation.type)
     self.assertTrue(station.id.lower() == climatePointStation.id)
     self.assertTrue(station.longitude == climatePointStation.longitude)
     self.assertTrue(station.latitude == climatePointStation.latitude)
     self.assertTrue(station.elevation == climatePointStation.elevation)
     self.assertTrue(station.name == climatePointStation.name)
     self.assertTrue(station.data == climatePointStation.data)
     self.assertTrue(station.startDate == climatePointStation.startDate)
     self.assertTrue(station.endDate == climatePointStation.endDate)
     self.assertTrue(station.variables == climatePointStation.variables)
     
     station.longitude = -76.716
     station.latitude = 39.317
     station.elevation = 128.0
     station.name = "My (longer) station name"
     station.data = "clim.dat"
     station.startDate = datetime.strptime("201006", "%Y%m")
     station.endDate = datetime.strptime("201310", "%Y%m")
     station.variables = [ClimatePointStation.VAR_PRECIP, \
                          ClimatePointStation.VAR_SNOW]
     station.writeToMetadata(self.context)
     
     climatePointStation = GenericMetadata.readClimatePointStations(self.context)[0]  
     self.assertTrue(station.type.lower() == climatePointStation.type)
     self.assertTrue(station.id.lower() == climatePointStation.id)
     self.assertTrue(station.longitude == climatePointStation.longitude)
     self.assertTrue(station.latitude == climatePointStation.latitude)
     self.assertTrue(station.elevation == climatePointStation.elevation)
     self.assertTrue(station.name == climatePointStation.name)
     self.assertTrue(station.data == climatePointStation.data)
     self.assertTrue(station.startDate == climatePointStation.startDate)
     self.assertTrue(station.endDate == climatePointStation.endDate)
     self.assertTrue(station.variables == climatePointStation.variables)
Пример #2
0
bbox = bboxFromString(studyArea['bbox_wgs84'])

# Find all GHCN stations within bounding box
stations = findStationsWithinBoundingBox(context.config, bbox)
print("Found %d stations in bounding box, downloading data..." %
      (len(stations)))
# Get data for each station
for station in stations:
    outFile = os.path.join(outDir, station[0])
    returnCode = getClimateDataForStation(context.config, context.projectDir,
                                          outFile, station[0])
    assert (returnCode)

    # Write metadata
    newStation = ClimatePointStation()
    newStation.type = "GHCN"
    newStation.id = station[0]
    newStation.longitude = station[1]
    newStation.latitude = station[2]
    newStation.elevation = station[3]
    newStation.name = station[4]
    newStation.data = outFile
    #newStation.startDate = datetime.strptime("200001", "%Y%m")
    #newStation.endDate = datetime.strptime("200101", "%Y%m")
    #newStation.variables = [ClimatePointStation.VAR_TMIN, \
    #                    ClimatePointStation.VAR_TMAX]
    newStation.writeToMetadata(context)

# Write processing history
GenericMetadata.appendProcessingHistoryItem(context, cmdline)
# Get study area parameters
studyArea = GenericMetadata.readStudyAreaEntries(context)
bbox = bboxFromString(studyArea["bbox_wgs84"])

# Get centroid of bounding box
(longitude, latitude) = calculateBoundingBoxCenter(bbox)
# Find nearest GHCN station
nearest = findStationNearestToCoordinates(context.config, longitude, latitude)
# Get data for station
outFile = os.path.join(outDir, nearest[0])
returnCode = getClimateDataForStation(context.config, context.projectDir, outFile, nearest[0])
assert returnCode

# Write metadata
station = ClimatePointStation()
station.type = "GHCN"
station.id = nearest[0]
station.longitude = nearest[1]
station.latitude = nearest[2]
station.elevation = nearest[3]
station.name = nearest[4]
station.data = outFile
# station.startDate = datetime.strptime("200001", "%Y%m")
# station.endDate = datetime.strptime("200101", "%Y%m")
# station.variables = [ClimatePointStation.VAR_TMIN, \
#                    ClimatePointStation.VAR_TMAX]
station.writeToMetadata(context)

# Write processing history
GenericMetadata.appendProcessingHistoryItem(context, cmdline)
# Get study area parameters
studyArea = GenericMetadata.readStudyAreaEntries(context)
bbox = bboxFromString(studyArea['bbox_wgs84'])

# Find all GHCN stations within bounding box
stations = findStationsWithinBoundingBox(context.config, bbox)
print "Found %d stations in bounding box, downloading data..." % (len(stations))
# Get data for each station
for station in stations:
    outFile = os.path.join(outDir, station[0])
    returnCode = getClimateDataForStation(context.config, context.projectDir, outFile, station[0])
    assert(returnCode)
    
    # Write metadata
    newStation = ClimatePointStation()
    newStation.type = "GHCN"
    newStation.id = station[0]
    newStation.longitude = station[1]
    newStation.latitude = station[2]
    newStation.elevation = station[3]
    newStation.name = station[4]
    newStation.data = outFile
    #newStation.startDate = datetime.strptime("200001", "%Y%m")
    #newStation.endDate = datetime.strptime("200101", "%Y%m")
    #newStation.variables = [ClimatePointStation.VAR_TMIN, \
    #                    ClimatePointStation.VAR_TMAX]
    newStation.writeToMetadata(context)
    
# Write processing history
GenericMetadata.appendProcessingHistoryItem(context, cmdline)
# Get study area parameters
studyArea = GenericMetadata.readStudyAreaEntries(context)
bbox = bboxFromString(studyArea['bbox_wgs84'])

# Get centroid of bounding box
(longitude, latitude) = calculateBoundingBoxCenter(bbox)
# Find nearest GHCN station
nearest = findStationNearestToCoordinates(context.config, longitude, latitude)
# Get data for station
outFile = os.path.join(outDir, nearest[0])
returnCode = getClimateDataForStation(context.config, context.projectDir,
                                      outFile, nearest[0])
assert (returnCode)

# Write metadata
station = ClimatePointStation()
station.type = "GHCN"
station.id = nearest[0]
station.longitude = nearest[1]
station.latitude = nearest[2]
station.elevation = nearest[3]
station.name = nearest[4]
station.data = outFile
#station.startDate = datetime.strptime("200001", "%Y%m")
#station.endDate = datetime.strptime("200101", "%Y%m")
#station.variables = [ClimatePointStation.VAR_TMIN, \
#                    ClimatePointStation.VAR_TMAX]
station.writeToMetadata(context)

# Write processing history
GenericMetadata.appendProcessingHistoryItem(context, cmdline)