77777777

区别,宏函数占用了大量的空间,而函数占用了时间。函数调用是要使用系统的栈来保存数据的,如果编译器里有栈检查选项,一般在函数的头会嵌入一些汇编语句对当前栈进行检查;同时,CPU也要在函数调用时保存和恢复当前的现场,进行压栈和弹栈操作,所以,函数调用需要一些CPU时间。而宏函数不存在这个问题。宏函数仅仅作为预先写好的代码嵌入到当前程序,不会产生函数调用,所以仅仅是占用了空间,在频繁调用同一个宏函数的时候,该现象尤其突出。

--- 0x420133f2: omac1_aes_128 at E:/espidf/v5.4.1/esp-idf/components/wpa_supplicant/esp_supplicant/src/crypto/crypto_mbedtls.c:920 --- 0x420135d6: ccmp_decrypt at E:/espidf/v5.4.1/esp-idf/components/wpa_supplicant/src/crypto/ccmp.c:141 --- 0x42013684: ccmp_encrypt at E:/espidf/v5.4.1/esp-idf/components/wpa_supplicant/src/crypto/ccmp.c:193 --- 0x42012f3e: esp_aes_gmac at E:/espidf/v5.4.1/esp-idf/components/wpa_supplicant/src/crypto/crypto_ops.c:24 --- 0x42013060: sha256_vector at E:/espidf/v5.4.1/esp-idf/components/wpa_supplicant/esp_supplicant/src/crypto/crypto_mbedtls.c:89 3fc9e3c0: 0x0000000a 0x00000020 0x00000001 0x00000000 0x00000020 0x00000000 0x00000005 0x00000000 3fc9e3e0: 0x00000000 0x00000001 0x00000001 0x00000000 0x00000001 0x00000000 0x00000006 0x00000000 3fc9e400: 0x000002f0 0x00000020 0x000000a1 0x00000000 0x00001801 0x00000007 0x00000001 0x40380c00 --- 0x40380c00: esp_ptr_in_rtc_dram_fast at E:/espidf/v5.4.1/esp-idf/components/esp_hw_support/include/esp_memory_utils.h:121 --- (inlined by) dram_alloc_to_iram_addr at E:/espidf/v5.4.1/esp-idf/components/heap/heap_caps_base.c:41 --- (inlined by) heap_caps_aligned_alloc_base at E:/espidf/v5.4.1/esp-idf/components/heap/heap_caps_base.c:150 3fc9e420: 0x1f2f3f4f 0x00001800 0x77770006 0x77777777 0x6c6c756e 0x69666977 0x00000000 0x00000000 3fc9e440: 0x00000000 0x00000000 0x00000000 0x00000000 0x00000008 0x38000000 0x38383838 0x00383838 3fc9e460: 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 3fc9e480: 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x38383838 0x38383838 3fc9e4a0: 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 3fc9e4c0: 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000005 0x3c0d8554 3fc9e4e0: 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x3c0c4000 0x420b35a8 --- 0x420b35a8: main_task at E:/espidf/v5.4.1/esp-idf/components/freertos/app_startup.c:209 3fc9e500: 0x00000000 0x00001388 0x00000001 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 3fc9e520: 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0xa5a5a5a5 0xa5a5a5a5 0xa5a5a5a5 3fc9e540: 0xa5a5a5a5 0xa5a5a5a5 0xa5a5a5a5 0xa5a5a5a5 0x00000150 0x3fc9dd80 0x00000002 0x3fc957c4 3fc9e560: 0x3fc957c4 0x3fc9e554 0x3fc957bc 0x00000018 0x3fca4640 0x3fca4640 0x3fc9e554 0x00000000 3fc9e580: 0x00000001 0x3fc9d550 0x6e69616d 0x00000000 0x00000000 0x00000000 0x3fc9e540 0x00000001 3fc9e5a0: 0x00000000 0x3fca2a90 0x42004e7c 0x00000000 0x3fc9be80 0x3fc9bee8 0x3fc9bf50 0x00000000 --- 0x42004e7c: pthread_cleanup_thread_specific_data_callback at E:/espidf/v5.4.1/esp-idf/components/pthread/pthread_local_storage.c:126 3fc9e5c0: 0x00000000 0x00000001 0x00000000 0x00000000 0x00000000 0x42004706 0x00000000 0x00000000 --- 0x42004706: esp_cleanup_r at E:/espidf/v5.4.1/esp-idf/components/newlib/newlib_init.c:43 ELF file SHA256: 04a1caf88 Rebooting... ESP-ROM:esp32c3-api1-20210207 Build:Feb 7 2021 rst:0xc (RTC_SW_CPU_RST),boot:0xd (SPI_FAST_FLASH_BOOT) Saved PC:0x403807f4 --- 0x403807f4: esp_restart_noos at E:/espidf/v5.4.1/esp-idf/components/esp_system/port/soc/esp32c3/system_internal.c:112 SPIWP:0xee mode:DIO, clock div:1 load:0x3fcd5820,len:0x1574 load:0x403cc710,len:0xc30 load:0x403ce710,len:0x2f64 entry 0x403cc71a I (24) boot: ESP-IDF v5.4.1 2nd stage bootloader I (24) boot: compile time Jun 27 2025 16:28:05 I (24) boot: chip revision: v0.4 I (25) boot: efuse block revision: v1.3 I (27) boot.esp32c3: SPI Speed : 80MHz I (31) boot.esp32c3: SPI Mode : DIO I (35) boot.esp32c3: SPI Flash Size : 2MB I (39) boot: Enabling RNG early entropy source... I (43) boot: Partition Table: I (46) boot: ## Label Usage Type ST Offset Length I (52) boot: 0 nvs WiFi data 01 02 00009000 00006000 I (59) boot: 1 phy_init RF data 01 01 0000f000 00001000 I (65) boot: 2 factory factory app 00 00 00010000 00100000 I (72) boot: End of partition table I (75) esp_image: segment 0: paddr=00010020 vaddr=3c0c0020 size=22a38h (141880) map I (105) esp_image: segment 1: paddr=00032a60 vaddr=3fc92800 size=02df8h ( 11768) load I (108) esp_image: segment 2: paddr=00035860 vaddr=40380000 size=0a7b8h ( 42936) load I (117) esp_image: segment 3: paddr=00040020 vaddr=42000020 size=b4088h (737416) map I (235) esp_image: segment 4: paddr=000f40b0 vaddr=4038a7b8 size=07f0ch ( 32524) load I (241) esp_image: segment 5: paddr=000fbfc4 vaddr=50000200 size=0001ch ( 28) load I (248) boot: Loaded app from partition at offset 0x10000 I (248) boot: Disabling RNG early entropy source... I (260) cpu_start: Unicore app I (268) cpu_start: Pro cpu start user code I (268) cpu_start: cpu freq: 160000000 Hz I (269) app_init: Application information: I (269) app_init: Project name: internal_communication I (274) app_init: App version: 1 I (277) app_init: Compile time: Jun 27 2025 16:27:06 I (282) app_init: ELF file SHA256: 04a1caf88... I (286) app_init: ESP-IDF: v5.4.1 I (290) efuse_init: Min chip rev: v0.3 I (294) efuse_init: Max chip rev: v1.99 I (298) efuse_init: Chip rev: v0.4 I (302) heap_init: Initializing. RAM available for dynamic allocation: I (308) heap_init: At 3FC9B840 len 000247C0 (145 KiB): RAM I (313) heap_init: At 3FCC0000 len 0001C710 (113 KiB): Retention RAM I (319) heap_init: At 3FCDC710 len 00002950 (10 KiB): Retention RAM I (325) heap_init: At 5000021C len 00001DCC (7 KiB): RTCRAM I (331) spi_flash: detected chip: generic I (334) spi_flash: flash io: dio W (337) spi_flash: Detected size(8192k) larger than the size in the binary image header(2048k). Using the size in the binary image header. I (350) sleep_gpio: Configure to isolate all GPIO pins in sleep state I (356) sleep_gpio: Enable automatic switching of GPIO sleep configuration I (362) main_task: Started on CPU0 I (362) main_task: Calling app_main() I (372) pp: pp rom version: 9387209 I (372) net80211: net80211 rom version: 9387209 I (382) wifi:wifi driver task: 3fca44c0, prio:23, stack:6656, core=0 I (382) wifi:wifi firmware version: 79fa3f41ba I (382) wifi:wifi certification version: v7.0 I (382) wifi:config NVS flash: enabled I (392) wifi:config nano formatting: disabled I (392) wifi:Init data frame dynamic rx buffer num: 32 I (402) wifi:Init static rx mgmt buffer num: 5 I (402) wifi:Init management short buffer num: 32 I (402) wifi:Init dynamic tx buffer num: 32 I (412) wifi:Init static tx FG buffer num: 2 I (412) wifi:Init static rx buffer size: 1600 I (422) wifi:Init static rx buffer num: 10 I (422) wifi:Init dynamic rx buffer num: 32 I (422) wifi_init: rx ba win: 6 I (432) wifi_init: accept mbox: 6 I (432) wifi_init: tcpip mbox: 32 I (432) wifi_init: udp mbox: 6 I (442) wifi_init: tcp mbox: 6 I (442) wifi_init: tcp tx win: 5760 I (442) wifi_init: tcp rx win: 5760 I (442) wifi_init: tcp mss: 1440 I (452) wifi_init: WiFi IRAM OP enabled I (452) wifi_init: WiFi RX IRAM OP enabled I (462) phy_init: phy_version 1200,2b7123f9,Feb 18 2025,15:22:21 I (492) phy_init: Saving new calibration data due to checksum failure or outdated calibration data, mode(0) I (522) wifi:mode : sta (34:cd:b0:97:58:bc) + softAP (34:cd:b0:97:58:bd) I (522) wifi:enable tsf I (522) wifi:Total power save buffer number: 16 I (522) wifi:Init max length of beacon: 752/752 I (522) wifi:Init max length of beacon: 752/752 I (532) mesh: <nvs>read layer:0, err:0x1102 I (532) mesh: <nvs>read assoc:0, err:0x1102 I (532) wifi:Set ps type: 1, coexist: 0 I (542) wifi:Total power save buffer number: 16 I (792) mesh: [IO]disable self-organizing<reconnect> I (792) mesh: [CONFIG]connect to router:nullwifi, 00:00:00:00:00:00 I (792) mesh_main: <MESH_EVENT_MESH_STARTED>ID:77:77:77:77:77:77 I (802) mesh_main: mesh starts successfully, heap:161708, root fixed<0>(tree), ps:1 assert failed: xTaskCreatePinnedToCore freertos_tasks_c_additions.h:163 (( ( ( ( BaseType_t ) xCoreID ) >= 0 && ( ( BaseType_t ) xCoreID ) < 1 ) ? ( ( BaseType_t ) 1 ) : ( ( BaseType_t ) 0 ) ) == ( ( Core 0 register dump: MEPC : 0x40380828 RA : 0x4038692c SP : 0x3fc9e1e0 GP : 0x3fc93000 --- 0x40380828: panic_abort at E:/espidf/v5.4.1/esp-idf/components/esp_system/panic.c:468 --- 0x4038692c: __ubsan_include at E:/espidf/v5.4.1/esp-idf/components/esp_system/ubsan.c:311 TP : 0x3fc9e540 T0 : 0x37363534 T1 : 0x7271706f T2 : 0x33323130 S0/FP : 0x0000007e S1 : 0x3fc9e3c7 A0 : 0x3fc9e238 A1 : 0x3c0c41f2 A2 : 0x0000007e A3 : 0x00000028 A4 : 0x00000001 A5 : 0x3fc9b000 A6 : 0x7a797877 A7 : 0x76757473 S2 : 0x00000000 S3 : 0x3fc9e230 S4 : 0x3fc9e238 S5 : 0x00000000 S6 : 0x00000003 S7 : 0x00000000 S8 : 0x00000000 S9 : 0x00000000 S10 : 0x00000000 S11 : 0x00000000 T3 : 0x6e6d6c6b T4 : 0x6a696867 T5 : 0x66656463 T6 : 0x62613938 MSTATUS : 0x00001881 MTVEC : 0x40380001 MCAUSE : 0x00000002 MTVAL : 0x00000000 --- 0x40380001: _vector_table at E:/espidf/v5.4.1/esp-idf/components/riscv/vectors_intc.S:54 MHARTID : 0x00000000 Stack memory: 3fc9e1e0: 0x00000000 0x00060000 0x3c0d726c 0x4038db14 0x00000000 0x00060000 0xc0380000 0x3c0c4174 --- 0x4038db14: newlib_include_assert_impl at E:/espidf/v5.4.1/esp-idf/components/newlib/assert.c:92 3fc9e200: 0x00333631 0x00000000 0x00000000 0x00000000 0x00000000 0x3fc947f0 0x3c0d726c 0x3fc94e2c 3fc9e220: 0x3c0c4258 0x3fc94800 0x3fc9e200 0x3fc94804 0x3c0c4174 0x3fc94a58 0x65737361 0x66207472 3fc9e240: 0x656c6961 0x78203a64 0x6b736154 0x61657243 0x69506574 0x64656e6e 0x6f436f54 0x66206572 3fc9e260: 0x72656572 0x5f736f74 0x6b736174 0x5f635f73 0x69646461 0x6e6f6974 0x3a682e73 0x20333631 3fc9e280: 0x28202828 0x28202820 0x73614220 0x70795465 0x20745f65 0x43782029 0x4965726f 0x20292044 3fc9e2a0: 0x30203d3e 0x20262620 0x20282028 0x65736142 0x65707954 0x2920745f 0x6f437820 0x44496572 3fc9e2c0: 0x3c202920 0x29203120 0x28203f20 0x42202820 0x54657361 0x5f657079 0x20292074 0x20292031 3fc9e2e0: 0x2028203a 0x61422028 0x79546573 0x745f6570 0x30202920 0x29202920 0x203d3d20 0x00282028 3fc9e300: 0x00000000 0x00000001 0x3c0c4a14 0x4200b2e0 0x00001000 0x3c0c5000 0x00000001 0x403893ee --- 0x4200b2e0: uart_event_task at D:/esp32_C3/internal_communication_client_0.1/main/uart.c:16 --- 0x403893ee: xTaskCreatePinnedToCore at E:/espidf/v5.4.1/esp-idf/components/freertos/esp_additions/freertos_tasks_c_additions.h:231 3fc9e320: 0x00000000 0x00000000 0x04c4b400 0x00000000 0x00000000 0x00000000 0x00000000 0x000277ac 3fc9e340: 0x00000003 0x3c0c5000 0x00000001 0x4200b510 0x0001c200 0x00000003 0x00000000 0x00000001 --- 0x4200b510: uart_init at D:/esp32_C3/internal_communication_client_0.1/main/uart.c:80 3fc9e360: 0x00000000 0x00000000 0x00000000 0x00000000 0x00000322 0x3c0c5560 0x3c0c553c 0x4200b2b0 --- 0x4200b2b0: app_main at D:/esp32_C3/internal_communication_client_0.1/main/mesh_main.c:349 3fc9e380: 0x3c0c5560 0x00000001 0xa5a5a5a5 0xa5a5a5a5 0x3fc92b38 0x0000002c 0x00000001 0x4201306e --- 0x4201306e: hmac_sha256_vector at E:/espidf/v5.4.1/esp-idf/components/wpa_supplicant/esp_supplicant/src/crypto/crypto_mbedtls.c:342 3fc9e3a0: 0x420132de 0x420131c2 0x42013224 0x420133f2 0x420135d6 0x42013684 0x42012f3e 0x42013060 --- 0x420132de: pbkdf2_sha1 at E:/espidf/v5.4.1/esp-idf/components/wpa_supplicant/esp_supplicant/src/crypto/crypto_mbedtls.c:752 --- 0x420131c2: aes_128_cbc_encrypt at E:/espidf/v5.4.1/esp-idf/components/wpa_supplicant/esp_supplicant/src/crypto/crypto_mbedtls.c:445 --- 0x42013224: aes_128_cbc_decrypt at E:/espidf/v5.4.1/esp-idf/components/wpa_supplicant/esp_supplicant/src/crypto/crypto_mbedtls.c:467 --- 0x420133f2: omac1_aes_128 at E:/espidf/v5.4.1/esp-idf/components/wpa_supplicant/esp_supplicant/src/crypto/crypto_mbedtls.c:920 --- 0x420135d6: ccmp_decrypt at E:/espidf/v5.4.1/esp-idf/components/wpa_supplicant/src/crypto/ccmp.c:141 --- 0x42013684: ccmp_encrypt at E:/espidf/v5.4.1/esp-idf/components/wpa_supplicant/src/crypto/ccmp.c:193 --- 0x42012f3e: esp_aes_gmac at E:/espidf/v5.4.1/esp-idf/components/wpa_supplicant/src/crypto/crypto_ops.c:24 --- 0x42013060: sha256_vector at E:/espidf/v5.4.1/esp-idf/components/wpa_supplicant/esp_supplicant/src/crypto/crypto_mbedtls.c:89 3fc9e3c0: 0x0000000a 0x00000020 0x00000001 0x00000000 0x00000020 0x00000000 0x00000005 0x00000000 3fc9e3e0: 0x00000000 0x00000001 0x00000001 0x00000000 0x00000001 0x00000000 0x00000006 0x00000000 3fc9e400: 0x000002f0 0x00000020 0x000000a1 0x00000000 0x00001801 0x00000007 0x00000001 0x40380c00 --- 0x40380c00: esp_ptr_in_rtc_dram_fast at E:/espidf/v5.4.1/esp-idf/components/esp_hw_support/include/esp_memory_utils.h:121 --- (inlined by) dram_alloc_to_iram_addr at E:/espidf/v5.4.1/esp-idf/components/heap/heap_caps_base.c:41 --- (inlined by) heap_caps_aligned_alloc_base at E:/espidf/v5.4.1/esp-idf/components/heap/heap_caps_base.c:150 3fc9e420: 0x1f2f3f4f 0x00001800 0x77770006 0x77777777 0x6c6c756e 0x69666977 0x00000000 0x00000000 3fc9e440: 0x00000000 0x00000000 0x00000000 0x00000000 0x00000008 0x38000000 0x38383838 0x00383838 3fc9e460: 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 3fc9e480: 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x38383838 0x38383838 3fc9e4a0: 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 3fc9e4c0: 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000005 0x3c0d8554 3fc9e4e0: 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x3c0c4000 0x420b35a8 --- 0x420b35a8: main_task at E:/espidf/v5.4.1/esp-idf/components/freertos/app_startup.c:209 3fc9e500: 0x00000000 0x00001388 0x00000001 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 3fc9e520: 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0xa5a5a5a5 0xa5a5a5a5 0xa5a5a5a5 3fc9e540: 0xa5a5a5a5 0xa5a5a5a5 0xa5a5a5a5 0xa5a5a5a5 0x00000150 0x3fc9dd80 0x00000002 0x3fc957c4 3fc9e560: 0x3fc957c4 0x3fc9e554 0x3fc957bc 0x00000018 0x3fca4640 0x3fca4640 0x3fc9e554 0x00000000 3fc9e580: 0x00000001 0x3fc9d550 0x6e69616d 0x00000000 0x00000000 0x00000000 0x3fc9e540 0x00000001 3fc9e5a0: 0x00000000 0x3fca2a90 0x42004e7c 0x00000000 0x3fc9be80 0x3fc9bee8 0x3fc9bf50 0x00000000 --- 0x42004e7c: pthread_cleanup_thread_specific_data_callback at E:/espidf/v5.4.1/esp-idf/components/pthread/pthread_local_storage.c:126 3fc9e5c0: 0x00000000 0x00000001 0x00000000 0x00000000 0x00000000 0x42004706 0x00000000 0x00000000 --- 0x42004706: esp_cleanup_r at E:/espidf/v5.4.1/esp-idf/components/newlib/newlib_init.c:43 ELF file SHA256: 04a1caf88 Rebooting... ESP-ROM:esp32c3-api1-20210207 Build:Feb 7 2021 rst:0xc (RTC_SW_CPU_RST),boot:0xd (SPI_FAST_FLASH_BOOT) Saved PC:0x403807f4 --- 0x403807f4: esp_restart_noos at E:/espidf/v5.4.1/esp-idf/components/esp_system/port/soc/esp32c3/system_internal.c:112 SPIWP:0xee mode:DIO, clock div:1 load:0x3fcd5820,len:0x1574 load:0x403cc710,len:0xc30 load:0x403ce710,len:0x2f64 entry 0x403cc71a I (24) boot: ESP-IDF v5.4.1 2nd stage bootloader I (24) boot: compile time Jun 27 2025 16:28:05 I (24) boot: chip revision: v0.4 I (25) boot: efuse block revision: v1.3 I (27) boot.esp32c3: SPI Speed : 80MHz I (31) boot.esp32c3: SPI Mode : DIO I (35) boot.esp32c3: SPI Flash Size : 2MB I (39) boot: Enabling RNG early entropy source... I (43) boot: Partition Table: I (46) boot: ## Label Usage Type ST Offset Length I (52) boot: 0 nvs WiFi data 01 02 00009000 00006000 I (59) boot: 1 phy_init RF data 01 01 0000f000 00001000 I (65) boot: 2 factory factory app 00 00 00010000 00100000 I (72) boot: End of partition table I (75) esp_image: segment 0: paddr=00010020 vaddr=3c0c0020 size=22a38h (141880) map I (105) esp_image: segment 1: paddr=00032a60 vaddr=3fc92800 size=02df8h ( 11768) load I (108) esp_image: segment 2: paddr=00035860 vaddr=40380000 size=0a7b8h ( 42936) load I (117) esp_image: segment 3: paddr=00040020 vaddr=42000020 size=b4088h (737416) map I (235) esp_image: segment 4: paddr=000f40b0 vaddr=4038a7b8 size=07f0ch ( 32524) load I (241) esp_image: segment 5: paddr=000fbfc4 vaddr=50000200 size=0001ch ( 28) load I (248) boot: Loaded app from partition at offset 0x10000 I (248) boot: Disabling RNG early entropy source... I (260) cpu_start: Unicore app I (268) cpu_start: Pro cpu start user code I (268) cpu_start: cpu freq: 160000000 Hz I (269) app_init: Application information: I (269) app_init: Project name: internal_communication I (273) app_init: App version: 1 I (277) app_init: Compile time: Jun 27 2025 16:27:06 I (282) app_init: ELF file SHA256: 04a1caf88... I (286) app_init: ESP-IDF: v5.4.1 I (290) efuse_init: Min chip rev: v0.3 I (294) efuse_init: Max chip rev: v1.99 I (298) efuse_init: Chip rev: v0.4 I (302) heap_init: Initializing. RAM available for dynamic allocation: I (308) heap_init: At 3FC9B840 len 000247C0 (145 KiB): RAM I (313) heap_init: At 3FCC0000 len 0001C710 (113 KiB): Retention RAM I (319) heap_init: At 3FCDC710 len 00002950 (10 KiB): Retention RAM I (325) heap_init: At 5000021C len 00001DCC (7 KiB): RTCRAM I (331) spi_flash: detected chip: generic I (334) spi_flash: flash io: dio W (337) spi_flash: Detected size(8192k) larger than the size in the binary image header(2048k). Using the size in the binary image header. I (350) sleep_gpio: Configure to isolate all GPIO pins in sleep state I (356) sleep_gpio: Enable automatic switching of GPIO sleep configuration I (362) main_task: Started on CPU0 I (362) main_task: Calling app_main() I (372) pp: pp rom version: 9387209 I (372) net80211: net80211 rom version: 9387209 I (382) wifi:wifi driver task: 3fca44c0, prio:23, stack:6656, core=0 I (382) wifi:wifi firmware version: 79fa3f41ba I (382) wifi:wifi certification version: v7.0 I (382) wifi:config NVS flash: enabled I (392) wifi:config nano formatting: disabled I (392) wifi:Init data frame dynamic rx buffer num: 32 I (402) wifi:Init static rx mgmt buffer num: 5 I (402) wifi:Init management short buffer num: 32 I (402) wifi:Init dynamic tx buffer num: 32 I (412) wifi:Init static tx FG buffer num: 2 I (412) wifi:Init static rx buffer size: 1600 I (422) wifi:Init static rx buffer num: 10 I (422) wifi:Init dynamic rx buffer num: 32 I (422) wifi_init: rx ba win: 6 I (432) wifi_init: accept mbox: 6 I (432) wifi_init: tcpip mbox: 32 I (432) wifi_init: udp mbox: 6 I (442) wifi_init: tcp mbox: 6 I (442) wifi_init: tcp tx win: 5760 I (442) wifi_init: tcp rx win: 5760 I (442) wifi_init: tcp mss: 1440 I (452) wifi_init: WiFi IRAM OP enabled I (452) wifi_init: WiFi RX IRAM OP enabled I (462) phy_init: phy_version 1200,2b7123f9,Feb 18 2025,15:22:21 I (492) phy_init: Saving new calibration data due to checksum failure or outdated calibration data, mode(0) I (572) wifi:mode : sta (34:cd:b0:97:58:bc) + softAP (34:cd:b0:97:58:bd) I (572) wifi:enable tsf I (572) wifi:Total power save buffer number: 16 I (572) wifi:Init max length of beacon: 752/752 I (582) wifi:Init max length of beacon: 752/752 I (582) mesh: <nvs>read layer:0, err:0x1102 I (582) mesh: <nvs>read assoc:0, err:0x1102 I (592) wifi:Set ps type: 1, coexist: 0
最新发布
06-28
import numpy as np import rasterio from sklearn.linear_model import LinearRegression from scipy.ndimage import zoom from sklearn.metrics import r2_score from glob import glob import os import pandas as pd import openpyxl def read_modis_data(filepath): with rasterio.open(filepath) as dataset: data = dataset.read(1) transform = dataset.transform crs = dataset.crs return data, transform, crs save_path=r'E:\Users\MOD05\out' mod05_files=glob(r'E:\Users\MOD05\dat\*.dat') #创建一个DataFrame来保存R²值 r2_results = pd.DataFrame(columns=['same_date', 'r2']) for mod05_path in mod05_files: same_date=os.path.split(mod05_path)[1].split('.')[1] # mod05_path = r'D:\shop\20241010\MODIS_humidity\处理过的\MOD05\MOD05_L2.A2020061.0425_Swath_2D_1_georef.dat' mod06_path =glob( r'E:\Users\MOD06\dat_day\*{}*.dat'.format(same_date))[0] mod07_path =glob( r'E:\Users\MOD07\dat_day_NAN\*{}*.dat'.format(same_date))[0] mod05, mod05_transform, mod05_crs = read_modis_data(mod05_path) mod06 = read_modis_data(mod06_path)[0] mod07 = read_modis_data(mod07_path)[0] # 获取MOD07有效值并进行线性回归,MOD06和MOD07的分辨率需要一致,因此对MOD06进行重采样 mod06_resampled = zoom(mod06, (mod07.shape[0] / mod06.shape[0], mod07.shape[1] / mod06.shape[1]), order=1) # 找到MOD07中的有效值索引 valid_indices = np.where(~np.isnan(mod06_resampled) & ~np.isnan(mod07)) # 提取有效值用于线性回归 mod07_valid = mod07[valid_indices] mod06_valid = mod06_resampled[valid_indices] # 线性回归拟合 MOD06 和 MOD07 model = LinearRegression() mod06_valid = mod06_valid.reshape(-1, 1) mod07_valid = mod07_valid.reshape(-1, 1) model.fit(mod06_valid, mod07_valid) # 计算R^2并打印 r2 = model.score(mod06_valid, mod07_valid) print(f"{same_date} 线性回归的R^2值为: {r2}") # 保存R^2值到DataFrame r2_results = pd.concat([r2_results, pd.DataFrame({'same_date': [same_date], 'r2': [r2]})], ignore_index=True) # 预测MOD07中的无效值(缺失值),只预测MOD07空缺且MOD06有值的位置 invalid_indices = np.where(np.isnan(mod07) & ~np.isnan(mod06_resampled)) mod06_invalid = mod06_resampled[invalid_indices].reshape(-1, 1) mod07_predictions = model.predict(mod06_invalid).reshape(-1) mod07[invalid_indices] = mod07_predictions # 计算水汽压e和饱和水汽压es def calculate_vapor_pressure(pw): return 4.2659 * pw + 5.9947 def calculate_saturation_vapor_pressure(sat): return 6.1078 * np.exp((17.27 * (sat-273.15)) / (sat-273.15+237.3)) # 将MOD07数据重采样到MOD05的分辨率 mod07_resampled = zoom(mod07, (mod05.shape[0] / mod07.shape[0], mod05.shape[1] / mod07.shape[1]), order=1) # 将MOD05数据和填充后的MOD07数据用于计算相对湿度 pw = mod05 sat = mod07_resampled e = calculate_vapor_pressure(pw) es = calculate_saturation_vapor_pressure(sat) # 计算相对湿度(相对湿度 = e / es * 100) relative_humidity = (e / es) * 100 # 保存计算得到的相对湿度数据 output_path = os.path.join(save_path,same_date+'.tif') with rasterio.open( output_path, 'w', driver='GTiff', height=mod05.shape[0], width=mod05.shape[1], count=1, dtype='float32', crs=mod05_crs, transform=mod05_transform ) as dst: dst.write(relative_humidity, 1) print("{} 相对湿度计算完成并保存到:".format(same_date), output_path) # 将R^2值保存到Excel文件中 r2_results.to_excel(r'E:\Users\MOD05\out\r2_results.xlsx', index=False) print("R^2值保存完成!") 这一串代码使用了MOD05,MOD06,MOD07三种数据,现在我要做的研究区只需要使用MOD05和MOD07两种数据,其中MOD05数据路径为C:\j\55555555 MOD07数据路径为C:\j\77777777 计算完成保存路径为C:\j\shuchu
05-10
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值